1This is elisp.info, produced by makeinfo version 6.7 from elisp.texi.
2
3This is the ‘GNU Emacs Lisp Reference Manual’ corresponding to Emacs
4version 27.2.
5
6   Copyright © 1990–1996, 1998–2021 Free Software Foundation, Inc.
7
8     Permission is granted to copy, distribute and/or modify this
9     document under the terms of the GNU Free Documentation License,
10     Version 1.3 or any later version published by the Free Software
11     Foundation; with the Invariant Sections being “GNU General Public
12     License,” with the Front-Cover Texts being “A GNU Manual,” and with
13     the Back-Cover Texts as in (a) below.  A copy of the license is
14     included in the section entitled “GNU Free Documentation License.”
15
16     (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
17     modify this GNU manual.  Buying copies from the FSF supports it in
18     developing GNU and promoting software freedom.”
19INFO-DIR-SECTION Emacs lisp
20START-INFO-DIR-ENTRY
21* Elisp: (elisp).               The Emacs Lisp Reference Manual.
22END-INFO-DIR-ENTRY
23
24
25File: elisp.info,  Node: Top,  Next: Introduction,  Up: (dir)
26
27Emacs Lisp
28**********
29
30This is the ‘GNU Emacs Lisp Reference Manual’ corresponding to Emacs
31version 27.2.
32
33   Copyright © 1990–1996, 1998–2021 Free Software Foundation, Inc.
34
35     Permission is granted to copy, distribute and/or modify this
36     document under the terms of the GNU Free Documentation License,
37     Version 1.3 or any later version published by the Free Software
38     Foundation; with the Invariant Sections being “GNU General Public
39     License,” with the Front-Cover Texts being “A GNU Manual,” and with
40     the Back-Cover Texts as in (a) below.  A copy of the license is
41     included in the section entitled “GNU Free Documentation License.”
42
43     (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
44     modify this GNU manual.  Buying copies from the FSF supports it in
45     developing GNU and promoting software freedom.”
46
47* Menu:
48
49* Introduction::            Introduction and conventions used.
50
51* Lisp Data Types::         Data types of objects in Emacs Lisp.
52* Numbers::                 Numbers and arithmetic functions.
53* Strings and Characters::  Strings, and functions that work on them.
54* Lists::                   Lists, cons cells, and related functions.
55* Sequences Arrays Vectors::  Lists, strings and vectors are called sequences.
56                                Certain functions act on any kind of sequence.
57                                The description of vectors is here as well.
58* Records::                 Compound objects with programmer-defined types.
59* Hash Tables::             Very fast lookup-tables.
60* Symbols::                 Symbols represent names, uniquely.
61
62* Evaluation::              How Lisp expressions are evaluated.
63* Control Structures::      Conditionals, loops, nonlocal exits.
64* Variables::               Using symbols in programs to stand for values.
65* Functions::               A function is a Lisp program
66                              that can be invoked from other functions.
67* Macros::                  Macros are a way to extend the Lisp language.
68* Customization::           Making variables and faces customizable.
69
70* Loading::                 Reading files of Lisp code into Lisp.
71* Byte Compilation::        Compilation makes programs run faster.
72* Debugging::               Tools and tips for debugging Lisp programs.
73
74* Read and Print::          Converting Lisp objects to text and back.
75* Minibuffers::             Using the minibuffer to read input.
76* Command Loop::            How the editor command loop works,
77                              and how you can call its subroutines.
78* Keymaps::                 Defining the bindings from keys to commands.
79* Modes::                   Defining major and minor modes.
80* Documentation::           Writing and using documentation strings.
81
82* Files::                   Accessing files.
83* Backups and Auto-Saving:: Controlling how backups and auto-save
84                              files are made.
85* Buffers::                 Creating and using buffer objects.
86* Windows::                 Manipulating windows and displaying buffers.
87* Frames::                  Making multiple system-level windows.
88* Positions::               Buffer positions and motion functions.
89* Markers::                 Markers represent positions and update
90                              automatically when the text is changed.
91
92* Text::                    Examining and changing text in buffers.
93* Non-ASCII Characters::    Non-ASCII text in buffers and strings.
94* Searching and Matching::  Searching buffers for strings or regexps.
95* Syntax Tables::           The syntax table controls word and list parsing.
96* Abbrevs::                 How Abbrev mode works, and its data structures.
97
98* Threads::                 Concurrency in Emacs Lisp.
99* Processes::               Running and communicating with subprocesses.
100* Display::                 Features for controlling the screen display.
101* System Interface::        Getting the user id, system type, environment
102                              variables, and other such things.
103
104* Packaging::               Preparing Lisp code for distribution.
105
106Appendices
107
108* Antinews::                Info for users downgrading to Emacs 26.
109* GNU Free Documentation License:: The license for this documentation.
110* GPL::                     Conditions for copying and changing GNU Emacs.
111* Tips::                    Advice and coding conventions for Emacs Lisp.
112* GNU Emacs Internals::     Building and dumping Emacs;
113                              internal data structures.
114* Standard Errors::         List of some standard error symbols.
115* Standard Keymaps::        List of some standard keymaps.
116* Standard Hooks::          List of some standard hook variables.
117
118* Index::                   Index including concepts, functions, variables,
119                              and other terms.
120
121
122
123 — The Detailed Node Listing —
124 ———————————
125
126Here are other nodes that are subnodes of those already listed,
127mentioned here so you can get to them in one step:
128
129Introduction
130
131* Caveats::                 Flaws and a request for help.
132* Lisp History::            Emacs Lisp is descended from Maclisp.
133* Conventions::             How the manual is formatted.
134* Version Info::            Which Emacs version is running?
135* Acknowledgments::         The authors, editors, and sponsors of this manual.
136
137Conventions
138
139* Some Terms::              Explanation of terms we use in this manual.
140* nil and t::               How the symbols ‘nil’ and ‘t’ are used.
141* Evaluation Notation::     The format we use for examples of evaluation.
142* Printing Notation::       The format we use when examples print text.
143* Error Messages::          The format we use for examples of errors.
144* Buffer Text Notation::    The format we use for buffer contents in examples.
145* Format of Descriptions::  Notation for describing functions, variables, etc.
146
147Format of Descriptions
148
149* A Sample Function Description::  A description of an imaginary
150                                     function, ‘foo’.
151* A Sample Variable Description::  A description of an imaginary
152                                     variable, ‘electric-future-map’.
153
154Lisp Data Types
155
156* Printed Representation::  How Lisp objects are represented as text.
157* Special Read Syntax::     An overview of all the special sequences.
158* Comments::                Comments and their formatting conventions.
159* Programming Types::       Types found in all Lisp systems.
160* Editing Types::           Types specific to Emacs.
161* Circular Objects::        Read syntax for circular structure.
162* Type Predicates::         Tests related to types.
163* Equality Predicates::     Tests of equality between any two objects.
164* Mutability::              Some objects should not be modified.
165
166Programming Types
167
168* Integer Type::        Numbers without fractional parts.
169* Floating-Point Type:: Numbers with fractional parts and with a large range.
170* Character Type::      The representation of letters, numbers and
171                          control characters.
172* Symbol Type::         A multi-use object that refers to a function,
173                        variable, or property list, and has a unique identity.
174* Sequence Type::       Both lists and arrays are classified as sequences.
175* Cons Cell Type::      Cons cells, and lists (which are made from cons cells).
176* Array Type::          Arrays include strings and vectors.
177* String Type::         An (efficient) array of characters.
178* Vector Type::         One-dimensional arrays.
179* Char-Table Type::     One-dimensional sparse arrays indexed by characters.
180* Bool-Vector Type::    One-dimensional arrays of ‘t’ or ‘nil’.
181* Hash Table Type::     Super-fast lookup tables.
182* Function Type::       A piece of executable code you can call from elsewhere.
183* Macro Type::          A method of expanding an expression into another
184                          expression, more fundamental but less pretty.
185* Primitive Function Type::     A function written in C, callable from Lisp.
186* Byte-Code Type::      A function written in Lisp, then compiled.
187* Record Type::         Compound objects with programmer-defined types.
188* Type Descriptors::    Objects holding information about types.
189* Autoload Type::       A type used for automatically loading seldom-used
190                          functions.
191* Finalizer Type::      Runs code when no longer reachable.
192
193Character Type
194
195* Basic Char Syntax::       Syntax for regular characters.
196* General Escape Syntax::   How to specify characters by their codes.
197* Ctl-Char Syntax::         Syntax for control characters.
198* Meta-Char Syntax::        Syntax for meta-characters.
199* Other Char Bits::         Syntax for hyper-, super-, and alt-characters.
200
201Cons Cell and List Types
202
203* Box Diagrams::            Drawing pictures of lists.
204* Dotted Pair Notation::    A general syntax for cons cells.
205* Association List Type::   A specially constructed list.
206
207String Type
208
209* Syntax for Strings::      How to specify Lisp strings.
210* Non-ASCII in Strings::    International characters in strings.
211* Nonprinting Characters::  Literal unprintable characters in strings.
212* Text Props and Strings::  Strings with text properties.
213
214Editing Types
215
216* Buffer Type::             The basic object of editing.
217* Marker Type::             A position in a buffer.
218* Window Type::             Buffers are displayed in windows.
219* Frame Type::              Windows subdivide frames.
220* Terminal Type::           A terminal device displays frames.
221* Window Configuration Type::  Recording the way a frame is subdivided.
222* Frame Configuration Type::   Recording the status of all frames.
223* Process Type::            A subprocess of Emacs running on the underlying OS.
224* Thread Type::             A thread of Emacs Lisp execution.
225* Mutex Type::              An exclusive lock for thread synchronization.
226* Condition Variable Type::    Condition variable for thread synchronization.
227* Stream Type::             Receive or send characters.
228* Keymap Type::             What function a keystroke invokes.
229* Overlay Type::            How an overlay is represented.
230* Font Type::               Fonts for displaying text.
231
232Numbers
233
234* Integer Basics::          Representation and range of integers.
235* Float Basics::            Representation and range of floating point.
236* Predicates on Numbers::   Testing for numbers.
237* Comparison of Numbers::   Equality and inequality predicates.
238* Numeric Conversions::     Converting float to integer and vice versa.
239* Arithmetic Operations::   How to add, subtract, multiply and divide.
240* Rounding Operations::     Explicitly rounding floating-point numbers.
241* Bitwise Operations::      Logical and, or, not, shifting.
242* Math Functions::          Trig, exponential and logarithmic functions.
243* Random Numbers::          Obtaining random integers, predictable or not.
244
245Strings and Characters
246
247* String Basics::           Basic properties of strings and characters.
248* Predicates for Strings::  Testing whether an object is a string or char.
249* Creating Strings::        Functions to allocate new strings.
250* Modifying Strings::       Altering the contents of an existing string.
251* Text Comparison::         Comparing characters or strings.
252* String Conversion::       Converting to and from characters and strings.
253* Formatting Strings::      ‘format’: Emacs’s analogue of ‘printf’.
254* Case Conversion::         Case conversion functions.
255* Case Tables::             Customizing case conversion.
256
257Lists
258
259* Cons Cells::              How lists are made out of cons cells.
260* List-related Predicates:: Is this object a list?  Comparing two lists.
261* List Elements::           Extracting the pieces of a list.
262* Building Lists::          Creating list structure.
263* List Variables::          Modifying lists stored in variables.
264* Modifying Lists::         Storing new pieces into an existing list.
265* Sets And Lists::          A list can represent a finite mathematical set.
266* Association Lists::       A list can represent a finite relation or mapping.
267* Property Lists::          A list of paired elements.
268
269Modifying Existing List Structure
270
271* Setcar::                  Replacing an element in a list.
272* Setcdr::                  Replacing part of the list backbone.
273                              This can be used to remove or add elements.
274* Rearrangement::           Reordering the elements in a list; combining lists.
275
276Property Lists
277
278* Plists and Alists::       Comparison of the advantages of property
279                              lists and association lists.
280* Plist Access::            Accessing property lists stored elsewhere.
281
282Sequences, Arrays, and Vectors
283
284* Sequence Functions::      Functions that accept any kind of sequence.
285* Arrays::                  Characteristics of arrays in Emacs Lisp.
286* Array Functions::         Functions specifically for arrays.
287* Vectors::                 Special characteristics of Emacs Lisp vectors.
288* Vector Functions::        Functions specifically for vectors.
289* Char-Tables::             How to work with char-tables.
290* Bool-Vectors::            How to work with bool-vectors.
291* Rings::                   Managing a fixed-size ring of objects.
292
293Records
294
295* Record Functions::        Functions for records.
296* Backward Compatibility::  Compatibility for cl-defstruct.
297
298Hash Tables
299
300* Creating Hash::           Functions to create hash tables.
301* Hash Access::             Reading and writing the hash table contents.
302* Defining Hash::           Defining new comparison methods.
303* Other Hash::              Miscellaneous.
304
305Symbols
306
307* Symbol Components::       Symbols have names, values, function definitions
308                              and property lists.
309* Definitions::             A definition says how a symbol will be used.
310* Creating Symbols::        How symbols are kept unique.
311* Symbol Properties::       Each symbol has a property list
312                              for recording miscellaneous information.
313
314Symbol Properties
315
316* Symbol Plists::           Accessing symbol properties.
317* Standard Properties::     Standard meanings of symbol properties.
318
319Evaluation
320
321* Intro Eval::              Evaluation in the scheme of things.
322* Forms::                   How various sorts of objects are evaluated.
323* Quoting::                 Avoiding evaluation (to put constants in
324                              the program).
325* Backquote::               Easier construction of list structure.
326* Eval::                    How to invoke the Lisp interpreter explicitly.
327* Deferred Eval::           Deferred and lazy evaluation of forms.
328
329Kinds of Forms
330
331* Self-Evaluating Forms::   Forms that evaluate to themselves.
332* Symbol Forms::            Symbols evaluate as variables.
333* Classifying Lists::       How to distinguish various sorts of list forms.
334* Function Indirection::    When a symbol appears as the car of a list,
335                              we find the real function via the symbol.
336* Function Forms::          Forms that call functions.
337* Macro Forms::             Forms that call macros.
338* Special Forms::           Special forms are idiosyncratic primitives,
339                              most of them extremely important.
340* Autoloading::             Functions set up to load files
341                              containing their real definitions.
342
343Control Structures
344
345* Sequencing::              Evaluation in textual order.
346* Conditionals::            ‘if’, ‘cond’, ‘when’, ‘unless’.
347* Combining Conditions::    ‘and’, ‘or’, ‘not’.
348* Pattern-Matching Conditional::  How to use ‘pcase’ and friends.
349* Iteration::               ‘while’ loops.
350* Generators::              Generic sequences and coroutines.
351* Nonlocal Exits::          Jumping out of a sequence.
352
353Nonlocal Exits
354
355* Catch and Throw::         Nonlocal exits for the program’s own purposes.
356* Examples of Catch::       Showing how such nonlocal exits can be written.
357* Errors::                  How errors are signaled and handled.
358* Cleanups::                Arranging to run a cleanup form if an
359                              error happens.
360
361Errors
362
363* Signaling Errors::        How to report an error.
364* Processing of Errors::    What Emacs does when you report an error.
365* Handling Errors::         How you can trap errors and continue execution.
366* Error Symbols::           How errors are classified for trapping them.
367
368Variables
369
370* Global Variables::        Variable values that exist permanently, everywhere.
371* Constant Variables::      Variables that never change.
372* Local Variables::         Variable values that exist only temporarily.
373* Void Variables::          Symbols that lack values.
374* Defining Variables::      A definition says a symbol is used as a variable.
375* Tips for Defining::       Things you should think about when you
376                              define a variable.
377* Accessing Variables::     Examining values of variables whose names
378                              are known only at run time.
379* Setting Variables::       Storing new values in variables.
380* Watching Variables::      Running a function when a variable is changed.
381* Variable Scoping::        How Lisp chooses among local and global values.
382* Buffer-Local Variables::  Variable values in effect only in one buffer.
383* File Local Variables::    Handling local variable lists in files.
384* Directory Local Variables:: Local variables common to all files in a
385                                directory.
386* Connection Local Variables::  Local variables common for remote connections.
387* Variable Aliases::        Variables that are aliases for other variables.
388* Variables with Restricted Values::  Non-constant variables whose value can
389                                        _not_ be an arbitrary Lisp object.
390* Generalized Variables::   Extending the concept of variables.
391
392Scoping Rules for Variable Bindings
393
394* Dynamic Binding::         The default for binding local variables in Emacs.
395* Dynamic Binding Tips::    Avoiding problems with dynamic binding.
396* Lexical Binding::         A different type of local variable binding.
397* Using Lexical Binding::   How to enable lexical binding.
398
399Buffer-Local Variables
400
401* Intro to Buffer-Local::   Introduction and concepts.
402* Creating Buffer-Local::   Creating and destroying buffer-local bindings.
403* Default Value::           The default value is seen in buffers
404                              that don’t have their own buffer-local values.
405
406Generalized Variables
407
408* Setting Generalized Variables::   The ‘setf’ macro.
409* Adding Generalized Variables::    Defining new ‘setf’ forms.
410
411Functions
412
413* What Is a Function::      Lisp functions vs. primitives; terminology.
414* Lambda Expressions::      How functions are expressed as Lisp objects.
415* Function Names::          A symbol can serve as the name of a function.
416* Defining Functions::      Lisp expressions for defining functions.
417* Calling Functions::       How to use an existing function.
418* Mapping Functions::       Applying a function to each element of a list, etc.
419* Anonymous Functions::     Lambda expressions are functions with no names.
420* Generic Functions::       Polymorphism, Emacs-style.
421* Function Cells::          Accessing or setting the function definition
422                              of a symbol.
423* Closures::                Functions that enclose a lexical environment.
424* Advising Functions::      Adding to the definition of a function.
425* Obsolete Functions::      Declaring functions obsolete.
426* Inline Functions::        Defining functions that the compiler
427                              will expand inline.
428* Declare Form::          Adding additional information about a function.
429* Declaring Functions::     Telling the compiler that a function is defined.
430* Function Safety::         Determining whether a function is safe to call.
431* Related Topics::          Cross-references to specific Lisp primitives
432                              that have a special bearing on how
433                              functions work.
434
435Lambda Expressions
436
437* Lambda Components::       The parts of a lambda expression.
438* Simple Lambda::           A simple example.
439* Argument List::           Details and special features of argument lists.
440* Function Documentation::  How to put documentation in a function.
441
442Advising Emacs Lisp Functions
443
444* Core Advising Primitives::  Primitives to manipulate advice.
445* Advising Named Functions::  Advising named functions.
446* Advice Combinators::        Ways to compose advice.
447* Porting Old Advice::        Adapting code using the old defadvice.
448
449Macros
450
451* Simple Macro::            A basic example.
452* Expansion::               How, when and why macros are expanded.
453* Compiling Macros::        How macros are expanded by the compiler.
454* Defining Macros::         How to write a macro definition.
455* Problems with Macros::    Don’t evaluate the macro arguments too many times.
456                              Don’t hide the user’s variables.
457* Indenting Macros::        Specifying how to indent macro calls.
458
459Common Problems Using Macros
460
461* Wrong Time::             Do the work in the expansion, not in the macro.
462* Argument Evaluation::    The expansion should evaluate each macro arg once.
463* Surprising Local Vars::  Local variable bindings in the expansion
464                              require special care.
465* Eval During Expansion::  Don’t evaluate them; put them in the expansion.
466* Repeated Expansion::     Avoid depending on how many times expansion is done.
467
468Customization Settings
469
470* Common Keywords::         Common keyword arguments for all kinds of
471                              customization declarations.
472* Group Definitions::       Writing customization group definitions.
473* Variable Definitions::    Declaring user options.
474* Customization Types::     Specifying the type of a user option.
475* Applying Customizations:: Functions to apply customization settings.
476* Custom Themes::           Writing Custom themes.
477
478Customization Types
479
480* Simple Types::            Simple customization types: sexp, integer, etc.
481* Composite Types::         Build new types from other types or data.
482* Splicing into Lists::     Splice elements into list with ‘:inline’.
483* Type Keywords::           Keyword-argument pairs in a customization type.
484* Defining New Types::      Give your type a name.
485
486Loading
487
488* How Programs Do Loading:: The ‘load’ function and others.
489* Load Suffixes::           Details about the suffixes that ‘load’ tries.
490* Library Search::          Finding a library to load.
491* Loading Non-ASCII::       Non-ASCII characters in Emacs Lisp files.
492* Autoload::                Setting up a function to autoload.
493* Repeated Loading::        Precautions about loading a file twice.
494* Named Features::          Loading a library if it isn’t already loaded.
495* Where Defined::           Finding which file defined a certain symbol.
496* Unloading::               How to unload a library that was loaded.
497* Hooks for Loading::       Providing code to be run when
498                              particular libraries are loaded.
499* Dynamic Modules::         Modules provide additional Lisp primitives.
500
501Byte Compilation
502
503* Speed of Byte-Code::      An example of speedup from byte compilation.
504* Compilation Functions::   Byte compilation functions.
505* Docs and Compilation::    Dynamic loading of documentation strings.
506* Dynamic Loading::         Dynamic loading of individual functions.
507* Eval During Compile::     Code to be evaluated when you compile.
508* Compiler Errors::         Handling compiler error messages.
509* Byte-Code Objects::       The data type used for byte-compiled functions.
510* Disassembly::             Disassembling byte-code; how to read byte-code.
511
512Debugging Lisp Programs
513
514* Debugger::                A debugger for the Emacs Lisp evaluator.
515* Edebug::                  A source-level Emacs Lisp debugger.
516* Syntax Errors::           How to find syntax errors.
517* Test Coverage::           Ensuring you have tested all branches in your code.
518* Profiling::               Measuring the resources that your code uses.
519
520The Lisp Debugger
521
522* Error Debugging::         Entering the debugger when an error happens.
523* Infinite Loops::          Stopping and debugging a program that doesn’t exit.
524* Function Debugging::      Entering it when a certain function is called.
525* Variable Debugging::      Entering it when a variable is modified.
526* Explicit Debug::          Entering it at a certain point in the program.
527* Using Debugger::          What the debugger does.
528* Backtraces::              What you see while in the debugger.
529* Debugger Commands::       Commands used while in the debugger.
530* Invoking the Debugger::   How to call the function ‘debug’.
531* Internals of Debugger::   Subroutines of the debugger, and global variables.
532
533Edebug
534
535* Using Edebug::            Introduction to use of Edebug.
536* Instrumenting::           You must instrument your code
537                              in order to debug it with Edebug.
538* Edebug Execution Modes::  Execution modes, stopping more or less often.
539* Jumping::                 Commands to jump to a specified place.
540* Edebug Misc::             Miscellaneous commands.
541* Breaks::                  Setting breakpoints to make the program stop.
542* Trapping Errors::         Trapping errors with Edebug.
543* Edebug Views::            Views inside and outside of Edebug.
544* Edebug Eval::             Evaluating expressions within Edebug.
545* Eval List::               Expressions whose values are displayed
546                              each time you enter Edebug.
547* Printing in Edebug::      Customization of printing.
548* Trace Buffer::            How to produce trace output in a buffer.
549* Coverage Testing::        How to test evaluation coverage.
550* The Outside Context::     Data that Edebug saves and restores.
551* Edebug and Macros::       Specifying how to handle macro calls.
552* Edebug Options::          Option variables for customizing Edebug.
553
554Breaks
555
556* Breakpoints::             Breakpoints at stop points.
557* Global Break Condition::  Breaking on an event.
558* Source Breakpoints::      Embedding breakpoints in source code.
559
560The Outside Context
561
562* Checking Whether to Stop::When Edebug decides what to do.
563* Edebug Display Update::   When Edebug updates the display.
564* Edebug Recursive Edit::   When Edebug stops execution.
565
566Edebug and Macros
567
568* Instrumenting Macro Calls::The basic problem.
569* Specification List::      How to specify complex patterns of evaluation.
570* Backtracking::            What Edebug does when matching fails.
571* Specification Examples::  To help understand specifications.
572
573Debugging Invalid Lisp Syntax
574
575* Excess Open::             How to find a spurious open paren or missing close.
576* Excess Close::            How to find a spurious close paren or missing open.
577
578Reading and Printing Lisp Objects
579
580* Streams Intro::           Overview of streams, reading and printing.
581* Input Streams::           Various data types that can be used as
582                              input streams.
583* Input Functions::         Functions to read Lisp objects from text.
584* Output Streams::          Various data types that can be used as
585                              output streams.
586* Output Functions::        Functions to print Lisp objects as text.
587* Output Variables::        Variables that control what the printing
588                              functions do.
589
590Minibuffers
591
592* Intro to Minibuffers::    Basic information about minibuffers.
593* Text from Minibuffer::    How to read a straight text string.
594* Object from Minibuffer::  How to read a Lisp object or expression.
595* Minibuffer History::      Recording previous minibuffer inputs
596                              so the user can reuse them.
597* Initial Input::           Specifying initial contents for the minibuffer.
598* Completion::              How to invoke and customize completion.
599* Yes-or-No Queries::       Asking a question with a simple answer.
600* Multiple Queries::        Asking a series of similar questions.
601* Reading a Password::      Reading a password from the terminal.
602* Minibuffer Commands::     Commands used as key bindings in minibuffers.
603* Minibuffer Windows::      Operating on the special minibuffer windows.
604* Minibuffer Contents::     How such commands access the minibuffer text.
605* Recursive Mini::          Whether recursive entry to minibuffer is allowed.
606* Minibuffer Misc::         Various customization hooks and variables.
607
608Completion
609
610* Basic Completion::        Low-level functions for completing strings.
611* Minibuffer Completion::   Invoking the minibuffer with completion.
612* Completion Commands::     Minibuffer commands that do completion.
613* High-Level Completion::   Convenient special cases of completion
614                              (reading buffer names, variable names, etc.).
615* Reading File Names::      Using completion to read file names and
616                              shell commands.
617* Completion Variables::    Variables controlling completion behavior.
618* Programmed Completion::   Writing your own completion function.
619* Completion in Buffers::   Completing text in ordinary buffers.
620
621Command Loop
622
623* Command Overview::    How the command loop reads commands.
624* Defining Commands::   Specifying how a function should read arguments.
625* Interactive Call::    Calling a command, so that it will read arguments.
626* Distinguish Interactive::     Making a command distinguish interactive calls.
627* Command Loop Info::   Variables set by the command loop for you to examine.
628* Adjusting Point::     Adjustment of point after a command.
629* Input Events::        What input looks like when you read it.
630* Reading Input::       How to read input events from the keyboard or mouse.
631* Special Events::      Events processed immediately and individually.
632* Waiting::             Waiting for user input or elapsed time.
633* Quitting::            How ‘C-g’ works.  How to catch or defer quitting.
634* Prefix Command Arguments::    How the commands to set prefix args work.
635* Recursive Editing::   Entering a recursive edit,
636                          and why you usually shouldn’t.
637* Disabling Commands::  How the command loop handles disabled commands.
638* Command History::     How the command history is set up, and how accessed.
639* Keyboard Macros::     How keyboard macros are implemented.
640
641Defining Commands
642
643* Using Interactive::       General rules for ‘interactive’.
644* Interactive Codes::       The standard letter-codes for reading arguments
645                              in various ways.
646* Interactive Examples::    Examples of how to read interactive arguments.
647* Generic Commands::        Select among command alternatives.
648
649
650Input Events
651
652* Keyboard Events::         Ordinary characters – keys with symbols on them.
653* Function Keys::           Function keys – keys with names, not symbols.
654* Mouse Events::            Overview of mouse events.
655* Click Events::            Pushing and releasing a mouse button.
656* Drag Events::             Moving the mouse before releasing the button.
657* Button-Down Events::      A button was pushed and not yet released.
658* Repeat Events::           Double and triple click (or drag, or down).
659* Motion Events::           Just moving the mouse, not pushing a button.
660* Focus Events::            Moving the mouse between frames.
661* Misc Events::             Other events the system can generate.
662* Event Examples::          Examples of the lists for mouse events.
663* Classifying Events::      Finding the modifier keys in an event symbol.
664                              Event types.
665* Accessing Mouse::         Functions to extract info from mouse events.
666* Accessing Scroll::        Functions to get info from scroll bar events.
667* Strings of Events::       Special considerations for putting
668                              keyboard character events in a string.
669
670Reading Input
671
672* Key Sequence Input::      How to read one key sequence.
673* Reading One Event::       How to read just one event.
674* Event Mod::               How Emacs modifies events as they are read.
675* Invoking the Input Method::   How reading an event uses the input method.
676* Quoted Character Input::  Asking the user to specify a character.
677* Event Input Misc::        How to reread or throw away input events.
678
679Keymaps
680
681* Key Sequences::           Key sequences as Lisp objects.
682* Keymap Basics::           Basic concepts of keymaps.
683* Format of Keymaps::       What a keymap looks like as a Lisp object.
684* Creating Keymaps::        Functions to create and copy keymaps.
685* Inheritance and Keymaps:: How one keymap can inherit the bindings
686                              of another keymap.
687* Prefix Keys::             Defining a key with a keymap as its definition.
688* Active Keymaps::          How Emacs searches the active keymaps
689                              for a key binding.
690* Searching Keymaps::       A pseudo-Lisp summary of searching active maps.
691* Controlling Active Maps:: Each buffer has a local keymap
692                               to override the standard (global) bindings.
693                               A minor mode can also override them.
694* Key Lookup::              Finding a key’s binding in one keymap.
695* Functions for Key Lookup::    How to request key lookup.
696* Changing Key Bindings::   Redefining a key in a keymap.
697* Remapping Commands::      A keymap can translate one command to another.
698* Translation Keymaps::     Keymaps for translating sequences of events.
699* Key Binding Commands::    Interactive interfaces for redefining keys.
700* Scanning Keymaps::        Looking through all keymaps, for printing help.
701* Menu Keymaps::            Defining a menu as a keymap.
702
703Menu Keymaps
704
705* Defining Menus::          How to make a keymap that defines a menu.
706* Mouse Menus::             How users actuate the menu with the mouse.
707* Keyboard Menus::          How users actuate the menu with the keyboard.
708* Menu Example::            Making a simple menu.
709* Menu Bar::                How to customize the menu bar.
710* Tool Bar::                A tool bar is a row of images.
711* Modifying Menus::         How to add new items to a menu.
712* Easy Menu::               A convenience macro for defining menus.
713
714Defining Menus
715
716* Simple Menu Items::       A simple kind of menu key binding.
717* Extended Menu Items::     More complex menu item definitions.
718* Menu Separators::         Drawing a horizontal line through a menu.
719* Alias Menu Items::        Using command aliases in menu items.
720
721Major and Minor Modes
722
723* Hooks::              How to use hooks; how to write code that provides hooks.
724* Major Modes::        Defining major modes.
725* Minor Modes::        Defining minor modes.
726* Mode Line Format::   Customizing the text that appears in the mode line.
727* Imenu::              Providing a menu of definitions made in a buffer.
728* Font Lock Mode::     How modes can highlight text according to syntax.
729* Auto-Indentation::   How to teach Emacs to indent for a major mode.
730* Desktop Save Mode::  How modes can have buffer state saved between
731                         Emacs sessions.
732
733Hooks
734
735* Running Hooks::      How to run a hook.
736* Setting Hooks::      How to put functions on a hook, or remove them.
737
738Major Modes
739
740* Major Mode Conventions::  Coding conventions for keymaps, etc.
741* Auto Major Mode::         How Emacs chooses the major mode automatically.
742* Mode Help::               Finding out how to use a mode.
743* Derived Modes::           Defining a new major mode based on another major
744                              mode.
745* Basic Major Modes::       Modes that other modes are often derived from.
746* Mode Hooks::              Hooks run at the end of major mode functions.
747* Tabulated List Mode::     Parent mode for buffers containing tabulated data.
748* Generic Modes::           Defining a simple major mode that supports
749                              comment syntax and Font Lock mode.
750* Example Major Modes::     Text mode and Lisp modes.
751
752Minor Modes
753
754* Minor Mode Conventions::  Tips for writing a minor mode.
755* Keymaps and Minor Modes:: How a minor mode can have its own keymap.
756* Defining Minor Modes::    A convenient facility for defining minor modes.
757
758Mode Line Format
759
760* Mode Line Basics::        Basic ideas of mode line control.
761* Mode Line Data::          The data structure that controls the mode line.
762* Mode Line Top::           The top level variable, mode-line-format.
763* Mode Line Variables::     Variables used in that data structure.
764* %-Constructs::            Putting information into a mode line.
765* Properties in Mode::      Using text properties in the mode line.
766* Header Lines::            Like a mode line, but at the top.
767* Emulating Mode Line::     Formatting text as the mode line would.
768
769Font Lock Mode
770
771* Font Lock Basics::        Overview of customizing Font Lock.
772* Search-based Fontification::  Fontification based on regexps.
773* Customizing Keywords::    Customizing search-based fontification.
774* Other Font Lock Variables::   Additional customization facilities.
775* Levels of Font Lock::     Each mode can define alternative levels
776                              so that the user can select more or less.
777* Precalculated Fontification:: How Lisp programs that produce the buffer
778                                  contents can also specify how to fontify it.
779* Faces for Font Lock::     Special faces specifically for Font Lock.
780* Syntactic Font Lock::     Fontification based on syntax tables.
781* Multiline Font Lock::     How to coerce Font Lock into properly
782                              highlighting multiline constructs.
783
784Multiline Font Lock Constructs
785
786* Font Lock Multiline::     Marking multiline chunks with a text property.
787* Region to Refontify::     Controlling which region gets refontified
788                              after a buffer change.
789
790Automatic Indentation of code
791
792* SMIE::                    A simple minded indentation engine.
793
794Simple Minded Indentation Engine
795
796* SMIE setup::              SMIE setup and features.
797* Operator Precedence Grammars:: A very simple parsing technique.
798* SMIE Grammar::            Defining the grammar of a language.
799* SMIE Lexer::              Defining tokens.
800* SMIE Tricks::             Working around the parser’s limitations.
801* SMIE Indentation::        Specifying indentation rules.
802* SMIE Indentation Helpers:: Helper functions for indentation rules.
803* SMIE Indentation Example:: Sample indentation rules.
804* SMIE Customization::      Customizing indentation.
805
806Documentation
807
808* Documentation Basics::    Where doc strings are defined and stored.
809* Accessing Documentation:: How Lisp programs can access doc strings.
810* Keys in Documentation::   Substituting current key bindings.
811* Text Quoting Style::      Quotation marks in doc strings and messages.
812* Describing Characters::   Making printable descriptions of
813                              non-printing characters and key sequences.
814* Help Functions::          Subroutines used by Emacs help facilities.
815
816Files
817
818* Visiting Files::          Reading files into Emacs buffers for editing.
819* Saving Buffers::          Writing changed buffers back into files.
820* Reading from Files::      Reading files into buffers without visiting.
821* Writing to Files::        Writing new files from parts of buffers.
822* File Locks::              Locking and unlocking files, to prevent
823                              simultaneous editing by two people.
824* Information about Files:: Testing existence, accessibility, size of files.
825* Changing Files::          Renaming files, changing permissions, etc.
826* File Names::              Decomposing and expanding file names.
827* Contents of Directories:: Getting a list of the files in a directory.
828* Create/Delete Dirs::      Creating and Deleting Directories.
829* Magic File Names::        Special handling for certain file names.
830* Format Conversion::       Conversion to and from various file formats.
831
832Visiting Files
833
834* Visiting Functions::      The usual interface functions for visiting.
835* Subroutines of Visiting:: Lower-level subroutines that they use.
836
837Information about Files
838
839* Testing Accessibility::   Is a given file readable?  Writable?
840* Kinds of Files::          Is it a directory?  A symbolic link?
841* Truenames::               Eliminating symbolic links from a file name.
842* File Attributes::         File sizes, modification times, etc.
843* Extended Attributes::     Extended file attributes for access control.
844* Locating Files::          How to find a file in standard places.
845
846File Names
847
848* File Name Components::    The directory part of a file name, and the rest.
849* Relative File Names::     Some file names are relative to a current directory.
850* Directory Names::         A directory’s name as a directory
851                              is different from its name as a file.
852* File Name Expansion::     Converting relative file names to absolute ones.
853* Unique File Names::       Generating names for temporary files.
854* File Name Completion::    Finding the completions for a given file name.
855* Standard File Names::     If your package uses a fixed file name,
856                              how to handle various operating systems simply.
857
858File Format Conversion
859
860* Format Conversion Overview::   ‘insert-file-contents’ and ‘write-region’.
861* Format Conversion Round-Trip:: Using ‘format-alist’.
862* Format Conversion Piecemeal::  Specifying non-paired conversion.
863
864Backups and Auto-Saving
865
866* Backup Files::            How backup files are made; how their names
867                              are chosen.
868* Auto-Saving::             How auto-save files are made; how their
869                              names are chosen.
870* Reverting::               ‘revert-buffer’, and how to customize
871                              what it does.
872
873Backup Files
874
875* Making Backups::          How Emacs makes backup files, and when.
876* Rename or Copy::          Two alternatives: renaming the old file
877                              or copying it.
878* Numbered Backups::        Keeping multiple backups for each source file.
879* Backup Names::            How backup file names are computed; customization.
880
881Buffers
882
883* Buffer Basics::           What is a buffer?
884* Current Buffer::          Designating a buffer as current
885                              so that primitives will access its contents.
886* Buffer Names::            Accessing and changing buffer names.
887* Buffer File Name::        The buffer file name indicates which file
888                              is visited.
889* Buffer Modification::     A buffer is “modified” if it needs to be saved.
890* Modification Time::       Determining whether the visited file was changed
891                              behind Emacs’s back.
892* Read Only Buffers::       Modifying text is not allowed in a
893                              read-only buffer.
894* Buffer List::             How to look at all the existing buffers.
895* Creating Buffers::        Functions that create buffers.
896* Killing Buffers::         Buffers exist until explicitly killed.
897* Indirect Buffers::        An indirect buffer shares text with some
898                              other buffer.
899* Swapping Text::           Swapping text between two buffers.
900* Buffer Gap::              The gap in the buffer.
901
902Windows
903
904* Basic Windows::           Basic information on using windows.
905* Windows and Frames::      Relating windows to the frame they appear on.
906* Window Sizes::            Accessing a window’s size.
907* Resizing Windows::        Changing the sizes of windows.
908* Preserving Window Sizes:: Preserving the size of windows.
909* Splitting Windows::       Splitting one window into two windows.
910* Deleting Windows::        Deleting a window gives its space to other windows.
911* Recombining Windows::     Preserving the frame layout when splitting and
912                              deleting windows.
913* Selecting Windows::       The selected window is the one that you edit in.
914* Cyclic Window Ordering::  Moving around the existing windows.
915* Buffers and Windows::     Each window displays the contents of a buffer.
916* Switching Buffers::       Higher-level functions for switching to a buffer.
917* Displaying Buffers::      Displaying a buffer in a suitable window.
918* Window History::          Each window remembers the buffers displayed in it.
919* Dedicated Windows::       How to avoid displaying another buffer in
920                              a specific window.
921* Quitting Windows::        How to restore the state prior to displaying a
922                              buffer.
923* Side Windows::            Special windows on a frame’s sides.
924* Atomic Windows::          Preserving parts of the window layout.
925* Window Point::            Each window has its own location of point.
926* Window Start and End::    Buffer positions indicating which text is
927                              on-screen in a window.
928* Textual Scrolling::       Moving text up and down through the window.
929* Vertical Scrolling::      Moving the contents up and down on the window.
930* Horizontal Scrolling::    Moving the contents sideways on the window.
931* Coordinates and Windows:: Converting coordinates to windows.
932* Mouse Window Auto-selection:: Automatically selecting windows with the mouse.
933* Window Configurations::   Saving and restoring the state of the screen.
934* Window Parameters::       Associating additional information with windows.
935* Window Hooks::            Hooks for scrolling, window size changes,
936                              redisplay going past a certain point,
937                              or window configuration changes.
938
939Displaying Buffers
940
941* Choosing Window::         How to choose a window for displaying a buffer.
942* Buffer Display Action Functions:: Support functions for buffer display.
943* Buffer Display Action Alists:: Alists for fine-tuning buffer display
944                              action functions.
945* Choosing Window Options:: Extra options affecting how buffers are displayed.
946* Precedence of Action Functions:: A tutorial explaining the precedence of
947                              buffer display action functions.
948* The Zen of Buffer Display:: How to avoid that buffers get lost in between
949                              windows.
950
951Side Windows
952
953* Displaying Buffers in Side Windows:: An action function for displaying
954                              buffers in side windows.
955* Side Window Options and Functions:: Further tuning of side windows.
956* Frame Layouts with Side Windows:: Setting up frame layouts with side
957                              windows.
958
959Frames
960
961* Creating Frames::         Creating additional frames.
962* Multiple Terminals::      Displaying on several different devices.
963* Frame Geometry::          Geometric properties of frames.
964* Frame Parameters::        Controlling frame size, position, font, etc.
965* Terminal Parameters::     Parameters common for all frames on terminal.
966* Frame Titles::            Automatic updating of frame titles.
967* Deleting Frames::         Frames last until explicitly deleted.
968* Finding All Frames::      How to examine all existing frames.
969* Minibuffers and Frames::  How a frame finds the minibuffer to use.
970* Input Focus::             Specifying the selected frame.
971* Visibility of Frames::    Frames may be visible or invisible, or icons.
972* Raising and Lowering::    Raising, Lowering and Restacking Frames.
973* Frame Configurations::    Saving the state of all frames.
974* Child Frames::            Making a frame the child of another.
975* Mouse Tracking::          Getting events that say when the mouse moves.
976* Mouse Position::          Asking where the mouse is, or moving it.
977* Pop-Up Menus::            Displaying a menu for the user to select from.
978* Dialog Boxes::            Displaying a box to ask yes or no.
979* Pointer Shape::           Specifying the shape of the mouse pointer.
980* Window System Selections::Transferring text to and from other X clients.
981* Drag and Drop::           Internals of Drag-and-Drop implementation.
982* Color Names::             Getting the definitions of color names.
983* Text Terminal Colors::    Defining colors for text terminals.
984* Resources::               Getting resource values from the server.
985* Display Feature Testing:: Determining the features of a terminal.
986
987Frame Geometry
988
989* Frame Layout::            Basic layout of frames.
990* Frame Font::              The default font of a frame and how to set it.
991* Frame Position::          The position of a frame on its display.
992* Frame Size::              Specifying and retrieving a frame’s size.
993* Implied Frame Resizing::  Implied resizing of frames and how to prevent it.
994
995Frame Parameters
996
997* Parameter Access::        How to change a frame’s parameters.
998* Initial Parameters::      Specifying frame parameters when you make a frame.
999* Window Frame Parameters:: List of frame parameters for window systems.
1000* Geometry::                Parsing geometry specifications.
1001
1002Window Frame Parameters
1003
1004* Basic Parameters::        Parameters that are fundamental.
1005* Position Parameters::     The position of the frame on the screen.
1006* Size Parameters::         Frame’s size.
1007* Layout Parameters::       Size of parts of the frame, and
1008                              enabling or disabling some parts.
1009* Buffer Parameters::       Which buffers have been or should be shown.
1010* Frame Interaction Parameters::  Parameters for interacting with other
1011                              frames.
1012* Mouse Dragging Parameters::  Parameters for resizing and moving
1013                              frames with the mouse.
1014* Management Parameters::   Communicating with the window manager.
1015* Cursor Parameters::       Controlling the cursor appearance.
1016* Font and Color Parameters:: Fonts and colors for the frame text.
1017
1018Positions
1019
1020* Point::                   The special position where editing takes place.
1021* Motion::                  Changing point.
1022* Excursions::              Temporary motion and buffer changes.
1023* Narrowing::               Restricting editing to a portion of the buffer.
1024
1025Motion
1026
1027* Character Motion::        Moving in terms of characters.
1028* Word Motion::             Moving in terms of words.
1029* Buffer End Motion::       Moving to the beginning or end of the buffer.
1030* Text Lines::              Moving in terms of lines of text.
1031* Screen Lines::            Moving in terms of lines as displayed.
1032* List Motion::             Moving by parsing lists and sexps.
1033* Skipping Characters::     Skipping characters belonging to a certain set.
1034
1035Markers
1036
1037* Overview of Markers::     The components of a marker, and how it relocates.
1038* Predicates on Markers::   Testing whether an object is a marker.
1039* Creating Markers::        Making empty markers or markers at certain places.
1040* Information from Markers::Finding the marker’s buffer or character position.
1041* Marker Insertion Types::  Two ways a marker can relocate when you
1042                              insert where it points.
1043* Moving Markers::          Moving the marker to a new buffer or position.
1044* The Mark::                How the mark is implemented with a marker.
1045* The Region::              How to access the region.
1046
1047Text
1048
1049* Near Point::              Examining text in the vicinity of point.
1050* Buffer Contents::         Examining text in a general fashion.
1051* Comparing Text::          Comparing substrings of buffers.
1052* Insertion::               Adding new text to a buffer.
1053* Commands for Insertion::  User-level commands to insert text.
1054* Deletion::                Removing text from a buffer.
1055* User-Level Deletion::     User-level commands to delete text.
1056* The Kill Ring::           Where removed text sometimes is saved for
1057                              later use.
1058* Undo::                    Undoing changes to the text of a buffer.
1059* Maintaining Undo::        How to enable and disable undo information.
1060                              How to control how much information is kept.
1061* Filling::                 Functions for explicit filling.
1062* Margins::                 How to specify margins for filling commands.
1063* Adaptive Fill::           Adaptive Fill mode chooses a fill prefix
1064                              from context.
1065* Auto Filling::            How auto-fill mode is implemented to break lines.
1066* Sorting::                 Functions for sorting parts of the buffer.
1067* Columns::                 Computing horizontal positions, and using them.
1068* Indentation::             Functions to insert or adjust indentation.
1069* Case Changes::            Case conversion of parts of the buffer.
1070* Text Properties::         Assigning Lisp property lists to text characters.
1071* Substitution::            Replacing a given character wherever it appears.
1072* Registers::               How registers are implemented.  Accessing
1073                              the text or position stored in a register.
1074* Transposition::           Swapping two portions of a buffer.
1075* Decompression::           Dealing with compressed data.
1076* Base 64::                 Conversion to or from base 64 encoding.
1077* Checksum/Hash::           Computing cryptographic hashes.
1078* GnuTLS Cryptography::     Cryptographic algorithms imported from GnuTLS.
1079* Parsing HTML/XML::        Parsing HTML and XML.
1080* Atomic Changes::          Installing several buffer changes atomically.
1081* Change Hooks::            Supplying functions to be run when text is changed.
1082
1083The Kill Ring
1084
1085* Kill Ring Concepts::      What text looks like in the kill ring.
1086* Kill Functions::          Functions that kill text.
1087* Yanking::                 How yanking is done.
1088* Yank Commands::           Commands that access the kill ring.
1089* Low-Level Kill Ring::     Functions and variables for kill ring access.
1090* Internals of Kill Ring::  Variables that hold kill ring data.
1091
1092Indentation
1093
1094* Primitive Indent::        Functions used to count and insert indentation.
1095* Mode-Specific Indent::    Customize indentation for different modes.
1096* Region Indent::           Indent all the lines in a region.
1097* Relative Indent::         Indent the current line based on previous lines.
1098* Indent Tabs::             Adjustable, typewriter-like tab stops.
1099* Motion by Indent::        Move to first non-blank character.
1100
1101Text Properties
1102
1103* Examining Properties::    Looking at the properties of one character.
1104* Changing Properties::     Setting the properties of a range of text.
1105* Property Search::         Searching for where a property changes value.
1106* Special Properties::      Particular properties with special meanings.
1107* Format Properties::       Properties for representing formatting of text.
1108* Sticky Properties::       How inserted text gets properties from
1109                              neighboring text.
1110* Lazy Properties::         Computing text properties in a lazy fashion
1111                              only when text is examined.
1112* Clickable Text::          Using text properties to make regions of text
1113                              do something when you click on them.
1114* Fields::                  The ‘field’ property defines
1115                              fields within the buffer.
1116* Not Intervals::           Why text properties do not use
1117                              Lisp-visible text intervals.
1118
1119Parsing HTML and XML
1120
1121* Document Object Model::   Access, manipulate and search the DOM.
1122
1123Non-ASCII Characters
1124
1125* Text Representations::    How Emacs represents text.
1126* Disabling Multibyte::     Controlling whether to use multibyte characters.
1127* Converting Representations::  Converting unibyte to multibyte and vice versa.
1128* Selecting a Representation::  Treating a byte sequence as unibyte or multi.
1129* Character Codes::         How unibyte and multibyte relate to
1130                                codes of individual characters.
1131* Character Properties::    Character attributes that define their
1132                                behavior and handling.
1133* Character Sets::          The space of possible character codes
1134                                is divided into various character sets.
1135* Scanning Charsets::       Which character sets are used in a buffer?
1136* Translation of Characters::   Translation tables are used for conversion.
1137* Coding Systems::          Coding systems are conversions for saving files.
1138* Input Methods::           Input methods allow users to enter various
1139                                non-ASCII characters without special keyboards.
1140* Locales::                 Interacting with the POSIX locale.
1141
1142Coding Systems
1143
1144* Coding System Basics::    Basic concepts.
1145* Encoding and I/O::        How file I/O functions handle coding systems.
1146* Lisp and Coding Systems:: Functions to operate on coding system names.
1147* User-Chosen Coding Systems::  Asking the user to choose a coding system.
1148* Default Coding Systems::  Controlling the default choices.
1149* Specifying Coding Systems::   Requesting a particular coding system
1150                                    for a single file operation.
1151* Explicit Encoding::       Encoding or decoding text without doing I/O.
1152* Terminal I/O Encoding::   Use of encoding for terminal I/O.
1153
1154Searching and Matching
1155
1156* String Search::           Search for an exact match.
1157* Searching and Case::      Case-independent or case-significant searching.
1158* Regular Expressions::     Describing classes of strings.
1159* Regexp Search::           Searching for a match for a regexp.
1160* POSIX Regexps::           Searching POSIX-style for the longest match.
1161* Match Data::              Finding out which part of the text matched,
1162                              after a string or regexp search.
1163* Search and Replace::      Commands that loop, searching and replacing.
1164* Standard Regexps::        Useful regexps for finding sentences, pages,...
1165
1166Regular Expressions
1167
1168* Syntax of Regexps::       Rules for writing regular expressions.
1169* Regexp Example::          Illustrates regular expression syntax.
1170* Rx Notation::             An alternative, structured regexp notation.
1171* Regexp Functions::        Functions for operating on regular expressions.
1172
1173Syntax of Regular Expressions
1174
1175* Regexp Special::          Special characters in regular expressions.
1176* Char Classes::            Character classes used in regular expressions.
1177* Regexp Backslash::        Backslash-sequences in regular expressions.
1178
1179The Match Data
1180
1181* Replacing Match::         Replacing a substring that was matched.
1182* Simple Match Data::       Accessing single items of match data,
1183                              such as where a particular subexpression started.
1184* Entire Match Data::       Accessing the entire match data at once, as a list.
1185* Saving Match Data::       Saving and restoring the match data.
1186
1187Syntax Tables
1188
1189* Syntax Basics::           Basic concepts of syntax tables.
1190* Syntax Descriptors::      How characters are classified.
1191* Syntax Table Functions::  How to create, examine and alter syntax tables.
1192* Syntax Properties::       Overriding syntax with text properties.
1193* Motion and Syntax::       Moving over characters with certain syntaxes.
1194* Parsing Expressions::     Parsing balanced expressions
1195                              using the syntax table.
1196* Syntax Table Internals::  How syntax table information is stored.
1197* Categories::              Another way of classifying character syntax.
1198
1199Syntax Descriptors
1200
1201* Syntax Class Table::      Table of syntax classes.
1202* Syntax Flags::            Additional flags each character can have.
1203
1204Parsing Expressions
1205
1206* Motion via Parsing::      Motion functions that work by parsing.
1207* Position Parse::          Determining the syntactic state of a position.
1208* Parser State::            How Emacs represents a syntactic state.
1209* Low-Level Parsing::       Parsing across a specified region.
1210* Control Parsing::         Parameters that affect parsing.
1211
1212Abbrevs and Abbrev Expansion
1213
1214* Abbrev Tables::           Creating and working with abbrev tables.
1215* Defining Abbrevs::        Specifying abbreviations and their expansions.
1216* Abbrev Files::            Saving abbrevs in files.
1217* Abbrev Expansion::        Controlling expansion; expansion subroutines.
1218* Standard Abbrev Tables::  Abbrev tables used by various major modes.
1219* Abbrev Properties::       How to read and set abbrev properties.
1220                            Which properties have which effect.
1221* Abbrev Table Properties:: How to read and set abbrev table properties.
1222                            Which properties have which effect.
1223
1224Threads
1225
1226* Basic Thread Functions::  Basic thread functions.
1227* Mutexes::                 Mutexes allow exclusive access to data.
1228* Condition Variables::     Inter-thread events.
1229* The Thread List::         Show the active threads.
1230
1231Processes
1232
1233* Subprocess Creation::     Functions that start subprocesses.
1234* Shell Arguments::         Quoting an argument to pass it to a shell.
1235* Synchronous Processes::   Details of using synchronous subprocesses.
1236* Asynchronous Processes::  Starting up an asynchronous subprocess.
1237* Deleting Processes::      Eliminating an asynchronous subprocess.
1238* Process Information::     Accessing run-status and other attributes.
1239* Input to Processes::      Sending input to an asynchronous subprocess.
1240* Signals to Processes::    Stopping, continuing or interrupting
1241                              an asynchronous subprocess.
1242* Output from Processes::   Collecting output from an asynchronous subprocess.
1243* Sentinels::               Sentinels run when process run-status changes.
1244* Query Before Exit::       Whether to query if exiting will kill a process.
1245* System Processes::        Accessing other processes running on your system.
1246* Transaction Queues::      Transaction-based communication with subprocesses.
1247* Network::                 Opening network connections.
1248* Network Servers::         Network servers let Emacs accept net connections.
1249* Datagrams::               UDP network connections.
1250* Low-Level Network::       Lower-level but more general function
1251                              to create connections and servers.
1252* Misc Network::            Additional relevant functions for net connections.
1253* Serial Ports::            Communicating with serial ports.
1254* Byte Packing::            Using bindat to pack and unpack binary data.
1255
1256Receiving Output from Processes
1257
1258* Process Buffers::         By default, output is put in a buffer.
1259* Filter Functions::        Filter functions accept output from the process.
1260* Decoding Output::         Filters can get unibyte or multibyte strings.
1261* Accepting Output::        How to wait until process output arrives.
1262
1263Low-Level Network Access
1264
1265* Network Processes::       Using ‘make-network-process’.
1266* Network Options::         Further control over network connections.
1267* Network Feature Testing:: Determining which network features work on
1268                              the machine you are using.
1269
1270Packing and Unpacking Byte Arrays
1271
1272* Bindat Spec::             Describing data layout.
1273* Bindat Functions::        Doing the unpacking and packing.
1274
1275Emacs Display
1276
1277* Refresh Screen::          Clearing the screen and redrawing everything on it.
1278* Forcing Redisplay::       Forcing redisplay.
1279* Truncation::              Folding or wrapping long text lines.
1280* The Echo Area::           Displaying messages at the bottom of the screen.
1281* Warnings::                Displaying warning messages for the user.
1282* Invisible Text::          Hiding part of the buffer text.
1283* Selective Display::       Hiding part of the buffer text (the old way).
1284* Temporary Displays::      Displays that go away automatically.
1285* Overlays::                Use overlays to highlight parts of the buffer.
1286* Size of Displayed Text::  How large displayed text is.
1287* Line Height::             Controlling the height of lines.
1288* Faces::                   A face defines a graphics style
1289                              for text characters: font, colors, etc.
1290* Fringes::                 Controlling window fringes.
1291* Scroll Bars::             Controlling scroll bars.
1292* Window Dividers::         Separating windows visually.
1293* Display Property::        Enabling special display features.
1294* Images::                  Displaying images in Emacs buffers.
1295* Buttons::                 Adding clickable buttons to Emacs buffers.
1296* Abstract Display::        Emacs’s Widget for Object Collections.
1297* Blinking::                How Emacs shows the matching open parenthesis.
1298* Character Display::       How Emacs displays individual characters.
1299* Beeping::                 Audible signal to the user.
1300* Window Systems::          Which window system is being used.
1301* Tooltips::                Tooltip display in Emacs.
1302* Bidirectional Display::   Display of bidirectional scripts, such as
1303                              Arabic and Farsi.
1304
1305The Echo Area
1306
1307* Displaying Messages::     Explicitly displaying text in the echo area.
1308* Progress::                Informing user about progress of a long operation.
1309* Logging Messages::        Echo area messages are logged for the user.
1310* Echo Area Customization:: Controlling the echo area.
1311
1312Reporting Warnings
1313
1314* Warning Basics::          Warnings concepts and functions to report them.
1315* Warning Variables::       Variables programs bind to customize
1316                              their warnings.
1317* Warning Options::         Variables users set to control display of warnings.
1318* Delayed Warnings::        Deferring a warning until the end of a command.
1319
1320Overlays
1321
1322* Managing Overlays::       Creating and moving overlays.
1323* Overlay Properties::      How to read and set properties.
1324                              What properties do to the screen display.
1325* Finding Overlays::        Searching for overlays.
1326
1327Faces
1328
1329* Face Attributes::         What is in a face?
1330* Defining Faces::          How to define a face.
1331* Attribute Functions::     Functions to examine and set face attributes.
1332* Displaying Faces::        How Emacs combines the faces specified for
1333                              a character.
1334* Face Remapping::          Remapping faces to alternative definitions.
1335* Face Functions::          How to define and examine faces.
1336* Auto Faces::              Hook for automatic face assignment.
1337* Basic Faces::             Faces that are defined by default.
1338* Font Selection::          Finding the best available font for a face.
1339* Font Lookup::             Looking up the names of available fonts
1340                              and information about them.
1341* Fontsets::                A fontset is a collection of fonts
1342                              that handle a range of character sets.
1343* Low-Level Font::          Lisp representation for character display fonts.
1344
1345Fringes
1346
1347* Fringe Size/Pos::         Specifying where to put the window fringes.
1348* Fringe Indicators::       Displaying indicator icons in the window fringes.
1349* Fringe Cursors::          Displaying cursors in the right fringe.
1350* Fringe Bitmaps::          Specifying bitmaps for fringe indicators.
1351* Customizing Bitmaps::     Specifying your own bitmaps to use in the fringes.
1352* Overlay Arrow::           Display of an arrow to indicate position.
1353
1354The ‘display’ Property
1355
1356* Replacing Specs::         Display specs that replace the text.
1357* Specified Space::         Displaying one space with a specified width.
1358* Pixel Specification::     Specifying space width or height in pixels.
1359* Other Display Specs::     Displaying an image; adjusting the height,
1360                              spacing, and other properties of text.
1361* Display Margins::         Displaying text or images to the side of
1362                              the main text.
1363
1364Images
1365
1366* Image Formats::           Supported image formats.
1367* Image Descriptors::       How to specify an image for use in ‘:display’.
1368* XBM Images::              Special features for XBM format.
1369* XPM Images::              Special features for XPM format.
1370* ImageMagick Images::      Special features available through ImageMagick.
1371* Other Image Types::       Various other formats are supported.
1372* Defining Images::         Convenient ways to define an image for later use.
1373* Showing Images::          Convenient ways to display an image once
1374                              it is defined.
1375* Multi-Frame Images::      Some images contain more than one frame.
1376* Image Cache::             Internal mechanisms of image display.
1377
1378Buttons
1379
1380* Button Properties::       Button properties with special meanings.
1381* Button Types::            Defining common properties for classes of buttons.
1382* Making Buttons::          Adding buttons to Emacs buffers.
1383* Manipulating Buttons::    Getting and setting properties of buttons.
1384* Button Buffer Commands::  Buffer-wide commands and bindings for buttons.
1385
1386Abstract Display
1387
1388* Abstract Display Functions::  Functions in the Ewoc package.
1389* Abstract Display Example::    Example of using Ewoc.
1390
1391Character Display
1392
1393* Usual Display::       The usual conventions for displaying characters.
1394* Display Tables::      What a display table consists of.
1395* Active Display Table::  How Emacs selects a display table to use.
1396* Glyphs::              How to define a glyph, and what glyphs mean.
1397* Glyphless Chars::     How glyphless characters are drawn.
1398
1399Operating System Interface
1400
1401* Starting Up::             Customizing Emacs startup processing.
1402* Getting Out::             How exiting works (permanent or temporary).
1403* System Environment::      Distinguish the name and kind of system.
1404* User Identification::     Finding the name and user id of the user.
1405* Time of Day::             Getting the current time.
1406* Time Conversion::         Converting among timestamp forms.
1407* Time Parsing::            Converting timestamps to text and vice versa.
1408* Processor Run Time::      Getting the run time used by Emacs.
1409* Time Calculations::       Adding, subtracting, comparing times, etc.
1410* Timers::                  Setting a timer to call a function at a
1411                              certain time.
1412* Idle Timers::             Setting a timer to call a function when Emacs has
1413                              been idle for a certain length of time.
1414* Terminal Input::          Accessing and recording terminal input.
1415* Terminal Output::         Controlling and recording terminal output.
1416* Sound Output::            Playing sounds on the computer’s speaker.
1417* X11 Keysyms::             Operating on key symbols for X Windows.
1418* Batch Mode::              Running Emacs without terminal interaction.
1419* Session Management::      Saving and restoring state with
1420                              X Session Management.
1421* Desktop Notifications::   Desktop notifications.
1422* File Notifications::      File notifications.
1423* Dynamic Libraries::       On-demand loading of support libraries.
1424* Security Considerations:: Running Emacs in an unfriendly environment.
1425
1426Starting Up Emacs
1427
1428* Startup Summary::         Sequence of actions Emacs performs at startup.
1429* Init File::               Details on reading the init file.
1430* Terminal-Specific::       How the terminal-specific Lisp file is read.
1431* Command-Line Arguments::  How command-line arguments are processed,
1432                              and how you can customize them.
1433
1434Getting Out of Emacs
1435
1436* Killing Emacs::           Exiting Emacs irreversibly.
1437* Suspending Emacs::        Exiting Emacs reversibly.
1438
1439Terminal Input
1440
1441* Input Modes::             Options for how input is processed.
1442* Recording Input::         Saving histories of recent or all input events.
1443
1444Preparing Lisp code for distribution
1445
1446* Packaging Basics::        The basic concepts of Emacs Lisp packages.
1447* Simple Packages::         How to package a single .el file.
1448* Multi-file Packages::     How to package multiple files.
1449* Package Archives::        Maintaining package archives.
1450
1451Tips and Conventions
1452
1453* Coding Conventions::      Conventions for clean and robust programs.
1454* Key Binding Conventions:: Which keys should be bound by which programs.
1455* Programming Tips::        Making Emacs code fit smoothly in Emacs.
1456* Compilation Tips::        Making compiled code run fast.
1457* Warning Tips::            Turning off compiler warnings.
1458* Documentation Tips::      Writing readable documentation strings.
1459* Comment Tips::            Conventions for writing comments.
1460* Library Headers::         Standard headers for library packages.
1461
1462GNU Emacs Internals
1463
1464* Building Emacs::          How the dumped Emacs is made.
1465* Pure Storage::            Kludge to make preloaded Lisp functions shareable.
1466* Garbage Collection::      Reclaiming space for Lisp objects no longer used.
1467* Stack-allocated Objects:: Temporary conses and strings on C stack.
1468* Memory Usage::            Info about total size of Lisp objects made so far.
1469* C Dialect::               What C variant Emacs is written in.
1470* Writing Emacs Primitives::  Writing C code for Emacs.
1471* Writing Dynamic Modules::   Writing loadable modules for Emacs.
1472* Object Internals::        Data formats of buffers, windows, processes.
1473* C Integer Types::         How C integer types are used inside Emacs.
1474
1475Writing Dynamic Modules
1476
1477* Module Initialization::
1478* Module Functions::
1479* Module Values::
1480* Module Misc::
1481* Module Nonlocal::
1482
1483Object Internals
1484
1485* Buffer Internals::        Components of a buffer structure.
1486* Window Internals::        Components of a window structure.
1487* Process Internals::       Components of a process structure.
1488
1489
1490File: elisp.info,  Node: Introduction,  Next: Lisp Data Types,  Prev: Top,  Up: Top
1491
14921 Introduction
1493**************
1494
1495Most of the GNU Emacs text editor is written in the programming language
1496called Emacs Lisp.  You can write new code in Emacs Lisp and install it
1497as an extension to the editor.  However, Emacs Lisp is more than a mere
1498extension language; it is a full computer programming language in its
1499own right.  You can use it as you would any other programming language.
1500
1501   Because Emacs Lisp is designed for use in an editor, it has special
1502features for scanning and parsing text as well as features for handling
1503files, buffers, displays, subprocesses, and so on.  Emacs Lisp is
1504closely integrated with the editing facilities; thus, editing commands
1505are functions that can also conveniently be called from Lisp programs,
1506and parameters for customization are ordinary Lisp variables.
1507
1508   This manual attempts to be a full description of Emacs Lisp.  For a
1509beginner’s introduction to Emacs Lisp, see ‘An Introduction to Emacs
1510Lisp Programming’, by Bob Chassell, also published by the Free Software
1511Foundation.  This manual presumes considerable familiarity with the use
1512of Emacs for editing; see ‘The GNU Emacs Manual’ for this basic
1513information.
1514
1515   Generally speaking, the earlier chapters describe features of Emacs
1516Lisp that have counterparts in many programming languages, and later
1517chapters describe features that are peculiar to Emacs Lisp or relate
1518specifically to editing.
1519
1520   This is the ‘GNU Emacs Lisp Reference Manual’, corresponding to Emacs
1521version 27.2.
1522
1523* Menu:
1524
1525* Caveats::             Flaws and a request for help.
1526* Lisp History::        Emacs Lisp is descended from Maclisp.
1527* Conventions::         How the manual is formatted.
1528* Version Info::        Which Emacs version is running?
1529* Acknowledgments::     The authors, editors, and sponsors of this manual.
1530
1531
1532File: elisp.info,  Node: Caveats,  Next: Lisp History,  Up: Introduction
1533
15341.1 Caveats
1535===========
1536
1537This manual has gone through numerous drafts.  It is nearly complete but
1538not flawless.  There are a few topics that are not covered, either
1539because we consider them secondary (such as most of the individual
1540modes) or because they are yet to be written.  Because we are not able
1541to deal with them completely, we have left out several parts
1542intentionally.
1543
1544   The manual should be fully correct in what it does cover, and it is
1545therefore open to criticism on anything it says—from specific examples
1546and descriptive text, to the ordering of chapters and sections.  If
1547something is confusing, or you find that you have to look at the sources
1548or experiment to learn something not covered in the manual, then perhaps
1549the manual should be fixed.  Please let us know.
1550
1551   As you use this manual, we ask that you send corrections as soon as
1552you find them.  If you think of a simple, real life example for a
1553function or group of functions, please make an effort to write it up and
1554send it in.  Please reference any comments to the node name and function
1555or variable name, as appropriate.  Also state the number of the edition
1556you are criticizing.
1557
1558   Please send comments and corrections using ‘M-x report-emacs-bug’.
1559
1560
1561File: elisp.info,  Node: Lisp History,  Next: Conventions,  Prev: Caveats,  Up: Introduction
1562
15631.2 Lisp History
1564================
1565
1566Lisp (LISt Processing language) was first developed in the late 1950s at
1567the Massachusetts Institute of Technology for research in artificial
1568intelligence.  The great power of the Lisp language makes it ideal for
1569other purposes as well, such as writing editing commands.
1570
1571   Dozens of Lisp implementations have been built over the years, each
1572with its own idiosyncrasies.  Many of them were inspired by Maclisp,
1573which was written in the 1960s at MIT’s Project MAC.  Eventually the
1574implementers of the descendants of Maclisp came together and developed a
1575standard for Lisp systems, called Common Lisp.  In the meantime, Gerry
1576Sussman and Guy Steele at MIT developed a simplified but very powerful
1577dialect of Lisp, called Scheme.
1578
1579   GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common
1580Lisp.  If you know Common Lisp, you will notice many similarities.
1581However, many features of Common Lisp have been omitted or simplified in
1582order to reduce the memory requirements of GNU Emacs.  Sometimes the
1583simplifications are so drastic that a Common Lisp user might be very
1584confused.  We will occasionally point out how GNU Emacs Lisp differs
1585from Common Lisp.  If you don’t know Common Lisp, don’t worry about it;
1586this manual is self-contained.
1587
1588   A certain amount of Common Lisp emulation is available via the
1589‘cl-lib’ library.  *Note Overview: (cl)Top.
1590
1591   Emacs Lisp is not at all influenced by Scheme; but the GNU project
1592has an implementation of Scheme, called Guile.  We use it in all new GNU
1593software that calls for extensibility.
1594
1595
1596File: elisp.info,  Node: Conventions,  Next: Version Info,  Prev: Lisp History,  Up: Introduction
1597
15981.3 Conventions
1599===============
1600
1601This section explains the notational conventions that are used in this
1602manual.  You may want to skip this section and refer back to it later.
1603
1604* Menu:
1605
1606* Some Terms::               Explanation of terms we use in this manual.
1607* nil and t::                How the symbols ‘nil’ and ‘t’ are used.
1608* Evaluation Notation::      The format we use for examples of evaluation.
1609* Printing Notation::        The format we use when examples print text.
1610* Error Messages::           The format we use for examples of errors.
1611* Buffer Text Notation::     The format we use for buffer contents in examples.
1612* Format of Descriptions::   Notation for describing functions, variables, etc.
1613
1614
1615File: elisp.info,  Node: Some Terms,  Next: nil and t,  Up: Conventions
1616
16171.3.1 Some Terms
1618----------------
1619
1620Throughout this manual, the phrases “the Lisp reader” and “the Lisp
1621printer” refer to those routines in Lisp that convert textual
1622representations of Lisp objects into actual Lisp objects, and vice
1623versa.  *Note Printed Representation::, for more details.  You, the
1624person reading this manual, are thought of as the programmer and are
1625addressed as “you”.  The user is the person who uses Lisp programs,
1626including those you write.
1627
1628   Examples of Lisp code are formatted like this: ‘(list 1 2 3)’.  Names
1629that represent metasyntactic variables, or arguments to a function being
1630described, are formatted like this: FIRST-NUMBER.
1631
1632
1633File: elisp.info,  Node: nil and t,  Next: Evaluation Notation,  Prev: Some Terms,  Up: Conventions
1634
16351.3.2 ‘nil’ and ‘t’
1636-------------------
1637
1638In Emacs Lisp, the symbol ‘nil’ has three separate meanings: it is a
1639symbol with the name ‘nil’; it is the logical truth value FALSE; and it
1640is the empty list—the list of zero elements.  When used as a variable,
1641‘nil’ always has the value ‘nil’.
1642
1643   As far as the Lisp reader is concerned, ‘()’ and ‘nil’ are identical:
1644they stand for the same object, the symbol ‘nil’.  The different ways of
1645writing the symbol are intended entirely for human readers.  After the
1646Lisp reader has read either ‘()’ or ‘nil’, there is no way to determine
1647which representation was actually written by the programmer.
1648
1649   In this manual, we write ‘()’ when we wish to emphasize that it means
1650the empty list, and we write ‘nil’ when we wish to emphasize that it
1651means the truth value FALSE.  That is a good convention to use in Lisp
1652programs also.
1653
1654     (cons 'foo ())                ; Emphasize the empty list
1655     (setq foo-flag nil)           ; Emphasize the truth value FALSE
1656
1657   In contexts where a truth value is expected, any non-‘nil’ value is
1658considered to be TRUE.  However, ‘t’ is the preferred way to represent
1659the truth value TRUE.  When you need to choose a value that represents
1660TRUE, and there is no other basis for choosing, use ‘t’.  The symbol ‘t’
1661always has the value ‘t’.
1662
1663   In Emacs Lisp, ‘nil’ and ‘t’ are special symbols that always evaluate
1664to themselves.  This is so that you do not need to quote them to use
1665them as constants in a program.  An attempt to change their values
1666results in a ‘setting-constant’ error.  *Note Constant Variables::.
1667
1668 -- Function: booleanp object
1669     Return non-‘nil’ if OBJECT is one of the two canonical boolean
1670     values: ‘t’ or ‘nil’.
1671
1672
1673File: elisp.info,  Node: Evaluation Notation,  Next: Printing Notation,  Prev: nil and t,  Up: Conventions
1674
16751.3.3 Evaluation Notation
1676-------------------------
1677
1678A Lisp expression that you can evaluate is called a “form”.  Evaluating
1679a form always produces a result, which is a Lisp object.  In the
1680examples in this manual, this is indicated with ‘⇒’:
1681
1682     (car '(1 2))
1683          ⇒ 1
1684
1685You can read this as “‘(car '(1 2))’ evaluates to 1”.
1686
1687   When a form is a macro call, it expands into a new form for Lisp to
1688evaluate.  We show the result of the expansion with ‘↦’.  We may or may
1689not show the result of the evaluation of the expanded form.
1690
1691     (third '(a b c))
1692          ↦ (car (cdr (cdr '(a b c))))
1693          ⇒ c
1694
1695   To help describe one form, we sometimes show another form that
1696produces identical results.  The exact equivalence of two forms is
1697indicated with ‘≡’.
1698
1699     (make-sparse-keymap) ≡ (list 'keymap)
1700
1701
1702File: elisp.info,  Node: Printing Notation,  Next: Error Messages,  Prev: Evaluation Notation,  Up: Conventions
1703
17041.3.4 Printing Notation
1705-----------------------
1706
1707Many of the examples in this manual print text when they are evaluated.
1708If you execute example code in a Lisp Interaction buffer (such as the
1709buffer ‘*scratch*’) by typing ‘C-j’ after the closing parenthesis of the
1710example, the printed text is inserted into the buffer.  If you execute
1711the example by other means (such as by evaluating the function
1712‘eval-region’), the printed text is displayed in the echo area.
1713
1714   Examples in this manual indicate printed text with ‘⊣’, irrespective
1715of where that text goes.  The value returned by evaluating the form
1716follows on a separate line with ‘⇒’.
1717
1718     (progn (prin1 'foo) (princ "\n") (prin1 'bar))
1719          ⊣ foo
1720          ⊣ bar
1721          ⇒ bar
1722
1723
1724File: elisp.info,  Node: Error Messages,  Next: Buffer Text Notation,  Prev: Printing Notation,  Up: Conventions
1725
17261.3.5 Error Messages
1727--------------------
1728
1729Some examples signal errors.  This normally displays an error message in
1730the echo area.  We show the error message on a line starting with
1731‘error→’.  Note that ‘error→’ itself does not appear in the echo area.
1732
1733     (+ 23 'x)
1734     error→ Wrong type argument: number-or-marker-p, x
1735
1736
1737File: elisp.info,  Node: Buffer Text Notation,  Next: Format of Descriptions,  Prev: Error Messages,  Up: Conventions
1738
17391.3.6 Buffer Text Notation
1740--------------------------
1741
1742Some examples describe modifications to the contents of a buffer, by
1743showing the before and after versions of the text.  These examples show
1744the contents of the buffer in question between two lines of dashes
1745containing the buffer name.  In addition, ‘★’ indicates the location of
1746point.  (The symbol for point, of course, is not part of the text in the
1747buffer; it indicates the place _between_ two characters where point is
1748currently located.)
1749
1750     ---------- Buffer: foo ----------
1751     This is the ★contents of foo.
1752     ---------- Buffer: foo ----------
1753
1754     (insert "changed ")
1755          ⇒ nil
1756     ---------- Buffer: foo ----------
1757     This is the changed ★contents of foo.
1758     ---------- Buffer: foo ----------
1759
1760
1761File: elisp.info,  Node: Format of Descriptions,  Prev: Buffer Text Notation,  Up: Conventions
1762
17631.3.7 Format of Descriptions
1764----------------------------
1765
1766Functions, variables, macros, commands, user options, and special forms
1767are described in this manual in a uniform format.  The first line of a
1768description contains the name of the item followed by its arguments, if
1769any.  The category—function, variable, or whatever—appears at the
1770beginning of the line.  The description follows on succeeding lines,
1771sometimes with examples.
1772
1773* Menu:
1774
1775* A Sample Function Description::       A description of an imaginary
1776                                          function, ‘foo’.
1777* A Sample Variable Description::       A description of an imaginary
1778                                          variable,
1779                                          ‘electric-future-map’.
1780
1781
1782File: elisp.info,  Node: A Sample Function Description,  Next: A Sample Variable Description,  Up: Format of Descriptions
1783
17841.3.7.1 A Sample Function Description
1785.....................................
1786
1787In a function description, the name of the function being described
1788appears first.  It is followed on the same line by a list of argument
1789names.  These names are also used in the body of the description, to
1790stand for the values of the arguments.
1791
1792   The appearance of the keyword ‘&optional’ in the argument list
1793indicates that the subsequent arguments may be omitted (omitted
1794arguments default to ‘nil’).  Do not write ‘&optional’ when you call the
1795function.
1796
1797   The keyword ‘&rest’ (which must be followed by a single argument
1798name) indicates that any number of arguments can follow.  The single
1799argument name following ‘&rest’ receives, as its value, a list of all
1800the remaining arguments passed to the function.  Do not write ‘&rest’
1801when you call the function.
1802
1803   Here is a description of an imaginary function ‘foo’:
1804
1805 -- Function: foo integer1 &optional integer2 &rest integers
1806     The function ‘foo’ subtracts INTEGER1 from INTEGER2, then adds all
1807     the rest of the arguments to the result.  If INTEGER2 is not
1808     supplied, then the number 19 is used by default.
1809
1810          (foo 1 5 3 9)
1811               ⇒ 16
1812          (foo 5)
1813               ⇒ 14
1814
1815     More generally,
1816
1817          (foo W X Y...)
18181819          (+ (- X W) Y...)
1820
1821   By convention, any argument whose name contains the name of a type
1822(e.g., INTEGER, INTEGER1 or BUFFER) is expected to be of that type.  A
1823plural of a type (such as BUFFERS) often means a list of objects of that
1824type.  An argument named OBJECT may be of any type.  (For a list of
1825Emacs object types, *note Lisp Data Types::.)  An argument with any
1826other sort of name (e.g., NEW-FILE) is specific to the function; if the
1827function has a documentation string, the type of the argument should be
1828described there (*note Documentation::).
1829
1830   *Note Lambda Expressions::, for a more complete description of
1831arguments modified by ‘&optional’ and ‘&rest’.
1832
1833   Command, macro, and special form descriptions have the same format,
1834but the word ‘Function’ is replaced by ‘Command’, ‘Macro’, or ‘Special
1835Form’, respectively.  Commands are simply functions that may be called
1836interactively; macros process their arguments differently from functions
1837(the arguments are not evaluated), but are presented the same way.
1838
1839   The descriptions of macros and special forms use a more complex
1840notation to specify optional and repeated arguments, because they can
1841break the argument list down into separate arguments in more complicated
1842ways.  ‘[OPTIONAL-ARG]’ means that OPTIONAL-ARG is optional and
1843‘REPEATED-ARGS...’ stands for zero or more arguments.  Parentheses are
1844used when several arguments are grouped into additional levels of list
1845structure.  Here is an example:
1846
1847 -- Special Form: count-loop (var [from to [inc]]) body...
1848     This imaginary special form implements a loop that executes the
1849     BODY forms and then increments the variable VAR on each iteration.
1850     On the first iteration, the variable has the value FROM; on
1851     subsequent iterations, it is incremented by one (or by INC if that
1852     is given).  The loop exits before executing BODY if VAR equals TO.
1853     Here is an example:
1854
1855          (count-loop (i 0 10)
1856            (prin1 i) (princ " ")
1857            (prin1 (aref vector i))
1858            (terpri))
1859
1860     If FROM and TO are omitted, VAR is bound to ‘nil’ before the loop
1861     begins, and the loop exits if VAR is non-‘nil’ at the beginning of
1862     an iteration.  Here is an example:
1863
1864          (count-loop (done)
1865            (if (pending)
1866                (fixit)
1867              (setq done t)))
1868
1869     In this special form, the arguments FROM and TO are optional, but
1870     must both be present or both absent.  If they are present, INC may
1871     optionally be specified as well.  These arguments are grouped with
1872     the argument VAR into a list, to distinguish them from BODY, which
1873     includes all remaining elements of the form.
1874
1875
1876File: elisp.info,  Node: A Sample Variable Description,  Prev: A Sample Function Description,  Up: Format of Descriptions
1877
18781.3.7.2 A Sample Variable Description
1879.....................................
1880
1881A “variable” is a name that can be “bound” (or “set”) to an object.  The
1882object to which a variable is bound is called a “value”; we say also
1883that variable holds that value.  Although nearly all variables can be
1884set by the user, certain variables exist specifically so that users can
1885change them; these are called “user options”.  Ordinary variables and
1886user options are described using a format like that for functions,
1887except that there are no arguments.
1888
1889   Here is a description of the imaginary ‘electric-future-map’
1890variable.
1891
1892 -- Variable: electric-future-map
1893     The value of this variable is a full keymap used by Electric
1894     Command Future mode.  The functions in this map allow you to edit
1895     commands you have not yet thought about executing.
1896
1897   User option descriptions have the same format, but ‘Variable’ is
1898replaced by ‘User Option’.
1899
1900
1901File: elisp.info,  Node: Version Info,  Next: Acknowledgments,  Prev: Conventions,  Up: Introduction
1902
19031.4 Version Information
1904=======================
1905
1906These facilities provide information about which version of Emacs is in
1907use.
1908
1909 -- Command: emacs-version &optional here
1910     This function returns a string describing the version of Emacs that
1911     is running.  It is useful to include this string in bug reports.
1912
1913          (emacs-version)
1914            ⇒ "GNU Emacs 26.1 (build 1, x86_64-unknown-linux-gnu,
1915                       GTK+ Version 3.16) of 2017-06-01"
1916
1917     If HERE is non-‘nil’, it inserts the text in the buffer before
1918     point, and returns ‘nil’.  When this function is called
1919     interactively, it prints the same information in the echo area, but
1920     giving a prefix argument makes HERE non-‘nil’.
1921
1922 -- Variable: emacs-build-time
1923     The value of this variable indicates the time at which Emacs was
1924     built.  It uses the style of ‘current-time’ (*note Time of Day::),
1925     or is ‘nil’ if the information is not available.
1926
1927          emacs-build-time
1928               ⇒ (20614 63694 515336 438000)
1929
1930 -- Variable: emacs-version
1931     The value of this variable is the version of Emacs being run.  It
1932     is a string such as ‘"26.1"’.  A value with three numeric
1933     components, such as ‘"26.0.91"’, indicates an unreleased test
1934     version.  (Prior to Emacs 26.1, the string includes an extra final
1935     component with the integer that is now stored in
1936     ‘emacs-build-number’; e.g., ‘"25.1.1"’.)
1937
1938 -- Variable: emacs-major-version
1939     The major version number of Emacs, as an integer.  For Emacs
1940     version 23.1, the value is 23.
1941
1942 -- Variable: emacs-minor-version
1943     The minor version number of Emacs, as an integer.  For Emacs
1944     version 23.1, the value is 1.
1945
1946 -- Variable: emacs-build-number
1947     An integer that increments each time Emacs is built in the same
1948     directory (without cleaning).  This is only of relevance when
1949     developing Emacs.
1950
1951 -- Variable: emacs-repository-version
1952     A string that gives the repository revision from which Emacs was
1953     built.  If Emacs was built outside revision control, the value is
1954     ‘nil’.
1955
1956 -- Variable: emacs-repository-branch
1957     A string that gives the repository branch from which Emacs was
1958     built.  In the most cases this is ‘"master"’.  If Emacs was built
1959     outside revision control, the value is ‘nil’.
1960
1961
1962File: elisp.info,  Node: Acknowledgments,  Prev: Version Info,  Up: Introduction
1963
19641.5 Acknowledgments
1965===================
1966
1967This manual was originally written by Robert Krawitz, Bil Lewis, Dan
1968LaLiberte, Richard M. Stallman and Chris Welty, the volunteers of the
1969GNU manual group, in an effort extending over several years.  Robert J.
1970Chassell helped to review and edit the manual, with the support of the
1971Defense Advanced Research Projects Agency, ARPA Order 6082, arranged by
1972Warren A. Hunt, Jr. of Computational Logic, Inc.  Additional sections
1973have since been written by Miles Bader, Lars Brinkhoff, Chong Yidong,
1974Kenichi Handa, Lute Kamstra, Juri Linkov, Glenn Morris, Thien-Thi
1975Nguyen, Dan Nicolaescu, Martin Rudalics, Kim F. Storm, Luc Teirlinck,
1976and Eli Zaretskii, and others.
1977
1978   Corrections were supplied by Drew Adams, Juanma Barranquero, Karl
1979Berry, Jim Blandy, Bard Bloom, Stephane Boucher, David Boyes, Alan
1980Carroll, Richard Davis, Lawrence R. Dodd, Peter Doornbosch, David A.
1981Duff, Chris Eich, Beverly Erlebacher, David Eckelkamp, Ralf Fassel,
1982Eirik Fuller, Stephen Gildea, Bob Glickstein, Eric Hanchrow, Jesper
1983Harder, George Hartzell, Nathan Hess, Masayuki Ida, Dan Jacobson, Jak
1984Kirman, Bob Knighten, Frederick M. Korz, Joe Lammens, Glenn M. Lewis, K.
1985Richard Magill, Brian Marick, Roland McGrath, Stefan Monnier, Skip
1986Montanaro, John Gardiner Myers, Thomas A. Peterson, Francesco Potortì,
1987Friedrich Pukelsheim, Arnold D. Robbins, Raul Rockwell, Jason Rumney,
1988Per Starbäck, Shinichirou Sugou, Kimmo Suominen, Edward Tharp, Bill
1989Trost, Rickard Westman, Jean White, Eduard Wiebe, Matthew Wilding, Carl
1990Witty, Dale Worley, Rusty Wright, and David D. Zuhn.
1991
1992   For a more complete list of contributors, please see the relevant
1993change log entries in the Emacs source repository.
1994
1995
1996File: elisp.info,  Node: Lisp Data Types,  Next: Numbers,  Prev: Introduction,  Up: Top
1997
19982 Lisp Data Types
1999*****************
2000
2001A Lisp “object” is a piece of data used and manipulated by Lisp
2002programs.  For our purposes, a “type” or “data type” is a set of
2003possible objects.
2004
2005   Every object belongs to at least one type.  Objects of the same type
2006have similar structures and may usually be used in the same contexts.
2007Types can overlap, and objects can belong to two or more types.
2008Consequently, we can ask whether an object belongs to a particular type,
2009but not for _the_ type of an object.
2010
2011   A few fundamental object types are built into Emacs.  These, from
2012which all other types are constructed, are called “primitive types”.
2013Each object belongs to one and only one primitive type.  These types
2014include “integer”, “float”, “cons”, “symbol”, “string”, “vector”,
2015“hash-table”, “subr”, “byte-code function”, and “record”, plus several
2016special types, such as “buffer”, that are related to editing.  (*Note
2017Editing Types::.)
2018
2019   Each primitive type has a corresponding Lisp function that checks
2020whether an object is a member of that type.
2021
2022   Lisp is unlike many other languages in that its objects are
2023“self-typing”: the primitive type of each object is implicit in the
2024object itself.  For example, if an object is a vector, nothing can treat
2025it as a number; Lisp knows it is a vector, not a number.
2026
2027   In most languages, the programmer must declare the data type of each
2028variable, and the type is known by the compiler but not represented in
2029the data.  Such type declarations do not exist in Emacs Lisp.  A Lisp
2030variable can have any type of value, and it remembers whatever value you
2031store in it, type and all.  (Actually, a small number of Emacs Lisp
2032variables can only take on values of a certain type.  *Note Variables
2033with Restricted Values::.)
2034
2035   This chapter describes the purpose, printed representation, and read
2036syntax of each of the standard types in GNU Emacs Lisp.  Details on how
2037to use these types can be found in later chapters.
2038
2039* Menu:
2040
2041* Printed Representation::      How Lisp objects are represented as text.
2042* Special Read Syntax::         An overview of all the special sequences.
2043* Comments::                    Comments and their formatting conventions.
2044* Programming Types::           Types found in all Lisp systems.
2045* Editing Types::               Types specific to Emacs.
2046* Circular Objects::            Read syntax for circular structure.
2047* Type Predicates::             Tests related to types.
2048* Equality Predicates::         Tests of equality between any two objects.
2049* Mutability::                  Some objects should not be modified.
2050
2051
2052File: elisp.info,  Node: Printed Representation,  Next: Special Read Syntax,  Up: Lisp Data Types
2053
20542.1 Printed Representation and Read Syntax
2055==========================================
2056
2057The “printed representation” of an object is the format of the output
2058generated by the Lisp printer (the function ‘prin1’) for that object.
2059Every data type has a unique printed representation.  The “read syntax”
2060of an object is the format of the input accepted by the Lisp reader (the
2061function ‘read’) for that object.  This is not necessarily unique; many
2062kinds of object have more than one syntax.  *Note Read and Print::.
2063
2064   In most cases, an object’s printed representation is also a read
2065syntax for the object.  However, some types have no read syntax, since
2066it does not make sense to enter objects of these types as constants in a
2067Lisp program.  These objects are printed in “hash notation”, which
2068consists of the characters ‘#<’, a descriptive string (typically the
2069type name followed by the name of the object), and a closing ‘>’.  For
2070example:
2071
2072     (current-buffer)
2073          ⇒ #<buffer objects.texi>
2074
2075Hash notation cannot be read at all, so the Lisp reader signals the
2076error ‘invalid-read-syntax’ whenever it encounters ‘#<’.
2077
2078   In other languages, an expression is text; it has no other form.  In
2079Lisp, an expression is primarily a Lisp object and only secondarily the
2080text that is the object’s read syntax.  Often there is no need to
2081emphasize this distinction, but you must keep it in the back of your
2082mind, or you will occasionally be very confused.
2083
2084   When you evaluate an expression interactively, the Lisp interpreter
2085first reads the textual representation of it, producing a Lisp object,
2086and then evaluates that object (*note Evaluation::).  However,
2087evaluation and reading are separate activities.  Reading returns the
2088Lisp object represented by the text that is read; the object may or may
2089not be evaluated later.  *Note Input Functions::, for a description of
2090‘read’, the basic function for reading objects.
2091
2092
2093File: elisp.info,  Node: Special Read Syntax,  Next: Comments,  Prev: Printed Representation,  Up: Lisp Data Types
2094
20952.2 Special Read Syntax
2096=======================
2097
2098Emacs Lisp represents many special objects and constructs via special
2099hash notations.
2100
2101‘#<...>’
2102     Objects that have no read syntax are presented like this (*note
2103     Printed Representation::).
2104
2105‘##’
2106     The printed representation of an interned symbol whose name is an
2107     empty string (*note Symbol Type::).
2108
2109‘#'’
2110     This is a shortcut for ‘function’, see *note Anonymous Functions::.
2111
2112‘#:’
2113     The printed representation of an uninterned symbol whose name is
2114     FOO is ‘#:FOO’ (*note Symbol Type::).
2115
2116‘#N’
2117     When printing circular structures, this construct is used to
2118     represent where the structure loops back onto itself, and ‘N’ is
2119     the starting list count:
2120
2121          (let ((a (list 1)))
2122            (setcdr a a))
2123          => (1 . #0)
2124
2125‘#N=’
2126‘#N#’
2127     ‘#N=’ gives the name to an object, and ‘#N#’ represents that
2128     object, so when reading back the object, they will be the same
2129     object instead of copies (*note Circular Objects::).
2130
2131‘#xN’
2132     ‘N’ represented as a hexadecimal number (‘#x2a’).
2133
2134‘#oN’
2135     ‘N’ represented as an octal number (‘#o52’).
2136
2137‘#bN’
2138     ‘N’ represented as a binary number (‘#b101010’).
2139
2140‘#(...)’
2141     String text properties (*note Text Props and Strings::).
2142
2143‘#^’
2144     A char table (*note Char-Table Type::).
2145
2146‘#s(hash-table ...)’
2147     A hash table (*note Hash Table Type::).
2148
2149‘?C’
2150     A character (*note Basic Char Syntax::).
2151
2152‘#$’
2153     The current file name in byte-compiled files (*note Docs and
2154     Compilation::).  This is not meant to be used in Emacs Lisp source
2155     files.
2156
2157‘#@N’
2158     Skip the next ‘N’ characters (*note Comments::).  This is used in
2159     byte-compiled files, and is not meant to be used in Emacs Lisp
2160     source files.
2161
2162
2163File: elisp.info,  Node: Comments,  Next: Programming Types,  Prev: Special Read Syntax,  Up: Lisp Data Types
2164
21652.3 Comments
2166============
2167
2168A “comment” is text that is written in a program only for the sake of
2169humans that read the program, and that has no effect on the meaning of
2170the program.  In Lisp, an unescaped semicolon (‘;’) starts a comment if
2171it is not within a string or character constant.  The comment continues
2172to the end of line.  The Lisp reader discards comments; they do not
2173become part of the Lisp objects which represent the program within the
2174Lisp system.
2175
2176   The ‘#@COUNT’ construct, which skips the next COUNT characters, is
2177useful for program-generated comments containing binary data.  The Emacs
2178Lisp byte compiler uses this in its output files (*note Byte
2179Compilation::).  It isn’t meant for source files, however.
2180
2181   *Note Comment Tips::, for conventions for formatting comments.
2182
2183
2184File: elisp.info,  Node: Programming Types,  Next: Editing Types,  Prev: Comments,  Up: Lisp Data Types
2185
21862.4 Programming Types
2187=====================
2188
2189There are two general categories of types in Emacs Lisp: those having to
2190do with Lisp programming, and those having to do with editing.  The
2191former exist in many Lisp implementations, in one form or another.  The
2192latter are unique to Emacs Lisp.
2193
2194* Menu:
2195
2196* Integer Type::        Numbers without fractional parts.
2197* Floating-Point Type:: Numbers with fractional parts and with a large range.
2198* Character Type::      The representation of letters, numbers and
2199                        control characters.
2200* Symbol Type::         A multi-use object that refers to a function,
2201                        variable, or property list, and has a unique identity.
2202* Sequence Type::       Both lists and arrays are classified as sequences.
2203* Cons Cell Type::      Cons cells, and lists (which are made from cons cells).
2204* Array Type::          Arrays include strings and vectors.
2205* String Type::         An (efficient) array of characters.
2206* Vector Type::         One-dimensional arrays.
2207* Char-Table Type::     One-dimensional sparse arrays indexed by characters.
2208* Bool-Vector Type::    One-dimensional arrays of ‘t’ or ‘nil’.
2209* Hash Table Type::     Super-fast lookup tables.
2210* Function Type::       A piece of executable code you can call from elsewhere.
2211* Macro Type::          A method of expanding an expression into another
2212                          expression, more fundamental but less pretty.
2213* Primitive Function Type::     A function written in C, callable from Lisp.
2214* Byte-Code Type::      A function written in Lisp, then compiled.
2215* Record Type::         Compound objects with programmer-defined types.
2216* Type Descriptors::    Objects holding information about types.
2217* Autoload Type::       A type used for automatically loading seldom-used
2218                        functions.
2219* Finalizer Type::      Runs code when no longer reachable.
2220
2221
2222File: elisp.info,  Node: Integer Type,  Next: Floating-Point Type,  Up: Programming Types
2223
22242.4.1 Integer Type
2225------------------
2226
2227Under the hood, there are two kinds of integers—small integers, called
2228“fixnums”, and large integers, called “bignums”.
2229
2230   The range of values for a fixnum depends on the machine.  The minimum
2231range is −536,870,912 to 536,870,911 (30 bits; i.e., −2**29 to 2**29 −
22321) but many machines provide a wider range.
2233
2234   Bignums can have arbitrary precision.  Operations that overflow a
2235fixnum will return a bignum instead.
2236
2237   All numbers can be compared with ‘eql’ or ‘=’; fixnums can also be
2238compared with ‘eq’.  To test whether an integer is a fixnum or a bignum,
2239you can compare it to ‘most-negative-fixnum’ and ‘most-positive-fixnum’,
2240or you can use the convenience predicates ‘fixnump’ and ‘bignump’ on any
2241object.
2242
2243   The read syntax for integers is a sequence of (base ten) digits with
2244an optional sign at the beginning and an optional period at the end.
2245The printed representation produced by the Lisp interpreter never has a
2246leading ‘+’ or a final ‘.’.
2247
2248     -1               ; The integer −1.
2249     1                ; The integer 1.
2250     1.               ; Also the integer 1.
2251     +1               ; Also the integer 1.
2252
2253
2254   *Note Numbers::, for more information.
2255
2256
2257File: elisp.info,  Node: Floating-Point Type,  Next: Character Type,  Prev: Integer Type,  Up: Programming Types
2258
22592.4.2 Floating-Point Type
2260-------------------------
2261
2262Floating-point numbers are the computer equivalent of scientific
2263notation; you can think of a floating-point number as a fraction
2264together with a power of ten.  The precise number of significant figures
2265and the range of possible exponents is machine-specific; Emacs uses the
2266C data type ‘double’ to store the value, and internally this records a
2267power of 2 rather than a power of 10.
2268
2269   The printed representation for floating-point numbers requires either
2270a decimal point (with at least one digit following), an exponent, or
2271both.  For example, ‘1500.0’, ‘+15e2’, ‘15.0e+2’, ‘+1500000e-3’, and
2272‘.15e4’ are five ways of writing a floating-point number whose value is
22731500.  They are all equivalent.
2274
2275   *Note Numbers::, for more information.
2276
2277
2278File: elisp.info,  Node: Character Type,  Next: Symbol Type,  Prev: Floating-Point Type,  Up: Programming Types
2279
22802.4.3 Character Type
2281--------------------
2282
2283A “character” in Emacs Lisp is nothing more than an integer.  In other
2284words, characters are represented by their character codes.  For
2285example, the character ‘A’ is represented as the integer 65.
2286
2287   Individual characters are used occasionally in programs, but it is
2288more common to work with _strings_, which are sequences composed of
2289characters.  *Note String Type::.
2290
2291   Characters in strings and buffers are currently limited to the range
2292of 0 to 4194303—twenty two bits (*note Character Codes::).  Codes 0
2293through 127 are ASCII codes; the rest are non-ASCII (*note Non-ASCII
2294Characters::).  Characters that represent keyboard input have a much
2295wider range, to encode modifier keys such as Control, Meta and Shift.
2296
2297   There are special functions for producing a human-readable textual
2298description of a character for the sake of messages.  *Note Describing
2299Characters::.
2300
2301* Menu:
2302
2303* Basic Char Syntax::      Syntax for regular characters.
2304* General Escape Syntax::  How to specify characters by their codes.
2305* Ctl-Char Syntax::        Syntax for control characters.
2306* Meta-Char Syntax::       Syntax for meta-characters.
2307* Other Char Bits::        Syntax for hyper-, super-, and alt-characters.
2308
2309
2310File: elisp.info,  Node: Basic Char Syntax,  Next: General Escape Syntax,  Up: Character Type
2311
23122.4.3.1 Basic Char Syntax
2313.........................
2314
2315Since characters are really integers, the printed representation of a
2316character is a decimal number.  This is also a possible read syntax for
2317a character, but writing characters that way in Lisp programs is not
2318clear programming.  You should _always_ use the special read syntax
2319formats that Emacs Lisp provides for characters.  These syntax formats
2320start with a question mark.
2321
2322   The usual read syntax for alphanumeric characters is a question mark
2323followed by the character; thus, ‘?A’ for the character ‘A’, ‘?B’ for
2324the character ‘B’, and ‘?a’ for the character ‘a’.
2325
2326   For example:
2327
2328     ?Q ⇒ 81     ?q ⇒ 113
2329
2330   You can use the same syntax for punctuation characters.  However, if
2331the punctuation character has a special syntactic meaning in Lisp, you
2332must quote it with a ‘\’.  For example, ‘?\(’ is the way to write the
2333open-paren character.  Likewise, if the character is ‘\’, you must use a
2334second ‘\’ to quote it: ‘?\\’.
2335
2336   You can express the characters control-g, backspace, tab, newline,
2337vertical tab, formfeed, space, return, del, and escape as ‘?\a’, ‘?\b’,
2338‘?\t’, ‘?\n’, ‘?\v’, ‘?\f’, ‘?\s’, ‘?\r’, ‘?\d’, and ‘?\e’,
2339respectively.  (‘?\s’ followed by a dash has a different meaning—it
2340applies the Super modifier to the following character.)  Thus,
2341
2342     ?\a ⇒ 7                 ; control-g, ‘C-g’
2343     ?\b ⇒ 8                 ; backspace, <BS>, ‘C-h’
2344     ?\t ⇒ 9                 ; tab, <TAB>, ‘C-i’
2345     ?\n ⇒ 10                ; newline, ‘C-j’
2346     ?\v ⇒ 11                ; vertical tab, ‘C-k’
2347     ?\f ⇒ 12                ; formfeed character, ‘C-l’
2348     ?\r ⇒ 13                ; carriage return, <RET>, ‘C-m’
2349     ?\e ⇒ 27                ; escape character, <ESC>, ‘C-[’
2350     ?\s ⇒ 32                ; space character, <SPC>
2351     ?\\ ⇒ 92                ; backslash character, ‘\’
2352     ?\d ⇒ 127               ; delete character, <DEL>
2353
2354   These sequences which start with backslash are also known as “escape
2355sequences”, because backslash plays the role of an escape character;
2356this has nothing to do with the character <ESC>.  ‘\s’ is meant for use
2357in character constants; in string constants, just write the space.
2358
2359   A backslash is allowed, and harmless, preceding any character without
2360a special escape meaning; thus, ‘?\+’ is equivalent to ‘?+’.  There is
2361no reason to add a backslash before most characters.  However, you must
2362add a backslash before any of the characters ‘()[]\;"’, and you should
2363add a backslash before any of the characters ‘|'`#.,’ to avoid confusing
2364the Emacs commands for editing Lisp code.  You should also add a
2365backslash before Unicode characters which resemble the previously
2366mentioned ASCII ones, to avoid confusing people reading your code.
2367Emacs will highlight some non-escaped commonly confused characters such
2368as ‘‘’ to encourage this.  You can also add a backslash before
2369whitespace characters such as space, tab, newline and formfeed.
2370However, it is cleaner to use one of the easily readable escape
2371sequences, such as ‘\t’ or ‘\s’, instead of an actual whitespace
2372character such as a tab or a space.  (If you do write backslash followed
2373by a space, you should write an extra space after the character constant
2374to separate it from the following text.)
2375
2376
2377File: elisp.info,  Node: General Escape Syntax,  Next: Ctl-Char Syntax,  Prev: Basic Char Syntax,  Up: Character Type
2378
23792.4.3.2 General Escape Syntax
2380.............................
2381
2382In addition to the specific escape sequences for special important
2383control characters, Emacs provides several types of escape syntax that
2384you can use to specify non-ASCII text characters.
2385
2386  1. You can specify characters by their Unicode names, if any.
2387     ‘?\N{NAME}’ represents the Unicode character named NAME.  Thus,
2388     ‘?\N{LATIN SMALL LETTER A WITH GRAVE}’ is equivalent to ‘?à’ and
2389     denotes the Unicode character U+00E0.  To simplify entering
2390     multi-line strings, you can replace spaces in the names by
2391     non-empty sequences of whitespace (e.g., newlines).
2392
2393  2. You can specify characters by their Unicode values.  ‘?\N{U+X}’
2394     represents a character with Unicode code point X, where X is a
2395     hexadecimal number.  Also, ‘?\uXXXX’ and ‘?\UXXXXXXXX’ represent
2396     code points XXXX and XXXXXXXX, respectively, where each X is a
2397     single hexadecimal digit.  For example, ‘?\N{U+E0}’, ‘?\u00e0’ and
2398     ‘?\U000000E0’ are all equivalent to ‘?à’ and to ‘?\N{LATIN SMALL
2399     LETTER A WITH GRAVE}’.  The Unicode Standard defines code points
2400     only up to ‘U+10FFFF’, so if you specify a code point higher than
2401     that, Emacs signals an error.
2402
2403  3. You can specify characters by their hexadecimal character codes.  A
2404     hexadecimal escape sequence consists of a backslash, ‘x’, and the
2405     hexadecimal character code.  Thus, ‘?\x41’ is the character ‘A’,
2406     ‘?\x1’ is the character ‘C-a’, and ‘?\xe0’ is the character ‘à’
2407     (‘a’ with grave accent).  You can use any number of hex digits, so
2408     you can represent any character code in this way.
2409
2410  4. You can specify characters by their character code in octal.  An
2411     octal escape sequence consists of a backslash followed by up to
2412     three octal digits; thus, ‘?\101’ for the character ‘A’, ‘?\001’
2413     for the character ‘C-a’, and ‘?\002’ for the character ‘C-b’.  Only
2414     characters up to octal code 777 can be specified this way.
2415
2416   These escape sequences may also be used in strings.  *Note Non-ASCII
2417in Strings::.
2418
2419
2420File: elisp.info,  Node: Ctl-Char Syntax,  Next: Meta-Char Syntax,  Prev: General Escape Syntax,  Up: Character Type
2421
24222.4.3.3 Control-Character Syntax
2423................................
2424
2425Control characters can be represented using yet another read syntax.
2426This consists of a question mark followed by a backslash, caret, and the
2427corresponding non-control character, in either upper or lower case.  For
2428example, both ‘?\^I’ and ‘?\^i’ are valid read syntax for the character
2429‘C-i’, the character whose value is 9.
2430
2431   Instead of the ‘^’, you can use ‘C-’; thus, ‘?\C-i’ is equivalent to
2432‘?\^I’ and to ‘?\^i’:
2433
2434     ?\^I ⇒ 9     ?\C-I ⇒ 9
2435
2436   In strings and buffers, the only control characters allowed are those
2437that exist in ASCII; but for keyboard input purposes, you can turn any
2438character into a control character with ‘C-’.  The character codes for
2439these non-ASCII control characters include the 2**26 bit as well as the
2440code for the corresponding non-control character.  Ordinary text
2441terminals have no way of generating non-ASCII control characters, but
2442you can generate them straightforwardly using X and other window
2443systems.
2444
2445   For historical reasons, Emacs treats the <DEL> character as the
2446control equivalent of ‘?’:
2447
2448     ?\^? ⇒ 127     ?\C-? ⇒ 127
2449
2450As a result, it is currently not possible to represent the character
2451‘Control-?’, which is a meaningful input character under X, using ‘\C-’.
2452It is not easy to change this, as various Lisp files refer to <DEL> in
2453this way.
2454
2455   For representing control characters to be found in files or strings,
2456we recommend the ‘^’ syntax; for control characters in keyboard input,
2457we prefer the ‘C-’ syntax.  Which one you use does not affect the
2458meaning of the program, but may guide the understanding of people who
2459read it.
2460
2461
2462File: elisp.info,  Node: Meta-Char Syntax,  Next: Other Char Bits,  Prev: Ctl-Char Syntax,  Up: Character Type
2463
24642.4.3.4 Meta-Character Syntax
2465.............................
2466
2467A “meta character” is a character typed with the <META> modifier key.
2468The integer that represents such a character has the 2**27 bit set.  We
2469use high bits for this and other modifiers to make possible a wide range
2470of basic character codes.
2471
2472   In a string, the 2**7 bit attached to an ASCII character indicates a
2473meta character; thus, the meta characters that can fit in a string have
2474codes in the range from 128 to 255, and are the meta versions of the
2475ordinary ASCII characters.  *Note Strings of Events::, for details about
2476<META>-handling in strings.
2477
2478   The read syntax for meta characters uses ‘\M-’.  For example, ‘?\M-A’
2479stands for ‘M-A’.  You can use ‘\M-’ together with octal character codes
2480(see below), with ‘\C-’, or with any other syntax for a character.
2481Thus, you can write ‘M-A’ as ‘?\M-A’, or as ‘?\M-\101’.  Likewise, you
2482can write ‘C-M-b’ as ‘?\M-\C-b’, ‘?\C-\M-b’, or ‘?\M-\002’.
2483
2484
2485File: elisp.info,  Node: Other Char Bits,  Prev: Meta-Char Syntax,  Up: Character Type
2486
24872.4.3.5 Other Character Modifier Bits
2488.....................................
2489
2490The case of a graphic character is indicated by its character code; for
2491example, ASCII distinguishes between the characters ‘a’ and ‘A’.  But
2492ASCII has no way to represent whether a control character is upper case
2493or lower case.  Emacs uses the 2**25 bit to indicate that the shift key
2494was used in typing a control character.  This distinction is possible
2495only when you use X terminals or other special terminals; ordinary text
2496terminals do not report the distinction.  The Lisp syntax for the shift
2497bit is ‘\S-’; thus, ‘?\C-\S-o’ or ‘?\C-\S-O’ represents the
2498shifted-control-o character.
2499
2500   The X Window System defines three other modifier bits that can be set
2501in a character: “hyper”, “super” and “alt”.  The syntaxes for these bits
2502are ‘\H-’, ‘\s-’ and ‘\A-’.  (Case is significant in these prefixes.)
2503Thus, ‘?\H-\M-\A-x’ represents ‘Alt-Hyper-Meta-x’.  (Note that ‘\s’ with
2504no following ‘-’ represents the space character.)  Numerically, the bit
2505values are 2**22 for alt, 2**23 for super and 2**24 for hyper.
2506
2507
2508File: elisp.info,  Node: Symbol Type,  Next: Sequence Type,  Prev: Character Type,  Up: Programming Types
2509
25102.4.4 Symbol Type
2511-----------------
2512
2513A “symbol” in GNU Emacs Lisp is an object with a name.  The symbol name
2514serves as the printed representation of the symbol.  In ordinary Lisp
2515use, with one single obarray (*note Creating Symbols::), a symbol’s name
2516is unique—no two symbols have the same name.
2517
2518   A symbol can serve as a variable, as a function name, or to hold a
2519property list.  Or it may serve only to be distinct from all other Lisp
2520objects, so that its presence in a data structure may be recognized
2521reliably.  In a given context, usually only one of these uses is
2522intended.  But you can use one symbol in all of these ways,
2523independently.
2524
2525   A symbol whose name starts with a colon (‘:’) is called a “keyword
2526symbol”.  These symbols automatically act as constants, and are normally
2527used only by comparing an unknown symbol with a few specific
2528alternatives.  *Note Constant Variables::.
2529
2530   A symbol name can contain any characters whatever.  Most symbol names
2531are written with letters, digits, and the punctuation characters
2532‘-+=*/’.  Such names require no special punctuation; the characters of
2533the name suffice as long as the name does not look like a number.  (If
2534it does, write a ‘\’ at the beginning of the name to force
2535interpretation as a symbol.)  The characters ‘_~!@$%^&:<>{}?’ are less
2536often used but also require no special punctuation.  Any other
2537characters may be included in a symbol’s name by escaping them with a
2538backslash.  In contrast to its use in strings, however, a backslash in
2539the name of a symbol simply quotes the single character that follows the
2540backslash.  For example, in a string, ‘\t’ represents a tab character;
2541in the name of a symbol, however, ‘\t’ merely quotes the letter ‘t’.  To
2542have a symbol with a tab character in its name, you must actually use a
2543tab (preceded with a backslash).  But it’s rare to do such a thing.
2544
2545     Common Lisp note: In Common Lisp, lower case letters are always
2546     folded to upper case, unless they are explicitly escaped.  In Emacs
2547     Lisp, upper case and lower case letters are distinct.
2548
2549   Here are several examples of symbol names.  Note that the ‘+’ in the
2550fourth example is escaped to prevent it from being read as a number.
2551This is not necessary in the sixth example because the rest of the name
2552makes it invalid as a number.
2553
2554     foo                 ; A symbol named ‘foo’.
2555     FOO                 ; A symbol named ‘FOO’, different from ‘foo’.
2556     1+                  ; A symbol named ‘1+’
2557                         ;   (not ‘+1’, which is an integer).
2558     \+1                 ; A symbol named ‘+1’
2559                         ;   (not a very readable name).
2560     \(*\ 1\ 2\)         ; A symbol named ‘(* 1 2)’ (a worse name).
2561     +-*/_~!@$%^&=:<>{}  ; A symbol named ‘+-*/_~!@$%^&=:<>{}’.
2562                         ;   These characters need not be escaped.
2563
2564   As an exception to the rule that a symbol’s name serves as its
2565printed representation, ‘##’ is the printed representation for an
2566interned symbol whose name is an empty string.  Furthermore, ‘#:FOO’ is
2567the printed representation for an uninterned symbol whose name is FOO.
2568(Normally, the Lisp reader interns all symbols; *note Creating
2569Symbols::.)
2570
2571
2572File: elisp.info,  Node: Sequence Type,  Next: Cons Cell Type,  Prev: Symbol Type,  Up: Programming Types
2573
25742.4.5 Sequence Types
2575--------------------
2576
2577A “sequence” is a Lisp object that represents an ordered set of
2578elements.  There are two kinds of sequence in Emacs Lisp: “lists” and
2579“arrays”.
2580
2581   Lists are the most commonly-used sequences.  A list can hold elements
2582of any type, and its length can be easily changed by adding or removing
2583elements.  See the next subsection for more about lists.
2584
2585   Arrays are fixed-length sequences.  They are further subdivided into
2586strings, vectors, char-tables and bool-vectors.  Vectors can hold
2587elements of any type, whereas string elements must be characters, and
2588bool-vector elements must be ‘t’ or ‘nil’.  Char-tables are like vectors
2589except that they are indexed by any valid character code.  The
2590characters in a string can have text properties like characters in a
2591buffer (*note Text Properties::), but vectors do not support text
2592properties, even when their elements happen to be characters.
2593
2594   Lists, strings and the other array types also share important
2595similarities.  For example, all have a length L, and all have elements
2596which can be indexed from zero to L minus one.  Several functions,
2597called sequence functions, accept any kind of sequence.  For example,
2598the function ‘length’ reports the length of any kind of sequence.  *Note
2599Sequences Arrays Vectors::.
2600
2601   It is generally impossible to read the same sequence twice, since
2602sequences are always created anew upon reading.  If you read the read
2603syntax for a sequence twice, you get two sequences with equal contents.
2604There is one exception: the empty list ‘()’ always stands for the same
2605object, ‘nil’.
2606
2607
2608File: elisp.info,  Node: Cons Cell Type,  Next: Array Type,  Prev: Sequence Type,  Up: Programming Types
2609
26102.4.6 Cons Cell and List Types
2611------------------------------
2612
2613A “cons cell” is an object that consists of two slots, called the CAR
2614slot and the CDR slot.  Each slot can “hold” any Lisp object.  We also
2615say that the CAR of this cons cell is whatever object its CAR slot
2616currently holds, and likewise for the CDR.
2617
2618   A “list” is a series of cons cells, linked together so that the CDR
2619slot of each cons cell holds either the next cons cell or the empty
2620list.  The empty list is actually the symbol ‘nil’.  *Note Lists::, for
2621details.  Because most cons cells are used as part of lists, we refer to
2622any structure made out of cons cells as a “list structure”.
2623
2624     A note to C programmers: a Lisp list thus works as a “linked list”
2625     built up of cons cells.  Because pointers in Lisp are implicit, we
2626     do not distinguish between a cons cell slot holding a value versus
2627     pointing to the value.
2628
2629   Because cons cells are so central to Lisp, we also have a word for an
2630object which is not a cons cell.  These objects are called “atoms”.
2631
2632   The read syntax and printed representation for lists are identical,
2633and consist of a left parenthesis, an arbitrary number of elements, and
2634a right parenthesis.  Here are examples of lists:
2635
2636     (A 2 "A")            ; A list of three elements.
2637     ()                   ; A list of no elements (the empty list).
2638     nil                  ; A list of no elements (the empty list).
2639     ("A ()")             ; A list of one element: the string ‘"A ()"’.
2640     (A ())               ; A list of two elements: ‘A’ and the empty list.
2641     (A nil)              ; Equivalent to the previous.
2642     ((A B C))            ; A list of one element
2643                          ;   (which is a list of three elements).
2644
2645   Upon reading, each object inside the parentheses becomes an element
2646of the list.  That is, a cons cell is made for each element.  The CAR
2647slot of the cons cell holds the element, and its CDR slot refers to the
2648next cons cell of the list, which holds the next element in the list.
2649The CDR slot of the last cons cell is set to hold ‘nil’.
2650
2651   The names CAR and CDR derive from the history of Lisp.  The original
2652Lisp implementation ran on an IBM 704 computer which divided words into
2653two parts, the address and the decrement; CAR was an instruction to
2654extract the contents of the address part of a register, and CDR an
2655instruction to extract the contents of the decrement.  By contrast, cons
2656cells are named for the function ‘cons’ that creates them, which in turn
2657was named for its purpose, the construction of cells.
2658
2659* Menu:
2660
2661* Box Diagrams::                Drawing pictures of lists.
2662* Dotted Pair Notation::        A general syntax for cons cells.
2663* Association List Type::       A specially constructed list.
2664
2665
2666File: elisp.info,  Node: Box Diagrams,  Next: Dotted Pair Notation,  Up: Cons Cell Type
2667
26682.4.6.1 Drawing Lists as Box Diagrams
2669.....................................
2670
2671A list can be illustrated by a diagram in which the cons cells are shown
2672as pairs of boxes, like dominoes.  (The Lisp reader cannot read such an
2673illustration; unlike the textual notation, which can be understood by
2674both humans and computers, the box illustrations can be understood only
2675by humans.)  This picture represents the three-element list ‘(rose
2676violet buttercup)’:
2677
2678         --- ---      --- ---      --- ---
2679        |   |   |--> |   |   |--> |   |   |--> nil
2680         --- ---      --- ---      --- ---
2681          |            |            |
2682          |            |            |
2683           --> rose     --> violet   --> buttercup
2684
2685   In this diagram, each box represents a slot that can hold or refer to
2686any Lisp object.  Each pair of boxes represents a cons cell.  Each arrow
2687represents a reference to a Lisp object, either an atom or another cons
2688cell.
2689
2690   In this example, the first box, which holds the CAR of the first cons
2691cell, refers to or holds ‘rose’ (a symbol).  The second box, holding the
2692CDR of the first cons cell, refers to the next pair of boxes, the second
2693cons cell.  The CAR of the second cons cell is ‘violet’, and its CDR is
2694the third cons cell.  The CDR of the third (and last) cons cell is
2695‘nil’.
2696
2697   Here is another diagram of the same list, ‘(rose violet buttercup)’,
2698sketched in a different manner:
2699
2700      ---------------       ----------------       -------------------
2701     | car   | cdr   |     | car    | cdr   |     | car       | cdr   |
2702     | rose  |   o-------->| violet |   o-------->| buttercup |  nil  |
2703     |       |       |     |        |       |     |           |       |
2704      ---------------       ----------------       -------------------
2705
2706   A list with no elements in it is the “empty list”; it is identical to
2707the symbol ‘nil’.  In other words, ‘nil’ is both a symbol and a list.
2708
2709   Here is the list ‘(A ())’, or equivalently ‘(A nil)’, depicted with
2710boxes and arrows:
2711
2712         --- ---      --- ---
2713        |   |   |--> |   |   |--> nil
2714         --- ---      --- ---
2715          |            |
2716          |            |
2717           --> A        --> nil
2718
2719   Here is a more complex illustration, showing the three-element list,
2720‘((pine needles) oak maple)’, the first element of which is a
2721two-element list:
2722
2723         --- ---      --- ---      --- ---
2724        |   |   |--> |   |   |--> |   |   |--> nil
2725         --- ---      --- ---      --- ---
2726          |            |            |
2727          |            |            |
2728          |             --> oak      --> maple
2729          |
2730          |     --- ---      --- ---
2731           --> |   |   |--> |   |   |--> nil
2732                --- ---      --- ---
2733                 |            |
2734                 |            |
2735                  --> pine     --> needles
2736
2737   The same list represented in the second box notation looks like this:
2738
2739      --------------       --------------       --------------
2740     | car   | cdr  |     | car   | cdr  |     | car   | cdr  |
2741     |   o   |   o------->| oak   |   o------->| maple |  nil |
2742     |   |   |      |     |       |      |     |       |      |
2743      -- | ---------       --------------       --------------
2744         |
2745         |
2746         |        --------------       ----------------
2747         |       | car   | cdr  |     | car     | cdr  |
2748          ------>| pine  |   o------->| needles |  nil |
2749                 |       |      |     |         |      |
2750                  --------------       ----------------
2751
2752
2753File: elisp.info,  Node: Dotted Pair Notation,  Next: Association List Type,  Prev: Box Diagrams,  Up: Cons Cell Type
2754
27552.4.6.2 Dotted Pair Notation
2756............................
2757
2758“Dotted pair notation” is a general syntax for cons cells that
2759represents the CAR and CDR explicitly.  In this syntax, ‘(A . B)’ stands
2760for a cons cell whose CAR is the object A and whose CDR is the object B.
2761Dotted pair notation is more general than list syntax because the CDR
2762does not have to be a list.  However, it is more cumbersome in cases
2763where list syntax would work.  In dotted pair notation, the list ‘(1 2
27643)’ is written as ‘(1 . (2 . (3 . nil)))’.  For ‘nil’-terminated lists,
2765you can use either notation, but list notation is usually clearer and
2766more convenient.  When printing a list, the dotted pair notation is only
2767used if the CDR of a cons cell is not a list.
2768
2769   Here’s an example using boxes to illustrate dotted pair notation.
2770This example shows the pair ‘(rose . violet)’:
2771
2772         --- ---
2773        |   |   |--> violet
2774         --- ---
2775          |
2776          |
2777           --> rose
2778
2779   You can combine dotted pair notation with list notation to represent
2780conveniently a chain of cons cells with a non-‘nil’ final CDR.  You
2781write a dot after the last element of the list, followed by the CDR of
2782the final cons cell.  For example, ‘(rose violet . buttercup)’ is
2783equivalent to ‘(rose . (violet . buttercup))’.  The object looks like
2784this:
2785
2786         --- ---      --- ---
2787        |   |   |--> |   |   |--> buttercup
2788         --- ---      --- ---
2789          |            |
2790          |            |
2791           --> rose     --> violet
2792
2793   The syntax ‘(rose . violet . buttercup)’ is invalid because there is
2794nothing that it could mean.  If anything, it would say to put
2795‘buttercup’ in the CDR of a cons cell whose CDR is already used for
2796‘violet’.
2797
2798   The list ‘(rose violet)’ is equivalent to ‘(rose . (violet))’, and
2799looks like this:
2800
2801         --- ---      --- ---
2802        |   |   |--> |   |   |--> nil
2803         --- ---      --- ---
2804          |            |
2805          |            |
2806           --> rose     --> violet
2807
2808   Similarly, the three-element list ‘(rose violet buttercup)’ is
2809equivalent to ‘(rose . (violet . (buttercup)))’.  It looks like this:
2810
2811         --- ---      --- ---      --- ---
2812        |   |   |--> |   |   |--> |   |   |--> nil
2813         --- ---      --- ---      --- ---
2814          |            |            |
2815          |            |            |
2816           --> rose     --> violet   --> buttercup
2817
2818
2819File: elisp.info,  Node: Association List Type,  Prev: Dotted Pair Notation,  Up: Cons Cell Type
2820
28212.4.6.3 Association List Type
2822.............................
2823
2824An “association list” or “alist” is a specially-constructed list whose
2825elements are cons cells.  In each element, the CAR is considered a
2826“key”, and the CDR is considered an “associated value”.  (In some cases,
2827the associated value is stored in the CAR of the CDR.)  Association
2828lists are often used as stacks, since it is easy to add or remove
2829associations at the front of the list.
2830
2831   For example,
2832
2833     (setq alist-of-colors
2834           '((rose . red) (lily . white) (buttercup . yellow)))
2835
2836sets the variable ‘alist-of-colors’ to an alist of three elements.  In
2837the first element, ‘rose’ is the key and ‘red’ is the value.
2838
2839   *Note Association Lists::, for a further explanation of alists and
2840for functions that work on alists.  *Note Hash Tables::, for another
2841kind of lookup table, which is much faster for handling a large number
2842of keys.
2843
2844
2845File: elisp.info,  Node: Array Type,  Next: String Type,  Prev: Cons Cell Type,  Up: Programming Types
2846
28472.4.7 Array Type
2848----------------
2849
2850An “array” is composed of an arbitrary number of slots for holding or
2851referring to other Lisp objects, arranged in a contiguous block of
2852memory.  Accessing any element of an array takes approximately the same
2853amount of time.  In contrast, accessing an element of a list requires
2854time proportional to the position of the element in the list.  (Elements
2855at the end of a list take longer to access than elements at the
2856beginning of a list.)
2857
2858   Emacs defines four types of array: strings, vectors, bool-vectors,
2859and char-tables.
2860
2861   A string is an array of characters and a vector is an array of
2862arbitrary objects.  A bool-vector can hold only ‘t’ or ‘nil’.  These
2863kinds of array may have any length up to the largest fixnum, subject to
2864system architecture limits and available memory.  Char-tables are sparse
2865arrays indexed by any valid character code; they can hold arbitrary
2866objects.
2867
2868   The first element of an array has index zero, the second element has
2869index 1, and so on.  This is called “zero-origin” indexing.  For
2870example, an array of four elements has indices 0, 1, 2, and 3.  The
2871largest possible index value is one less than the length of the array.
2872Once an array is created, its length is fixed.
2873
2874   All Emacs Lisp arrays are one-dimensional.  (Most other programming
2875languages support multidimensional arrays, but they are not essential;
2876you can get the same effect with nested one-dimensional arrays.)  Each
2877type of array has its own read syntax; see the following sections for
2878details.
2879
2880   The array type is a subset of the sequence type, and contains the
2881string type, the vector type, the bool-vector type, and the char-table
2882type.
2883
2884
2885File: elisp.info,  Node: String Type,  Next: Vector Type,  Prev: Array Type,  Up: Programming Types
2886
28872.4.8 String Type
2888-----------------
2889
2890A “string” is an array of characters.  Strings are used for many
2891purposes in Emacs, as can be expected in a text editor; for example, as
2892the names of Lisp symbols, as messages for the user, and to represent
2893text extracted from buffers.  Strings in Lisp are constants: evaluation
2894of a string returns the same string.
2895
2896   *Note Strings and Characters::, for functions that operate on
2897strings.
2898
2899* Menu:
2900
2901* Syntax for Strings::      How to specify Lisp strings.
2902* Non-ASCII in Strings::    International characters in strings.
2903* Nonprinting Characters::  Literal unprintable characters in strings.
2904* Text Props and Strings::  Strings with text properties.
2905
2906
2907File: elisp.info,  Node: Syntax for Strings,  Next: Non-ASCII in Strings,  Up: String Type
2908
29092.4.8.1 Syntax for Strings
2910..........................
2911
2912The read syntax for a string is a double-quote, an arbitrary number of
2913characters, and another double-quote, ‘"like this"’.  To include a
2914double-quote in a string, precede it with a backslash; thus, ‘"\""’ is a
2915string containing just one double-quote character.  Likewise, you can
2916include a backslash by preceding it with another backslash, like this:
2917‘"this \\ is a single embedded backslash"’.
2918
2919   The newline character is not special in the read syntax for strings;
2920if you write a new line between the double-quotes, it becomes a
2921character in the string.  But an escaped newline—one that is preceded by
2922‘\’—does not become part of the string; i.e., the Lisp reader ignores an
2923escaped newline while reading a string.  An escaped space ‘\ ’ is
2924likewise ignored.
2925
2926     "It is useful to include newlines
2927     in documentation strings,
2928     but the newline is \
2929     ignored if escaped."
2930          ⇒ "It is useful to include newlines
2931     in documentation strings,
2932     but the newline is ignored if escaped."
2933
2934
2935File: elisp.info,  Node: Non-ASCII in Strings,  Next: Nonprinting Characters,  Prev: Syntax for Strings,  Up: String Type
2936
29372.4.8.2 Non-ASCII Characters in Strings
2938.......................................
2939
2940There are two text representations for non-ASCII characters in Emacs
2941strings: multibyte and unibyte (*note Text Representations::).  Roughly
2942speaking, unibyte strings store raw bytes, while multibyte strings store
2943human-readable text.  Each character in a unibyte string is a byte,
2944i.e., its value is between 0 and 255.  By contrast, each character in a
2945multibyte string may have a value between 0 to 4194303 (*note Character
2946Type::).  In both cases, characters above 127 are non-ASCII.
2947
2948   You can include a non-ASCII character in a string constant by writing
2949it literally.  If the string constant is read from a multibyte source,
2950such as a multibyte buffer or string, or a file that would be visited as
2951multibyte, then Emacs reads each non-ASCII character as a multibyte
2952character and automatically makes the string a multibyte string.  If the
2953string constant is read from a unibyte source, then Emacs reads the
2954non-ASCII character as unibyte, and makes the string unibyte.
2955
2956   Instead of writing a character literally into a multibyte string, you
2957can write it as its character code using an escape sequence.  *Note
2958General Escape Syntax::, for details about escape sequences.
2959
2960   If you use any Unicode-style escape sequence ‘\uNNNN’ or ‘\U00NNNNNN’
2961in a string constant (even for an ASCII character), Emacs automatically
2962assumes that it is multibyte.
2963
2964   You can also use hexadecimal escape sequences (‘\xN’) and octal
2965escape sequences (‘\N’) in string constants.  *But beware:* If a string
2966constant contains hexadecimal or octal escape sequences, and these
2967escape sequences all specify unibyte characters (i.e., less than 256),
2968and there are no other literal non-ASCII characters or Unicode-style
2969escape sequences in the string, then Emacs automatically assumes that it
2970is a unibyte string.  That is to say, it assumes that all non-ASCII
2971characters occurring in the string are 8-bit raw bytes.
2972
2973   In hexadecimal and octal escape sequences, the escaped character code
2974may contain a variable number of digits, so the first subsequent
2975character which is not a valid hexadecimal or octal digit terminates the
2976escape sequence.  If the next character in a string could be interpreted
2977as a hexadecimal or octal digit, write ‘\ ’ (backslash and space) to
2978terminate the escape sequence.  For example, ‘\xe0\ ’ represents one
2979character, ‘a’ with grave accent.  ‘\ ’ in a string constant is just
2980like backslash-newline; it does not contribute any character to the
2981string, but it does terminate any preceding hex escape.
2982
2983
2984File: elisp.info,  Node: Nonprinting Characters,  Next: Text Props and Strings,  Prev: Non-ASCII in Strings,  Up: String Type
2985
29862.4.8.3 Nonprinting Characters in Strings
2987.........................................
2988
2989You can use the same backslash escape-sequences in a string constant as
2990in character literals (but do not use the question mark that begins a
2991character constant).  For example, you can write a string containing the
2992nonprinting characters tab and ‘C-a’, with commas and spaces between
2993them, like this: ‘"\t, \C-a"’.  *Note Character Type::, for a
2994description of the read syntax for characters.
2995
2996   However, not all of the characters you can write with backslash
2997escape-sequences are valid in strings.  The only control characters that
2998a string can hold are the ASCII control characters.  Strings do not
2999distinguish case in ASCII control characters.
3000
3001   Properly speaking, strings cannot hold meta characters; but when a
3002string is to be used as a key sequence, there is a special convention
3003that provides a way to represent meta versions of ASCII characters in a
3004string.  If you use the ‘\M-’ syntax to indicate a meta character in a
3005string constant, this sets the 2**7 bit of the character in the string.
3006If the string is used in ‘define-key’ or ‘lookup-key’, this numeric code
3007is translated into the equivalent meta character.  *Note Character
3008Type::.
3009
3010   Strings cannot hold characters that have the hyper, super, or alt
3011modifiers.
3012
3013
3014File: elisp.info,  Node: Text Props and Strings,  Prev: Nonprinting Characters,  Up: String Type
3015
30162.4.8.4 Text Properties in Strings
3017..................................
3018
3019A string can hold properties for the characters it contains, in addition
3020to the characters themselves.  This enables programs that copy text
3021between strings and buffers to copy the text’s properties with no
3022special effort.  *Note Text Properties::, for an explanation of what
3023text properties mean.  Strings with text properties use a special read
3024and print syntax:
3025
3026     #("CHARACTERS" PROPERTY-DATA...)
3027
3028where PROPERTY-DATA consists of zero or more elements, in groups of
3029three as follows:
3030
3031     BEG END PLIST
3032
3033The elements BEG and END are integers, and together specify a range of
3034indices in the string; PLIST is the property list for that range.  For
3035example,
3036
3037     #("foo bar" 0 3 (face bold) 3 4 nil 4 7 (face italic))
3038
3039represents a string whose textual contents are ‘foo bar’, in which the
3040first three characters have a ‘face’ property with value ‘bold’, and the
3041last three have a ‘face’ property with value ‘italic’.  (The fourth
3042character has no text properties, so its property list is ‘nil’.  It is
3043not actually necessary to mention ranges with ‘nil’ as the property
3044list, since any characters not mentioned in any range will default to
3045having no properties.)
3046
3047
3048File: elisp.info,  Node: Vector Type,  Next: Char-Table Type,  Prev: String Type,  Up: Programming Types
3049
30502.4.9 Vector Type
3051-----------------
3052
3053A “vector” is a one-dimensional array of elements of any type.  It takes
3054a constant amount of time to access any element of a vector.  (In a
3055list, the access time of an element is proportional to the distance of
3056the element from the beginning of the list.)
3057
3058   The printed representation of a vector consists of a left square
3059bracket, the elements, and a right square bracket.  This is also the
3060read syntax.  Like numbers and strings, vectors are considered constants
3061for evaluation.
3062
3063     [1 "two" (three)]      ; A vector of three elements.
3064          ⇒ [1 "two" (three)]
3065
3066   *Note Vectors::, for functions that work with vectors.
3067
3068
3069File: elisp.info,  Node: Char-Table Type,  Next: Bool-Vector Type,  Prev: Vector Type,  Up: Programming Types
3070
30712.4.10 Char-Table Type
3072----------------------
3073
3074A “char-table” is a one-dimensional array of elements of any type,
3075indexed by character codes.  Char-tables have certain extra features to
3076make them more useful for many jobs that involve assigning information
3077to character codes—for example, a char-table can have a parent to
3078inherit from, a default value, and a small number of extra slots to use
3079for special purposes.  A char-table can also specify a single value for
3080a whole character set.
3081
3082   The printed representation of a char-table is like a vector except
3083that there is an extra ‘#^’ at the beginning.(1)
3084
3085   *Note Char-Tables::, for special functions to operate on char-tables.
3086Uses of char-tables include:
3087
3088   • Case tables (*note Case Tables::).
3089
3090   • Character category tables (*note Categories::).
3091
3092   • Display tables (*note Display Tables::).
3093
3094   • Syntax tables (*note Syntax Tables::).
3095
3096   ---------- Footnotes ----------
3097
3098   (1) You may also encounter ‘#^^’, used for sub-char-tables.
3099
3100
3101File: elisp.info,  Node: Bool-Vector Type,  Next: Hash Table Type,  Prev: Char-Table Type,  Up: Programming Types
3102
31032.4.11 Bool-Vector Type
3104-----------------------
3105
3106A “bool-vector” is a one-dimensional array whose elements must be ‘t’ or
3107‘nil’.
3108
3109   The printed representation of a bool-vector is like a string, except
3110that it begins with ‘#&’ followed by the length.  The string constant
3111that follows actually specifies the contents of the bool-vector as a
3112bitmap—each character in the string contains 8 bits, which specify the
3113next 8 elements of the bool-vector (1 stands for ‘t’, and 0 for ‘nil’).
3114The least significant bits of the character correspond to the lowest
3115indices in the bool-vector.
3116
3117     (make-bool-vector 3 t)
3118          ⇒ #&3"^G"
3119     (make-bool-vector 3 nil)
3120          ⇒ #&3"^@"
3121
3122These results make sense, because the binary code for ‘C-g’ is 111 and
3123‘C-@’ is the character with code 0.
3124
3125   If the length is not a multiple of 8, the printed representation
3126shows extra elements, but these extras really make no difference.  For
3127instance, in the next example, the two bool-vectors are equal, because
3128only the first 3 bits are used:
3129
3130     (equal #&3"\377" #&3"\007")
3131          ⇒ t
3132
3133
3134File: elisp.info,  Node: Hash Table Type,  Next: Function Type,  Prev: Bool-Vector Type,  Up: Programming Types
3135
31362.4.12 Hash Table Type
3137----------------------
3138
3139A hash table is a very fast kind of lookup table, somewhat like an alist
3140in that it maps keys to corresponding values, but much faster.  The
3141printed representation of a hash table specifies its properties and
3142contents, like this:
3143
3144     (make-hash-table)
3145          ⇒ #s(hash-table size 65 test eql rehash-size 1.5
3146                                  rehash-threshold 0.8125 data ())
3147
3148*Note Hash Tables::, for more information about hash tables.
3149
3150
3151File: elisp.info,  Node: Function Type,  Next: Macro Type,  Prev: Hash Table Type,  Up: Programming Types
3152
31532.4.13 Function Type
3154--------------------
3155
3156Lisp functions are executable code, just like functions in other
3157programming languages.  In Lisp, unlike most languages, functions are
3158also Lisp objects.  A non-compiled function in Lisp is a lambda
3159expression: that is, a list whose first element is the symbol ‘lambda’
3160(*note Lambda Expressions::).
3161
3162   In most programming languages, it is impossible to have a function
3163without a name.  In Lisp, a function has no intrinsic name.  A lambda
3164expression can be called as a function even though it has no name; to
3165emphasize this, we also call it an “anonymous function” (*note Anonymous
3166Functions::).  A named function in Lisp is just a symbol with a valid
3167function in its function cell (*note Defining Functions::).
3168
3169   Most of the time, functions are called when their names are written
3170in Lisp expressions in Lisp programs.  However, you can construct or
3171obtain a function object at run time and then call it with the primitive
3172functions ‘funcall’ and ‘apply’.  *Note Calling Functions::.
3173
3174
3175File: elisp.info,  Node: Macro Type,  Next: Primitive Function Type,  Prev: Function Type,  Up: Programming Types
3176
31772.4.14 Macro Type
3178-----------------
3179
3180A “Lisp macro” is a user-defined construct that extends the Lisp
3181language.  It is represented as an object much like a function, but with
3182different argument-passing semantics.  A Lisp macro has the form of a
3183list whose first element is the symbol ‘macro’ and whose CDR is a Lisp
3184function object, including the ‘lambda’ symbol.
3185
3186   Lisp macro objects are usually defined with the built-in ‘defmacro’
3187macro, but any list that begins with ‘macro’ is a macro as far as Emacs
3188is concerned.  *Note Macros::, for an explanation of how to write a
3189macro.
3190
3191   *Warning*: Lisp macros and keyboard macros (*note Keyboard Macros::)
3192are entirely different things.  When we use the word “macro” without
3193qualification, we mean a Lisp macro, not a keyboard macro.
3194
3195
3196File: elisp.info,  Node: Primitive Function Type,  Next: Byte-Code Type,  Prev: Macro Type,  Up: Programming Types
3197
31982.4.15 Primitive Function Type
3199------------------------------
3200
3201A “primitive function” is a function callable from Lisp but written in
3202the C programming language.  Primitive functions are also called “subrs”
3203or “built-in functions”.  (The word “subr” is derived from
3204“subroutine”.)  Most primitive functions evaluate all their arguments
3205when they are called.  A primitive function that does not evaluate all
3206its arguments is called a “special form” (*note Special Forms::).
3207
3208   It does not matter to the caller of a function whether the function
3209is primitive.  However, this does matter if you try to redefine a
3210primitive with a function written in Lisp.  The reason is that the
3211primitive function may be called directly from C code.  Calls to the
3212redefined function from Lisp will use the new definition, but calls from
3213C code may still use the built-in definition.  Therefore, *we discourage
3214redefinition of primitive functions*.
3215
3216   The term “function” refers to all Emacs functions, whether written in
3217Lisp or C.  *Note Function Type::, for information about the functions
3218written in Lisp.
3219
3220   Primitive functions have no read syntax and print in hash notation
3221with the name of the subroutine.
3222
3223     (symbol-function 'car)          ; Access the function cell
3224                                     ;   of the symbol.
3225          ⇒ #<subr car>
3226     (subrp (symbol-function 'car))  ; Is this a primitive function?
3227          ⇒ t                       ; Yes.
3228
3229
3230File: elisp.info,  Node: Byte-Code Type,  Next: Record Type,  Prev: Primitive Function Type,  Up: Programming Types
3231
32322.4.16 Byte-Code Function Type
3233------------------------------
3234
3235“Byte-code function objects” are produced by byte-compiling Lisp code
3236(*note Byte Compilation::).  Internally, a byte-code function object is
3237much like a vector; however, the evaluator handles this data type
3238specially when it appears in a function call.  *Note Byte-Code
3239Objects::.
3240
3241   The printed representation and read syntax for a byte-code function
3242object is like that for a vector, with an additional ‘#’ before the
3243opening ‘[’.
3244
3245
3246File: elisp.info,  Node: Record Type,  Next: Type Descriptors,  Prev: Byte-Code Type,  Up: Programming Types
3247
32482.4.17 Record Type
3249------------------
3250
3251A “record” is much like a ‘vector’.  However, the first element is used
3252to hold its type as returned by ‘type-of’.  The purpose of records is to
3253allow programmers to create objects with new types that are not built
3254into Emacs.
3255
3256   *Note Records::, for functions that work with records.
3257
3258
3259File: elisp.info,  Node: Type Descriptors,  Next: Autoload Type,  Prev: Record Type,  Up: Programming Types
3260
32612.4.18 Type Descriptors
3262-----------------------
3263
3264A “type descriptor” is a ‘record’ which holds information about a type.
3265Slot 1 in the record must be a symbol naming the type, and ‘type-of’
3266relies on this to return the type of ‘record’ objects.  No other type
3267descriptor slot is used by Emacs; they are free for use by Lisp
3268extensions.
3269
3270   An example of a type descriptor is any instance of
3271‘cl-structure-class’.
3272
3273
3274File: elisp.info,  Node: Autoload Type,  Next: Finalizer Type,  Prev: Type Descriptors,  Up: Programming Types
3275
32762.4.19 Autoload Type
3277--------------------
3278
3279An “autoload object” is a list whose first element is the symbol
3280‘autoload’.  It is stored as the function definition of a symbol, where
3281it serves as a placeholder for the real definition.  The autoload object
3282says that the real definition is found in a file of Lisp code that
3283should be loaded when necessary.  It contains the name of the file, plus
3284some other information about the real definition.
3285
3286   After the file has been loaded, the symbol should have a new function
3287definition that is not an autoload object.  The new definition is then
3288called as if it had been there to begin with.  From the user’s point of
3289view, the function call works as expected, using the function definition
3290in the loaded file.
3291
3292   An autoload object is usually created with the function ‘autoload’,
3293which stores the object in the function cell of a symbol.  *Note
3294Autoload::, for more details.
3295
3296
3297File: elisp.info,  Node: Finalizer Type,  Prev: Autoload Type,  Up: Programming Types
3298
32992.4.20 Finalizer Type
3300---------------------
3301
3302A “finalizer object” helps Lisp code clean up after objects that are no
3303longer needed.  A finalizer holds a Lisp function object.  When a
3304finalizer object becomes unreachable after a garbage collection pass,
3305Emacs calls the finalizer’s associated function object.  When deciding
3306whether a finalizer is reachable, Emacs does not count references from
3307finalizer objects themselves, allowing you to use finalizers without
3308having to worry about accidentally capturing references to finalized
3309objects themselves.
3310
3311   Errors in finalizers are printed to ‘*Messages*’.  Emacs runs a given
3312finalizer object’s associated function exactly once, even if that
3313function fails.
3314
3315 -- Function: make-finalizer function
3316     Make a finalizer that will run FUNCTION.  FUNCTION will be called
3317     after garbage collection when the returned finalizer object becomes
3318     unreachable.  If the finalizer object is reachable only through
3319     references from finalizer objects, it does not count as reachable
3320     for the purpose of deciding whether to run FUNCTION.  FUNCTION will
3321     be run once per finalizer object.
3322
3323
3324File: elisp.info,  Node: Editing Types,  Next: Circular Objects,  Prev: Programming Types,  Up: Lisp Data Types
3325
33262.5 Editing Types
3327=================
3328
3329The types in the previous section are used for general programming
3330purposes, and most of them are common to most Lisp dialects.  Emacs Lisp
3331provides several additional data types for purposes connected with
3332editing.
3333
3334* Menu:
3335
3336* Buffer Type::         The basic object of editing.
3337* Marker Type::         A position in a buffer.
3338* Window Type::         Buffers are displayed in windows.
3339* Frame Type::          Windows subdivide frames.
3340* Terminal Type::       A terminal device displays frames.
3341* Window Configuration Type::   Recording the way a frame is subdivided.
3342* Frame Configuration Type::    Recording the status of all frames.
3343* Process Type::        A subprocess of Emacs running on the underlying OS.
3344* Thread Type::         A thread of Emacs Lisp execution.
3345* Mutex Type::          An exclusive lock for thread synchronization.
3346* Condition Variable Type::     Condition variable for thread synchronization.
3347* Stream Type::         Receive or send characters.
3348* Keymap Type::         What function a keystroke invokes.
3349* Overlay Type::        How an overlay is represented.
3350* Font Type::           Fonts for displaying text.
3351
3352
3353File: elisp.info,  Node: Buffer Type,  Next: Marker Type,  Up: Editing Types
3354
33552.5.1 Buffer Type
3356-----------------
3357
3358A “buffer” is an object that holds text that can be edited (*note
3359Buffers::).  Most buffers hold the contents of a disk file (*note
3360Files::) so they can be edited, but some are used for other purposes.
3361Most buffers are also meant to be seen by the user, and therefore
3362displayed, at some time, in a window (*note Windows::).  But a buffer
3363need not be displayed in any window.  Each buffer has a designated
3364position called “point” (*note Positions::); most editing commands act
3365on the contents of the current buffer in the neighborhood of point.  At
3366any time, one buffer is the “current buffer”.
3367
3368   The contents of a buffer are much like a string, but buffers are not
3369used like strings in Emacs Lisp, and the available operations are
3370different.  For example, you can insert text efficiently into an
3371existing buffer, altering the buffer’s contents, whereas inserting text
3372into a string requires concatenating substrings, and the result is an
3373entirely new string object.
3374
3375   Many of the standard Emacs functions manipulate or test the
3376characters in the current buffer; a whole chapter in this manual is
3377devoted to describing these functions (*note Text::).
3378
3379   Several other data structures are associated with each buffer:
3380
3381   • a local syntax table (*note Syntax Tables::);
3382
3383   • a local keymap (*note Keymaps::); and,
3384
3385   • a list of buffer-local variable bindings (*note Buffer-Local
3386     Variables::).
3387
3388   • overlays (*note Overlays::).
3389
3390   • text properties for the text in the buffer (*note Text
3391     Properties::).
3392
3393The local keymap and variable list contain entries that individually
3394override global bindings or values.  These are used to customize the
3395behavior of programs in different buffers, without actually changing the
3396programs.
3397
3398   A buffer may be “indirect”, which means it shares the text of another
3399buffer, but presents it differently.  *Note Indirect Buffers::.
3400
3401   Buffers have no read syntax.  They print in hash notation, showing
3402the buffer name.
3403
3404     (current-buffer)
3405          ⇒ #<buffer objects.texi>
3406
3407
3408File: elisp.info,  Node: Marker Type,  Next: Window Type,  Prev: Buffer Type,  Up: Editing Types
3409
34102.5.2 Marker Type
3411-----------------
3412
3413A “marker” denotes a position in a specific buffer.  Markers therefore
3414have two components: one for the buffer, and one for the position.
3415Changes in the buffer’s text automatically relocate the position value
3416as necessary to ensure that the marker always points between the same
3417two characters in the buffer.
3418
3419   Markers have no read syntax.  They print in hash notation, giving the
3420current character position and the name of the buffer.
3421
3422     (point-marker)
3423          ⇒ #<marker at 10779 in objects.texi>
3424
3425   *Note Markers::, for information on how to test, create, copy, and
3426move markers.
3427
3428
3429File: elisp.info,  Node: Window Type,  Next: Frame Type,  Prev: Marker Type,  Up: Editing Types
3430
34312.5.3 Window Type
3432-----------------
3433
3434A “window” describes the portion of the terminal screen that Emacs uses
3435to display a buffer.  Every window has one associated buffer, whose
3436contents appear in the window.  By contrast, a given buffer may appear
3437in one window, no window, or several windows.
3438
3439   Though many windows may exist simultaneously, at any time one window
3440is designated the “selected window”.  This is the window where the
3441cursor is (usually) displayed when Emacs is ready for a command.  The
3442selected window usually displays the current buffer (*note Current
3443Buffer::), but this is not necessarily the case.
3444
3445   Windows are grouped on the screen into frames; each window belongs to
3446one and only one frame.  *Note Frame Type::.
3447
3448   Windows have no read syntax.  They print in hash notation, giving the
3449window number and the name of the buffer being displayed.  The window
3450numbers exist to identify windows uniquely, since the buffer displayed
3451in any given window can change frequently.
3452
3453     (selected-window)
3454          ⇒ #<window 1 on objects.texi>
3455
3456   *Note Windows::, for a description of the functions that work on
3457windows.
3458
3459
3460File: elisp.info,  Node: Frame Type,  Next: Terminal Type,  Prev: Window Type,  Up: Editing Types
3461
34622.5.4 Frame Type
3463----------------
3464
3465A “frame” is a screen area that contains one or more Emacs windows; we
3466also use the term “frame” to refer to the Lisp object that Emacs uses to
3467refer to the screen area.
3468
3469   Frames have no read syntax.  They print in hash notation, giving the
3470frame’s title, plus its address in core (useful to identify the frame
3471uniquely).
3472
3473     (selected-frame)
3474          ⇒ #<frame emacs@psilocin.gnu.org 0xdac80>
3475
3476   *Note Frames::, for a description of the functions that work on
3477frames.
3478
3479
3480File: elisp.info,  Node: Terminal Type,  Next: Window Configuration Type,  Prev: Frame Type,  Up: Editing Types
3481
34822.5.5 Terminal Type
3483-------------------
3484
3485A “terminal” is a device capable of displaying one or more Emacs frames
3486(*note Frame Type::).
3487
3488   Terminals have no read syntax.  They print in hash notation giving
3489the terminal’s ordinal number and its TTY device file name.
3490
3491     (get-device-terminal nil)
3492          ⇒ #<terminal 1 on /dev/tty>
3493
3494
3495File: elisp.info,  Node: Window Configuration Type,  Next: Frame Configuration Type,  Prev: Terminal Type,  Up: Editing Types
3496
34972.5.6 Window Configuration Type
3498-------------------------------
3499
3500A “window configuration” stores information about the positions, sizes,
3501and contents of the windows in a frame, so you can recreate the same
3502arrangement of windows later.
3503
3504   Window configurations do not have a read syntax; their print syntax
3505looks like ‘#<window-configuration>’.  *Note Window Configurations::,
3506for a description of several functions related to window configurations.
3507
3508
3509File: elisp.info,  Node: Frame Configuration Type,  Next: Process Type,  Prev: Window Configuration Type,  Up: Editing Types
3510
35112.5.7 Frame Configuration Type
3512------------------------------
3513
3514A “frame configuration” stores information about the positions, sizes,
3515and contents of the windows in all frames.  It is not a primitive
3516type—it is actually a list whose CAR is ‘frame-configuration’ and whose
3517CDR is an alist.  Each alist element describes one frame, which appears
3518as the CAR of that element.
3519
3520   *Note Frame Configurations::, for a description of several functions
3521related to frame configurations.
3522
3523
3524File: elisp.info,  Node: Process Type,  Next: Thread Type,  Prev: Frame Configuration Type,  Up: Editing Types
3525
35262.5.8 Process Type
3527------------------
3528
3529The word “process” usually means a running program.  Emacs itself runs
3530in a process of this sort.  However, in Emacs Lisp, a process is a Lisp
3531object that designates a subprocess created by the Emacs process.
3532Programs such as shells, GDB, ftp, and compilers, running in
3533subprocesses of Emacs, extend the capabilities of Emacs.  An Emacs
3534subprocess takes textual input from Emacs and returns textual output to
3535Emacs for further manipulation.  Emacs can also send signals to the
3536subprocess.
3537
3538   Process objects have no read syntax.  They print in hash notation,
3539giving the name of the process:
3540
3541     (process-list)
3542          ⇒ (#<process shell>)
3543
3544   *Note Processes::, for information about functions that create,
3545delete, return information about, send input or signals to, and receive
3546output from processes.
3547
3548
3549File: elisp.info,  Node: Thread Type,  Next: Mutex Type,  Prev: Process Type,  Up: Editing Types
3550
35512.5.9 Thread Type
3552-----------------
3553
3554A “thread” in Emacs represents a separate thread of Emacs Lisp
3555execution.  It runs its own Lisp program, has its own current buffer,
3556and can have subprocesses locked to it, i.e. subprocesses whose output
3557only this thread can accept.  *Note Threads::.
3558
3559   Thread objects have no read syntax.  They print in hash notation,
3560giving the name of the thread (if it has been given a name) or its
3561address in core:
3562
3563     (all-threads)
3564         ⇒ (#<thread 0176fc40>)
3565
3566
3567File: elisp.info,  Node: Mutex Type,  Next: Condition Variable Type,  Prev: Thread Type,  Up: Editing Types
3568
35692.5.10 Mutex Type
3570-----------------
3571
3572A “mutex” is an exclusive lock that threads can own and disown, in order
3573to synchronize between them.  *Note Mutexes::.
3574
3575   Mutex objects have no read syntax.  They print in hash notation,
3576giving the name of the mutex (if it has been given a name) or its
3577address in core:
3578
3579     (make-mutex "my-mutex")
3580         ⇒ #<mutex my-mutex>
3581     (make-mutex)
3582         ⇒ #<mutex 01c7e4e0>
3583
3584
3585File: elisp.info,  Node: Condition Variable Type,  Next: Stream Type,  Prev: Mutex Type,  Up: Editing Types
3586
35872.5.11 Condition Variable Type
3588------------------------------
3589
3590A “condition variable” is a device for a more complex thread
3591synchronization than the one supported by a mutex.  A thread can wait on
3592a condition variable, to be woken up when some other thread notifies the
3593condition.
3594
3595   Condition variable objects have no read syntax.  They print in hash
3596notation, giving the name of the condition variable (if it has been
3597given a name) or its address in core:
3598
3599     (make-condition-variable (make-mutex))
3600         ⇒ #<condvar 01c45ae8>
3601
3602
3603File: elisp.info,  Node: Stream Type,  Next: Keymap Type,  Prev: Condition Variable Type,  Up: Editing Types
3604
36052.5.12 Stream Type
3606------------------
3607
3608A “stream” is an object that can be used as a source or sink for
3609characters—either to supply characters for input or to accept them as
3610output.  Many different types can be used this way: markers, buffers,
3611strings, and functions.  Most often, input streams (character sources)
3612obtain characters from the keyboard, a buffer, or a file, and output
3613streams (character sinks) send characters to a buffer, such as a
3614‘*Help*’ buffer, or to the echo area.
3615
3616   The object ‘nil’, in addition to its other meanings, may be used as a
3617stream.  It stands for the value of the variable ‘standard-input’ or
3618‘standard-output’.  Also, the object ‘t’ as a stream specifies input
3619using the minibuffer (*note Minibuffers::) or output in the echo area
3620(*note The Echo Area::).
3621
3622   Streams have no special printed representation or read syntax, and
3623print as whatever primitive type they are.
3624
3625   *Note Read and Print::, for a description of functions related to
3626streams, including parsing and printing functions.
3627
3628
3629File: elisp.info,  Node: Keymap Type,  Next: Overlay Type,  Prev: Stream Type,  Up: Editing Types
3630
36312.5.13 Keymap Type
3632------------------
3633
3634A “keymap” maps keys typed by the user to commands.  This mapping
3635controls how the user’s command input is executed.  A keymap is actually
3636a list whose CAR is the symbol ‘keymap’.
3637
3638   *Note Keymaps::, for information about creating keymaps, handling
3639prefix keys, local as well as global keymaps, and changing key bindings.
3640
3641
3642File: elisp.info,  Node: Overlay Type,  Next: Font Type,  Prev: Keymap Type,  Up: Editing Types
3643
36442.5.14 Overlay Type
3645-------------------
3646
3647An “overlay” specifies properties that apply to a part of a buffer.
3648Each overlay applies to a specified range of the buffer, and contains a
3649property list (a list whose elements are alternating property names and
3650values).  Overlay properties are used to present parts of the buffer
3651temporarily in a different display style.  Overlays have no read syntax,
3652and print in hash notation, giving the buffer name and range of
3653positions.
3654
3655   *Note Overlays::, for information on how you can create and use
3656overlays.
3657
3658
3659File: elisp.info,  Node: Font Type,  Prev: Overlay Type,  Up: Editing Types
3660
36612.5.15 Font Type
3662----------------
3663
3664A “font” specifies how to display text on a graphical terminal.  There
3665are actually three separate font types—“font objects”, “font specs”, and
3666“font entities”—each of which has slightly different properties.  None
3667of them have a read syntax; their print syntax looks like
3668‘#<font-object>’, ‘#<font-spec>’, and ‘#<font-entity>’ respectively.
3669*Note Low-Level Font::, for a description of these Lisp objects.
3670
3671
3672File: elisp.info,  Node: Circular Objects,  Next: Type Predicates,  Prev: Editing Types,  Up: Lisp Data Types
3673
36742.6 Read Syntax for Circular Objects
3675====================================
3676
3677To represent shared or circular structures within a complex of Lisp
3678objects, you can use the reader constructs ‘#N=’ and ‘#N#’.
3679
3680   Use ‘#N=’ before an object to label it for later reference;
3681subsequently, you can use ‘#N#’ to refer the same object in another
3682place.  Here, N is some integer.  For example, here is how to make a
3683list in which the first element recurs as the third element:
3684
3685     (#1=(a) b #1#)
3686
3687This differs from ordinary syntax such as this
3688
3689     ((a) b (a))
3690
3691which would result in a list whose first and third elements look alike
3692but are not the same Lisp object.  This shows the difference:
3693
3694     (prog1 nil
3695       (setq x '(#1=(a) b #1#)))
3696     (eq (nth 0 x) (nth 2 x))
3697          ⇒ t
3698     (setq x '((a) b (a)))
3699     (eq (nth 0 x) (nth 2 x))
3700          ⇒ nil
3701
3702   You can also use the same syntax to make a circular structure, which
3703appears as an element within itself.  Here is an example:
3704
3705     #1=(a #1#)
3706
3707This makes a list whose second element is the list itself.  Here’s how
3708you can see that it really works:
3709
3710     (prog1 nil
3711       (setq x '#1=(a #1#)))
3712     (eq x (cadr x))
3713          ⇒ t
3714
3715   The Lisp printer can produce this syntax to record circular and
3716shared structure in a Lisp object, if you bind the variable
3717‘print-circle’ to a non-‘nil’ value.  *Note Output Variables::.
3718
3719
3720File: elisp.info,  Node: Type Predicates,  Next: Equality Predicates,  Prev: Circular Objects,  Up: Lisp Data Types
3721
37222.7 Type Predicates
3723===================
3724
3725The Emacs Lisp interpreter itself does not perform type checking on the
3726actual arguments passed to functions when they are called.  It could not
3727do so, since function arguments in Lisp do not have declared data types,
3728as they do in other programming languages.  It is therefore up to the
3729individual function to test whether each actual argument belongs to a
3730type that the function can use.
3731
3732   All built-in functions do check the types of their actual arguments
3733when appropriate, and signal a ‘wrong-type-argument’ error if an
3734argument is of the wrong type.  For example, here is what happens if you
3735pass an argument to ‘+’ that it cannot handle:
3736
3737     (+ 2 'a)
3738          error→ Wrong type argument: number-or-marker-p, a
3739
3740   If you want your program to handle different types differently, you
3741must do explicit type checking.  The most common way to check the type
3742of an object is to call a “type predicate” function.  Emacs has a type
3743predicate for each type, as well as some predicates for combinations of
3744types.
3745
3746   A type predicate function takes one argument; it returns ‘t’ if the
3747argument belongs to the appropriate type, and ‘nil’ otherwise.
3748Following a general Lisp convention for predicate functions, most type
3749predicates’ names end with ‘p’.
3750
3751   Here is an example which uses the predicates ‘listp’ to check for a
3752list and ‘symbolp’ to check for a symbol.
3753
3754     (defun add-on (x)
3755       (cond ((symbolp x)
3756              ;; If X is a symbol, put it on LIST.
3757              (setq list (cons x list)))
3758             ((listp x)
3759              ;; If X is a list, add its elements to LIST.
3760              (setq list (append x list)))
3761             (t
3762              ;; We handle only symbols and lists.
3763              (error "Invalid argument %s in add-on" x))))
3764
3765   Here is a table of predefined type predicates, in alphabetical order,
3766with references to further information.
3767
3768‘atom’
3769     *Note atom: List-related Predicates.
3770
3771‘arrayp’
3772     *Note arrayp: Array Functions.
3773
3774‘bignump’
3775     *Note floatp: Predicates on Numbers.
3776
3777‘bool-vector-p’
3778     *Note bool-vector-p: Bool-Vectors.
3779
3780‘booleanp’
3781     *Note booleanp: nil and t.
3782
3783‘bufferp’
3784     *Note bufferp: Buffer Basics.
3785
3786‘byte-code-function-p’
3787     *Note byte-code-function-p: Byte-Code Type.
3788
3789‘case-table-p’
3790     *Note case-table-p: Case Tables.
3791
3792‘char-or-string-p’
3793     *Note char-or-string-p: Predicates for Strings.
3794
3795‘char-table-p’
3796     *Note char-table-p: Char-Tables.
3797
3798‘commandp’
3799     *Note commandp: Interactive Call.
3800
3801‘condition-variable-p’
3802     *Note condition-variable-p: Condition Variables.
3803
3804‘consp’
3805     *Note consp: List-related Predicates.
3806
3807‘custom-variable-p’
3808     *Note custom-variable-p: Variable Definitions.
3809
3810‘fixnump’
3811     *Note floatp: Predicates on Numbers.
3812
3813‘floatp’
3814     *Note floatp: Predicates on Numbers.
3815
3816‘fontp’
3817     *Note Low-Level Font::.
3818
3819‘frame-configuration-p’
3820     *Note frame-configuration-p: Frame Configurations.
3821
3822‘frame-live-p’
3823     *Note frame-live-p: Deleting Frames.
3824
3825‘framep’
3826     *Note framep: Frames.
3827
3828‘functionp’
3829     *Note functionp: Functions.
3830
3831‘hash-table-p’
3832     *Note hash-table-p: Other Hash.
3833
3834‘integer-or-marker-p’
3835     *Note integer-or-marker-p: Predicates on Markers.
3836
3837‘integerp’
3838     *Note integerp: Predicates on Numbers.
3839
3840‘keymapp’
3841     *Note keymapp: Creating Keymaps.
3842
3843‘keywordp’
3844     *Note Constant Variables::.
3845
3846‘listp’
3847     *Note listp: List-related Predicates.
3848
3849‘markerp’
3850     *Note markerp: Predicates on Markers.
3851
3852‘mutexp’
3853     *Note mutexp: Mutexes.
3854
3855‘nlistp’
3856     *Note nlistp: List-related Predicates.
3857
3858‘number-or-marker-p’
3859     *Note number-or-marker-p: Predicates on Markers.
3860
3861‘numberp’
3862     *Note numberp: Predicates on Numbers.
3863
3864‘overlayp’
3865     *Note overlayp: Overlays.
3866
3867‘processp’
3868     *Note processp: Processes.
3869
3870‘recordp’
3871     *Note recordp: Record Type.
3872
3873‘sequencep’
3874     *Note sequencep: Sequence Functions.
3875
3876‘string-or-null-p’
3877     *Note string-or-null-p: Predicates for Strings.
3878
3879‘stringp’
3880     *Note stringp: Predicates for Strings.
3881
3882‘subrp’
3883     *Note subrp: Function Cells.
3884
3885‘symbolp’
3886     *Note symbolp: Symbols.
3887
3888‘syntax-table-p’
3889     *Note syntax-table-p: Syntax Tables.
3890
3891‘threadp’
3892     *Note threadp: Basic Thread Functions.
3893
3894‘vectorp’
3895     *Note vectorp: Vectors.
3896
3897‘wholenump’
3898     *Note wholenump: Predicates on Numbers.
3899
3900‘window-configuration-p’
3901     *Note window-configuration-p: Window Configurations.
3902
3903‘window-live-p’
3904     *Note window-live-p: Deleting Windows.
3905
3906‘windowp’
3907     *Note windowp: Basic Windows.
3908
3909   The most general way to check the type of an object is to call the
3910function ‘type-of’.  Recall that each object belongs to one and only one
3911primitive type; ‘type-of’ tells you which one (*note Lisp Data Types::).
3912But ‘type-of’ knows nothing about non-primitive types.  In most cases,
3913it is more convenient to use type predicates than ‘type-of’.
3914
3915 -- Function: type-of object
3916     This function returns a symbol naming the primitive type of OBJECT.
3917     The value is one of the symbols ‘bool-vector’, ‘buffer’,
3918     ‘char-table’, ‘compiled-function’, ‘condition-variable’, ‘cons’,
3919     ‘finalizer’, ‘float’, ‘font-entity’, ‘font-object’, ‘font-spec’,
3920     ‘frame’, ‘hash-table’, ‘integer’, ‘marker’, ‘mutex’, ‘overlay’,
3921     ‘process’, ‘string’, ‘subr’, ‘symbol’, ‘thread’, ‘vector’,
3922     ‘window’, or ‘window-configuration’.  However, if OBJECT is a
3923     record, the type specified by its first slot is returned; *note
3924     Records::.
3925
3926          (type-of 1)
3927               ⇒ integer
3928          (type-of 'nil)
3929               ⇒ symbol
3930          (type-of '())    ; ‘()’ is ‘nil’.
3931               ⇒ symbol
3932          (type-of '(x))
3933               ⇒ cons
3934          (type-of (record 'foo))
3935               ⇒ foo
3936
3937
3938File: elisp.info,  Node: Equality Predicates,  Next: Mutability,  Prev: Type Predicates,  Up: Lisp Data Types
3939
39402.8 Equality Predicates
3941=======================
3942
3943Here we describe functions that test for equality between two objects.
3944Other functions test equality of contents between objects of specific
3945types, e.g., strings.  For these predicates, see the appropriate chapter
3946describing the data type.
3947
3948 -- Function: eq object1 object2
3949     This function returns ‘t’ if OBJECT1 and OBJECT2 are the same
3950     object, and ‘nil’ otherwise.
3951
3952     If OBJECT1 and OBJECT2 are symbols with the same name, they are
3953     normally the same object—but see *note Creating Symbols:: for
3954     exceptions.  For other non-numeric types (e.g., lists, vectors,
3955     strings), two arguments with the same contents or elements are not
3956     necessarily ‘eq’ to each other: they are ‘eq’ only if they are the
3957     same object, meaning that a change in the contents of one will be
3958     reflected by the same change in the contents of the other.
3959
3960     If OBJECT1 and OBJECT2 are numbers with differing types or values,
3961     then they cannot be the same object and ‘eq’ returns ‘nil’.  If
3962     they are fixnums with the same value, then they are the same object
3963     and ‘eq’ returns ‘t’.  If they were computed separately but happen
3964     to have the same value and the same non-fixnum numeric type, then
3965     they might or might not be the same object, and ‘eq’ returns ‘t’ or
3966     ‘nil’ depending on whether the Lisp interpreter created one object
3967     or two.
3968
3969          (eq 'foo 'foo)
3970               ⇒ t
3971
3972          (eq ?A ?A)
3973               ⇒ t
3974
3975          (eq 3.0 3.0)
3976               ⇒ t or nil
3977          ;; Equal floats may or may not be the same object.
3978
3979          (eq (make-string 3 ?A) (make-string 3 ?A))
3980               ⇒ nil
3981
3982          (eq "asdf" "asdf")
3983               ⇒ t or nil
3984          ;; Equal string constants or may not be the same object.
3985
3986          (eq '(1 (2 (3))) '(1 (2 (3))))
3987               ⇒ nil
3988
3989          (setq foo '(1 (2 (3))))
3990               ⇒ (1 (2 (3)))
3991          (eq foo foo)
3992               ⇒ t
3993          (eq foo '(1 (2 (3))))
3994               ⇒ nil
3995
3996          (eq [(1 2) 3] [(1 2) 3])
3997               ⇒ nil
3998
3999          (eq (point-marker) (point-marker))
4000               ⇒ nil
4001
4002     The ‘make-symbol’ function returns an uninterned symbol, distinct
4003     from the symbol that is used if you write the name in a Lisp
4004     expression.  Distinct symbols with the same name are not ‘eq’.
4005     *Note Creating Symbols::.
4006
4007          (eq (make-symbol "foo") 'foo)
4008               ⇒ nil
4009
4010     The Emacs Lisp byte compiler may collapse identical literal
4011     objects, such as literal strings, into references to the same
4012     object, with the effect that the byte-compiled code will compare
4013     such objects as ‘eq’, while the interpreted version of the same
4014     code will not.  Therefore, your code should never rely on objects
4015     with the same literal contents being either ‘eq’ or not ‘eq’, it
4016     should instead use functions that compare object contents such as
4017     ‘equal’, described below.  Similarly, your code should not modify
4018     literal objects (e.g., put text properties on literal strings),
4019     since doing that might affect other literal objects of the same
4020     contents, if the byte compiler collapses them.
4021
4022 -- Function: equal object1 object2
4023     This function returns ‘t’ if OBJECT1 and OBJECT2 have equal
4024     components, and ‘nil’ otherwise.  Whereas ‘eq’ tests if its
4025     arguments are the same object, ‘equal’ looks inside nonidentical
4026     arguments to see if their elements or contents are the same.  So,
4027     if two objects are ‘eq’, they are ‘equal’, but the converse is not
4028     always true.
4029
4030          (equal 'foo 'foo)
4031               ⇒ t
4032
4033          (equal 456 456)
4034               ⇒ t
4035
4036          (equal "asdf" "asdf")
4037               ⇒ t
4038          (eq "asdf" "asdf")
4039               ⇒ nil
4040
4041          (equal '(1 (2 (3))) '(1 (2 (3))))
4042               ⇒ t
4043          (eq '(1 (2 (3))) '(1 (2 (3))))
4044               ⇒ nil
4045
4046          (equal [(1 2) 3] [(1 2) 3])
4047               ⇒ t
4048          (eq [(1 2) 3] [(1 2) 3])
4049               ⇒ nil
4050
4051          (equal (point-marker) (point-marker))
4052               ⇒ t
4053
4054          (eq (point-marker) (point-marker))
4055               ⇒ nil
4056
4057     Comparison of strings is case-sensitive, but does not take account
4058     of text properties—it compares only the characters in the strings.
4059     *Note Text Properties::.  Use ‘equal-including-properties’ to also
4060     compare text properties.  For technical reasons, a unibyte string
4061     and a multibyte string are ‘equal’ if and only if they contain the
4062     same sequence of character codes and all these codes are in the
4063     range 0 through 127 (ASCII).
4064
4065          (equal "asdf" "ASDF")
4066               ⇒ nil
4067
4068     However, two distinct buffers are never considered ‘equal’, even if
4069     their textual contents are the same.
4070
4071   For ‘equal’, equality is defined recursively; for example, given two
4072cons cells X and Y, ‘(equal X Y)’ returns ‘t’ if and only if both the
4073expressions below return ‘t’:
4074
4075     (equal (car X) (car Y))
4076     (equal (cdr X) (cdr Y))
4077
4078   Comparing circular lists may therefore cause deep recursion that
4079leads to an error, and this may result in counterintuitive behavior such
4080as ‘(equal a b)’ returning ‘t’ whereas ‘(equal b a)’ signals an error.
4081
4082 -- Function: equal-including-properties object1 object2
4083     This function behaves like ‘equal’ in all cases but also requires
4084     that for two strings to be equal, they have the same text
4085     properties.
4086
4087          (equal "asdf" (propertize "asdf" 'asdf t))
4088               ⇒ t
4089          (equal-including-properties "asdf"
4090                                      (propertize "asdf" 'asdf t))
4091               ⇒ nil
4092
4093
4094File: elisp.info,  Node: Mutability,  Prev: Equality Predicates,  Up: Lisp Data Types
4095
40962.9 Mutability
4097==============
4098
4099Some Lisp objects should never change.  For example, the Lisp expression
4100‘"aaa"’ yields a string, but you should not change its contents.  And
4101some objects cannot be changed; for example, although you can create a
4102new number by calculating one, Lisp provides no operation to change the
4103value of an existing number.
4104
4105   Other Lisp objects are “mutable”: it is safe to change their values
4106via destructive operations involving side effects.  For example, an
4107existing marker can be changed by moving the marker to point to
4108somewhere else.
4109
4110   Although numbers never change and all markers are mutable, some types
4111have members some of which are mutable and others not.  These types
4112include conses, vectors, and strings.  For example, although ‘"cons"’
4113and ‘(symbol-name 'cons)’ both yield strings that should not be changed,
4114‘(copy-sequence "cons")’ and ‘(make-string 3 ?a)’ both yield mutable
4115strings that can be changed via later calls to ‘aset’.
4116
4117   A mutable object stops being mutable if it is part of an expression
4118that is evaluated.  For example:
4119
4120     (let* ((x (list 0.5))
4121            (y (eval (list 'quote x))))
4122       (setcar x 1.5) ;; The program should not do this.
4123       y)
4124
4125Although the list ‘(0.5)’ was mutable when it was created, it should not
4126have been changed via ‘setcar’ because it given to ‘eval’.  The reverse
4127does not occur: an object that should not be changed never becomes
4128mutable afterwards.
4129
4130   If a program attempts to change objects that should not be changed,
4131the resulting behavior is undefined: the Lisp interpreter might signal
4132an error, or it might crash or behave unpredictably in other ways.(1)
4133
4134   When similar constants occur as parts of a program, the Lisp
4135interpreter might save time or space by reusing existing constants or
4136their components.  For example, ‘(eq "abc" "abc")’ returns ‘t’ if the
4137interpreter creates only one instance of the string literal ‘"abc"’, and
4138returns ‘nil’ if it creates two instances.  Lisp programs should be
4139written so that they work regardless of whether this optimization is in
4140use.
4141
4142   ---------- Footnotes ----------
4143
4144   (1) This is the behavior specified for languages like Common Lisp and
4145C for constants, and this differs from languages like JavaScript and
4146Python where an interpreter is required to signal an error if a program
4147attempts to change an immutable object.  Ideally the Emacs Lisp
4148interpreter will evolve in latter direction.
4149
4150
4151File: elisp.info,  Node: Numbers,  Next: Strings and Characters,  Prev: Lisp Data Types,  Up: Top
4152
41533 Numbers
4154*********
4155
4156GNU Emacs supports two numeric data types: “integers” and
4157“floating-point numbers”.  Integers are whole numbers such as −3, 0, 7,
415813, and 511.  Floating-point numbers are numbers with fractional parts,
4159such as −4.5, 0.0, and 2.71828.  They can also be expressed in
4160exponential notation: ‘1.5e2’ is the same as ‘150.0’; here, ‘e2’ stands
4161for ten to the second power, and that is multiplied by 1.5.  Integer
4162computations are exact.  Floating-point computations often involve
4163rounding errors, as the numbers have a fixed amount of precision.
4164
4165* Menu:
4166
4167* Integer Basics::            Representation and range of integers.
4168* Float Basics::              Representation and range of floating point.
4169* Predicates on Numbers::     Testing for numbers.
4170* Comparison of Numbers::     Equality and inequality predicates.
4171* Numeric Conversions::       Converting float to integer and vice versa.
4172* Arithmetic Operations::     How to add, subtract, multiply and divide.
4173* Rounding Operations::       Explicitly rounding floating-point numbers.
4174* Bitwise Operations::        Logical and, or, not, shifting.
4175* Math Functions::            Trig, exponential and logarithmic functions.
4176* Random Numbers::            Obtaining random integers, predictable or not.
4177
4178
4179File: elisp.info,  Node: Integer Basics,  Next: Float Basics,  Up: Numbers
4180
41813.1 Integer Basics
4182==================
4183
4184The Lisp reader reads an integer as a nonempty sequence of decimal
4185digits with optional initial sign and optional final period.
4186
4187      1               ; The integer 1.
4188      1.              ; The integer 1.
4189     +1               ; Also the integer 1.
4190     -1               ; The integer −1.
4191      0               ; The integer 0.
4192     -0               ; The integer 0.
4193
4194   The syntax for integers in bases other than 10 consists of ‘#’
4195followed by a radix indication followed by one or more digits.  The
4196radix indications are ‘b’ for binary, ‘o’ for octal, ‘x’ for hex, and
4197‘RADIXr’ for radix RADIX.  Thus, ‘#bINTEGER’ reads INTEGER in binary,
4198and ‘#RADIXrINTEGER’ reads INTEGER in radix RADIX.  Allowed values of
4199RADIX run from 2 to 36, and allowed digits are the first RADIX
4200characters taken from ‘0’–‘9’, ‘A’–‘Z’.  Letter case is ignored and
4201there is no initial sign or final period.  For example:
4202
4203     #b101100 ⇒ 44
4204     #o54 ⇒ 44
4205     #x2c ⇒ 44
4206     #24r1k ⇒ 44
4207
4208   To understand how various functions work on integers, especially the
4209bitwise operators (*note Bitwise Operations::), it is often helpful to
4210view the numbers in their binary form.
4211
4212   In binary, the decimal integer 5 looks like this:
4213
4214     ...000101
4215
4216(The ellipsis ‘...’ stands for a conceptually infinite number of bits
4217that match the leading bit; here, an infinite number of 0 bits.  Later
4218examples also use this ‘...’ notation.)
4219
4220   The integer −1 looks like this:
4221
4222     ...111111
4223
4224−1 is represented as all ones.  (This is called “two’s complement”
4225notation.)
4226
4227   Subtracting 4 from −1 returns the negative integer −5.  In binary,
4228the decimal integer 4 is 100.  Consequently, −5 looks like this:
4229
4230     ...111011
4231
4232   Many of the functions described in this chapter accept markers for
4233arguments in place of numbers.  (*Note Markers::.)  Since the actual
4234arguments to such functions may be either numbers or markers, we often
4235give these arguments the name NUMBER-OR-MARKER.  When the argument value
4236is a marker, its position value is used and its buffer is ignored.
4237
4238   In Emacs Lisp, text characters are represented by integers.  Any
4239integer between zero and the value of ‘(max-char)’, inclusive, is
4240considered to be valid as a character.  *Note Character Codes::.
4241
4242   Integers in Emacs Lisp are not limited to the machine word size.
4243Under the hood, though, there are two kinds of integers: smaller ones,
4244called “fixnums”, and larger ones, called “bignums”.  Although Emacs
4245Lisp code ordinarily should not depend on whether an integer is a fixnum
4246or a bignum, older Emacs versions support only fixnums, some functions
4247in Emacs still accept only fixnums, and older Emacs Lisp code may have
4248trouble when given bignums.  For example, while older Emacs Lisp code
4249could safely compare integers for numeric equality with ‘eq’, the
4250presence of bignums means that equality predicates like ‘eql’ and ‘=’
4251should now be used to compare integers.
4252
4253   The range of values for bignums is limited by the amount of main
4254memory, by machine characteristics such as the size of the word used to
4255represent a bignum’s exponent, and by the ‘integer-width’ variable.
4256These limits are typically much more generous than the limits for
4257fixnums.  A bignum is never numerically equal to a fixnum; Emacs always
4258represents an integer in fixnum range as a fixnum, not a bignum.
4259
4260   The range of values for a fixnum depends on the machine.  The minimum
4261range is −536,870,912 to 536,870,911 (30 bits; i.e., −2**29 to 2**29 −
42621), but many machines provide a wider range.
4263
4264 -- Variable: most-positive-fixnum
4265     The value of this variable is the greatest “small” integer that
4266     Emacs Lisp can handle.  Typical values are 2**29 − 1 on 32-bit and
4267     2**61 − 1 on 64-bit platforms.
4268
4269 -- Variable: most-negative-fixnum
4270     The value of this variable is the numerically least “small” integer
4271     that Emacs Lisp can handle.  It is negative.  Typical values are
4272     −2**29 on 32-bit and −2**61 on 64-bit platforms.
4273
4274 -- Variable: integer-width
4275     The value of this variable is a nonnegative integer that controls
4276     whether Emacs signals a range error when a large integer would be
4277     calculated.  Integers with absolute values less than 2**N, where N
4278     is this variable’s value, do not signal a range error.  Attempts to
4279     create larger integers typically signal a range error, although
4280     there might be no signal if a larger integer can be created
4281     cheaply.  Setting this variable to a large number can be costly if
4282     a computation creates huge integers.
4283
4284
4285File: elisp.info,  Node: Float Basics,  Next: Predicates on Numbers,  Prev: Integer Basics,  Up: Numbers
4286
42873.2 Floating-Point Basics
4288=========================
4289
4290Floating-point numbers are useful for representing numbers that are not
4291integral.  The range of floating-point numbers is the same as the range
4292of the C data type ‘double’ on the machine you are using.  On all
4293computers supported by Emacs, this is IEEE binary64 floating point
4294format, which is standardized by IEEE Std 754-2019 and is discussed
4295further in David Goldberg’s paper “What Every Computer Scientist Should
4296Know About Floating-Point Arithmetic
4297(https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)”.  On
4298modern platforms, floating-point operations follow the IEEE-754 standard
4299closely; however, results are not always rounded correctly on some
4300obsolescent platforms, notably 32-bit x86.
4301
4302   The read syntax for floating-point numbers requires either a decimal
4303point, an exponent, or both.  Optional signs (‘+’ or ‘-’) precede the
4304number and its exponent.  For example, ‘1500.0’, ‘+15e2’, ‘15.0e+2’,
4305‘+1500000e-3’, and ‘.15e4’ are five ways of writing a floating-point
4306number whose value is 1500.  They are all equivalent.  Like Common Lisp,
4307Emacs Lisp requires at least one digit after any decimal point in a
4308floating-point number; ‘1500.’ is an integer, not a floating-point
4309number.
4310
4311   Emacs Lisp treats ‘-0.0’ as numerically equal to ordinary zero with
4312respect to numeric comparisons like ‘=’.  This follows the IEEE
4313floating-point standard, which says ‘-0.0’ and ‘0.0’ are numerically
4314equal even though other operations can distinguish them.
4315
4316   The IEEE floating-point standard supports positive infinity and
4317negative infinity as floating-point values.  It also provides for a
4318class of values called NaN, or “not a number”; numerical functions
4319return such values in cases where there is no correct answer.  For
4320example, ‘(/ 0.0 0.0)’ returns a NaN.  A NaN is never numerically equal
4321to any value, not even to itself.  NaNs carry a sign and a significand,
4322and non-numeric functions treat two NaNs as equal when their signs and
4323significands agree.  Significands of NaNs are machine-dependent, as are
4324the digits in their string representation.
4325
4326   When NaNs and signed zeros are involved, non-numeric functions like
4327‘eql’, ‘equal’, ‘sxhash-eql’, ‘sxhash-equal’ and ‘gethash’ determine
4328whether values are indistinguishable, not whether they are numerically
4329equal.  For example, when X and Y are the same NaN, ‘(equal x y)’
4330returns ‘t’ whereas ‘(= x y)’ uses numeric comparison and returns ‘nil’;
4331conversely, ‘(equal 0.0 -0.0)’ returns ‘nil’ whereas ‘(= 0.0 -0.0)’
4332returns ‘t’.
4333
4334   Here are read syntaxes for these special floating-point values:
4335
4336infinity
4337     ‘1.0e+INF’ and ‘-1.0e+INF’
4338not-a-number
4339     ‘0.0e+NaN’ and ‘-0.0e+NaN’
4340
4341   The following functions are specialized for handling floating-point
4342numbers:
4343
4344 -- Function: isnan x
4345     This predicate returns ‘t’ if its floating-point argument is a NaN,
4346     ‘nil’ otherwise.
4347
4348 -- Function: frexp x
4349     This function returns a cons cell ‘(S . E)’, where S and E are
4350     respectively the significand and exponent of the floating-point
4351     number X.
4352
4353     If X is finite, then S is a floating-point number between 0.5
4354     (inclusive) and 1.0 (exclusive), E is an integer, and X = S * 2**E.
4355     If X is zero or infinity, then S is the same as X.  If X is a NaN,
4356     then S is also a NaN.  If X is zero, then E is 0.
4357
4358 -- Function: ldexp s e
4359     Given a numeric significand S and an integer exponent E, this
4360     function returns the floating point number S * 2**E.
4361
4362 -- Function: copysign x1 x2
4363     This function copies the sign of X2 to the value of X1, and returns
4364     the result.  X1 and X2 must be floating point.
4365
4366 -- Function: logb x
4367     This function returns the binary exponent of X.  More precisely, if
4368     X is finite and nonzero, the value is the logarithm base 2 of |x|,
4369     rounded down to an integer.  If X is zero or infinite, the value is
4370     infinity; if X is a NaN, the value is a NaN.
4371
4372          (logb 10)
4373               ⇒ 3
4374          (logb 10.0e20)
4375               ⇒ 69
4376          (logb 0)
4377               ⇒ -1.0e+INF
4378
4379
4380File: elisp.info,  Node: Predicates on Numbers,  Next: Comparison of Numbers,  Prev: Float Basics,  Up: Numbers
4381
43823.3 Type Predicates for Numbers
4383===============================
4384
4385The functions in this section test for numbers, or for a specific type
4386of number.  The functions ‘integerp’ and ‘floatp’ can take any type of
4387Lisp object as argument (they would not be of much use otherwise), but
4388the ‘zerop’ predicate requires a number as its argument.  See also
4389‘integer-or-marker-p’ and ‘number-or-marker-p’, in *note Predicates on
4390Markers::.
4391
4392 -- Function: bignump object
4393     This predicate tests whether its argument is a large integer, and
4394     returns ‘t’ if so, ‘nil’ otherwise.  Unlike small integers, large
4395     integers can be ‘=’ or ‘eql’ even if they are not ‘eq’.
4396
4397 -- Function: fixnump object
4398     This predicate tests whether its argument is a small integer, and
4399     returns ‘t’ if so, ‘nil’ otherwise.  Small integers can be compared
4400     with ‘eq’.
4401
4402 -- Function: floatp object
4403     This predicate tests whether its argument is floating point and
4404     returns ‘t’ if so, ‘nil’ otherwise.
4405
4406 -- Function: integerp object
4407     This predicate tests whether its argument is an integer, and
4408     returns ‘t’ if so, ‘nil’ otherwise.
4409
4410 -- Function: numberp object
4411     This predicate tests whether its argument is a number (either
4412     integer or floating point), and returns ‘t’ if so, ‘nil’ otherwise.
4413
4414 -- Function: natnump object
4415     This predicate (whose name comes from the phrase “natural number”)
4416     tests to see whether its argument is a nonnegative integer, and
4417     returns ‘t’ if so, ‘nil’ otherwise.  0 is considered non-negative.
4418
4419     ‘wholenump’ is a synonym for ‘natnump’.
4420
4421 -- Function: zerop number
4422     This predicate tests whether its argument is zero, and returns ‘t’
4423     if so, ‘nil’ otherwise.  The argument must be a number.
4424
4425     ‘(zerop x)’ is equivalent to ‘(= x 0)’.
4426
4427
4428File: elisp.info,  Node: Comparison of Numbers,  Next: Numeric Conversions,  Prev: Predicates on Numbers,  Up: Numbers
4429
44303.4 Comparison of Numbers
4431=========================
4432
4433To test numbers for numerical equality, you should normally use ‘=’
4434instead of non-numeric comparison predicates like ‘eq’, ‘eql’ and
4435‘equal’.  Distinct floating-point and large integer objects can be
4436numerically equal.  If you use ‘eq’ to compare them, you test whether
4437they are the same _object_; if you use ‘eql’ or ‘equal’, you test
4438whether their values are _indistinguishable_.  In contrast, ‘=’ uses
4439numeric comparison, and sometimes returns ‘t’ when a non-numeric
4440comparison would return ‘nil’ and vice versa.  *Note Float Basics::.
4441
4442   In Emacs Lisp, if two fixnums are numerically equal, they are the
4443same Lisp object.  That is, ‘eq’ is equivalent to ‘=’ on fixnums.  It is
4444sometimes convenient to use ‘eq’ for comparing an unknown value with a
4445fixnum, because ‘eq’ does not report an error if the unknown value is
4446not a number—it accepts arguments of any type.  By contrast, ‘=’ signals
4447an error if the arguments are not numbers or markers.  However, it is
4448better programming practice to use ‘=’ if you can, even for comparing
4449integers.
4450
4451   Sometimes it is useful to compare numbers with ‘eql’ or ‘equal’,
4452which treat two numbers as equal if they have the same data type (both
4453integers, or both floating point) and the same value.  By contrast, ‘=’
4454can treat an integer and a floating-point number as equal.  *Note
4455Equality Predicates::.
4456
4457   There is another wrinkle: because floating-point arithmetic is not
4458exact, it is often a bad idea to check for equality of floating-point
4459values.  Usually it is better to test for approximate equality.  Here’s
4460a function to do this:
4461
4462     (defvar fuzz-factor 1.0e-6)
4463     (defun approx-equal (x y)
4464       (or (= x y)
4465           (< (/ (abs (- x y))
4466                 (max (abs x) (abs y)))
4467              fuzz-factor)))
4468
4469 -- Function: = number-or-marker &rest number-or-markers
4470     This function tests whether all its arguments are numerically
4471     equal, and returns ‘t’ if so, ‘nil’ otherwise.
4472
4473 -- Function: eql value1 value2
4474     This function acts like ‘eq’ except when both arguments are
4475     numbers.  It compares numbers by type and numeric value, so that
4476     ‘(eql 1.0 1)’ returns ‘nil’, but ‘(eql 1.0 1.0)’ and ‘(eql 1 1)’
4477     both return ‘t’.  This can be used to compare large integers as
4478     well as small ones.
4479
4480 -- Function: /= number-or-marker1 number-or-marker2
4481     This function tests whether its arguments are numerically equal,
4482     and returns ‘t’ if they are not, and ‘nil’ if they are.
4483
4484 -- Function: < number-or-marker &rest number-or-markers
4485     This function tests whether each argument is strictly less than the
4486     following argument.  It returns ‘t’ if so, ‘nil’ otherwise.
4487
4488 -- Function: <= number-or-marker &rest number-or-markers
4489     This function tests whether each argument is less than or equal to
4490     the following argument.  It returns ‘t’ if so, ‘nil’ otherwise.
4491
4492 -- Function: > number-or-marker &rest number-or-markers
4493     This function tests whether each argument is strictly greater than
4494     the following argument.  It returns ‘t’ if so, ‘nil’ otherwise.
4495
4496 -- Function: >= number-or-marker &rest number-or-markers
4497     This function tests whether each argument is greater than or equal
4498     to the following argument.  It returns ‘t’ if so, ‘nil’ otherwise.
4499
4500 -- Function: max number-or-marker &rest numbers-or-markers
4501     This function returns the largest of its arguments.
4502
4503          (max 20)
4504               ⇒ 20
4505          (max 1 2.5)
4506               ⇒ 2.5
4507          (max 1 3 2.5)
4508               ⇒ 3
4509
4510 -- Function: min number-or-marker &rest numbers-or-markers
4511     This function returns the smallest of its arguments.
4512
4513          (min -4 1)
4514               ⇒ -4
4515
4516 -- Function: abs number
4517     This function returns the absolute value of NUMBER.
4518
4519
4520File: elisp.info,  Node: Numeric Conversions,  Next: Arithmetic Operations,  Prev: Comparison of Numbers,  Up: Numbers
4521
45223.5 Numeric Conversions
4523=======================
4524
4525To convert an integer to floating point, use the function ‘float’.
4526
4527 -- Function: float number
4528     This returns NUMBER converted to floating point.  If NUMBER is
4529     already floating point, ‘float’ returns it unchanged.
4530
4531   There are four functions to convert floating-point numbers to
4532integers; they differ in how they round.  All accept an argument NUMBER
4533and an optional argument DIVISOR.  Both arguments may be integers or
4534floating-point numbers.  DIVISOR may also be ‘nil’.  If DIVISOR is ‘nil’
4535or omitted, these functions convert NUMBER to an integer, or return it
4536unchanged if it already is an integer.  If DIVISOR is non-‘nil’, they
4537divide NUMBER by DIVISOR and convert the result to an integer.  If
4538DIVISOR is zero (whether integer or floating point), Emacs signals an
4539‘arith-error’ error.
4540
4541 -- Function: truncate number &optional divisor
4542     This returns NUMBER, converted to an integer by rounding towards
4543     zero.
4544
4545          (truncate 1.2)
4546               ⇒ 1
4547          (truncate 1.7)
4548               ⇒ 1
4549          (truncate -1.2)
4550               ⇒ -1
4551          (truncate -1.7)
4552               ⇒ -1
4553
4554 -- Function: floor number &optional divisor
4555     This returns NUMBER, converted to an integer by rounding downward
4556     (towards negative infinity).
4557
4558     If DIVISOR is specified, this uses the kind of division operation
4559     that corresponds to ‘mod’, rounding downward.
4560
4561          (floor 1.2)
4562               ⇒ 1
4563          (floor 1.7)
4564               ⇒ 1
4565          (floor -1.2)
4566               ⇒ -2
4567          (floor -1.7)
4568               ⇒ -2
4569          (floor 5.99 3)
4570               ⇒ 1
4571
4572 -- Function: ceiling number &optional divisor
4573     This returns NUMBER, converted to an integer by rounding upward
4574     (towards positive infinity).
4575
4576          (ceiling 1.2)
4577               ⇒ 2
4578          (ceiling 1.7)
4579               ⇒ 2
4580          (ceiling -1.2)
4581               ⇒ -1
4582          (ceiling -1.7)
4583               ⇒ -1
4584
4585 -- Function: round number &optional divisor
4586     This returns NUMBER, converted to an integer by rounding towards
4587     the nearest integer.  Rounding a value equidistant between two
4588     integers returns the even integer.
4589
4590          (round 1.2)
4591               ⇒ 1
4592          (round 1.7)
4593               ⇒ 2
4594          (round -1.2)
4595               ⇒ -1
4596          (round -1.7)
4597               ⇒ -2
4598
4599
4600File: elisp.info,  Node: Arithmetic Operations,  Next: Rounding Operations,  Prev: Numeric Conversions,  Up: Numbers
4601
46023.6 Arithmetic Operations
4603=========================
4604
4605Emacs Lisp provides the traditional four arithmetic operations
4606(addition, subtraction, multiplication, and division), as well as
4607remainder and modulus functions, and functions to add or subtract 1.
4608Except for ‘%’, each of these functions accepts both integer and
4609floating-point arguments, and returns a floating-point number if any
4610argument is floating point.
4611
4612 -- Function: 1+ number-or-marker
4613     This function returns NUMBER-OR-MARKER plus 1.  For example,
4614
4615          (setq foo 4)
4616               ⇒ 4
4617          (1+ foo)
4618               ⇒ 5
4619
4620     This function is not analogous to the C operator ‘++’—it does not
4621     increment a variable.  It just computes a sum.  Thus, if we
4622     continue,
4623
4624          foo
4625               ⇒ 4
4626
4627     If you want to increment the variable, you must use ‘setq’, like
4628     this:
4629
4630          (setq foo (1+ foo))
4631               ⇒ 5
4632
4633 -- Function: 1- number-or-marker
4634     This function returns NUMBER-OR-MARKER minus 1.
4635
4636 -- Function: + &rest numbers-or-markers
4637     This function adds its arguments together.  When given no
4638     arguments, ‘+’ returns 0.
4639
4640          (+)
4641               ⇒ 0
4642          (+ 1)
4643               ⇒ 1
4644          (+ 1 2 3 4)
4645               ⇒ 10
4646
4647 -- Function: - &optional number-or-marker &rest more-numbers-or-markers
4648     The ‘-’ function serves two purposes: negation and subtraction.
4649     When ‘-’ has a single argument, the value is the negative of the
4650     argument.  When there are multiple arguments, ‘-’ subtracts each of
4651     the MORE-NUMBERS-OR-MARKERS from NUMBER-OR-MARKER, cumulatively.
4652     If there are no arguments, the result is 0.
4653
4654          (- 10 1 2 3 4)
4655               ⇒ 0
4656          (- 10)
4657               ⇒ -10
4658          (-)
4659               ⇒ 0
4660
4661 -- Function: * &rest numbers-or-markers
4662     This function multiplies its arguments together, and returns the
4663     product.  When given no arguments, ‘*’ returns 1.
4664
4665          (*)
4666               ⇒ 1
4667          (* 1)
4668               ⇒ 1
4669          (* 1 2 3 4)
4670               ⇒ 24
4671
4672 -- Function: / number &rest divisors
4673     With one or more DIVISORS, this function divides NUMBER by each
4674     divisor in DIVISORS in turn, and returns the quotient.  With no
4675     DIVISORS, this function returns 1/NUMBER, i.e., the multiplicative
4676     inverse of NUMBER.  Each argument may be a number or a marker.
4677
4678     If all the arguments are integers, the result is an integer,
4679     obtained by rounding the quotient towards zero after each division.
4680
4681          (/ 6 2)
4682               ⇒ 3
4683          (/ 5 2)
4684               ⇒ 2
4685          (/ 5.0 2)
4686               ⇒ 2.5
4687          (/ 5 2.0)
4688               ⇒ 2.5
4689          (/ 5.0 2.0)
4690               ⇒ 2.5
4691          (/ 4.0)
4692               ⇒ 0.25
4693          (/ 4)
4694               ⇒ 0
4695          (/ 25 3 2)
4696               ⇒ 4
4697          (/ -17 6)
4698               ⇒ -2
4699
4700     If you divide an integer by the integer 0, Emacs signals an
4701     ‘arith-error’ error (*note Errors::).  Floating-point division of a
4702     nonzero number by zero yields either positive or negative infinity
4703     (*note Float Basics::).
4704
4705 -- Function: % dividend divisor
4706     This function returns the integer remainder after division of
4707     DIVIDEND by DIVISOR.  The arguments must be integers or markers.
4708
4709     For any two integers DIVIDEND and DIVISOR,
4710
4711          (+ (% DIVIDEND DIVISOR)
4712             (* (/ DIVIDEND DIVISOR) DIVISOR))
4713
4714     always equals DIVIDEND if DIVISOR is nonzero.
4715
4716          (% 9 4)
4717               ⇒ 1
4718          (% -9 4)
4719               ⇒ -1
4720          (% 9 -4)
4721               ⇒ 1
4722          (% -9 -4)
4723               ⇒ -1
4724
4725 -- Function: mod dividend divisor
4726     This function returns the value of DIVIDEND modulo DIVISOR; in
4727     other words, the remainder after division of DIVIDEND by DIVISOR,
4728     but with the same sign as DIVISOR.  The arguments must be numbers
4729     or markers.
4730
4731     Unlike ‘%’, ‘mod’ permits floating-point arguments; it rounds the
4732     quotient downward (towards minus infinity) to an integer, and uses
4733     that quotient to compute the remainder.
4734
4735     If DIVISOR is zero, ‘mod’ signals an ‘arith-error’ error if both
4736     arguments are integers, and returns a NaN otherwise.
4737
4738          (mod 9 4)
4739               ⇒ 1
4740          (mod -9 4)
4741               ⇒ 3
4742          (mod 9 -4)
4743               ⇒ -3
4744          (mod -9 -4)
4745               ⇒ -1
4746          (mod 5.5 2.5)
4747               ⇒ .5
4748
4749     For any two numbers DIVIDEND and DIVISOR,
4750
4751          (+ (mod DIVIDEND DIVISOR)
4752             (* (floor DIVIDEND DIVISOR) DIVISOR))
4753
4754     always equals DIVIDEND, subject to rounding error if either
4755     argument is floating point and to an ‘arith-error’ if DIVIDEND is
4756     an integer and DIVISOR is 0.  For ‘floor’, see *note Numeric
4757     Conversions::.
4758
4759
4760File: elisp.info,  Node: Rounding Operations,  Next: Bitwise Operations,  Prev: Arithmetic Operations,  Up: Numbers
4761
47623.7 Rounding Operations
4763=======================
4764
4765The functions ‘ffloor’, ‘fceiling’, ‘fround’, and ‘ftruncate’ take a
4766floating-point argument and return a floating-point result whose value
4767is a nearby integer.  ‘ffloor’ returns the nearest integer below;
4768‘fceiling’, the nearest integer above; ‘ftruncate’, the nearest integer
4769in the direction towards zero; ‘fround’, the nearest integer.
4770
4771 -- Function: ffloor float
4772     This function rounds FLOAT to the next lower integral value, and
4773     returns that value as a floating-point number.
4774
4775 -- Function: fceiling float
4776     This function rounds FLOAT to the next higher integral value, and
4777     returns that value as a floating-point number.
4778
4779 -- Function: ftruncate float
4780     This function rounds FLOAT towards zero to an integral value, and
4781     returns that value as a floating-point number.
4782
4783 -- Function: fround float
4784     This function rounds FLOAT to the nearest integral value, and
4785     returns that value as a floating-point number.  Rounding a value
4786     equidistant between two integers returns the even integer.
4787
4788
4789File: elisp.info,  Node: Bitwise Operations,  Next: Math Functions,  Prev: Rounding Operations,  Up: Numbers
4790
47913.8 Bitwise Operations on Integers
4792==================================
4793
4794In a computer, an integer is represented as a binary number, a sequence
4795of “bits” (digits which are either zero or one).  Conceptually the bit
4796sequence is infinite on the left, with the most-significant bits being
4797all zeros or all ones.  A bitwise operation acts on the individual bits
4798of such a sequence.  For example, “shifting” moves the whole sequence
4799left or right one or more places, reproducing the same pattern moved
4800over.
4801
4802   The bitwise operations in Emacs Lisp apply only to integers.
4803
4804 -- Function: ash integer1 count
4805     ‘ash’ (“arithmetic shift”) shifts the bits in INTEGER1 to the left
4806     COUNT places, or to the right if COUNT is negative.  Left shifts
4807     introduce zero bits on the right; right shifts discard the
4808     rightmost bits.  Considered as an integer operation, ‘ash’
4809     multiplies INTEGER1 by 2**COUNT, and then converts the result to an
4810     integer by rounding downward, toward minus infinity.
4811
4812     Here are examples of ‘ash’, shifting a pattern of bits one place to
4813     the left and to the right.  These examples show only the low-order
4814     bits of the binary pattern; leading bits all agree with the
4815     highest-order bit shown.  As you can see, shifting left by one is
4816     equivalent to multiplying by two, whereas shifting right by one is
4817     equivalent to dividing by two and then rounding toward minus
4818     infinity.
4819
4820          (ash 7 1) ⇒ 14
4821          ;; Decimal 7 becomes decimal 14.
4822          ...000111
48234824          ...001110
4825
4826          (ash 7 -1) ⇒ 3
4827          ...000111
48284829          ...000011
4830
4831          (ash -7 1) ⇒ -14
4832          ...111001
48334834          ...110010
4835
4836          (ash -7 -1) ⇒ -4
4837          ...111001
48384839          ...111100
4840
4841     Here are examples of shifting left or right by two bits:
4842
4843                            ;         binary values
4844          (ash 5 2)         ;   5  =  ...000101
4845               ⇒ 20         ;      =  ...010100
4846          (ash -5 2)        ;  -5  =  ...111011
4847               ⇒ -20        ;      =  ...101100
4848          (ash 5 -2)
4849               ⇒ 1          ;      =  ...000001
4850          (ash -5 -2)
4851               ⇒ -2         ;      =  ...111110
4852
4853 -- Function: lsh integer1 count
4854     ‘lsh’, which is an abbreviation for “logical shift”, shifts the
4855     bits in INTEGER1 to the left COUNT places, or to the right if COUNT
4856     is negative, bringing zeros into the vacated bits.  If COUNT is
4857     negative, then INTEGER1 must be either a fixnum or a positive
4858     bignum, and ‘lsh’ treats a negative fixnum as if it were unsigned
4859     by subtracting twice ‘most-negative-fixnum’ before shifting,
4860     producing a nonnegative result.  This quirky behavior dates back to
4861     when Emacs supported only fixnums; nowadays ‘ash’ is a better
4862     choice.
4863
4864     As ‘lsh’ behaves like ‘ash’ except when INTEGER1 and COUNT1 are
4865     both negative, the following examples focus on these exceptional
4866     cases.  These examples assume 30-bit fixnums.
4867
4868                           ;      binary values
4869          (ash -7 -1)      ; -7 = ...111111111111111111111111111001
4870               ⇒ -4        ;    = ...111111111111111111111111111100
4871          (lsh -7 -1)
4872               ⇒ 536870908 ;    = ...011111111111111111111111111100
4873          (ash -5 -2)      ; -5 = ...111111111111111111111111111011
4874               ⇒ -2        ;    = ...111111111111111111111111111110
4875          (lsh -5 -2)
4876               ⇒ 268435454 ;    = ...001111111111111111111111111110
4877
4878 -- Function: logand &rest ints-or-markers
4879     This function returns the bitwise AND of the arguments: the Nth bit
4880     is 1 in the result if, and only if, the Nth bit is 1 in all the
4881     arguments.
4882
4883     For example, using 4-bit binary numbers, the bitwise AND of 13 and
4884     12 is 12: 1101 combined with 1100 produces 1100.  In both the
4885     binary numbers, the leftmost two bits are both 1 so the leftmost
4886     two bits of the returned value are both 1.  However, for the
4887     rightmost two bits, each is 0 in at least one of the arguments, so
4888     the rightmost two bits of the returned value are both 0.
4889
4890     Therefore,
4891
4892          (logand 13 12)
4893               ⇒ 12
4894
4895     If ‘logand’ is not passed any argument, it returns a value of −1.
4896     This number is an identity element for ‘logand’ because its binary
4897     representation consists entirely of ones.  If ‘logand’ is passed
4898     just one argument, it returns that argument.
4899
4900                             ;        binary values
4901
4902          (logand 14 13)     ; 14  =  ...001110
4903                             ; 13  =  ...001101
4904               ⇒ 12         ; 12  =  ...001100
4905
4906          (logand 14 13 4)   ; 14  =  ...001110
4907                             ; 13  =  ...001101
4908                             ;  4  =  ...000100
4909               ⇒ 4          ;  4  =  ...000100
4910
4911          (logand)
4912               ⇒ -1         ; -1  =  ...111111
4913
4914 -- Function: logior &rest ints-or-markers
4915     This function returns the bitwise inclusive OR of its arguments:
4916     the Nth bit is 1 in the result if, and only if, the Nth bit is 1 in
4917     at least one of the arguments.  If there are no arguments, the
4918     result is 0, which is an identity element for this operation.  If
4919     ‘logior’ is passed just one argument, it returns that argument.
4920
4921                             ;        binary values
4922
4923          (logior 12 5)      ; 12  =  ...001100
4924                             ;  5  =  ...000101
4925               ⇒ 13         ; 13  =  ...001101
4926
4927          (logior 12 5 7)    ; 12  =  ...001100
4928                             ;  5  =  ...000101
4929                             ;  7  =  ...000111
4930               ⇒ 15         ; 15  =  ...001111
4931
4932 -- Function: logxor &rest ints-or-markers
4933     This function returns the bitwise exclusive OR of its arguments:
4934     the Nth bit is 1 in the result if, and only if, the Nth bit is 1 in
4935     an odd number of the arguments.  If there are no arguments, the
4936     result is 0, which is an identity element for this operation.  If
4937     ‘logxor’ is passed just one argument, it returns that argument.
4938
4939                             ;        binary values
4940
4941          (logxor 12 5)      ; 12  =  ...001100
4942                             ;  5  =  ...000101
4943               ⇒ 9          ;  9  =  ...001001
4944
4945          (logxor 12 5 7)    ; 12  =  ...001100
4946                             ;  5  =  ...000101
4947                             ;  7  =  ...000111
4948               ⇒ 14         ; 14  =  ...001110
4949
4950 -- Function: lognot integer
4951     This function returns the bitwise complement of its argument: the
4952     Nth bit is one in the result if, and only if, the Nth bit is zero
4953     in INTEGER, and vice-versa.  The result equals −1 − INTEGER.
4954
4955          (lognot 5)
4956               ⇒ -6
4957          ;;  5  =  ...000101
4958          ;; becomes
4959          ;; -6  =  ...111010
4960
4961 -- Function: logcount integer
4962     This function returns the “Hamming weight” of INTEGER: the number
4963     of ones in the binary representation of INTEGER.  If INTEGER is
4964     negative, it returns the number of zero bits in its two’s
4965     complement binary representation.  The result is always
4966     nonnegative.
4967
4968          (logcount 43)     ;  43 = ...000101011
4969               ⇒ 4
4970          (logcount -43)    ; -43 = ...111010101
4971               ⇒ 3
4972
4973
4974File: elisp.info,  Node: Math Functions,  Next: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
4975
49763.9 Standard Mathematical Functions
4977===================================
4978
4979These mathematical functions allow integers as well as floating-point
4980numbers as arguments.
4981
4982 -- Function: sin arg
4983 -- Function: cos arg
4984 -- Function: tan arg
4985     These are the basic trigonometric functions, with argument ARG
4986     measured in radians.
4987
4988 -- Function: asin arg
4989     The value of ‘(asin ARG)’ is a number between −pi/2 and pi/2
4990     (inclusive) whose sine is ARG.  If ARG is out of range (outside
4991     [−1, 1]), ‘asin’ returns a NaN.
4992
4993 -- Function: acos arg
4994     The value of ‘(acos ARG)’ is a number between 0 and pi (inclusive)
4995     whose cosine is ARG.  If ARG is out of range (outside [−1, 1]),
4996     ‘acos’ returns a NaN.
4997
4998 -- Function: atan y &optional x
4999     The value of ‘(atan Y)’ is a number between −pi/2 and pi/2
5000     (exclusive) whose tangent is Y.  If the optional second argument X
5001     is given, the value of ‘(atan y x)’ is the angle in radians between
5002     the vector ‘[X, Y]’ and the ‘X’ axis.
5003
5004 -- Function: exp arg
5005     This is the exponential function; it returns e to the power ARG.
5006
5007 -- Function: log arg &optional base
5008     This function returns the logarithm of ARG, with base BASE.  If you
5009     don’t specify BASE, the natural base e is used.  If ARG or BASE is
5010     negative, ‘log’ returns a NaN.
5011
5012 -- Function: expt x y
5013     This function returns X raised to power Y.  If both arguments are
5014     integers and Y is nonnegative, the result is an integer; in this
5015     case, overflow signals an error, so watch out.  If X is a finite
5016     negative number and Y is a finite non-integer, ‘expt’ returns a
5017     NaN.
5018
5019 -- Function: sqrt arg
5020     This returns the square root of ARG.  If ARG is finite and less
5021     than zero, ‘sqrt’ returns a NaN.
5022
5023   In addition, Emacs defines the following common mathematical
5024constants:
5025
5026 -- Variable: float-e
5027     The mathematical constant e (2.71828...).
5028
5029 -- Variable: float-pi
5030     The mathematical constant pi (3.14159...).
5031
5032
5033File: elisp.info,  Node: Random Numbers,  Prev: Math Functions,  Up: Numbers
5034
50353.10 Random Numbers
5036===================
5037
5038A deterministic computer program cannot generate true random numbers.
5039For most purposes, “pseudo-random numbers” suffice.  A series of
5040pseudo-random numbers is generated in a deterministic fashion.  The
5041numbers are not truly random, but they have certain properties that
5042mimic a random series.  For example, all possible values occur equally
5043often in a pseudo-random series.
5044
5045   Pseudo-random numbers are generated from a “seed value”.  Starting
5046from any given seed, the ‘random’ function always generates the same
5047sequence of numbers.  By default, Emacs initializes the random seed at
5048startup, in such a way that the sequence of values of ‘random’ (with
5049overwhelming likelihood) differs in each Emacs run.
5050
5051   Sometimes you want the random number sequence to be repeatable.  For
5052example, when debugging a program whose behavior depends on the random
5053number sequence, it is helpful to get the same behavior in each program
5054run.  To make the sequence repeat, execute ‘(random "")’.  This sets the
5055seed to a constant value for your particular Emacs executable (though it
5056may differ for other Emacs builds).  You can use other strings to choose
5057various seed values.
5058
5059 -- Function: random &optional limit
5060     This function returns a pseudo-random integer.  Repeated calls
5061     return a series of pseudo-random integers.
5062
5063     If LIMIT is a positive fixnum, the value is chosen to be
5064     nonnegative and less than LIMIT.  Otherwise, the value might be any
5065     fixnum, i.e., any integer from ‘most-negative-fixnum’ through
5066     ‘most-positive-fixnum’ (*note Integer Basics::).
5067
5068     If LIMIT is ‘t’, it means to choose a new seed as if Emacs were
5069     restarting, typically from the system entropy.  On systems lacking
5070     entropy pools, choose the seed from less-random volatile data such
5071     as the current time.
5072
5073     If LIMIT is a string, it means to choose a new seed based on the
5074     string’s contents.
5075
5076
5077File: elisp.info,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
5078
50794 Strings and Characters
5080************************
5081
5082A string in Emacs Lisp is an array that contains an ordered sequence of
5083characters.  Strings are used as names of symbols, buffers, and files;
5084to send messages to users; to hold text being copied between buffers;
5085and for many other purposes.  Because strings are so important, Emacs
5086Lisp has many functions expressly for manipulating them.  Emacs Lisp
5087programs use strings more often than individual characters.
5088
5089   *Note Strings of Events::, for special considerations for strings of
5090keyboard character events.
5091
5092* Menu:
5093
5094* Basics: String Basics.      Basic properties of strings and characters.
5095* Predicates for Strings::    Testing whether an object is a string or char.
5096* Creating Strings::          Functions to allocate new strings.
5097* Modifying Strings::         Altering the contents of an existing string.
5098* Text Comparison::           Comparing characters or strings.
5099* String Conversion::         Converting to and from characters and strings.
5100* Formatting Strings::        ‘format’: Emacs’s analogue of ‘printf’.
5101* Custom Format Strings::     Formatting custom ‘format’ specifications.
5102* Case Conversion::           Case conversion functions.
5103* Case Tables::               Customizing case conversion.
5104
5105
5106File: elisp.info,  Node: String Basics,  Next: Predicates for Strings,  Up: Strings and Characters
5107
51084.1 String and Character Basics
5109===============================
5110
5111A character is a Lisp object which represents a single character of
5112text.  In Emacs Lisp, characters are simply integers; whether an integer
5113is a character or not is determined only by how it is used.  *Note
5114Character Codes::, for details about character representation in Emacs.
5115
5116   A string is a fixed sequence of characters.  It is a type of sequence
5117called a “array”, meaning that its length is fixed and cannot be altered
5118once it is created (*note Sequences Arrays Vectors::).  Unlike in C,
5119Emacs Lisp strings are _not_ terminated by a distinguished character
5120code.
5121
5122   Since strings are arrays, and therefore sequences as well, you can
5123operate on them with the general array and sequence functions documented
5124in *note Sequences Arrays Vectors::.  For example, you can access
5125individual characters in a string using the function ‘aref’ (*note Array
5126Functions::).
5127
5128   There are two text representations for non-ASCII characters in Emacs
5129strings (and in buffers): unibyte and multibyte.  For most Lisp
5130programming, you don’t need to be concerned with these two
5131representations.  *Note Text Representations::, for details.
5132
5133   Sometimes key sequences are represented as unibyte strings.  When a
5134unibyte string is a key sequence, string elements in the range 128 to
5135255 represent meta characters (which are large integers) rather than
5136character codes in the range 128 to 255.  Strings cannot hold characters
5137that have the hyper, super or alt modifiers; they can hold ASCII control
5138characters, but no other control characters.  They do not distinguish
5139case in ASCII control characters.  If you want to store such characters
5140in a sequence, such as a key sequence, you must use a vector instead of
5141a string.  *Note Character Type::, for more information about keyboard
5142input characters.
5143
5144   Strings are useful for holding regular expressions.  You can also
5145match regular expressions against strings with ‘string-match’ (*note
5146Regexp Search::).  The functions ‘match-string’ (*note Simple Match
5147Data::) and ‘replace-match’ (*note Replacing Match::) are useful for
5148decomposing and modifying strings after matching regular expressions
5149against them.
5150
5151   Like a buffer, a string can contain text properties for the
5152characters in it, as well as the characters themselves.  *Note Text
5153Properties::.  All the Lisp primitives that copy text from strings to
5154buffers or other strings also copy the properties of the characters
5155being copied.
5156
5157   *Note Text::, for information about functions that display strings or
5158copy them into buffers.  *Note Character Type::, and *note String
5159Type::, for information about the syntax of characters and strings.
5160*Note Non-ASCII Characters::, for functions to convert between text
5161representations and to encode and decode character codes.  Also, note
5162that ‘length’ should _not_ be used for computing the width of a string
5163on display; use ‘string-width’ (*note Size of Displayed Text::) instead.
5164
5165
5166File: elisp.info,  Node: Predicates for Strings,  Next: Creating Strings,  Prev: String Basics,  Up: Strings and Characters
5167
51684.2 Predicates for Strings
5169==========================
5170
5171For more information about general sequence and array predicates, see
5172*note Sequences Arrays Vectors::, and *note Arrays::.
5173
5174 -- Function: stringp object
5175     This function returns ‘t’ if OBJECT is a string, ‘nil’ otherwise.
5176
5177 -- Function: string-or-null-p object
5178     This function returns ‘t’ if OBJECT is a string or ‘nil’.  It
5179     returns ‘nil’ otherwise.
5180
5181 -- Function: char-or-string-p object
5182     This function returns ‘t’ if OBJECT is a string or a character
5183     (i.e., an integer), ‘nil’ otherwise.
5184
5185
5186File: elisp.info,  Node: Creating Strings,  Next: Modifying Strings,  Prev: Predicates for Strings,  Up: Strings and Characters
5187
51884.3 Creating Strings
5189====================
5190
5191The following functions create strings, either from scratch, or by
5192putting strings together, or by taking them apart.  (For functions that
5193create strings based on the modified contents of other strings, like
5194‘string-replace’ and ‘replace-regexp-in-string’, see *note Search and
5195Replace::.)
5196
5197 -- Function: make-string count character &optional multibyte
5198     This function returns a string made up of COUNT repetitions of
5199     CHARACTER.  If COUNT is negative, an error is signaled.
5200
5201          (make-string 5 ?x)
5202               ⇒ "xxxxx"
5203          (make-string 0 ?x)
5204               ⇒ ""
5205
5206     Normally, if CHARACTER is an ASCII character, the result is a
5207     unibyte string.  But if the optional argument MULTIBYTE is
5208     non-‘nil’, the function will produce a multibyte string instead.
5209     This is useful when you later need to concatenate the result with
5210     non-ASCII strings or replace some of its characters with non-ASCII
5211     characters.
5212
5213     Other functions to compare with this one include ‘make-vector’
5214     (*note Vectors::) and ‘make-list’ (*note Building Lists::).
5215
5216 -- Function: string &rest characters
5217     This returns a string containing the characters CHARACTERS.
5218
5219          (string ?a ?b ?c)
5220               ⇒ "abc"
5221
5222 -- Function: substring string &optional start end
5223     This function returns a new string which consists of those
5224     characters from STRING in the range from (and including) the
5225     character at the index START up to (but excluding) the character at
5226     the index END.  The first character is at index zero.  With one
5227     argument, this function just copies STRING.
5228
5229          (substring "abcdefg" 0 3)
5230               ⇒ "abc"
5231
5232     In the above example, the index for ‘a’ is 0, the index for ‘b’ is
5233     1, and the index for ‘c’ is 2.  The index 3—which is the fourth
5234     character in the string—marks the character position up to which
5235     the substring is copied.  Thus, ‘abc’ is copied from the string
5236     ‘"abcdefg"’.
5237
5238     A negative number counts from the end of the string, so that −1
5239     signifies the index of the last character of the string.  For
5240     example:
5241
5242          (substring "abcdefg" -3 -1)
5243               ⇒ "ef"
5244
5245     In this example, the index for ‘e’ is −3, the index for ‘f’ is −2,
5246     and the index for ‘g’ is −1.  Therefore, ‘e’ and ‘f’ are included,
5247     and ‘g’ is excluded.
5248
5249     When ‘nil’ is used for END, it stands for the length of the string.
5250     Thus,
5251
5252          (substring "abcdefg" -3 nil)
5253               ⇒ "efg"
5254
5255     Omitting the argument END is equivalent to specifying ‘nil’.  It
5256     follows that ‘(substring STRING 0)’ returns a copy of all of
5257     STRING.
5258
5259          (substring "abcdefg" 0)
5260               ⇒ "abcdefg"
5261
5262     But we recommend ‘copy-sequence’ for this purpose (*note Sequence
5263     Functions::).
5264
5265     If the characters copied from STRING have text properties, the
5266     properties are copied into the new string also.  *Note Text
5267     Properties::.
5268
5269     ‘substring’ also accepts a vector for the first argument.  For
5270     example:
5271
5272          (substring [a b (c) "d"] 1 3)
5273               ⇒ [b (c)]
5274
5275     A ‘wrong-type-argument’ error is signaled if START is not an
5276     integer or if END is neither an integer nor ‘nil’.  An
5277     ‘args-out-of-range’ error is signaled if START indicates a
5278     character following END, or if either integer is out of range for
5279     STRING.
5280
5281     Contrast this function with ‘buffer-substring’ (*note Buffer
5282     Contents::), which returns a string containing a portion of the
5283     text in the current buffer.  The beginning of a string is at index
5284     0, but the beginning of a buffer is at index 1.
5285
5286 -- Function: substring-no-properties string &optional start end
5287     This works like ‘substring’ but discards all text properties from
5288     the value.  Also, START may be omitted or ‘nil’, which is
5289     equivalent to 0.  Thus, ‘(substring-no-properties STRING)’ returns
5290     a copy of STRING, with all text properties removed.
5291
5292 -- Function: concat &rest sequences
5293     This function returns a string consisting of the characters in the
5294     arguments passed to it (along with their text properties, if any).
5295     The arguments may be strings, lists of numbers, or vectors of
5296     numbers; they are not themselves changed.  If ‘concat’ receives no
5297     arguments, it returns an empty string.
5298
5299          (concat "abc" "-def")
5300               ⇒ "abc-def"
5301          (concat "abc" (list 120 121) [122])
5302               ⇒ "abcxyz"
5303          ;; ‘nil’ is an empty sequence.
5304          (concat "abc" nil "-def")
5305               ⇒ "abc-def"
5306          (concat "The " "quick brown " "fox.")
5307               ⇒ "The quick brown fox."
5308          (concat)
5309               ⇒ ""
5310
5311     This function does not always allocate a new string.  Callers are
5312     advised not rely on the result being a new string nor on it being
5313     ‘eq’ to an existing string.
5314
5315     In particular, mutating the returned value may inadvertently change
5316     another string, alter a constant string in the program, or even
5317     raise an error.  To obtain a string that you can safely mutate, use
5318     ‘copy-sequence’ on the result.
5319
5320     For information about other concatenation functions, see the
5321     description of ‘mapconcat’ in *note Mapping Functions::, ‘vconcat’
5322     in *note Vector Functions::, and ‘append’ in *note Building
5323     Lists::.  For concatenating individual command-line arguments into
5324     a string to be used as a shell command, see *note
5325     combine-and-quote-strings: Shell Arguments.
5326
5327 -- Function: split-string string &optional separators omit-nulls trim
5328     This function splits STRING into substrings based on the regular
5329     expression SEPARATORS (*note Regular Expressions::).  Each match
5330     for SEPARATORS defines a splitting point; the substrings between
5331     splitting points are made into a list, which is returned.
5332
5333     If SEPARATORS is ‘nil’ (or omitted), the default is the value of
5334     ‘split-string-default-separators’ and the function behaves as if
5335     OMIT-NULLS were ‘t’.
5336
5337     If OMIT-NULLS is ‘nil’ (or omitted), the result contains null
5338     strings whenever there are two consecutive matches for SEPARATORS,
5339     or a match is adjacent to the beginning or end of STRING.  If
5340     OMIT-NULLS is ‘t’, these null strings are omitted from the result.
5341
5342     If the optional argument TRIM is non-‘nil’, it should be a regular
5343     expression to match text to trim from the beginning and end of each
5344     substring.  If trimming makes the substring empty, it is treated as
5345     null.
5346
5347     If you need to split a string into a list of individual
5348     command-line arguments suitable for ‘call-process’ or
5349     ‘start-process’, see *note split-string-and-unquote: Shell
5350     Arguments.
5351
5352     Examples:
5353
5354          (split-string "  two words ")
5355               ⇒ ("two" "words")
5356
5357     The result is not ‘("" "two" "words" "")’, which would rarely be
5358     useful.  If you need such a result, use an explicit value for
5359     SEPARATORS:
5360
5361          (split-string "  two words "
5362                        split-string-default-separators)
5363               ⇒ ("" "two" "words" "")
5364
5365          (split-string "Soup is good food" "o")
5366               ⇒ ("S" "up is g" "" "d f" "" "d")
5367          (split-string "Soup is good food" "o" t)
5368               ⇒ ("S" "up is g" "d f" "d")
5369          (split-string "Soup is good food" "o+")
5370               ⇒ ("S" "up is g" "d f" "d")
5371
5372     Empty matches do count, except that ‘split-string’ will not look
5373     for a final empty match when it already reached the end of the
5374     string using a non-empty match or when STRING is empty:
5375
5376          (split-string "aooob" "o*")
5377               ⇒ ("" "a" "" "b" "")
5378          (split-string "ooaboo" "o*")
5379               ⇒ ("" "" "a" "b" "")
5380          (split-string "" "")
5381               ⇒ ("")
5382
5383     However, when SEPARATORS can match the empty string, OMIT-NULLS is
5384     usually ‘t’, so that the subtleties in the three previous examples
5385     are rarely relevant:
5386
5387          (split-string "Soup is good food" "o*" t)
5388               ⇒ ("S" "u" "p" " " "i" "s" " " "g" "d" " " "f" "d")
5389          (split-string "Nice doggy!" "" t)
5390               ⇒ ("N" "i" "c" "e" " " "d" "o" "g" "g" "y" "!")
5391          (split-string "" "" t)
5392               ⇒ nil
5393
5394     Somewhat odd, but predictable, behavior can occur for certain
5395     “non-greedy” values of SEPARATORS that can prefer empty matches
5396     over non-empty matches.  Again, such values rarely occur in
5397     practice:
5398
5399          (split-string "ooo" "o*" t)
5400               ⇒ nil
5401          (split-string "ooo" "\\|o+" t)
5402               ⇒ ("o" "o" "o")
5403
5404 -- Variable: split-string-default-separators
5405     The default value of SEPARATORS for ‘split-string’.  Its usual
5406     value is ‘"[ \f\t\n\r\v]+"’.
5407
5408
5409File: elisp.info,  Node: Modifying Strings,  Next: Text Comparison,  Prev: Creating Strings,  Up: Strings and Characters
5410
54114.4 Modifying Strings
5412=====================
5413
5414You can alter the contents of a mutable string via operations described
5415in this section.  *Note Mutability::.
5416
5417   The most basic way to alter the contents of an existing string is
5418with ‘aset’ (*note Array Functions::).  ‘(aset STRING IDX CHAR)’ stores
5419CHAR into STRING at index IDX.  Each character occupies one or more
5420bytes, and if CHAR needs a different number of bytes from the character
5421already present at that index, ‘aset’ signals an error.
5422
5423   A more powerful function is ‘store-substring’:
5424
5425 -- Function: store-substring string idx obj
5426     This function alters part of the contents of the string STRING, by
5427     storing OBJ starting at index IDX.  The argument OBJ may be either
5428     a character or a (smaller) string.
5429
5430     Since it is impossible to change the length of an existing string,
5431     it is an error if OBJ doesn’t fit within STRING’s actual length, or
5432     if any new character requires a different number of bytes from the
5433     character currently present at that point in STRING.
5434
5435   To clear out a string that contained a password, use ‘clear-string’:
5436
5437 -- Function: clear-string string
5438     This makes STRING a unibyte string and clears its contents to
5439     zeros.  It may also change STRING’s length.
5440
5441
5442File: elisp.info,  Node: Text Comparison,  Next: String Conversion,  Prev: Modifying Strings,  Up: Strings and Characters
5443
54444.5 Comparison of Characters and Strings
5445========================================
5446
5447 -- Function: char-equal character1 character2
5448     This function returns ‘t’ if the arguments represent the same
5449     character, ‘nil’ otherwise.  This function ignores differences in
5450     case if ‘case-fold-search’ is non-‘nil’.
5451
5452          (char-equal ?x ?x)
5453               ⇒ t
5454          (let ((case-fold-search nil))
5455            (char-equal ?x ?X))
5456               ⇒ nil
5457
5458 -- Function: string= string1 string2
5459     This function returns ‘t’ if the characters of the two strings
5460     match exactly.  Symbols are also allowed as arguments, in which
5461     case the symbol names are used.  Case is always significant,
5462     regardless of ‘case-fold-search’.
5463
5464     This function is equivalent to ‘equal’ for comparing two strings
5465     (*note Equality Predicates::).  In particular, the text properties
5466     of the two strings are ignored; use ‘equal-including-properties’ if
5467     you need to distinguish between strings that differ only in their
5468     text properties.  However, unlike ‘equal’, if either argument is
5469     not a string or symbol, ‘string=’ signals an error.
5470
5471          (string= "abc" "abc")
5472               ⇒ t
5473          (string= "abc" "ABC")
5474               ⇒ nil
5475          (string= "ab" "ABC")
5476               ⇒ nil
5477
5478     For technical reasons, a unibyte and a multibyte string are ‘equal’
5479     if and only if they contain the same sequence of character codes
5480     and all these codes are either in the range 0 through 127 (ASCII)
5481     or 160 through 255 (‘eight-bit-graphic’).  However, when a unibyte
5482     string is converted to a multibyte string, all characters with
5483     codes in the range 160 through 255 are converted to characters with
5484     higher codes, whereas ASCII characters remain unchanged.  Thus, a
5485     unibyte string and its conversion to multibyte are only ‘equal’ if
5486     the string is all ASCII.  Character codes 160 through 255 are not
5487     entirely proper in multibyte text, even though they can occur.  As
5488     a consequence, the situation where a unibyte and a multibyte string
5489     are ‘equal’ without both being all ASCII is a technical oddity that
5490     very few Emacs Lisp programmers ever get confronted with.  *Note
5491     Text Representations::.
5492
5493 -- Function: string-equal string1 string2
5494     ‘string-equal’ is another name for ‘string=’.
5495
5496 -- Function: string-collate-equalp string1 string2 &optional locale
5497          ignore-case
5498     This function returns ‘t’ if STRING1 and STRING2 are equal with
5499     respect to collation rules.  A collation rule is not only
5500     determined by the lexicographic order of the characters contained
5501     in STRING1 and STRING2, but also further rules about relations
5502     between these characters.  Usually, it is defined by the LOCALE
5503     environment Emacs is running with.
5504
5505     For example, characters with different coding points but the same
5506     meaning might be considered as equal, like different grave accent
5507     Unicode characters:
5508
5509          (string-collate-equalp (string ?\uFF40) (string ?\u1FEF))
5510               ⇒ t
5511
5512     The optional argument LOCALE, a string, overrides the setting of
5513     your current locale identifier for collation.  The value is system
5514     dependent; a LOCALE ‘"en_US.UTF-8"’ is applicable on POSIX systems,
5515     while it would be, e.g., ‘"enu_USA.1252"’ on MS-Windows systems.
5516
5517     If IGNORE-CASE is non-‘nil’, characters are converted to lower-case
5518     before comparing them.
5519
5520     To emulate Unicode-compliant collation on MS-Windows systems, bind
5521     ‘w32-collate-ignore-punctuation’ to a non-‘nil’ value, since the
5522     codeset part of the locale cannot be ‘"UTF-8"’ on MS-Windows.
5523
5524     If your system does not support a locale environment, this function
5525     behaves like ‘string-equal’.
5526
5527     Do _not_ use this function to compare file names for equality, as
5528     filesystems generally don’t honor linguistic equivalence of strings
5529     that collation implements.
5530
5531 -- Function: string< string1 string2
5532     This function compares two strings a character at a time.  It scans
5533     both the strings at the same time to find the first pair of
5534     corresponding characters that do not match.  If the lesser
5535     character of these two is the character from STRING1, then STRING1
5536     is less, and this function returns ‘t’.  If the lesser character is
5537     the one from STRING2, then STRING1 is greater, and this function
5538     returns ‘nil’.  If the two strings match entirely, the value is
5539     ‘nil’.
5540
5541     Pairs of characters are compared according to their character
5542     codes.  Keep in mind that lower case letters have higher numeric
5543     values in the ASCII character set than their upper case
5544     counterparts; digits and many punctuation characters have a lower
5545     numeric value than upper case letters.  An ASCII character is less
5546     than any non-ASCII character; a unibyte non-ASCII character is
5547     always less than any multibyte non-ASCII character (*note Text
5548     Representations::).
5549
5550          (string< "abc" "abd")
5551               ⇒ t
5552          (string< "abd" "abc")
5553               ⇒ nil
5554          (string< "123" "abc")
5555               ⇒ t
5556
5557     When the strings have different lengths, and they match up to the
5558     length of STRING1, then the result is ‘t’.  If they match up to the
5559     length of STRING2, the result is ‘nil’.  A string of no characters
5560     is less than any other string.
5561
5562          (string< "" "abc")
5563               ⇒ t
5564          (string< "ab" "abc")
5565               ⇒ t
5566          (string< "abc" "")
5567               ⇒ nil
5568          (string< "abc" "ab")
5569               ⇒ nil
5570          (string< "" "")
5571               ⇒ nil
5572
5573     Symbols are also allowed as arguments, in which case their print
5574     names are compared.
5575
5576 -- Function: string-lessp string1 string2
5577     ‘string-lessp’ is another name for ‘string<’.
5578
5579 -- Function: string-greaterp string1 string2
5580     This function returns the result of comparing STRING1 and STRING2
5581     in the opposite order, i.e., it is equivalent to calling
5582     ‘(string-lessp STRING2 STRING1)’.
5583
5584 -- Function: string-collate-lessp string1 string2 &optional locale
5585          ignore-case
5586     This function returns ‘t’ if STRING1 is less than STRING2 in
5587     collation order.  A collation order is not only determined by the
5588     lexicographic order of the characters contained in STRING1 and
5589     STRING2, but also further rules about relations between these
5590     characters.  Usually, it is defined by the LOCALE environment Emacs
5591     is running with.
5592
5593     For example, punctuation and whitespace characters might be ignored
5594     for sorting (*note Sequence Functions::):
5595
5596          (sort (list "11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp)
5597               ⇒ ("11" "1 1" "1.1" "12" "1 2" "1.2")
5598
5599     This behavior is system-dependent; e.g., punctuation and whitespace
5600     are never ignored on Cygwin, regardless of locale.
5601
5602     The optional argument LOCALE, a string, overrides the setting of
5603     your current locale identifier for collation.  The value is system
5604     dependent; a LOCALE ‘"en_US.UTF-8"’ is applicable on POSIX systems,
5605     while it would be, e.g., ‘"enu_USA.1252"’ on MS-Windows systems.
5606     The LOCALE value of ‘"POSIX"’ or ‘"C"’ lets ‘string-collate-lessp’
5607     behave like ‘string-lessp’:
5608
5609          (sort (list "11" "12" "1 1" "1 2" "1.1" "1.2")
5610                (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX")))
5611               ⇒ ("1 1" "1 2" "1.1" "1.2" "11" "12")
5612
5613     If IGNORE-CASE is non-‘nil’, characters are converted to lower-case
5614     before comparing them.
5615
5616     To emulate Unicode-compliant collation on MS-Windows systems, bind
5617     ‘w32-collate-ignore-punctuation’ to a non-‘nil’ value, since the
5618     codeset part of the locale cannot be ‘"UTF-8"’ on MS-Windows.
5619
5620     If your system does not support a locale environment, this function
5621     behaves like ‘string-lessp’.
5622
5623 -- Function: string-version-lessp string1 string2
5624     This function compares strings lexicographically, except it treats
5625     sequences of numerical characters as if they comprised a base-ten
5626     number, and then compares the numbers.  So ‘foo2.png’ is “smaller”
5627     than ‘foo12.png’ according to this predicate, even if ‘12’ is
5628     lexicographically “smaller” than ‘2’.
5629
5630 -- Function: string-prefix-p string1 string2 &optional ignore-case
5631     This function returns non-‘nil’ if STRING1 is a prefix of STRING2;
5632     i.e., if STRING2 starts with STRING1.  If the optional argument
5633     IGNORE-CASE is non-‘nil’, the comparison ignores case differences.
5634
5635 -- Function: string-suffix-p suffix string &optional ignore-case
5636     This function returns non-‘nil’ if SUFFIX is a suffix of STRING;
5637     i.e., if STRING ends with SUFFIX.  If the optional argument
5638     IGNORE-CASE is non-‘nil’, the comparison ignores case differences.
5639
5640 -- Function: compare-strings string1 start1 end1 string2 start2 end2
5641          &optional ignore-case
5642     This function compares a specified part of STRING1 with a specified
5643     part of STRING2.  The specified part of STRING1 runs from index
5644     START1 (inclusive) up to index END1 (exclusive); ‘nil’ for START1
5645     means the start of the string, while ‘nil’ for END1 means the
5646     length of the string.  Likewise, the specified part of STRING2 runs
5647     from index START2 up to index END2.
5648
5649     The strings are compared by the numeric values of their characters.
5650     For instance, STR1 is considered less than STR2 if its first
5651     differing character has a smaller numeric value.  If IGNORE-CASE is
5652     non-‘nil’, characters are converted to upper-case before comparing
5653     them.  Unibyte strings are converted to multibyte for comparison
5654     (*note Text Representations::), so that a unibyte string and its
5655     conversion to multibyte are always regarded as equal.
5656
5657     If the specified portions of the two strings match, the value is
5658     ‘t’.  Otherwise, the value is an integer which indicates how many
5659     leading characters agree, and which string is less.  Its absolute
5660     value is one plus the number of characters that agree at the
5661     beginning of the two strings.  The sign is negative if STRING1 (or
5662     its specified portion) is less.
5663
5664 -- Function: string-distance string1 string2 &optional bytecompare
5665     This function returns the “Levenshtein distance” between the source
5666     string STRING1 and the target string STRING2.  The Levenshtein
5667     distance is the number of single-character changes—deletions,
5668     insertions, or replacements—required to transform the source string
5669     into the target string; it is one possible definition of the “edit
5670     distance” between strings.
5671
5672     Letter-case of the strings is significant for the computed
5673     distance, but their text properties are ignored.  If the optional
5674     argument BYTECOMPARE is non-‘nil’, the function calculates the
5675     distance in terms of bytes instead of characters.  The byte-wise
5676     comparison uses the internal Emacs representation of characters, so
5677     it will produce inaccurate results for multibyte strings that
5678     include raw bytes (*note Text Representations::); make the strings
5679     unibyte by encoding them (*note Explicit Encoding::) if you need
5680     accurate results with raw bytes.
5681
5682 -- Function: assoc-string key alist &optional case-fold
5683     This function works like ‘assoc’, except that KEY must be a string
5684     or symbol, and comparison is done using ‘compare-strings’.  Symbols
5685     are converted to strings before testing.  If CASE-FOLD is
5686     non-‘nil’, KEY and the elements of ALIST are converted to
5687     upper-case before comparison.  Unlike ‘assoc’, this function can
5688     also match elements of the alist that are strings or symbols rather
5689     than conses.  In particular, ALIST can be a list of strings or
5690     symbols rather than an actual alist.  *Note Association Lists::.
5691
5692   See also the function ‘compare-buffer-substrings’ in *note Comparing
5693Text::, for a way to compare text in buffers.  The function
5694‘string-match’, which matches a regular expression against a string, can
5695be used for a kind of string comparison; see *note Regexp Search::.
5696
5697
5698File: elisp.info,  Node: String Conversion,  Next: Formatting Strings,  Prev: Text Comparison,  Up: Strings and Characters
5699
57004.6 Conversion of Characters and Strings
5701========================================
5702
5703This section describes functions for converting between characters,
5704strings and integers.  ‘format’ (*note Formatting Strings::) and
5705‘prin1-to-string’ (*note Output Functions::) can also convert Lisp
5706objects into strings.  ‘read-from-string’ (*note Input Functions::) can
5707convert a string representation of a Lisp object into an object.  The
5708functions ‘string-to-multibyte’ and ‘string-to-unibyte’ convert the text
5709representation of a string (*note Converting Representations::).
5710
5711   *Note Documentation::, for functions that produce textual
5712descriptions of text characters and general input events
5713(‘single-key-description’ and ‘text-char-description’).  These are used
5714primarily for making help messages.
5715
5716 -- Function: number-to-string number
5717     This function returns a string consisting of the printed base-ten
5718     representation of NUMBER.  The returned value starts with a minus
5719     sign if the argument is negative.
5720
5721          (number-to-string 256)
5722               ⇒ "256"
5723          (number-to-string -23)
5724               ⇒ "-23"
5725          (number-to-string -23.5)
5726               ⇒ "-23.5"
5727
5728     ‘int-to-string’ is a semi-obsolete alias for this function.
5729
5730     See also the function ‘format’ in *note Formatting Strings::.
5731
5732 -- Function: string-to-number string &optional base
5733     This function returns the numeric value of the characters in
5734     STRING.  If BASE is non-‘nil’, it must be an integer between 2 and
5735     16 (inclusive), and integers are converted in that base.  If BASE
5736     is ‘nil’, then base ten is used.  Floating-point conversion only
5737     works in base ten; we have not implemented other radices for
5738     floating-point numbers, because that would be much more work and
5739     does not seem useful.  If STRING looks like an integer but its
5740     value is too large to fit into a Lisp integer, ‘string-to-number’
5741     returns a floating-point result.
5742
5743     The parsing skips spaces and tabs at the beginning of STRING, then
5744     reads as much of STRING as it can interpret as a number in the
5745     given base.  (On some systems it ignores other whitespace at the
5746     beginning, not just spaces and tabs.)  If STRING cannot be
5747     interpreted as a number, this function returns 0.
5748
5749          (string-to-number "256")
5750               ⇒ 256
5751          (string-to-number "25 is a perfect square.")
5752               ⇒ 25
5753          (string-to-number "X256")
5754               ⇒ 0
5755          (string-to-number "-4.5")
5756               ⇒ -4.5
5757          (string-to-number "1e5")
5758               ⇒ 100000.0
5759
5760     ‘string-to-int’ is an obsolete alias for this function.
5761
5762 -- Function: char-to-string character
5763     This function returns a new string containing one character,
5764     CHARACTER.  This function is semi-obsolete because the function
5765     ‘string’ is more general.  *Note Creating Strings::.
5766
5767 -- Function: string-to-char string
5768     This function returns the first character in STRING.  This mostly
5769     identical to ‘(aref string 0)’, except that it returns 0 if the
5770     string is empty.  (The value is also 0 when the first character of
5771     STRING is the null character, ASCII code 0.)  This function may be
5772     eliminated in the future if it does not seem useful enough to
5773     retain.
5774
5775   Here are some other functions that can convert to or from a string:
5776
5777‘concat’
5778     This function converts a vector or a list into a string.  *Note
5779     Creating Strings::.
5780
5781‘vconcat’
5782     This function converts a string into a vector.  *Note Vector
5783     Functions::.
5784
5785‘append’
5786     This function converts a string into a list.  *Note Building
5787     Lists::.
5788
5789‘byte-to-string’
5790     This function converts a byte of character data into a unibyte
5791     string.  *Note Converting Representations::.
5792
5793
5794File: elisp.info,  Node: Formatting Strings,  Next: Custom Format Strings,  Prev: String Conversion,  Up: Strings and Characters
5795
57964.7 Formatting Strings
5797======================
5798
5799“Formatting” means constructing a string by substituting computed values
5800at various places in a constant string.  This constant string controls
5801how the other values are printed, as well as where they appear; it is
5802called a “format string”.
5803
5804   Formatting is often useful for computing messages to be displayed.
5805In fact, the functions ‘message’ and ‘error’ provide the same formatting
5806feature described here; they differ from ‘format-message’ only in how
5807they use the result of formatting.
5808
5809 -- Function: format string &rest objects
5810     This function returns a string equal to STRING, replacing any
5811     format specifications with encodings of the corresponding OBJECTS.
5812     The arguments OBJECTS are the computed values to be formatted.
5813
5814     The characters in STRING, other than the format specifications, are
5815     copied directly into the output, including their text properties,
5816     if any.  Any text properties of the format specifications are
5817     copied to the produced string representations of the argument
5818     OBJECTS.
5819
5820     The output string need not be newly-allocated.  For example, if ‘x’
5821     is the string ‘"foo"’, the expressions ‘(eq x (format x))’ and ‘(eq
5822     x (format "%s" x))’ might both yield ‘t’.
5823
5824 -- Function: format-message string &rest objects
5825     This function acts like ‘format’, except it also converts any grave
5826     accents (`) and apostrophes (') in STRING as per the value of
5827     ‘text-quoting-style’.
5828
5829     Typically grave accent and apostrophe in the format translate to
5830     matching curved quotes, e.g., "Missing `%s'" might result in
5831     "Missing ‘foo’".  *Note Text Quoting Style::, for how to influence
5832     or inhibit this translation.
5833
5834   A format specification is a sequence of characters beginning with a
5835‘%’.  Thus, if there is a ‘%d’ in STRING, the ‘format’ function replaces
5836it with the printed representation of one of the values to be formatted
5837(one of the arguments OBJECTS).  For example:
5838
5839     (format "The value of fill-column is %d." fill-column)
5840          ⇒ "The value of fill-column is 72."
5841
5842   Since ‘format’ interprets ‘%’ characters as format specifications,
5843you should _never_ pass an arbitrary string as the first argument.  This
5844is particularly true when the string is generated by some Lisp code.
5845Unless the string is _known_ to never include any ‘%’ characters, pass
5846‘"%s"’, described below, as the first argument, and the string as the
5847second, like this:
5848
5849       (format "%s" ARBITRARY-STRING)
5850
5851   Certain format specifications require values of particular types.  If
5852you supply a value that doesn’t fit the requirements, an error is
5853signaled.
5854
5855   Here is a table of valid format specifications:
5856
5857‘%s’
5858     Replace the specification with the printed representation of the
5859     object, made without quoting (that is, using ‘princ’, not
5860     ‘prin1’—*note Output Functions::).  Thus, strings are represented
5861     by their contents alone, with no ‘"’ characters, and symbols appear
5862     without ‘\’ characters.
5863
5864     If the object is a string, its text properties are copied into the
5865     output.  The text properties of the ‘%s’ itself are also copied,
5866     but those of the object take priority.
5867
5868‘%S’
5869     Replace the specification with the printed representation of the
5870     object, made with quoting (that is, using ‘prin1’—*note Output
5871     Functions::).  Thus, strings are enclosed in ‘"’ characters, and
5872     ‘\’ characters appear where necessary before special characters.
5873
5874‘%o’
5875     Replace the specification with the base-eight representation of an
5876     integer.  Negative integers are formatted in a platform-dependent
5877     way.  The object can also be a floating-point number that is
5878     formatted as an integer, dropping any fraction.
5879
5880‘%d’
5881     Replace the specification with the base-ten representation of a
5882     signed integer.  The object can also be a floating-point number
5883     that is formatted as an integer, dropping any fraction.
5884
5885‘%x’
5886‘%X’
5887     Replace the specification with the base-sixteen representation of
5888     an integer.  Negative integers are formatted in a
5889     platform-dependent way.  ‘%x’ uses lower case and ‘%X’ uses upper
5890     case.  The object can also be a floating-point number that is
5891     formatted as an integer, dropping any fraction.
5892
5893‘%c’
5894     Replace the specification with the character which is the value
5895     given.
5896
5897‘%e’
5898     Replace the specification with the exponential notation for a
5899     floating-point number.
5900
5901‘%f’
5902     Replace the specification with the decimal-point notation for a
5903     floating-point number.
5904
5905‘%g’
5906     Replace the specification with notation for a floating-point
5907     number, using either exponential notation or decimal-point
5908     notation.  The exponential notation is used if the exponent would
5909     be less than −4 or greater than or equal to the precision (default:
5910     6).  By default, trailing zeros are removed from the fractional
5911     portion of the result and a decimal-point character appears only if
5912     it is followed by a digit.
5913
5914‘%%’
5915     Replace the specification with a single ‘%’.  This format
5916     specification is unusual in that its only form is plain ‘%%’ and
5917     that it does not use a value.  For example, ‘(format "%% %d" 30)’
5918     returns ‘"% 30"’.
5919
5920   Any other format character results in an ‘Invalid format operation’
5921error.
5922
5923   Here are several examples, which assume the typical
5924‘text-quoting-style’ settings:
5925
5926     (format "The octal value of %d is %o,
5927              and the hex value is %x." 18 18 18)
5928          ⇒ "The octal value of 18 is 22,
5929              and the hex value is 12."
5930
5931     (format-message
5932      "The name of this buffer is ‘%s’." (buffer-name))
5933          ⇒ "The name of this buffer is ‘strings.texi’."
5934
5935     (format-message
5936      "The buffer object prints as `%s'." (current-buffer))
5937          ⇒ "The buffer object prints as ‘strings.texi’."
5938
5939   By default, format specifications correspond to successive values
5940from OBJECTS.  Thus, the first format specification in STRING uses the
5941first such value, the second format specification uses the second such
5942value, and so on.  Any extra format specifications (those for which
5943there are no corresponding values) cause an error.  Any extra values to
5944be formatted are ignored.
5945
5946   A format specification can have a “field number”, which is a decimal
5947number immediately after the initial ‘%’, followed by a literal dollar
5948sign ‘$’.  It causes the format specification to convert the argument
5949with the given number instead of the next argument.  Field numbers start
5950at 1.  A format can contain either numbered or unnumbered format
5951specifications but not both, except that ‘%%’ can be mixed with numbered
5952specifications.
5953
5954     (format "%2$s, %3$s, %%, %1$s" "x" "y" "z")
5955          ⇒ "y, z, %, x"
5956
5957   After the ‘%’ and any field number, you can put certain “flag
5958characters”.
5959
5960   The flag ‘+’ inserts a plus sign before a nonnegative number, so that
5961it always has a sign.  A space character as flag inserts a space before
5962a nonnegative number.  (Otherwise, nonnegative numbers start with the
5963first digit.)  These flags are useful for ensuring that nonnegative and
5964negative numbers use the same number of columns.  They are ignored
5965except for ‘%d’, ‘%e’, ‘%f’, ‘%g’, and if both flags are used, ‘+’ takes
5966precedence.
5967
5968   The flag ‘#’ specifies an alternate form which depends on the format
5969in use.  For ‘%o’, it ensures that the result begins with a ‘0’.  For
5970‘%x’ and ‘%X’, it prefixes nonzero results with ‘0x’ or ‘0X’.  For ‘%e’
5971and ‘%f’, the ‘#’ flag means include a decimal point even if the
5972precision is zero.  For ‘%g’, it always includes a decimal point, and
5973also forces any trailing zeros after the decimal point to be left in
5974place where they would otherwise be removed.
5975
5976   The flag ‘0’ ensures that the padding consists of ‘0’ characters
5977instead of spaces.  This flag is ignored for non-numerical specification
5978characters like ‘%s’, ‘%S’ and ‘%c’.  These specification characters
5979accept the ‘0’ flag, but still pad with _spaces_.
5980
5981   The flag ‘-’ causes any padding inserted by the width, if specified,
5982to be inserted on the right rather than the left.  If both ‘-’ and ‘0’
5983are present, the ‘0’ flag is ignored.
5984
5985     (format "%06d is padded on the left with zeros" 123)
5986          ⇒ "000123 is padded on the left with zeros"
5987
5988     (format "'%-6d' is padded on the right" 123)
5989          ⇒ "'123   ' is padded on the right"
5990
5991     (format "The word '%-7s' actually has %d letters in it."
5992             "foo" (length "foo"))
5993          ⇒ "The word 'foo    ' actually has 3 letters in it."
5994
5995   A specification can have a “width”, which is a decimal number that
5996appears after any field number and flags.  If the printed representation
5997of the object contains fewer characters than this width, ‘format’
5998extends it with padding.  Any padding introduced by the width normally
5999consists of spaces inserted on the left:
6000
6001     (format "%5d is padded on the left with spaces" 123)
6002          ⇒ "  123 is padded on the left with spaces"
6003
6004If the width is too small, ‘format’ does not truncate the object’s
6005printed representation.  Thus, you can use a width to specify a minimum
6006spacing between columns with no risk of losing information.  In the
6007following two examples, ‘%7s’ specifies a minimum width of 7.  In the
6008first case, the string inserted in place of ‘%7s’ has only 3 letters,
6009and needs 4 blank spaces as padding.  In the second case, the string
6010‘"specification"’ is 13 letters wide but is not truncated.
6011
6012     (format "The word '%7s' has %d letters in it."
6013             "foo" (length "foo"))
6014          ⇒ "The word '    foo' has 3 letters in it."
6015     (format "The word '%7s' has %d letters in it."
6016             "specification" (length "specification"))
6017          ⇒ "The word 'specification' has 13 letters in it."
6018
6019   All the specification characters allow an optional “precision” after
6020the field number, flags and width, if present.  The precision is a
6021decimal-point ‘.’ followed by a digit-string.  For the floating-point
6022specifications (‘%e’ and ‘%f’), the precision specifies how many digits
6023following the decimal point to show; if zero, the decimal-point itself
6024is also omitted.  For ‘%g’, the precision specifies how many significant
6025digits to show (significant digits are the first digit before the
6026decimal point and all the digits after it).  If the precision of %g is
6027zero or unspecified, it is treated as 1.  For ‘%s’ and ‘%S’, the
6028precision truncates the string to the given width, so ‘%.3s’ shows only
6029the first three characters of the representation for OBJECT.  For other
6030specification characters, the effect of precision is what the local
6031library functions of the ‘printf’ family produce.
6032
6033   If you plan to use ‘read’ later on the formatted string to retrieve a
6034copy of the formatted value, use a specification that lets ‘read’
6035reconstruct the value.  To format numbers in this reversible way you can
6036use ‘%s’ and ‘%S’, to format just integers you can also use ‘%d’, and to
6037format just nonnegative integers you can also use ‘#x%x’ and ‘#o%o’.
6038Other formats may be problematic; for example, ‘%d’ and ‘%g’ can
6039mishandle NaNs and can lose precision and type, and ‘#x%x’ and ‘#o%o’
6040can mishandle negative integers.  *Note Input Functions::.
6041
6042   The functions described in this section accept a fixed set of
6043specification characters.  The next section describes a function
6044‘format-spec’ which can accept custom specification characters, such as
6045‘%a’ or ‘%z’.
6046
6047
6048File: elisp.info,  Node: Custom Format Strings,  Next: Case Conversion,  Prev: Formatting Strings,  Up: Strings and Characters
6049
60504.8 Custom Format Strings
6051=========================
6052
6053Sometimes it is useful to allow users and Lisp programs alike to control
6054how certain text is generated via custom format control strings.  For
6055example, a format string could control how to display someone’s
6056forename, surname, and email address.  Using the function ‘format’
6057described in the previous section, the format string could be something
6058like ‘"%s %s <%s>"’.  This approach quickly becomes impractical,
6059however, as it can be unclear which specification character corresponds
6060to which piece of information.
6061
6062   A more convenient format string for such cases would be something
6063like ‘"%f %l <%e>"’, where each specification character carries more
6064semantic information and can easily be rearranged relative to other
6065specification characters, making such format strings more easily
6066customizable by the user.
6067
6068   The function ‘format-spec’ described in this section performs a
6069similar function to ‘format’, except it operates on format control
6070strings that use arbitrary specification characters.
6071
6072 -- Function: format-spec template spec-alist &optional only-present
6073     This function returns a string produced from the format string
6074     TEMPLATE according to conversions specified in SPEC-ALIST, which is
6075     an alist (*note Association Lists::) of the form
6076     ‘(LETTER . REPLACEMENT)’.  Each specification ‘%LETTER’ in TEMPLATE
6077     will be replaced by REPLACEMENT when formatting the resulting
6078     string.
6079
6080     The characters in TEMPLATE, other than the format specifications,
6081     are copied directly into the output, including their text
6082     properties, if any.  Any text properties of the format
6083     specifications are copied to their replacements.
6084
6085     Using an alist to specify conversions gives rise to some useful
6086     properties:
6087
6088        • If SPEC-ALIST contains more unique LETTER keys than there are
6089          unique specification characters in TEMPLATE, the unused keys
6090          are simply ignored.
6091        • If SPEC-ALIST contains more than one association with the same
6092          LETTER, the closest one to the start of the list is used.
6093        • If TEMPLATE contains the same specification character more
6094          than once, then the same REPLACEMENT found in SPEC-ALIST is
6095          used as a basis for all of that character’s substitutions.
6096        • The order of specifications in TEMPLATE need not correspond to
6097          the order of associations in SPEC-ALIST.
6098
6099     The optional argument ONLY-PRESENT indicates how to handle
6100     specification characters in TEMPLATE that are not found in
6101     SPEC-ALIST.  If it is ‘nil’ or omitted, the function signals an
6102     error.  Otherwise, those format specifications and any occurrences
6103     of ‘%%’ in TEMPLATE are left verbatim in the output, including
6104     their text properties, if any.
6105
6106   The syntax of format specifications accepted by ‘format-spec’ is
6107similar, but not identical, to that accepted by ‘format’.  In both
6108cases, a format specification is a sequence of characters beginning with
6109‘%’ and ending with an alphabetic letter such as ‘s’.
6110
6111   Unlike ‘format’, which assigns specific meanings to a fixed set of
6112specification characters, ‘format-spec’ accepts arbitrary specification
6113characters and treats them all equally.  For example:
6114
6115     (setq my-site-info
6116           (list (cons ?s system-name)
6117                 (cons ?t (symbol-name system-type))
6118                 (cons ?c system-configuration)
6119                 (cons ?v emacs-version)
6120                 (cons ?e invocation-name)
6121                 (cons ?p (number-to-string (emacs-pid)))
6122                 (cons ?a user-mail-address)
6123                 (cons ?n user-full-name)))
6124
6125     (format-spec "%e %v (%c)" my-site-info)
6126          ⇒ "emacs 27.1 (x86_64-pc-linux-gnu)"
6127
6128     (format-spec "%n <%a>" my-site-info)
6129          ⇒ "Emacs Developers <emacs-devel@gnu.org>"
6130
6131   A format specification can include any number of the following flag
6132characters immediately after the ‘%’ to modify aspects of the
6133substitution.
6134
6135‘0’
6136     This flag causes any padding specified by the width to consist of
6137     ‘0’ characters instead of spaces.
6138
6139‘-’
6140     This flag causes any padding specified by the width to be inserted
6141     on the right rather than the left.
6142
6143‘<’
6144     This flag causes the substitution to be truncated on the left to
6145     the given width, if specified.
6146
6147‘>’
6148     This flag causes the substitution to be truncated on the right to
6149     the given width, if specified.
6150
6151‘^’
6152     This flag converts the substituted text to upper case (*note Case
6153     Conversion::).
6154
6155‘_’
6156     This flag converts the substituted text to lower case (*note Case
6157     Conversion::).
6158
6159   The result of using contradictory flags (for instance, both upper and
6160lower case) is undefined.
6161
6162   As is the case with ‘format’, a format specification can include a
6163width, which is a decimal number that appears after any flags.  If a
6164substitution contains fewer characters than its specified width, it is
6165padded on the left:
6166
6167     (format-spec "%8a is padded on the left with spaces"
6168                  '((?a . "alpha")))
6169          ⇒ "   alpha is padded on the left with spaces"
6170
6171   Here is a more complicated example that combines several
6172aforementioned features:
6173
6174     (setq my-battery-info
6175           (list (cons ?p "73")      ; Percentage
6176                 (cons ?L "Battery") ; Status
6177                 (cons ?t "2:23")    ; Remaining time
6178                 (cons ?c "24330")   ; Capacity
6179                 (cons ?r "10.6")))  ; Rate of discharge
6180
6181     (format-spec "%>^-3L : %3p%% (%05t left)" my-battery-info)
6182          ⇒ "BAT :  73% (02:23 left)"
6183
6184     (format-spec "%>^-3L : %3p%% (%05t left)"
6185                  (cons (cons ?L "AC")
6186                        my-battery-info))
6187          ⇒ "AC  :  73% (02:23 left)"
6188
6189   As the examples in this section illustrate, ‘format-spec’ is often
6190used for selectively formatting an assortment of different pieces of
6191information.  This is useful in programs that provide user-customizable
6192format strings, as the user can choose to format with a regular syntax
6193and in any desired order only a subset of the information that the
6194program makes available.
6195
6196
6197File: elisp.info,  Node: Case Conversion,  Next: Case Tables,  Prev: Custom Format Strings,  Up: Strings and Characters
6198
61994.9 Case Conversion in Lisp
6200===========================
6201
6202The character case functions change the case of single characters or of
6203the contents of strings.  The functions normally convert only alphabetic
6204characters (the letters ‘A’ through ‘Z’ and ‘a’ through ‘z’, as well as
6205non-ASCII letters); other characters are not altered.  You can specify a
6206different case conversion mapping by specifying a case table (*note Case
6207Tables::).
6208
6209   These functions do not modify the strings that are passed to them as
6210arguments.
6211
6212   The examples below use the characters ‘X’ and ‘x’ which have ASCII
6213codes 88 and 120 respectively.
6214
6215 -- Function: downcase string-or-char
6216     This function converts STRING-OR-CHAR, which should be either a
6217     character or a string, to lower case.
6218
6219     When STRING-OR-CHAR is a string, this function returns a new string
6220     in which each letter in the argument that is upper case is
6221     converted to lower case.  When STRING-OR-CHAR is a character, this
6222     function returns the corresponding lower case character (an
6223     integer); if the original character is lower case, or is not a
6224     letter, the return value is equal to the original character.
6225
6226          (downcase "The cat in the hat")
6227               ⇒ "the cat in the hat"
6228
6229          (downcase ?X)
6230               ⇒ 120
6231
6232 -- Function: upcase string-or-char
6233     This function converts STRING-OR-CHAR, which should be either a
6234     character or a string, to upper case.
6235
6236     When STRING-OR-CHAR is a string, this function returns a new string
6237     in which each letter in the argument that is lower case is
6238     converted to upper case.  When STRING-OR-CHAR is a character, this
6239     function returns the corresponding upper case character (an
6240     integer); if the original character is upper case, or is not a
6241     letter, the return value is equal to the original character.
6242
6243          (upcase "The cat in the hat")
6244               ⇒ "THE CAT IN THE HAT"
6245
6246          (upcase ?x)
6247               ⇒ 88
6248
6249 -- Function: capitalize string-or-char
6250     This function capitalizes strings or characters.  If STRING-OR-CHAR
6251     is a string, the function returns a new string whose contents are a
6252     copy of STRING-OR-CHAR in which each word has been capitalized.
6253     This means that the first character of each word is converted to
6254     upper case, and the rest are converted to lower case.
6255
6256     The definition of a word is any sequence of consecutive characters
6257     that are assigned to the word constituent syntax class in the
6258     current syntax table (*note Syntax Class Table::).
6259
6260     When STRING-OR-CHAR is a character, this function does the same
6261     thing as ‘upcase’.
6262
6263          (capitalize "The cat in the hat")
6264               ⇒ "The Cat In The Hat"
6265
6266          (capitalize "THE 77TH-HATTED CAT")
6267               ⇒ "The 77th-Hatted Cat"
6268
6269          (capitalize ?x)
6270               ⇒ 88
6271
6272 -- Function: upcase-initials string-or-char
6273     If STRING-OR-CHAR is a string, this function capitalizes the
6274     initials of the words in STRING-OR-CHAR, without altering any
6275     letters other than the initials.  It returns a new string whose
6276     contents are a copy of STRING-OR-CHAR, in which each word has had
6277     its initial letter converted to upper case.
6278
6279     The definition of a word is any sequence of consecutive characters
6280     that are assigned to the word constituent syntax class in the
6281     current syntax table (*note Syntax Class Table::).
6282
6283     When the argument to ‘upcase-initials’ is a character,
6284     ‘upcase-initials’ has the same result as ‘upcase’.
6285
6286          (upcase-initials "The CAT in the hAt")
6287               ⇒ "The CAT In The HAt"
6288
6289   Note that case conversion is not a one-to-one mapping of codepoints
6290and length of the result may differ from length of the argument.
6291Furthermore, because passing a character forces return type to be a
6292character, functions are unable to perform proper substitution and
6293result may differ compared to treating a one-character string.  For
6294example:
6295
6296     (upcase "fi")  ; note: single character, ligature "fi"
6297          ⇒ "FI"
6298     (upcase ?fi)
6299          ⇒ 64257  ; i.e. ?fi
6300
6301   To avoid this, a character must first be converted into a string,
6302using ‘string’ function, before being passed to one of the casing
6303functions.  Of course, no assumptions on the length of the result may be
6304made.
6305
6306   Mapping for such special cases are taken from ‘special-uppercase’,
6307‘special-lowercase’ and ‘special-titlecase’ *Note Character
6308Properties::.
6309
6310   *Note Text Comparison::, for functions that compare strings; some of
6311them ignore case differences, or can optionally ignore case differences.
6312
6313
6314File: elisp.info,  Node: Case Tables,  Prev: Case Conversion,  Up: Strings and Characters
6315
63164.10 The Case Table
6317===================
6318
6319You can customize case conversion by installing a special “case table”.
6320A case table specifies the mapping between upper case and lower case
6321letters.  It affects both the case conversion functions for Lisp objects
6322(see the previous section) and those that apply to text in the buffer
6323(*note Case Changes::).  Each buffer has a case table; there is also a
6324standard case table which is used to initialize the case table of new
6325buffers.
6326
6327   A case table is a char-table (*note Char-Tables::) whose subtype is
6328‘case-table’.  This char-table maps each character into the
6329corresponding lower case character.  It has three extra slots, which
6330hold related tables:
6331
6332UPCASE
6333     The upcase table maps each character into the corresponding upper
6334     case character.
6335CANONICALIZE
6336     The canonicalize table maps all of a set of case-related characters
6337     into a particular member of that set.
6338EQUIVALENCES
6339     The equivalences table maps each one of a set of case-related
6340     characters into the next character in that set.
6341
6342   In simple cases, all you need to specify is the mapping to
6343lower-case; the three related tables will be calculated automatically
6344from that one.
6345
6346   For some languages, upper and lower case letters are not in
6347one-to-one correspondence.  There may be two different lower case
6348letters with the same upper case equivalent.  In these cases, you need
6349to specify the maps for both lower case and upper case.
6350
6351   The extra table CANONICALIZE maps each character to a canonical
6352equivalent; any two characters that are related by case-conversion have
6353the same canonical equivalent character.  For example, since ‘a’ and ‘A’
6354are related by case-conversion, they should have the same canonical
6355equivalent character (which should be either ‘a’ for both of them, or
6356‘A’ for both of them).
6357
6358   The extra table EQUIVALENCES is a map that cyclically permutes each
6359equivalence class (of characters with the same canonical equivalent).
6360(For ordinary ASCII, this would map ‘a’ into ‘A’ and ‘A’ into ‘a’, and
6361likewise for each set of equivalent characters.)
6362
6363   When constructing a case table, you can provide ‘nil’ for
6364CANONICALIZE; then Emacs fills in this slot from the lower case and
6365upper case mappings.  You can also provide ‘nil’ for EQUIVALENCES; then
6366Emacs fills in this slot from CANONICALIZE.  In a case table that is
6367actually in use, those components are non-‘nil’.  Do not try to specify
6368EQUIVALENCES without also specifying CANONICALIZE.
6369
6370   Here are the functions for working with case tables:
6371
6372 -- Function: case-table-p object
6373     This predicate returns non-‘nil’ if OBJECT is a valid case table.
6374
6375 -- Function: set-standard-case-table table
6376     This function makes TABLE the standard case table, so that it will
6377     be used in any buffers created subsequently.
6378
6379 -- Function: standard-case-table
6380     This returns the standard case table.
6381
6382 -- Function: current-case-table
6383     This function returns the current buffer’s case table.
6384
6385 -- Function: set-case-table table
6386     This sets the current buffer’s case table to TABLE.
6387
6388 -- Macro: with-case-table table body...
6389     The ‘with-case-table’ macro saves the current case table, makes
6390     TABLE the current case table, evaluates the BODY forms, and finally
6391     restores the case table.  The return value is the value of the last
6392     form in BODY.  The case table is restored even in case of an
6393     abnormal exit via ‘throw’ or error (*note Nonlocal Exits::).
6394
6395   Some language environments modify the case conversions of ASCII
6396characters; for example, in the Turkish language environment, the ASCII
6397capital I is downcased into a Turkish dotless i (‘ı’).  This can
6398interfere with code that requires ordinary ASCII case conversion, such
6399as implementations of ASCII-based network protocols.  In that case, use
6400the ‘with-case-table’ macro with the variable ASCII-CASE-TABLE, which
6401stores the unmodified case table for the ASCII character set.
6402
6403 -- Variable: ascii-case-table
6404     The case table for the ASCII character set.  This should not be
6405     modified by any language environment settings.
6406
6407   The following three functions are convenient subroutines for packages
6408that define non-ASCII character sets.  They modify the specified case
6409table CASE-TABLE; they also modify the standard syntax table.  *Note
6410Syntax Tables::.  Normally you would use these functions to change the
6411standard case table.
6412
6413 -- Function: set-case-syntax-pair uc lc case-table
6414     This function specifies a pair of corresponding letters, one upper
6415     case and one lower case.
6416
6417 -- Function: set-case-syntax-delims l r case-table
6418     This function makes characters L and R a matching pair of
6419     case-invariant delimiters.
6420
6421 -- Function: set-case-syntax char syntax case-table
6422     This function makes CHAR case-invariant, with syntax SYNTAX.
6423
6424 -- Command: describe-buffer-case-table
6425     This command displays a description of the contents of the current
6426     buffer’s case table.
6427
6428
6429File: elisp.info,  Node: Lists,  Next: Sequences Arrays Vectors,  Prev: Strings and Characters,  Up: Top
6430
64315 Lists
6432*******
6433
6434A “list” represents a sequence of zero or more elements (which may be
6435any Lisp objects).  The important difference between lists and vectors
6436is that two or more lists can share part of their structure; in
6437addition, you can insert or delete elements in a list without copying
6438the whole list.
6439
6440* Menu:
6441
6442* Cons Cells::          How lists are made out of cons cells.
6443* List-related Predicates::        Is this object a list?  Comparing two lists.
6444* List Elements::       Extracting the pieces of a list.
6445* Building Lists::      Creating list structure.
6446* List Variables::      Modifying lists stored in variables.
6447* Modifying Lists::     Storing new pieces into an existing list.
6448* Sets And Lists::      A list can represent a finite mathematical set.
6449* Association Lists::   A list can represent a finite relation or mapping.
6450* Property Lists::      A list of paired elements.
6451
6452
6453File: elisp.info,  Node: Cons Cells,  Next: List-related Predicates,  Up: Lists
6454
64555.1 Lists and Cons Cells
6456========================
6457
6458Lists in Lisp are not a primitive data type; they are built up from
6459“cons cells” (*note Cons Cell Type::).  A cons cell is a data object
6460that represents an ordered pair.  That is, it has two slots, and each
6461slot “holds”, or “refers to”, some Lisp object.  One slot is known as
6462the CAR, and the other is known as the CDR.  (These names are
6463traditional; see *note Cons Cell Type::.)  CDR is pronounced “could-er”.
6464
6465   We say that “the CAR of this cons cell is” whatever object its CAR
6466slot currently holds, and likewise for the CDR.
6467
6468   A list is a series of cons cells chained together, so that each cell
6469refers to the next one.  There is one cons cell for each element of the
6470list.  By convention, the CARs of the cons cells hold the elements of
6471the list, and the CDRs are used to chain the list (this asymmetry
6472between CAR and CDR is entirely a matter of convention; at the level of
6473cons cells, the CAR and CDR slots have similar properties).  Hence, the
6474CDR slot of each cons cell in a list refers to the following cons cell.
6475
6476   Also by convention, the CDR of the last cons cell in a list is ‘nil’.
6477We call such a ‘nil’-terminated structure a “proper list”(1).  In Emacs
6478Lisp, the symbol ‘nil’ is both a symbol and a list with no elements.
6479For convenience, the symbol ‘nil’ is considered to have ‘nil’ as its CDR
6480(and also as its CAR).
6481
6482   Hence, the CDR of a proper list is always a proper list.  The CDR of
6483a nonempty proper list is a proper list containing all the elements
6484except the first.
6485
6486   If the CDR of a list’s last cons cell is some value other than ‘nil’,
6487we call the structure a “dotted list”, since its printed representation
6488would use dotted pair notation (*note Dotted Pair Notation::).  There is
6489one other possibility: some cons cell’s CDR could point to one of the
6490previous cons cells in the list.  We call that structure a “circular
6491list”.
6492
6493   For some purposes, it does not matter whether a list is proper,
6494circular or dotted.  If a program doesn’t look far enough down the list
6495to see the CDR of the final cons cell, it won’t care.  However, some
6496functions that operate on lists demand proper lists and signal errors if
6497given a dotted list.  Most functions that try to find the end of a list
6498enter infinite loops if given a circular list.
6499
6500   Because most cons cells are used as part of lists, we refer to any
6501structure made out of cons cells as a “list structure”.
6502
6503   ---------- Footnotes ----------
6504
6505   (1) It is sometimes also referred to as a “true list”, but we
6506generally do not use this terminology in this manual.
6507
6508
6509File: elisp.info,  Node: List-related Predicates,  Next: List Elements,  Prev: Cons Cells,  Up: Lists
6510
65115.2 Predicates on Lists
6512=======================
6513
6514The following predicates test whether a Lisp object is an atom, whether
6515it is a cons cell or is a list, or whether it is the distinguished
6516object ‘nil’.  (Many of these predicates can be defined in terms of the
6517others, but they are used so often that it is worth having them.)
6518
6519 -- Function: consp object
6520     This function returns ‘t’ if OBJECT is a cons cell, ‘nil’
6521     otherwise.  ‘nil’ is not a cons cell, although it _is_ a list.
6522
6523 -- Function: atom object
6524     This function returns ‘t’ if OBJECT is an atom, ‘nil’ otherwise.
6525     All objects except cons cells are atoms.  The symbol ‘nil’ is an
6526     atom and is also a list; it is the only Lisp object that is both.
6527
6528          (atom OBJECT) ≡ (not (consp OBJECT))
6529
6530 -- Function: listp object
6531     This function returns ‘t’ if OBJECT is a cons cell or ‘nil’.
6532     Otherwise, it returns ‘nil’.
6533
6534          (listp '(1))
6535               ⇒ t
6536          (listp '())
6537               ⇒ t
6538
6539 -- Function: nlistp object
6540     This function is the opposite of ‘listp’: it returns ‘t’ if OBJECT
6541     is not a list.  Otherwise, it returns ‘nil’.
6542
6543          (listp OBJECT) ≡ (not (nlistp OBJECT))
6544
6545 -- Function: null object
6546     This function returns ‘t’ if OBJECT is ‘nil’, and returns ‘nil’
6547     otherwise.  This function is identical to ‘not’, but as a matter of
6548     clarity we use ‘null’ when OBJECT is considered a list and ‘not’
6549     when it is considered a truth value (see ‘not’ in *note Combining
6550     Conditions::).
6551
6552          (null '(1))
6553               ⇒ nil
6554          (null '())
6555               ⇒ t
6556
6557 -- Function: proper-list-p object
6558     This function returns the length of OBJECT if it is a proper list,
6559     ‘nil’ otherwise (*note Cons Cells::).  In addition to satisfying
6560     ‘listp’, a proper list is neither circular nor dotted.
6561
6562          (proper-list-p '(a b c))
6563              ⇒ 3
6564          (proper-list-p '(a b . c))
6565              ⇒ nil
6566
6567
6568File: elisp.info,  Node: List Elements,  Next: Building Lists,  Prev: List-related Predicates,  Up: Lists
6569
65705.3 Accessing Elements of Lists
6571===============================
6572
6573 -- Function: car cons-cell
6574     This function returns the value referred to by the first slot of
6575     the cons cell CONS-CELL.  In other words, it returns the CAR of
6576     CONS-CELL.
6577
6578     As a special case, if CONS-CELL is ‘nil’, this function returns
6579     ‘nil’.  Therefore, any list is a valid argument.  An error is
6580     signaled if the argument is not a cons cell or ‘nil’.
6581
6582          (car '(a b c))
6583               ⇒ a
6584          (car '())
6585               ⇒ nil
6586
6587 -- Function: cdr cons-cell
6588     This function returns the value referred to by the second slot of
6589     the cons cell CONS-CELL.  In other words, it returns the CDR of
6590     CONS-CELL.
6591
6592     As a special case, if CONS-CELL is ‘nil’, this function returns
6593     ‘nil’; therefore, any list is a valid argument.  An error is
6594     signaled if the argument is not a cons cell or ‘nil’.
6595
6596          (cdr '(a b c))
6597               ⇒ (b c)
6598          (cdr '())
6599               ⇒ nil
6600
6601 -- Function: car-safe object
6602     This function lets you take the CAR of a cons cell while avoiding
6603     errors for other data types.  It returns the CAR of OBJECT if
6604     OBJECT is a cons cell, ‘nil’ otherwise.  This is in contrast to
6605     ‘car’, which signals an error if OBJECT is not a list.
6606
6607          (car-safe OBJECT)
66086609          (let ((x OBJECT))
6610            (if (consp x)
6611                (car x)
6612              nil))
6613
6614 -- Function: cdr-safe object
6615     This function lets you take the CDR of a cons cell while avoiding
6616     errors for other data types.  It returns the CDR of OBJECT if
6617     OBJECT is a cons cell, ‘nil’ otherwise.  This is in contrast to
6618     ‘cdr’, which signals an error if OBJECT is not a list.
6619
6620          (cdr-safe OBJECT)
66216622          (let ((x OBJECT))
6623            (if (consp x)
6624                (cdr x)
6625              nil))
6626
6627 -- Macro: pop listname
6628     This macro provides a convenient way to examine the CAR of a list,
6629     and take it off the list, all at once.  It operates on the list
6630     stored in LISTNAME.  It removes the first element from the list,
6631     saves the CDR into LISTNAME, then returns the removed element.
6632
6633     In the simplest case, LISTNAME is an unquoted symbol naming a list;
6634     in that case, this macro is equivalent to
6635     ‘(prog1 (car listname) (setq listname (cdr listname)))’.
6636
6637          x
6638               ⇒ (a b c)
6639          (pop x)
6640               ⇒ a
6641          x
6642               ⇒ (b c)
6643
6644     More generally, LISTNAME can be a generalized variable.  In that
6645     case, this macro saves into LISTNAME using ‘setf’.  *Note
6646     Generalized Variables::.
6647
6648     For the ‘push’ macro, which adds an element to a list, *Note List
6649     Variables::.
6650
6651 -- Function: nth n list
6652     This function returns the Nth element of LIST.  Elements are
6653     numbered starting with zero, so the CAR of LIST is element number
6654     zero.  If the length of LIST is N or less, the value is ‘nil’.
6655
6656          (nth 2 '(1 2 3 4))
6657               ⇒ 3
6658          (nth 10 '(1 2 3 4))
6659               ⇒ nil
6660
6661          (nth n x) ≡ (car (nthcdr n x))
6662
6663     The function ‘elt’ is similar, but applies to any kind of sequence.
6664     For historical reasons, it takes its arguments in the opposite
6665     order.  *Note Sequence Functions::.
6666
6667 -- Function: nthcdr n list
6668     This function returns the Nth CDR of LIST.  In other words, it
6669     skips past the first N links of LIST and returns what follows.
6670
6671     If N is zero, ‘nthcdr’ returns all of LIST.  If the length of LIST
6672     is N or less, ‘nthcdr’ returns ‘nil’.
6673
6674          (nthcdr 1 '(1 2 3 4))
6675               ⇒ (2 3 4)
6676          (nthcdr 10 '(1 2 3 4))
6677               ⇒ nil
6678          (nthcdr 0 '(1 2 3 4))
6679               ⇒ (1 2 3 4)
6680
6681 -- Function: last list &optional n
6682     This function returns the last link of LIST.  The ‘car’ of this
6683     link is the list’s last element.  If LIST is null, ‘nil’ is
6684     returned.  If N is non-‘nil’, the Nth-to-last link is returned
6685     instead, or the whole of LIST if N is bigger than LIST’s length.
6686
6687 -- Function: safe-length list
6688     This function returns the length of LIST, with no risk of either an
6689     error or an infinite loop.  It generally returns the number of
6690     distinct cons cells in the list.  However, for circular lists, the
6691     value is just an upper bound; it is often too large.
6692
6693     If LIST is not ‘nil’ or a cons cell, ‘safe-length’ returns 0.
6694
6695   The most common way to compute the length of a list, when you are not
6696worried that it may be circular, is with ‘length’.  *Note Sequence
6697Functions::.
6698
6699 -- Function: caar cons-cell
6700     This is the same as ‘(car (car CONS-CELL))’.
6701
6702 -- Function: cadr cons-cell
6703     This is the same as ‘(car (cdr CONS-CELL))’ or ‘(nth 1 CONS-CELL)’.
6704
6705 -- Function: cdar cons-cell
6706     This is the same as ‘(cdr (car CONS-CELL))’.
6707
6708 -- Function: cddr cons-cell
6709     This is the same as ‘(cdr (cdr CONS-CELL))’ or ‘(nthcdr 2
6710     CONS-CELL)’.
6711
6712   In addition to the above, 24 additional compositions of ‘car’ and
6713‘cdr’ are defined as ‘cXXXr’ and ‘cXXXXr’, where each ‘X’ is either ‘a’
6714or ‘d’.  ‘cadr’, ‘caddr’, and ‘cadddr’ pick out the second, third or
6715fourth elements of a list, respectively.  ‘cl-lib’ provides the same
6716under the names ‘cl-second’, ‘cl-third’, and ‘cl-fourth’.  *Note
6717(cl)List Functions::.
6718
6719 -- Function: butlast x &optional n
6720     This function returns the list X with the last element, or the last
6721     N elements, removed.  If N is greater than zero it makes a copy of
6722     the list so as not to damage the original list.  In general,
6723     ‘(append (butlast X N) (last X N))’ will return a list equal to X.
6724
6725 -- Function: nbutlast x &optional n
6726     This is a version of ‘butlast’ that works by destructively
6727     modifying the ‘cdr’ of the appropriate element, rather than making
6728     a copy of the list.
6729
6730
6731File: elisp.info,  Node: Building Lists,  Next: List Variables,  Prev: List Elements,  Up: Lists
6732
67335.4 Building Cons Cells and Lists
6734=================================
6735
6736Many functions build lists, as lists reside at the very heart of Lisp.
6737‘cons’ is the fundamental list-building function; however, it is
6738interesting to note that ‘list’ is used more times in the source code
6739for Emacs than ‘cons’.
6740
6741 -- Function: cons object1 object2
6742     This function is the most basic function for building new list
6743     structure.  It creates a new cons cell, making OBJECT1 the CAR, and
6744     OBJECT2 the CDR.  It then returns the new cons cell.  The arguments
6745     OBJECT1 and OBJECT2 may be any Lisp objects, but most often OBJECT2
6746     is a list.
6747
6748          (cons 1 '(2))
6749               ⇒ (1 2)
6750          (cons 1 '())
6751               ⇒ (1)
6752          (cons 1 2)
6753               ⇒ (1 . 2)
6754
6755     ‘cons’ is often used to add a single element to the front of a
6756     list.  This is called “consing the element onto the list”.  (1) For
6757     example:
6758
6759          (setq list (cons newelt list))
6760
6761     Note that there is no conflict between the variable named ‘list’
6762     used in this example and the function named ‘list’ described below;
6763     any symbol can serve both purposes.
6764
6765 -- Function: list &rest objects
6766     This function creates a list with OBJECTS as its elements.  The
6767     resulting list is always ‘nil’-terminated.  If no OBJECTS are
6768     given, the empty list is returned.
6769
6770          (list 1 2 3 4 5)
6771               ⇒ (1 2 3 4 5)
6772          (list 1 2 '(3 4 5) 'foo)
6773               ⇒ (1 2 (3 4 5) foo)
6774          (list)
6775               ⇒ nil
6776
6777 -- Function: make-list length object
6778     This function creates a list of LENGTH elements, in which each
6779     element is OBJECT.  Compare ‘make-list’ with ‘make-string’ (*note
6780     Creating Strings::).
6781
6782          (make-list 3 'pigs)
6783               ⇒ (pigs pigs pigs)
6784          (make-list 0 'pigs)
6785               ⇒ nil
6786          (setq l (make-list 3 '(a b)))
6787               ⇒ ((a b) (a b) (a b))
6788          (eq (car l) (cadr l))
6789               ⇒ t
6790
6791 -- Function: append &rest sequences
6792     This function returns a list containing all the elements of
6793     SEQUENCES.  The SEQUENCES may be lists, vectors, bool-vectors, or
6794     strings, but the last one should usually be a list.  All arguments
6795     except the last one are copied, so none of the arguments is
6796     altered.  (See ‘nconc’ in *note Rearrangement::, for a way to join
6797     lists with no copying.)
6798
6799     More generally, the final argument to ‘append’ may be any Lisp
6800     object.  The final argument is not copied or converted; it becomes
6801     the CDR of the last cons cell in the new list.  If the final
6802     argument is itself a list, then its elements become in effect
6803     elements of the result list.  If the final element is not a list,
6804     the result is a dotted list since its final CDR is not ‘nil’ as
6805     required in a proper list (*note Cons Cells::).
6806
6807   Here is an example of using ‘append’:
6808
6809     (setq trees '(pine oak))
6810          ⇒ (pine oak)
6811     (setq more-trees (append '(maple birch) trees))
6812          ⇒ (maple birch pine oak)
6813
6814     trees
6815          ⇒ (pine oak)
6816     more-trees
6817          ⇒ (maple birch pine oak)
6818     (eq trees (cdr (cdr more-trees)))
6819          ⇒ t
6820
6821   You can see how ‘append’ works by looking at a box diagram.  The
6822variable ‘trees’ is set to the list ‘(pine oak)’ and then the variable
6823‘more-trees’ is set to the list ‘(maple birch pine oak)’.  However, the
6824variable ‘trees’ continues to refer to the original list:
6825
6826     more-trees                trees
6827     |                           |
6828     |     --- ---      --- ---   -> --- ---      --- ---
6829      --> |   |   |--> |   |   |--> |   |   |--> |   |   |--> nil
6830           --- ---      --- ---      --- ---      --- ---
6831            |            |            |            |
6832            |            |            |            |
6833             --> maple    -->birch     --> pine     --> oak
6834
6835   An empty sequence contributes nothing to the value returned by
6836‘append’.  As a consequence of this, a final ‘nil’ argument forces a
6837copy of the previous argument:
6838
6839     trees
6840          ⇒ (pine oak)
6841     (setq wood (append trees nil))
6842          ⇒ (pine oak)
6843     wood
6844          ⇒ (pine oak)
6845     (eq wood trees)
6846          ⇒ nil
6847
6848This once was the usual way to copy a list, before the function
6849‘copy-sequence’ was invented.  *Note Sequences Arrays Vectors::.
6850
6851   Here we show the use of vectors and strings as arguments to ‘append’:
6852
6853     (append [a b] "cd" nil)
6854          ⇒ (a b 99 100)
6855
6856   With the help of ‘apply’ (*note Calling Functions::), we can append
6857all the lists in a list of lists:
6858
6859     (apply 'append '((a b c) nil (x y z) nil))
6860          ⇒ (a b c x y z)
6861
6862   If no SEQUENCES are given, ‘nil’ is returned:
6863
6864     (append)
6865          ⇒ nil
6866
6867   Here are some examples where the final argument is not a list:
6868
6869     (append '(x y) 'z)
6870          ⇒ (x y . z)
6871     (append '(x y) [z])
6872          ⇒ (x y . [z])
6873
6874The second example shows that when the final argument is a sequence but
6875not a list, the sequence’s elements do not become elements of the
6876resulting list.  Instead, the sequence becomes the final CDR, like any
6877other non-list final argument.
6878
6879 -- Function: copy-tree tree &optional vecp
6880     This function returns a copy of the tree TREE.  If TREE is a cons
6881     cell, this makes a new cons cell with the same CAR and CDR, then
6882     recursively copies the CAR and CDR in the same way.
6883
6884     Normally, when TREE is anything other than a cons cell, ‘copy-tree’
6885     simply returns TREE.  However, if VECP is non-‘nil’, it copies
6886     vectors too (and operates recursively on their elements).
6887
6888 -- Function: flatten-tree tree
6889     This function returns a “flattened” copy of TREE, that is, a list
6890     containing all the non-‘nil’ terminal nodes, or leaves, of the tree
6891     of cons cells rooted at TREE.  Leaves in the returned list are in
6892     the same order as in TREE.
6893
6894     (flatten-tree '(1 (2 . 3) nil (4 5 (6)) 7))
6895         ⇒(1 2 3 4 5 6 7)
6896
6897 -- Function: number-sequence from &optional to separation
6898     This function returns a list of numbers starting with FROM and
6899     incrementing by SEPARATION, and ending at or just before TO.
6900     SEPARATION can be positive or negative and defaults to 1.  If TO is
6901     ‘nil’ or numerically equal to FROM, the value is the one-element
6902     list ‘(FROM)’.  If TO is less than FROM with a positive SEPARATION,
6903     or greater than FROM with a negative SEPARATION, the value is ‘nil’
6904     because those arguments specify an empty sequence.
6905
6906     If SEPARATION is 0 and TO is neither ‘nil’ nor numerically equal to
6907     FROM, ‘number-sequence’ signals an error, since those arguments
6908     specify an infinite sequence.
6909
6910     All arguments are numbers.  Floating-point arguments can be tricky,
6911     because floating-point arithmetic is inexact.  For instance,
6912     depending on the machine, it may quite well happen that
6913     ‘(number-sequence 0.4 0.6 0.2)’ returns the one element list
6914     ‘(0.4)’, whereas ‘(number-sequence 0.4 0.8 0.2)’ returns a list
6915     with three elements.  The Nth element of the list is computed by
6916     the exact formula ‘(+ FROM (* N SEPARATION))’.  Thus, if one wants
6917     to make sure that TO is included in the list, one can pass an
6918     expression of this exact type for TO.  Alternatively, one can
6919     replace TO with a slightly larger value (or a slightly more
6920     negative value if SEPARATION is negative).
6921
6922     Some examples:
6923
6924          (number-sequence 4 9)
6925               ⇒ (4 5 6 7 8 9)
6926          (number-sequence 9 4 -1)
6927               ⇒ (9 8 7 6 5 4)
6928          (number-sequence 9 4 -2)
6929               ⇒ (9 7 5)
6930          (number-sequence 8)
6931               ⇒ (8)
6932          (number-sequence 8 5)
6933               ⇒ nil
6934          (number-sequence 5 8 -1)
6935               ⇒ nil
6936          (number-sequence 1.5 6 2)
6937               ⇒ (1.5 3.5 5.5)
6938
6939   ---------- Footnotes ----------
6940
6941   (1) There is no strictly equivalent way to add an element to the end
6942of a list.  You can use ‘(append LISTNAME (list NEWELT))’, which creates
6943a whole new list by copying LISTNAME and adding NEWELT to its end.  Or
6944you can use ‘(nconc LISTNAME (list NEWELT))’, which modifies LISTNAME by
6945following all the CDRs and then replacing the terminating ‘nil’.
6946Compare this to adding an element to the beginning of a list with
6947‘cons’, which neither copies nor modifies the list.
6948
6949
6950File: elisp.info,  Node: List Variables,  Next: Modifying Lists,  Prev: Building Lists,  Up: Lists
6951
69525.5 Modifying List Variables
6953============================
6954
6955These functions, and one macro, provide convenient ways to modify a list
6956which is stored in a variable.
6957
6958 -- Macro: push element listname
6959     This macro creates a new list whose CAR is ELEMENT and whose CDR is
6960     the list specified by LISTNAME, and saves that list in LISTNAME.
6961     In the simplest case, LISTNAME is an unquoted symbol naming a list,
6962     and this macro is equivalent to
6963     ‘(setq LISTNAME (cons ELEMENT LISTNAME))’.
6964
6965          (setq l '(a b))
6966               ⇒ (a b)
6967          (push 'c l)
6968               ⇒ (c a b)
6969          l
6970               ⇒ (c a b)
6971
6972     More generally, ‘listname’ can be a generalized variable.  In that
6973     case, this macro does the equivalent of
6974     ‘(setf LISTNAME (cons ELEMENT LISTNAME))’.  *Note Generalized
6975     Variables::.
6976
6977     For the ‘pop’ macro, which removes the first element from a list,
6978     *Note List Elements::.
6979
6980   Two functions modify lists that are the values of variables.
6981
6982 -- Function: add-to-list symbol element &optional append compare-fn
6983     This function sets the variable SYMBOL by consing ELEMENT onto the
6984     old value, if ELEMENT is not already a member of that value.  It
6985     returns the resulting list, whether updated or not.  The value of
6986     SYMBOL had better be a list already before the call.  ‘add-to-list’
6987     uses COMPARE-FN to compare ELEMENT against existing list members;
6988     if COMPARE-FN is ‘nil’, it uses ‘equal’.
6989
6990     Normally, if ELEMENT is added, it is added to the front of SYMBOL,
6991     but if the optional argument APPEND is non-‘nil’, it is added at
6992     the end.
6993
6994     The argument SYMBOL is not implicitly quoted; ‘add-to-list’ is an
6995     ordinary function, like ‘set’ and unlike ‘setq’.  Quote the
6996     argument yourself if that is what you want.
6997
6998     Do not use this function when SYMBOL refers to a lexical variable.
6999
7000   Here’s a scenario showing how to use ‘add-to-list’:
7001
7002     (setq foo '(a b))
7003          ⇒ (a b)
7004
7005     (add-to-list 'foo 'c)     ;; Add ‘c’.
7006          ⇒ (c a b)
7007
7008     (add-to-list 'foo 'b)     ;; No effect.
7009          ⇒ (c a b)
7010
7011     foo                       ;; ‘foo’ was changed.
7012          ⇒ (c a b)
7013
7014   An equivalent expression for ‘(add-to-list 'VAR VALUE)’ is this:
7015
7016     (if (member VALUE VAR)
7017         VAR
7018       (setq VAR (cons VALUE VAR)))
7019
7020 -- Function: add-to-ordered-list symbol element &optional order
7021     This function sets the variable SYMBOL by inserting ELEMENT into
7022     the old value, which must be a list, at the position specified by
7023     ORDER.  If ELEMENT is already a member of the list, its position in
7024     the list is adjusted according to ORDER.  Membership is tested
7025     using ‘eq’.  This function returns the resulting list, whether
7026     updated or not.
7027
7028     The ORDER is typically a number (integer or float), and the
7029     elements of the list are sorted in non-decreasing numerical order.
7030
7031     ORDER may also be omitted or ‘nil’.  Then the numeric order of
7032     ELEMENT stays unchanged if it already has one; otherwise, ELEMENT
7033     has no numeric order.  Elements without a numeric list order are
7034     placed at the end of the list, in no particular order.
7035
7036     Any other value for ORDER removes the numeric order of ELEMENT if
7037     it already has one; otherwise, it is equivalent to ‘nil’.
7038
7039     The argument SYMBOL is not implicitly quoted; ‘add-to-ordered-list’
7040     is an ordinary function, like ‘set’ and unlike ‘setq’.  Quote the
7041     argument yourself if necessary.
7042
7043     The ordering information is stored in a hash table on SYMBOL’s
7044     ‘list-order’ property.  SYMBOL cannot refer to a lexical variable.
7045
7046   Here’s a scenario showing how to use ‘add-to-ordered-list’:
7047
7048     (setq foo '())
7049          ⇒ nil
7050
7051     (add-to-ordered-list 'foo 'a 1)     ;; Add ‘a’.
7052          ⇒ (a)
7053
7054     (add-to-ordered-list 'foo 'c 3)     ;; Add ‘c’.
7055          ⇒ (a c)
7056
7057     (add-to-ordered-list 'foo 'b 2)     ;; Add ‘b’.
7058          ⇒ (a b c)
7059
7060     (add-to-ordered-list 'foo 'b 4)     ;; Move ‘b’.
7061          ⇒ (a c b)
7062
7063     (add-to-ordered-list 'foo 'd)       ;; Append ‘d’.
7064          ⇒ (a c b d)
7065
7066     (add-to-ordered-list 'foo 'e)       ;; Add ‘e’.
7067          ⇒ (a c b e d)
7068
7069     foo                       ;; ‘foo’ was changed.
7070          ⇒ (a c b e d)
7071
7072
7073File: elisp.info,  Node: Modifying Lists,  Next: Sets And Lists,  Prev: List Variables,  Up: Lists
7074
70755.6 Modifying Existing List Structure
7076=====================================
7077
7078You can modify the CAR and CDR contents of a cons cell with the
7079primitives ‘setcar’ and ‘setcdr’.  These are destructive operations
7080because they change existing list structure.  Destructive operations
7081should be applied only to mutable lists, that is, lists constructed via
7082‘cons’, ‘list’ or similar operations.  Lists created by quoting are part
7083of the program and should not be changed by destructive operations.
7084*Note Mutability::.
7085
7086     Common Lisp note: Common Lisp uses functions ‘rplaca’ and ‘rplacd’
7087     to alter list structure; they change structure the same way as
7088     ‘setcar’ and ‘setcdr’, but the Common Lisp functions return the
7089     cons cell while ‘setcar’ and ‘setcdr’ return the new CAR or CDR.
7090
7091* Menu:
7092
7093* Setcar::          Replacing an element in a list.
7094* Setcdr::          Replacing part of the list backbone.
7095                      This can be used to remove or add elements.
7096* Rearrangement::   Reordering the elements in a list; combining lists.
7097
7098
7099File: elisp.info,  Node: Setcar,  Next: Setcdr,  Up: Modifying Lists
7100
71015.6.1 Altering List Elements with ‘setcar’
7102------------------------------------------
7103
7104Changing the CAR of a cons cell is done with ‘setcar’.  When used on a
7105list, ‘setcar’ replaces one element of a list with a different element.
7106
7107 -- Function: setcar cons object
7108     This function stores OBJECT as the new CAR of CONS, replacing its
7109     previous CAR.  In other words, it changes the CAR slot of CONS to
7110     refer to OBJECT.  It returns the value OBJECT.  For example:
7111
7112          (setq x (list 1 2))
7113               ⇒ (1 2)
7114          (setcar x 4)
7115               ⇒ 4
7116          x
7117               ⇒ (4 2)
7118
7119   When a cons cell is part of the shared structure of several lists,
7120storing a new CAR into the cons changes one element of each of these
7121lists.  Here is an example:
7122
7123     ;; Create two lists that are partly shared.
7124     (setq x1 (list 'a 'b 'c))
7125          ⇒ (a b c)
7126     (setq x2 (cons 'z (cdr x1)))
7127          ⇒ (z b c)
7128
7129     ;; Replace the CAR of a shared link.
7130     (setcar (cdr x1) 'foo)
7131          ⇒ foo
7132     x1                           ; Both lists are changed.
7133          ⇒ (a foo c)
7134     x2
7135          ⇒ (z foo c)
7136
7137     ;; Replace the CAR of a link that is not shared.
7138     (setcar x1 'baz)
7139          ⇒ baz
7140     x1                           ; Only one list is changed.
7141          ⇒ (baz foo c)
7142     x2
7143          ⇒ (z foo c)
7144
7145   Here is a graphical depiction of the shared structure of the two
7146lists in the variables ‘x1’ and ‘x2’, showing why replacing ‘b’ changes
7147them both:
7148
7149             --- ---        --- ---      --- ---
7150     x1---> |   |   |----> |   |   |--> |   |   |--> nil
7151             --- ---        --- ---      --- ---
7152              |        -->   |            |
7153              |       |      |            |
7154               --> a  |       --> b        --> c
7155                      |
7156            --- ---   |
7157     x2--> |   |   |--
7158            --- ---
7159             |
7160             |
7161              --> z
7162
7163   Here is an alternative form of box diagram, showing the same
7164relationship:
7165
7166     x1:
7167      --------------       --------------       --------------
7168     | car   | cdr  |     | car   | cdr  |     | car   | cdr  |
7169     |   a   |   o------->|   b   |   o------->|   c   |  nil |
7170     |       |      |  -->|       |      |     |       |      |
7171      --------------  |    --------------       --------------
7172                      |
7173     x2:              |
7174      --------------  |
7175     | car   | cdr  | |
7176     |   z   |   o----
7177     |       |      |
7178      --------------
7179
7180
7181File: elisp.info,  Node: Setcdr,  Next: Rearrangement,  Prev: Setcar,  Up: Modifying Lists
7182
71835.6.2 Altering the CDR of a List
7184--------------------------------
7185
7186The lowest-level primitive for modifying a CDR is ‘setcdr’:
7187
7188 -- Function: setcdr cons object
7189     This function stores OBJECT as the new CDR of CONS, replacing its
7190     previous CDR.  In other words, it changes the CDR slot of CONS to
7191     refer to OBJECT.  It returns the value OBJECT.
7192
7193   Here is an example of replacing the CDR of a list with a different
7194list.  All but the first element of the list are removed in favor of a
7195different sequence of elements.  The first element is unchanged, because
7196it resides in the CAR of the list, and is not reached via the CDR.
7197
7198     (setq x (list 1 2 3))
7199          ⇒ (1 2 3)
7200     (setcdr x '(4))
7201          ⇒ (4)
7202     x
7203          ⇒ (1 4)
7204
7205   You can delete elements from the middle of a list by altering the
7206CDRs of the cons cells in the list.  For example, here we delete the
7207second element, ‘b’, from the list ‘(a b c)’, by changing the CDR of the
7208first cons cell:
7209
7210     (setq x1 (list 'a 'b 'c))
7211          ⇒ (a b c)
7212     (setcdr x1 (cdr (cdr x1)))
7213          ⇒ (c)
7214     x1
7215          ⇒ (a c)
7216
7217   Here is the result in box notation:
7218
7219                        --------------------
7220                       |                    |
7221      --------------   |   --------------   |    --------------
7222     | car   | cdr  |  |  | car   | cdr  |   -->| car   | cdr  |
7223     |   a   |   o-----   |   b   |   o-------->|   c   |  nil |
7224     |       |      |     |       |      |      |       |      |
7225      --------------       --------------        --------------
7226
7227The second cons cell, which previously held the element ‘b’, still
7228exists and its CAR is still ‘b’, but it no longer forms part of this
7229list.
7230
7231   It is equally easy to insert a new element by changing CDRs:
7232
7233     (setq x1 (list 'a 'b 'c))
7234          ⇒ (a b c)
7235     (setcdr x1 (cons 'd (cdr x1)))
7236          ⇒ (d b c)
7237     x1
7238          ⇒ (a d b c)
7239
7240   Here is this result in box notation:
7241
7242      --------------        -------------       -------------
7243     | car  | cdr   |      | car  | cdr  |     | car  | cdr  |
7244     |   a  |   o   |   -->|   b  |   o------->|   c  |  nil |
7245     |      |   |   |  |   |      |      |     |      |      |
7246      --------- | --   |    -------------       -------------
7247                |      |
7248          -----         --------
7249         |                      |
7250         |    ---------------   |
7251         |   | car   | cdr   |  |
7252          -->|   d   |   o------
7253             |       |       |
7254              ---------------
7255
7256
7257File: elisp.info,  Node: Rearrangement,  Prev: Setcdr,  Up: Modifying Lists
7258
72595.6.3 Functions that Rearrange Lists
7260------------------------------------
7261
7262Here are some functions that rearrange lists destructively by modifying
7263the CDRs of their component cons cells.  These functions are destructive
7264because they chew up the original lists passed to them as arguments,
7265relinking their cons cells to form a new list that is the returned
7266value.
7267
7268   See ‘delq’, in *note Sets And Lists::, for another function that
7269modifies cons cells.
7270
7271 -- Function: nconc &rest lists
7272     This function returns a list containing all the elements of LISTS.
7273     Unlike ‘append’ (*note Building Lists::), the LISTS are _not_
7274     copied.  Instead, the last CDR of each of the LISTS is changed to
7275     refer to the following list.  The last of the LISTS is not altered.
7276     For example:
7277
7278          (setq x (list 1 2 3))
7279               ⇒ (1 2 3)
7280          (nconc x '(4 5))
7281               ⇒ (1 2 3 4 5)
7282          x
7283               ⇒ (1 2 3 4 5)
7284
7285     Since the last argument of ‘nconc’ is not itself modified, it is
7286     reasonable to use a constant list, such as ‘'(4 5)’, as in the
7287     above example.  For the same reason, the last argument need not be
7288     a list:
7289
7290          (setq x (list 1 2 3))
7291               ⇒ (1 2 3)
7292          (nconc x 'z)
7293               ⇒ (1 2 3 . z)
7294          x
7295               ⇒ (1 2 3 . z)
7296
7297     However, the other arguments (all but the last) should be mutable
7298     lists.
7299
7300     A common pitfall is to use a constant list as a non-last argument
7301     to ‘nconc’.  If you do this, the resulting behavior is undefined.
7302     It is possible that your program will change each time you run it!
7303     Here is what might happen (though this is not guaranteed to
7304     happen):
7305
7306          (defun add-foo (x)            ; We want this function to add
7307            (nconc '(foo) x))           ;   ‘foo’ to the front of its arg.
7308
7309          (symbol-function 'add-foo)
7310               ⇒ (lambda (x) (nconc '(foo) x))
7311
7312          (setq xx (add-foo '(1 2)))    ; It seems to work.
7313               ⇒ (foo 1 2)
7314          (setq xy (add-foo '(3 4)))    ; What happened?
7315               ⇒ (foo 1 2 3 4)
7316          (eq xx xy)
7317               ⇒ t
7318
7319          (symbol-function 'add-foo)
7320               ⇒ (lambda (x) (nconc '(foo 1 2 3 4) x))
7321
7322
7323File: elisp.info,  Node: Sets And Lists,  Next: Association Lists,  Prev: Modifying Lists,  Up: Lists
7324
73255.7 Using Lists as Sets
7326=======================
7327
7328A list can represent an unordered mathematical set—simply consider a
7329value an element of a set if it appears in the list, and ignore the
7330order of the list.  To form the union of two sets, use ‘append’ (as long
7331as you don’t mind having duplicate elements).  You can remove ‘equal’
7332duplicates using ‘delete-dups’.  Other useful functions for sets include
7333‘memq’ and ‘delq’, and their ‘equal’ versions, ‘member’ and ‘delete’.
7334
7335     Common Lisp note: Common Lisp has functions ‘union’ (which avoids
7336     duplicate elements) and ‘intersection’ for set operations.  In
7337     Emacs Lisp, variants of these facilities are provided by the
7338     ‘cl-lib’ library.  *Note (cl)Lists as Sets::.
7339
7340 -- Function: memq object list
7341     This function tests to see whether OBJECT is a member of LIST.  If
7342     it is, ‘memq’ returns a list starting with the first occurrence of
7343     OBJECT.  Otherwise, it returns ‘nil’.  The letter ‘q’ in ‘memq’
7344     says that it uses ‘eq’ to compare OBJECT against the elements of
7345     the list.  For example:
7346
7347          (memq 'b '(a b c b a))
7348               ⇒ (b c b a)
7349          (memq '(2) '((1) (2)))    ; The two ‘(2)’s need not be ‘eq’.
7350               ⇒ Unspecified; might be ‘nil’ or ‘((2))’.
7351
7352 -- Function: delq object list
7353     This function destructively removes all elements ‘eq’ to OBJECT
7354     from LIST, and returns the resulting list.  The letter ‘q’ in
7355     ‘delq’ says that it uses ‘eq’ to compare OBJECT against the
7356     elements of the list, like ‘memq’ and ‘remq’.
7357
7358     Typically, when you invoke ‘delq’, you should use the return value
7359     by assigning it to the variable which held the original list.  The
7360     reason for this is explained below.
7361
7362   The ‘delq’ function deletes elements from the front of the list by
7363simply advancing down the list, and returning a sublist that starts
7364after those elements.  For example:
7365
7366     (delq 'a '(a b c)) ≡ (cdr '(a b c))
7367
7368When an element to be deleted appears in the middle of the list,
7369removing it involves changing the CDRs (*note Setcdr::).
7370
7371     (setq sample-list (list 'a 'b 'c '(4)))
7372          ⇒ (a b c (4))
7373     (delq 'a sample-list)
7374          ⇒ (b c (4))
7375     sample-list
7376          ⇒ (a b c (4))
7377     (delq 'c sample-list)
7378          ⇒ (a b (4))
7379     sample-list
7380          ⇒ (a b (4))
7381
7382   Note that ‘(delq 'c sample-list)’ modifies ‘sample-list’ to splice
7383out the third element, but ‘(delq 'a sample-list)’ does not splice
7384anything—it just returns a shorter list.  Don’t assume that a variable
7385which formerly held the argument LIST now has fewer elements, or that it
7386still holds the original list!  Instead, save the result of ‘delq’ and
7387use that.  Most often we store the result back into the variable that
7388held the original list:
7389
7390     (setq flowers (delq 'rose flowers))
7391
7392   In the following example, the ‘(list 4)’ that ‘delq’ attempts to
7393match and the ‘(4)’ in the ‘sample-list’ are ‘equal’ but not ‘eq’:
7394
7395     (delq (list 4) sample-list)
7396          ⇒ (a c (4))
7397
7398   If you want to delete elements that are ‘equal’ to a given value, use
7399‘delete’ (see below).
7400
7401 -- Function: remq object list
7402     This function returns a copy of LIST, with all elements removed
7403     which are ‘eq’ to OBJECT.  The letter ‘q’ in ‘remq’ says that it
7404     uses ‘eq’ to compare OBJECT against the elements of ‘list’.
7405
7406          (setq sample-list (list 'a 'b 'c 'a 'b 'c))
7407               ⇒ (a b c a b c)
7408          (remq 'a sample-list)
7409               ⇒ (b c b c)
7410          sample-list
7411               ⇒ (a b c a b c)
7412
7413 -- Function: memql object list
7414     The function ‘memql’ tests to see whether OBJECT is a member of
7415     LIST, comparing members with OBJECT using ‘eql’, so floating-point
7416     elements are compared by value.  If OBJECT is a member, ‘memql’
7417     returns a list starting with its first occurrence in LIST.
7418     Otherwise, it returns ‘nil’.
7419
7420     Compare this with ‘memq’:
7421
7422          (memql 1.2 '(1.1 1.2 1.3))  ; ‘1.2’ and ‘1.2’ are ‘eql’.
7423               ⇒ (1.2 1.3)
7424          (memq 1.2 '(1.1 1.2 1.3))  ; The two ‘1.2’s need not be ‘eq’.
7425               ⇒ Unspecified; might be ‘nil’ or ‘(1.2 1.3)’.
7426
7427   The following three functions are like ‘memq’, ‘delq’ and ‘remq’, but
7428use ‘equal’ rather than ‘eq’ to compare elements.  *Note Equality
7429Predicates::.
7430
7431 -- Function: member object list
7432     The function ‘member’ tests to see whether OBJECT is a member of
7433     LIST, comparing members with OBJECT using ‘equal’.  If OBJECT is a
7434     member, ‘member’ returns a list starting with its first occurrence
7435     in LIST.  Otherwise, it returns ‘nil’.
7436
7437     Compare this with ‘memq’:
7438
7439          (member '(2) '((1) (2)))  ; ‘(2)’ and ‘(2)’ are ‘equal’.
7440               ⇒ ((2))
7441          (memq '(2) '((1) (2)))    ; The two ‘(2)’s need not be ‘eq’.
7442               ⇒ Unspecified; might be ‘nil’ or ‘(2)’.
7443          ;; Two strings with the same contents are ‘equal’.
7444          (member "foo" '("foo" "bar"))
7445               ⇒ ("foo" "bar")
7446
7447 -- Function: delete object sequence
7448     This function removes all elements ‘equal’ to OBJECT from SEQUENCE,
7449     and returns the resulting sequence.
7450
7451     If SEQUENCE is a list, ‘delete’ is to ‘delq’ as ‘member’ is to
7452     ‘memq’: it uses ‘equal’ to compare elements with OBJECT, like
7453     ‘member’; when it finds an element that matches, it cuts the
7454     element out just as ‘delq’ would.  As with ‘delq’, you should
7455     typically use the return value by assigning it to the variable
7456     which held the original list.
7457
7458     If ‘sequence’ is a vector or string, ‘delete’ returns a copy of
7459     ‘sequence’ with all elements ‘equal’ to ‘object’ removed.
7460
7461     For example:
7462
7463          (setq l (list '(2) '(1) '(2)))
7464          (delete '(2) l)
7465               ⇒ ((1))
7466          l
7467               ⇒ ((2) (1))
7468          ;; If you want to change ‘l’ reliably,
7469          ;; write ‘(setq l (delete '(2) l))’.
7470          (setq l (list '(2) '(1) '(2)))
7471          (delete '(1) l)
7472               ⇒ ((2) (2))
7473          l
7474               ⇒ ((2) (2))
7475          ;; In this case, it makes no difference whether you set ‘l’,
7476          ;; but you should do so for the sake of the other case.
7477          (delete '(2) [(2) (1) (2)])
7478               ⇒ [(1)]
7479
7480 -- Function: remove object sequence
7481     This function is the non-destructive counterpart of ‘delete’.  It
7482     returns a copy of ‘sequence’, a list, vector, or string, with
7483     elements ‘equal’ to ‘object’ removed.  For example:
7484
7485          (remove '(2) '((2) (1) (2)))
7486               ⇒ ((1))
7487          (remove '(2) [(2) (1) (2)])
7488               ⇒ [(1)]
7489
7490     Common Lisp note: The functions ‘member’, ‘delete’ and ‘remove’ in
7491     GNU Emacs Lisp are derived from Maclisp, not Common Lisp.  The
7492     Common Lisp versions do not use ‘equal’ to compare elements.
7493
7494 -- Function: member-ignore-case object list
7495     This function is like ‘member’, except that OBJECT should be a
7496     string and that it ignores differences in letter-case and text
7497     representation: upper-case and lower-case letters are treated as
7498     equal, and unibyte strings are converted to multibyte prior to
7499     comparison.
7500
7501 -- Function: delete-dups list
7502     This function destructively removes all ‘equal’ duplicates from
7503     LIST, stores the result in LIST and returns it.  Of several ‘equal’
7504     occurrences of an element in LIST, ‘delete-dups’ keeps the first
7505     one.
7506
7507   See also the function ‘add-to-list’, in *note List Variables::, for a
7508way to add an element to a list stored in a variable and used as a set.
7509
7510
7511File: elisp.info,  Node: Association Lists,  Next: Property Lists,  Prev: Sets And Lists,  Up: Lists
7512
75135.8 Association Lists
7514=====================
7515
7516An “association list”, or “alist” for short, records a mapping from keys
7517to values.  It is a list of cons cells called “associations”: the CAR of
7518each cons cell is the “key”, and the CDR is the “associated value”.(1)
7519
7520   Here is an example of an alist.  The key ‘pine’ is associated with
7521the value ‘cones’; the key ‘oak’ is associated with ‘acorns’; and the
7522key ‘maple’ is associated with ‘seeds’.
7523
7524     ((pine . cones)
7525      (oak . acorns)
7526      (maple . seeds))
7527
7528   Both the values and the keys in an alist may be any Lisp objects.
7529For example, in the following alist, the symbol ‘a’ is associated with
7530the number ‘1’, and the string ‘"b"’ is associated with the _list_ ‘(2
75313)’, which is the CDR of the alist element:
7532
7533     ((a . 1) ("b" 2 3))
7534
7535   Sometimes it is better to design an alist to store the associated
7536value in the CAR of the CDR of the element.  Here is an example of such
7537an alist:
7538
7539     ((rose red) (lily white) (buttercup yellow))
7540
7541Here we regard ‘red’ as the value associated with ‘rose’.  One advantage
7542of this kind of alist is that you can store other related
7543information—even a list of other items—in the CDR of the CDR.  One
7544disadvantage is that you cannot use ‘rassq’ (see below) to find the
7545element containing a given value.  When neither of these considerations
7546is important, the choice is a matter of taste, as long as you are
7547consistent about it for any given alist.
7548
7549   The same alist shown above could be regarded as having the associated
7550value in the CDR of the element; the value associated with ‘rose’ would
7551be the list ‘(red)’.
7552
7553   Association lists are often used to record information that you might
7554otherwise keep on a stack, since new associations may be added easily to
7555the front of the list.  When searching an association list for an
7556association with a given key, the first one found is returned, if there
7557is more than one.
7558
7559   In Emacs Lisp, it is _not_ an error if an element of an association
7560list is not a cons cell.  The alist search functions simply ignore such
7561elements.  Many other versions of Lisp signal errors in such cases.
7562
7563   Note that property lists are similar to association lists in several
7564respects.  A property list behaves like an association list in which
7565each key can occur only once.  *Note Property Lists::, for a comparison
7566of property lists and association lists.
7567
7568 -- Function: assoc key alist &optional testfn
7569     This function returns the first association for KEY in ALIST,
7570     comparing KEY against the alist elements using TESTFN if it is
7571     non-‘nil’ and ‘equal’ otherwise (*note Equality Predicates::).  It
7572     returns ‘nil’ if no association in ALIST has a CAR equal to KEY.
7573     For example:
7574
7575          (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
7576               ⇒ ((pine . cones) (oak . acorns) (maple . seeds))
7577          (assoc 'oak trees)
7578               ⇒ (oak . acorns)
7579          (cdr (assoc 'oak trees))
7580               ⇒ acorns
7581          (assoc 'birch trees)
7582               ⇒ nil
7583
7584     Here is another example, in which the keys and values are not
7585     symbols:
7586
7587          (setq needles-per-cluster
7588                '((2 "Austrian Pine" "Red Pine")
7589                  (3 "Pitch Pine")
7590                  (5 "White Pine")))
7591
7592          (cdr (assoc 3 needles-per-cluster))
7593               ⇒ ("Pitch Pine")
7594          (cdr (assoc 2 needles-per-cluster))
7595               ⇒ ("Austrian Pine" "Red Pine")
7596
7597   The function ‘assoc-string’ is much like ‘assoc’ except that it
7598ignores certain differences between strings.  *Note Text Comparison::.
7599
7600 -- Function: rassoc value alist
7601     This function returns the first association with value VALUE in
7602     ALIST.  It returns ‘nil’ if no association in ALIST has a CDR
7603     ‘equal’ to VALUE.
7604
7605     ‘rassoc’ is like ‘assoc’ except that it compares the CDR of each
7606     ALIST association instead of the CAR.  You can think of this as
7607     reverse ‘assoc’, finding the key for a given value.
7608
7609 -- Function: assq key alist
7610     This function is like ‘assoc’ in that it returns the first
7611     association for KEY in ALIST, but it makes the comparison using
7612     ‘eq’.  ‘assq’ returns ‘nil’ if no association in ALIST has a CAR
7613     ‘eq’ to KEY.  This function is used more often than ‘assoc’, since
7614     ‘eq’ is faster than ‘equal’ and most alists use symbols as keys.
7615     *Note Equality Predicates::.
7616
7617          (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
7618               ⇒ ((pine . cones) (oak . acorns) (maple . seeds))
7619          (assq 'pine trees)
7620               ⇒ (pine . cones)
7621
7622     On the other hand, ‘assq’ is not usually useful in alists where the
7623     keys may not be symbols:
7624
7625          (setq leaves
7626                '(("simple leaves" . oak)
7627                  ("compound leaves" . horsechestnut)))
7628
7629          (assq "simple leaves" leaves)
7630               ⇒ Unspecified; might be ‘nil’ or ‘("simple leaves" . oak)’.
7631          (assoc "simple leaves" leaves)
7632               ⇒ ("simple leaves" . oak)
7633
7634 -- Function: alist-get key alist &optional default remove testfn
7635     This function is similar to ‘assq’.  It finds the first association
7636     ‘(KEY . VALUE)’ by comparing KEY with ALIST elements, and, if
7637     found, returns the VALUE of that association.  If no association is
7638     found, the function returns DEFAULT.  Comparison of KEY against
7639     ALIST elements uses the function specified by TESTFN, defaulting to
7640     ‘eq’.
7641
7642     This is a generalized variable (*note Generalized Variables::) that
7643     can be used to change a value with ‘setf’.  When using it to set a
7644     value, optional argument REMOVE non-‘nil’ means to remove KEY’s
7645     association from ALIST if the new value is ‘eql’ to DEFAULT.
7646
7647 -- Function: rassq value alist
7648     This function returns the first association with value VALUE in
7649     ALIST.  It returns ‘nil’ if no association in ALIST has a CDR ‘eq’
7650     to VALUE.
7651
7652     ‘rassq’ is like ‘assq’ except that it compares the CDR of each
7653     ALIST association instead of the CAR.  You can think of this as
7654     reverse ‘assq’, finding the key for a given value.
7655
7656     For example:
7657
7658          (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
7659
7660          (rassq 'acorns trees)
7661               ⇒ (oak . acorns)
7662          (rassq 'spores trees)
7663               ⇒ nil
7664
7665     ‘rassq’ cannot search for a value stored in the CAR of the CDR of
7666     an element:
7667
7668          (setq colors '((rose red) (lily white) (buttercup yellow)))
7669
7670          (rassq 'white colors)
7671               ⇒ nil
7672
7673     In this case, the CDR of the association ‘(lily white)’ is not the
7674     symbol ‘white’, but rather the list ‘(white)’.  This becomes
7675     clearer if the association is written in dotted pair notation:
7676
7677          (lily white) ≡ (lily . (white))
7678
7679 -- Function: assoc-default key alist &optional test default
7680     This function searches ALIST for a match for KEY.  For each element
7681     of ALIST, it compares the element (if it is an atom) or the
7682     element’s CAR (if it is a cons) against KEY, by calling TEST with
7683     two arguments: the element or its CAR, and KEY.  The arguments are
7684     passed in that order so that you can get useful results using
7685     ‘string-match’ with an alist that contains regular expressions
7686     (*note Regexp Search::).  If TEST is omitted or ‘nil’, ‘equal’ is
7687     used for comparison.
7688
7689     If an alist element matches KEY by this criterion, then
7690     ‘assoc-default’ returns a value based on this element.  If the
7691     element is a cons, then the value is the element’s CDR.  Otherwise,
7692     the return value is DEFAULT.
7693
7694     If no alist element matches KEY, ‘assoc-default’ returns ‘nil’.
7695
7696 -- Function: copy-alist alist
7697     This function returns a two-level deep copy of ALIST: it creates a
7698     new copy of each association, so that you can alter the
7699     associations of the new alist without changing the old one.
7700
7701          (setq needles-per-cluster
7702                '((2 . ("Austrian Pine" "Red Pine"))
7703                  (3 . ("Pitch Pine"))
7704                  (5 . ("White Pine"))))
77057706          ((2 "Austrian Pine" "Red Pine")
7707           (3 "Pitch Pine")
7708           (5 "White Pine"))
7709
7710          (setq copy (copy-alist needles-per-cluster))
77117712          ((2 "Austrian Pine" "Red Pine")
7713           (3 "Pitch Pine")
7714           (5 "White Pine"))
7715
7716          (eq needles-per-cluster copy)
7717               ⇒ nil
7718          (equal needles-per-cluster copy)
7719               ⇒ t
7720          (eq (car needles-per-cluster) (car copy))
7721               ⇒ nil
7722          (cdr (car (cdr needles-per-cluster)))
7723               ⇒ ("Pitch Pine")
7724          (eq (cdr (car (cdr needles-per-cluster)))
7725              (cdr (car (cdr copy))))
7726               ⇒ t
7727
7728     This example shows how ‘copy-alist’ makes it possible to change the
7729     associations of one copy without affecting the other:
7730
7731          (setcdr (assq 3 copy) '("Martian Vacuum Pine"))
7732          (cdr (assq 3 needles-per-cluster))
7733               ⇒ ("Pitch Pine")
7734
7735 -- Function: assq-delete-all key alist
7736     This function deletes from ALIST all the elements whose CAR is ‘eq’
7737     to KEY, much as if you used ‘delq’ to delete each such element one
7738     by one.  It returns the shortened alist, and often modifies the
7739     original list structure of ALIST.  For correct results, use the
7740     return value of ‘assq-delete-all’ rather than looking at the saved
7741     value of ALIST.
7742
7743          (setq alist (list '(foo 1) '(bar 2) '(foo 3) '(lose 4)))
7744               ⇒ ((foo 1) (bar 2) (foo 3) (lose 4))
7745          (assq-delete-all 'foo alist)
7746               ⇒ ((bar 2) (lose 4))
7747          alist
7748               ⇒ ((foo 1) (bar 2) (lose 4))
7749
7750 -- Function: assoc-delete-all key alist &optional test
7751     This function is like ‘assq-delete-all’ except that it accepts an
7752     optional argument TEST, a predicate function to compare the keys in
7753     ALIST.  If omitted or ‘nil’, TEST defaults to ‘equal’.  As
7754     ‘assq-delete-all’, this function often modifies the original list
7755     structure of ALIST.
7756
7757 -- Function: rassq-delete-all value alist
7758     This function deletes from ALIST all the elements whose CDR is ‘eq’
7759     to VALUE.  It returns the shortened alist, and often modifies the
7760     original list structure of ALIST.  ‘rassq-delete-all’ is like
7761     ‘assq-delete-all’ except that it compares the CDR of each ALIST
7762     association instead of the CAR.
7763
7764 -- Macro: let-alist alist body
7765     Creates a binding for each symbol used as keys the association list
7766     ALIST, prefixed with dot.  This can be useful when accessing
7767     several items in the same association list, and it’s best
7768     understood through a simple example:
7769
7770          (setq colors '((rose . red) (lily . white) (buttercup . yellow)))
7771          (let-alist colors
7772            (if (eq .rose 'red)
7773                .lily))
7774          => white
7775
7776     The BODY is inspected at compilation time, and only the symbols
7777     that appear in BODY with a ‘.’ as the first character in the symbol
7778     name will be bound.  Finding the keys is done with ‘assq’, and the
7779     ‘cdr’ of the return value of this ‘assq’ is assigned as the value
7780     for the binding.
7781
7782     Nested association lists is supported:
7783
7784          (setq colors '((rose . red) (lily (belladonna . yellow) (brindisi . pink))))
7785          (let-alist colors
7786            (if (eq .rose 'red)
7787                .lily.belladonna))
7788          => yellow
7789
7790     Nesting ‘let-alist’ inside each other is allowed, but the code in
7791     the inner ‘let-alist’ can’t access the variables bound by the outer
7792     ‘let-alist’.
7793
7794   ---------- Footnotes ----------
7795
7796   (1) This usage of “key” is not related to the term “key sequence”; it
7797means a value used to look up an item in a table.  In this case, the
7798table is the alist, and the alist associations are the items.
7799
7800
7801File: elisp.info,  Node: Property Lists,  Prev: Association Lists,  Up: Lists
7802
78035.9 Property Lists
7804==================
7805
7806A “property list” (“plist” for short) is a list of paired elements.
7807Each of the pairs associates a property name (usually a symbol) with a
7808property or value.  Here is an example of a property list:
7809
7810     (pine cones numbers (1 2 3) color "blue")
7811
7812This property list associates ‘pine’ with ‘cones’, ‘numbers’ with ‘(1 2
78133)’, and ‘color’ with ‘"blue"’.  The property names and values can be
7814any Lisp objects, but the names are usually symbols (as they are in this
7815example).
7816
7817   Property lists are used in several contexts.  For instance, the
7818function ‘put-text-property’ takes an argument which is a property list,
7819specifying text properties and associated values which are to be applied
7820to text in a string or buffer.  *Note Text Properties::.
7821
7822   Another prominent use of property lists is for storing symbol
7823properties.  Every symbol possesses a list of properties, used to record
7824miscellaneous information about the symbol; these properties are stored
7825in the form of a property list.  *Note Symbol Properties::.
7826
7827* Menu:
7828
7829* Plists and Alists::           Comparison of the advantages of property
7830                                  lists and association lists.
7831* Plist Access::                Accessing property lists stored elsewhere.
7832
7833
7834File: elisp.info,  Node: Plists and Alists,  Next: Plist Access,  Up: Property Lists
7835
78365.9.1 Property Lists and Association Lists
7837------------------------------------------
7838
7839Association lists (*note Association Lists::) are very similar to
7840property lists.  In contrast to association lists, the order of the
7841pairs in the property list is not significant, since the property names
7842must be distinct.
7843
7844   Property lists are better than association lists for attaching
7845information to various Lisp function names or variables.  If your
7846program keeps all such information in one association list, it will
7847typically need to search that entire list each time it checks for an
7848association for a particular Lisp function name or variable, which could
7849be slow.  By contrast, if you keep the same information in the property
7850lists of the function names or variables themselves, each search will
7851scan only the length of one property list, which is usually short.  This
7852is why the documentation for a variable is recorded in a property named
7853‘variable-documentation’.  The byte compiler likewise uses properties to
7854record those functions needing special treatment.
7855
7856   However, association lists have their own advantages.  Depending on
7857your application, it may be faster to add an association to the front of
7858an association list than to update a property.  All properties for a
7859symbol are stored in the same property list, so there is a possibility
7860of a conflict between different uses of a property name.  (For this
7861reason, it is a good idea to choose property names that are probably
7862unique, such as by beginning the property name with the program’s usual
7863name-prefix for variables and functions.)  An association list may be
7864used like a stack where associations are pushed on the front of the list
7865and later discarded; this is not possible with a property list.
7866
7867
7868File: elisp.info,  Node: Plist Access,  Prev: Plists and Alists,  Up: Property Lists
7869
78705.9.2 Property Lists Outside Symbols
7871------------------------------------
7872
7873The following functions can be used to manipulate property lists.  They
7874all compare property names using ‘eq’.
7875
7876 -- Function: plist-get plist property
7877     This returns the value of the PROPERTY property stored in the
7878     property list PLIST.  It accepts a malformed PLIST argument.  If
7879     PROPERTY is not found in the PLIST, it returns ‘nil’.  For example,
7880
7881          (plist-get '(foo 4) 'foo)
7882               ⇒ 4
7883          (plist-get '(foo 4 bad) 'foo)
7884               ⇒ 4
7885          (plist-get '(foo 4 bad) 'bad)
7886               ⇒ nil
7887          (plist-get '(foo 4 bad) 'bar)
7888               ⇒ nil
7889
7890 -- Function: plist-put plist property value
7891     This stores VALUE as the value of the PROPERTY property in the
7892     property list PLIST.  It may modify PLIST destructively, or it may
7893     construct a new list structure without altering the old.  The
7894     function returns the modified property list, so you can store that
7895     back in the place where you got PLIST.  For example,
7896
7897          (setq my-plist (list 'bar t 'foo 4))
7898               ⇒ (bar t foo 4)
7899          (setq my-plist (plist-put my-plist 'foo 69))
7900               ⇒ (bar t foo 69)
7901          (setq my-plist (plist-put my-plist 'quux '(a)))
7902               ⇒ (bar t foo 69 quux (a))
7903
7904 -- Function: lax-plist-get plist property
7905     Like ‘plist-get’ except that it compares properties using ‘equal’
7906     instead of ‘eq’.
7907
7908 -- Function: lax-plist-put plist property value
7909     Like ‘plist-put’ except that it compares properties using ‘equal’
7910     instead of ‘eq’.
7911
7912 -- Function: plist-member plist property
7913     This returns non-‘nil’ if PLIST contains the given PROPERTY.
7914     Unlike ‘plist-get’, this allows you to distinguish between a
7915     missing property and a property with the value ‘nil’.  The value is
7916     actually the tail of PLIST whose ‘car’ is PROPERTY.
7917
7918
7919File: elisp.info,  Node: Sequences Arrays Vectors,  Next: Records,  Prev: Lists,  Up: Top
7920
79216 Sequences, Arrays, and Vectors
7922********************************
7923
7924The “sequence” type is the union of two other Lisp types: lists and
7925arrays.  In other words, any list is a sequence, and any array is a
7926sequence.  The common property that all sequences have is that each is
7927an ordered collection of elements.
7928
7929   An “array” is a fixed-length object with a slot for each of its
7930elements.  All the elements are accessible in constant time.  The four
7931types of arrays are strings, vectors, char-tables and bool-vectors.
7932
7933   A list is a sequence of elements, but it is not a single primitive
7934object; it is made of cons cells, one cell per element.  Finding the Nth
7935element requires looking through N cons cells, so elements farther from
7936the beginning of the list take longer to access.  But it is possible to
7937add elements to the list, or remove elements.
7938
7939   The following diagram shows the relationship between these types:
7940
7941               _____________________________________________
7942              |                                             |
7943              |          Sequence                           |
7944              |  ______   ________________________________  |
7945              | |      | |                                | |
7946              | | List | |             Array              | |
7947              | |      | |    ________       ________     | |
7948              | |______| |   |        |     |        |    | |
7949              |          |   | Vector |     | String |    | |
7950              |          |   |________|     |________|    | |
7951              |          |  ____________   _____________  | |
7952              |          | |            | |             | | |
7953              |          | | Char-table | | Bool-vector | | |
7954              |          | |____________| |_____________| | |
7955              |          |________________________________| |
7956              |_____________________________________________|
7957
7958* Menu:
7959
7960* Sequence Functions::    Functions that accept any kind of sequence.
7961* Arrays::                Characteristics of arrays in Emacs Lisp.
7962* Array Functions::       Functions specifically for arrays.
7963* Vectors::               Special characteristics of Emacs Lisp vectors.
7964* Vector Functions::      Functions specifically for vectors.
7965* Char-Tables::           How to work with char-tables.
7966* Bool-Vectors::          How to work with bool-vectors.
7967* Rings::                 Managing a fixed-size ring of objects.
7968
7969
7970File: elisp.info,  Node: Sequence Functions,  Next: Arrays,  Up: Sequences Arrays Vectors
7971
79726.1 Sequences
7973=============
7974
7975This section describes functions that accept any kind of sequence.
7976
7977 -- Function: sequencep object
7978     This function returns ‘t’ if OBJECT is a list, vector, string,
7979     bool-vector, or char-table, ‘nil’ otherwise.  See also ‘seqp’
7980     below.
7981
7982 -- Function: length sequence
7983     This function returns the number of elements in SEQUENCE.  The
7984     function signals the ‘wrong-type-argument’ error if the argument is
7985     not a sequence or is a dotted list; it signals the ‘circular-list’
7986     error if the argument is a circular list.  For a char-table, the
7987     value returned is always one more than the maximum Emacs character
7988     code.
7989
7990     *Note Definition of safe-length::, for the related function
7991     ‘safe-length’.
7992
7993          (length '(1 2 3))
7994              ⇒ 3
7995          (length ())
7996              ⇒ 0
7997          (length "foobar")
7998              ⇒ 6
7999          (length [1 2 3])
8000              ⇒ 3
8001          (length (make-bool-vector 5 nil))
8002              ⇒ 5
8003
8004See also ‘string-bytes’, in *note Text Representations::.
8005
8006   If you need to compute the width of a string on display, you should
8007use ‘string-width’ (*note Size of Displayed Text::), not ‘length’, since
8008‘length’ only counts the number of characters, but does not account for
8009the display width of each character.
8010
8011 -- Function: elt sequence index
8012     This function returns the element of SEQUENCE indexed by INDEX.
8013     Legitimate values of INDEX are integers ranging from 0 up to one
8014     less than the length of SEQUENCE.  If SEQUENCE is a list,
8015     out-of-range values behave as for ‘nth’.  *Note Definition of
8016     nth::.  Otherwise, out-of-range values trigger an
8017     ‘args-out-of-range’ error.
8018
8019          (elt [1 2 3 4] 2)
8020               ⇒ 3
8021          (elt '(1 2 3 4) 2)
8022               ⇒ 3
8023          ;; We use ‘string’ to show clearly which character ‘elt’ returns.
8024          (string (elt "1234" 2))
8025               ⇒ "3"
8026          (elt [1 2 3 4] 4)
8027               error→ Args out of range: [1 2 3 4], 4
8028          (elt [1 2 3 4] -1)
8029               error→ Args out of range: [1 2 3 4], -1
8030
8031     This function generalizes ‘aref’ (*note Array Functions::) and
8032     ‘nth’ (*note Definition of nth::).
8033
8034 -- Function: copy-sequence seqr
8035     This function returns a copy of SEQR, which should be either a
8036     sequence or a record.  The copy is the same type of object as the
8037     original, and it has the same elements in the same order.  However,
8038     if SEQR is empty, like a string or a vector of zero length, the
8039     value returned by this function might not be a copy, but an empty
8040     object of the same type and identical to SEQR.
8041
8042     Storing a new element into the copy does not affect the original
8043     SEQR, and vice versa.  However, the elements of the copy are not
8044     copies; they are identical (‘eq’) to the elements of the original.
8045     Therefore, changes made within these elements, as found via the
8046     copy, are also visible in the original.
8047
8048     If the argument is a string with text properties, the property list
8049     in the copy is itself a copy, not shared with the original’s
8050     property list.  However, the actual values of the properties are
8051     shared.  *Note Text Properties::.
8052
8053     This function does not work for dotted lists.  Trying to copy a
8054     circular list may cause an infinite loop.
8055
8056     See also ‘append’ in *note Building Lists::, ‘concat’ in *note
8057     Creating Strings::, and ‘vconcat’ in *note Vector Functions::, for
8058     other ways to copy sequences.
8059
8060          (setq bar (list 1 2))
8061               ⇒ (1 2)
8062          (setq x (vector 'foo bar))
8063               ⇒ [foo (1 2)]
8064          (setq y (copy-sequence x))
8065               ⇒ [foo (1 2)]
8066
8067          (eq x y)
8068               ⇒ nil
8069          (equal x y)
8070               ⇒ t
8071          (eq (elt x 1) (elt y 1))
8072               ⇒ t
8073
8074          ;; Replacing an element of one sequence.
8075          (aset x 0 'quux)
8076          x ⇒ [quux (1 2)]
8077          y ⇒ [foo (1 2)]
8078
8079          ;; Modifying the inside of a shared element.
8080          (setcar (aref x 1) 69)
8081          x ⇒ [quux (69 2)]
8082          y ⇒ [foo (69 2)]
8083
8084 -- Function: reverse sequence
8085     This function creates a new sequence whose elements are the
8086     elements of SEQUENCE, but in reverse order.  The original argument
8087     SEQUENCE is _not_ altered.  Note that char-tables cannot be
8088     reversed.
8089
8090          (setq x '(1 2 3 4))
8091               ⇒ (1 2 3 4)
8092          (reverse x)
8093               ⇒ (4 3 2 1)
8094          x
8095               ⇒ (1 2 3 4)
8096          (setq x [1 2 3 4])
8097               ⇒ [1 2 3 4]
8098          (reverse x)
8099               ⇒ [4 3 2 1]
8100          x
8101               ⇒ [1 2 3 4]
8102          (setq x "xyzzy")
8103               ⇒ "xyzzy"
8104          (reverse x)
8105               ⇒ "yzzyx"
8106          x
8107               ⇒ "xyzzy"
8108
8109 -- Function: nreverse sequence
8110     This function reverses the order of the elements of SEQUENCE.
8111     Unlike ‘reverse’ the original SEQUENCE may be modified.
8112
8113     For example:
8114
8115          (setq x (list 'a 'b 'c))
8116               ⇒ (a b c)
8117          x
8118               ⇒ (a b c)
8119          (nreverse x)
8120               ⇒ (c b a)
8121          ;; The cons cell that was first is now last.
8122          x
8123               ⇒ (a)
8124
8125     To avoid confusion, we usually store the result of ‘nreverse’ back
8126     in the same variable which held the original list:
8127
8128          (setq x (nreverse x))
8129
8130     Here is the ‘nreverse’ of our favorite example, ‘(a b c)’,
8131     presented graphically:
8132
8133          Original list head:                       Reversed list:
8134           -------------        -------------        ------------
8135          | car  | cdr  |      | car  | cdr  |      | car | cdr  |
8136          |   a  |  nil |<--   |   b  |   o  |<--   |   c |   o  |
8137          |      |      |   |  |      |   |  |   |  |     |   |  |
8138           -------------    |   --------- | -    |   -------- | -
8139                            |             |      |            |
8140                             -------------        ------------
8141
8142     For the vector, it is even simpler because you don’t need setq:
8143
8144          (setq x (copy-sequence [1 2 3 4]))
8145               ⇒ [1 2 3 4]
8146          (nreverse x)
8147               ⇒ [4 3 2 1]
8148          x
8149               ⇒ [4 3 2 1]
8150
8151     Note that unlike ‘reverse’, this function doesn’t work with
8152     strings.  Although you can alter string data by using ‘aset’, it is
8153     strongly encouraged to treat strings as immutable even when they
8154     are mutable.  *Note Mutability::.
8155
8156 -- Function: sort sequence predicate
8157     This function sorts SEQUENCE stably.  Note that this function
8158     doesn’t work for all sequences; it may be used only for lists and
8159     vectors.  If SEQUENCE is a list, it is modified destructively.
8160     This functions returns the sorted SEQUENCE and compares elements
8161     using PREDICATE.  A stable sort is one in which elements with equal
8162     sort keys maintain their relative order before and after the sort.
8163     Stability is important when successive sorts are used to order
8164     elements according to different criteria.
8165
8166     The argument PREDICATE must be a function that accepts two
8167     arguments.  It is called with two elements of SEQUENCE.  To get an
8168     increasing order sort, the PREDICATE should return non-‘nil’ if the
8169     first element is “less” than the second, or ‘nil’ if not.
8170
8171     The comparison function PREDICATE must give reliable results for
8172     any given pair of arguments, at least within a single call to
8173     ‘sort’.  It must be “antisymmetric”; that is, if A is less than B,
8174     B must not be less than A.  It must be “transitive”—that is, if A
8175     is less than B, and B is less than C, then A must be less than C.
8176     If you use a comparison function which does not meet these
8177     requirements, the result of ‘sort’ is unpredictable.
8178
8179     The destructive aspect of ‘sort’ for lists is that it rearranges
8180     the cons cells forming SEQUENCE by changing CDRs.  A nondestructive
8181     sort function would create new cons cells to store the elements in
8182     their sorted order.  If you wish to make a sorted copy without
8183     destroying the original, copy it first with ‘copy-sequence’ and
8184     then sort.
8185
8186     Sorting does not change the CARs of the cons cells in SEQUENCE; the
8187     cons cell that originally contained the element ‘a’ in SEQUENCE
8188     still has ‘a’ in its CAR after sorting, but it now appears in a
8189     different position in the list due to the change of CDRs.  For
8190     example:
8191
8192          (setq nums (list 1 3 2 6 5 4 0))
8193               ⇒ (1 3 2 6 5 4 0)
8194          (sort nums #'<)
8195               ⇒ (0 1 2 3 4 5 6)
8196          nums
8197               ⇒ (1 2 3 4 5 6)
8198
8199     *Warning*: Note that the list in ‘nums’ no longer contains 0; this
8200     is the same cons cell that it was before, but it is no longer the
8201     first one in the list.  Don’t assume a variable that formerly held
8202     the argument now holds the entire sorted list!  Instead, save the
8203     result of ‘sort’ and use that.  Most often we store the result back
8204     into the variable that held the original list:
8205
8206          (setq nums (sort nums #'<))
8207
8208     For the better understanding of what stable sort is, consider the
8209     following vector example.  After sorting, all items whose ‘car’ is
8210     8 are grouped at the beginning of ‘vector’, but their relative
8211     order is preserved.  All items whose ‘car’ is 9 are grouped at the
8212     end of ‘vector’, but their relative order is also preserved:
8213
8214          (setq
8215            vector
8216            (vector '(8 . "xxx") '(9 . "aaa") '(8 . "bbb") '(9 . "zzz")
8217                    '(9 . "ppp") '(8 . "ttt") '(8 . "eee") '(9 . "fff")))
8218               ⇒ [(8 . "xxx") (9 . "aaa") (8 . "bbb") (9 . "zzz")
8219                   (9 . "ppp") (8 . "ttt") (8 . "eee") (9 . "fff")]
8220          (sort vector (lambda (x y) (< (car x) (car y))))
8221               ⇒ [(8 . "xxx") (8 . "bbb") (8 . "ttt") (8 . "eee")
8222                   (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")]
8223
8224     *Note Sorting::, for more functions that perform sorting.  See
8225     ‘documentation’ in *note Accessing Documentation::, for a useful
8226     example of ‘sort’.
8227
8228   The ‘seq.el’ library provides the following additional sequence
8229manipulation macros and functions, prefixed with ‘seq-’.  To use them,
8230you must first load the ‘seq’ library.
8231
8232   All functions defined in this library are free of side-effects; i.e.,
8233they do not modify any sequence (list, vector, or string) that you pass
8234as an argument.  Unless otherwise stated, the result is a sequence of
8235the same type as the input.  For those functions that take a predicate,
8236this should be a function of one argument.
8237
8238   The ‘seq.el’ library can be extended to work with additional types of
8239sequential data-structures.  For that purpose, all functions are defined
8240using ‘cl-defgeneric’.  *Note Generic Functions::, for more details
8241about using ‘cl-defgeneric’ for adding extensions.
8242
8243 -- Function: seq-elt sequence index
8244     This function returns the element of SEQUENCE at the specified
8245     INDEX, which is an integer whose valid value range is zero to one
8246     less than the length of SEQUENCE.  For out-of-range values on
8247     built-in sequence types, ‘seq-elt’ behaves like ‘elt’.  For the
8248     details, see *note Definition of elt::.
8249
8250          (seq-elt [1 2 3 4] 2)
8251          ⇒ 3
8252
8253     ‘seq-elt’ returns places settable using ‘setf’ (*note Setting
8254     Generalized Variables::).
8255
8256          (setq vec [1 2 3 4])
8257          (setf (seq-elt vec 2) 5)
8258          vec
8259          ⇒ [1 2 5 4]
8260
8261 -- Function: seq-length sequence
8262     This function returns the number of elements in SEQUENCE.  For
8263     built-in sequence types, ‘seq-length’ behaves like ‘length’.  *Note
8264     Definition of length::.
8265
8266 -- Function: seqp object
8267     This function returns non-‘nil’ if OBJECT is a sequence (a list or
8268     array), or any additional type of sequence defined via ‘seq.el8269     generic functions.  This is an extensible variant of ‘sequencep’.
8270
8271          (seqp [1 2])
8272          ⇒ t
8273          (seqp 2)
8274          ⇒ nil
8275
8276 -- Function: seq-drop sequence n
8277     This function returns all but the first N (an integer) elements of
8278     SEQUENCE.  If N is negative or zero, the result is SEQUENCE.
8279
8280          (seq-drop [1 2 3 4 5 6] 3)
8281          ⇒ [4 5 6]
8282          (seq-drop "hello world" -4)
8283          ⇒ "hello world"
8284
8285 -- Function: seq-take sequence n
8286     This function returns the first N (an integer) elements of
8287     SEQUENCE.  If N is negative or zero, the result is ‘nil’.
8288
8289          (seq-take '(1 2 3 4) 3)
8290          ⇒ (1 2 3)
8291          (seq-take [1 2 3 4] 0)
8292          ⇒ []
8293
8294 -- Function: seq-take-while predicate sequence
8295     This function returns the members of SEQUENCE in order, stopping
8296     before the first one for which PREDICATE returns ‘nil’.
8297
8298          (seq-take-while (lambda (elt) (> elt 0)) '(1 2 3 -1 -2))
8299          ⇒ (1 2 3)
8300          (seq-take-while (lambda (elt) (> elt 0)) [-1 4 6])
8301          ⇒ []
8302
8303 -- Function: seq-drop-while predicate sequence
8304     This function returns the members of SEQUENCE in order, starting
8305     from the first one for which PREDICATE returns ‘nil’.
8306
8307          (seq-drop-while (lambda (elt) (> elt 0)) '(1 2 3 -1 -2))
8308          ⇒ (-1 -2)
8309          (seq-drop-while (lambda (elt) (< elt 0)) [1 4 6])
8310          ⇒ [1 4 6]
8311
8312 -- Function: seq-do function sequence
8313     This function applies FUNCTION to each element of SEQUENCE in turn
8314     (presumably for side effects), and returns SEQUENCE.
8315
8316 -- Function: seq-map function sequence
8317     This function returns the result of applying FUNCTION to each
8318     element of SEQUENCE.  The returned value is a list.
8319
8320          (seq-map #'1+ '(2 4 6))
8321          ⇒ (3 5 7)
8322          (seq-map #'symbol-name [foo bar])
8323          ⇒ ("foo" "bar")
8324
8325 -- Function: seq-map-indexed function sequence
8326     This function returns the result of applying FUNCTION to each
8327     element of SEQUENCE and its index within SEQ.  The returned value
8328     is a list.
8329
8330          (seq-map-indexed (lambda (elt idx)
8331                             (list idx elt))
8332                           '(a b c))
8333          ⇒ ((0 a) (1 b) (2 c))
8334
8335 -- Function: seq-mapn function &rest sequences
8336     This function returns the result of applying FUNCTION to each
8337     element of SEQUENCES.  The arity (*note subr-arity: What Is a
8338     Function.) of FUNCTION must match the number of sequences.  Mapping
8339     stops at the end of the shortest sequence, and the returned value
8340     is a list.
8341
8342          (seq-mapn #'+ '(2 4 6) '(20 40 60))
8343          ⇒ (22 44 66)
8344          (seq-mapn #'concat '("moskito" "bite") ["bee" "sting"])
8345          ⇒ ("moskitobee" "bitesting")
8346
8347 -- Function: seq-filter predicate sequence
8348     This function returns a list of all the elements in SEQUENCE for
8349     which PREDICATE returns non-‘nil’.
8350
8351          (seq-filter (lambda (elt) (> elt 0)) [1 -1 3 -3 5])
8352          ⇒ (1 3 5)
8353          (seq-filter (lambda (elt) (> elt 0)) '(-1 -3 -5))
8354          ⇒ nil
8355
8356 -- Function: seq-remove predicate sequence
8357     This function returns a list of all the elements in SEQUENCE for
8358     which PREDICATE returns ‘nil’.
8359
8360          (seq-remove (lambda (elt) (> elt 0)) [1 -1 3 -3 5])
8361          ⇒ (-1 -3)
8362          (seq-remove (lambda (elt) (< elt 0)) '(-1 -3 -5))
8363          ⇒ nil
8364
8365 -- Function: seq-reduce function sequence initial-value
8366     This function returns the result of calling FUNCTION with
8367     INITIAL-VALUE and the first element of SEQUENCE, then calling
8368     FUNCTION with that result and the second element of SEQUENCE, then
8369     with that result and the third element of SEQUENCE, etc.  FUNCTION
8370     should be a function of two arguments.
8371
8372     FUNCTION is called with two arguments.  INTIAL-VALUE (and then the
8373     accumulated value) is used as the first argument, and the elements
8374     in SEQUENCE are used for the second argument.
8375
8376     If SEQUENCE is empty, this returns INITIAL-VALUE without calling
8377     FUNCTION.
8378
8379          (seq-reduce #'+ [1 2 3 4] 0)
8380          ⇒ 10
8381          (seq-reduce #'+ '(1 2 3 4) 5)
8382          ⇒ 15
8383          (seq-reduce #'+ '() 3)
8384          ⇒ 3
8385
8386 -- Function: seq-some predicate sequence
8387     This function returns the first non-‘nil’ value returned by
8388     applying PREDICATE to each element of SEQUENCE in turn.
8389
8390          (seq-some #'numberp ["abc" 1 nil])
8391          ⇒ t
8392          (seq-some #'numberp ["abc" "def"])
8393          ⇒ nil
8394          (seq-some #'null ["abc" 1 nil])
8395          ⇒ t
8396          (seq-some #'1+ [2 4 6])
8397          ⇒ 3
8398
8399 -- Function: seq-find predicate sequence &optional default
8400     This function returns the first element in SEQUENCE for which
8401     PREDICATE returns non-‘nil’.  If no element matches PREDICATE, the
8402     function returns DEFAULT.
8403
8404     Note that this function has an ambiguity if the found element is
8405     identical to DEFAULT, as in that case it cannot be known whether an
8406     element was found or not.
8407
8408          (seq-find #'numberp ["abc" 1 nil])
8409          ⇒ 1
8410          (seq-find #'numberp ["abc" "def"])
8411          ⇒ nil
8412
8413 -- Function: seq-every-p predicate sequence
8414     This function returns non-‘nil’ if applying PREDICATE to every
8415     element of SEQUENCE returns non-‘nil’.
8416
8417          (seq-every-p #'numberp [2 4 6])
8418          ⇒ t
8419          (seq-every-p #'numberp [2 4 "6"])
8420          ⇒ nil
8421
8422 -- Function: seq-empty-p sequence
8423     This function returns non-‘nil’ if SEQUENCE is empty.
8424
8425          (seq-empty-p "not empty")
8426          ⇒ nil
8427          (seq-empty-p "")
8428          ⇒ t
8429
8430 -- Function: seq-count predicate sequence
8431     This function returns the number of elements in SEQUENCE for which
8432     PREDICATE returns non-‘nil’.
8433
8434          (seq-count (lambda (elt) (> elt 0)) [-1 2 0 3 -2])
8435          ⇒ 2
8436
8437 -- Function: seq-sort function sequence
8438     This function returns a copy of SEQUENCE that is sorted according
8439     to FUNCTION, a function of two arguments that returns non-‘nil’ if
8440     the first argument should sort before the second.
8441
8442 -- Function: seq-sort-by function predicate sequence
8443     This function is similar to ‘seq-sort’, but the elements of
8444     SEQUENCE are transformed by applying FUNCTION on them before being
8445     sorted.  FUNCTION is a function of one argument.
8446
8447          (seq-sort-by #'seq-length #'> ["a" "ab" "abc"])
8448          ⇒ ["abc" "ab" "a"]
8449
8450 -- Function: seq-contains-p sequence elt &optional function
8451     This function returns non-‘nil’ if at least one element in SEQUENCE
8452     is equal to ELT.  If the optional argument FUNCTION is non-‘nil’,
8453     it is a function of two arguments to use instead of the default
8454     ‘equal’.
8455
8456          (seq-contains-p '(symbol1 symbol2) 'symbol1)
8457          ⇒ t
8458          (seq-contains-p '(symbol1 symbol2) 'symbol3)
8459          ⇒ nil
8460
8461 -- Function: seq-set-equal-p sequence1 sequence2 &optional testfn
8462     This function checks whether SEQUENCE1 and SEQUENCE2 contain the
8463     same elements, regardless of the order.  If the optional argument
8464     TESTFN is non-‘nil’, it is a function of two arguments to use
8465     instead of the default ‘equal’.
8466
8467          (seq-set-equal-p '(a b c) '(c b a))
8468          ⇒ t
8469          (seq-set-equal-p '(a b c) '(c b))
8470          ⇒ nil
8471          (seq-set-equal-p '("a" "b" "c") '("c" "b" "a"))
8472          ⇒ t
8473          (seq-set-equal-p '("a" "b" "c") '("c" "b" "a") #'eq)
8474          ⇒ nil
8475
8476 -- Function: seq-position sequence elt &optional function
8477     This function returns the index of the first element in SEQUENCE
8478     that is equal to ELT.  If the optional argument FUNCTION is
8479     non-‘nil’, it is a function of two arguments to use instead of the
8480     default ‘equal’.
8481
8482          (seq-position '(a b c) 'b)
8483          ⇒ 1
8484          (seq-position '(a b c) 'd)
8485          ⇒ nil
8486
8487 -- Function: seq-uniq sequence &optional function
8488     This function returns a list of the elements of SEQUENCE with
8489     duplicates removed.  If the optional argument FUNCTION is
8490     non-‘nil’, it is a function of two arguments to use instead of the
8491     default ‘equal’.
8492
8493          (seq-uniq '(1 2 2 1 3))
8494          ⇒ (1 2 3)
8495          (seq-uniq '(1 2 2.0 1.0) #'=)
8496          ⇒ (1 2)
8497
8498 -- Function: seq-subseq sequence start &optional end
8499     This function returns a subset of SEQUENCE from START to END, both
8500     integers (END defaults to the last element).  If START or END is
8501     negative, it counts from the end of SEQUENCE.
8502
8503          (seq-subseq '(1 2 3 4 5) 1)
8504          ⇒ (2 3 4 5)
8505          (seq-subseq '[1 2 3 4 5] 1 3)
8506          ⇒ [2 3]
8507          (seq-subseq '[1 2 3 4 5] -3 -1)
8508          ⇒ [3 4]
8509
8510 -- Function: seq-concatenate type &rest sequences
8511     This function returns a sequence of type TYPE made of the
8512     concatenation of SEQUENCES.  TYPE may be: ‘vector’, ‘list’ or
8513     ‘string’.
8514
8515          (seq-concatenate 'list '(1 2) '(3 4) [5 6])
8516          ⇒ (1 2 3 4 5 6)
8517          (seq-concatenate 'string "Hello " "world")
8518          ⇒ "Hello world"
8519
8520 -- Function: seq-mapcat function sequence &optional type
8521     This function returns the result of applying ‘seq-concatenate’ to
8522     the result of applying FUNCTION to each element of SEQUENCE.  The
8523     result is a sequence of type TYPE, or a list if TYPE is ‘nil’.
8524
8525          (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4)))
8526          ⇒ (1 2 3 4 5 6)
8527
8528 -- Function: seq-partition sequence n
8529     This function returns a list of the elements of SEQUENCE grouped
8530     into sub-sequences of length N.  The last sequence may contain less
8531     elements than N.  N must be an integer.  If N is a negative integer
8532     or 0, the return value is ‘nil’.
8533
8534          (seq-partition '(0 1 2 3 4 5 6 7) 3)
8535          ⇒ ((0 1 2) (3 4 5) (6 7))
8536
8537 -- Function: seq-intersection sequence1 sequence2 &optional function
8538     This function returns a list of the elements that appear both in
8539     SEQUENCE1 and SEQUENCE2.  If the optional argument FUNCTION is
8540     non-‘nil’, it is a function of two arguments to use to compare
8541     elements instead of the default ‘equal’.
8542
8543          (seq-intersection [2 3 4 5] [1 3 5 6 7])
8544          ⇒ (3 5)
8545
8546 -- Function: seq-difference sequence1 sequence2 &optional function
8547     This function returns a list of the elements that appear in
8548     SEQUENCE1 but not in SEQUENCE2.  If the optional argument FUNCTION
8549     is non-‘nil’, it is a function of two arguments to use to compare
8550     elements instead of the default ‘equal’.
8551
8552          (seq-difference '(2 3 4 5) [1 3 5 6 7])
8553          ⇒ (2 4)
8554
8555 -- Function: seq-group-by function sequence
8556     This function separates the elements of SEQUENCE into an alist
8557     whose keys are the result of applying FUNCTION to each element of
8558     SEQUENCE.  Keys are compared using ‘equal’.
8559
8560          (seq-group-by #'integerp '(1 2.1 3 2 3.2))
8561          ⇒ ((t 1 3 2) (nil 2.1 3.2))
8562          (seq-group-by #'car '((a 1) (b 2) (a 3) (c 4)))
8563          ⇒ ((b (b 2)) (a (a 1) (a 3)) (c (c 4)))
8564
8565 -- Function: seq-into sequence type
8566     This function converts the sequence SEQUENCE into a sequence of
8567     type TYPE.  TYPE can be one of the following symbols: ‘vector’,
8568     ‘string’ or ‘list’.
8569
8570          (seq-into [1 2 3] 'list)
8571          ⇒ (1 2 3)
8572          (seq-into nil 'vector)
8573          ⇒ []
8574          (seq-into "hello" 'vector)
8575          ⇒ [104 101 108 108 111]
8576
8577 -- Function: seq-min sequence
8578     This function returns the smallest element of SEQUENCE.  The
8579     elements of SEQUENCE must be numbers or markers (*note Markers::).
8580
8581          (seq-min [3 1 2])
8582          ⇒ 1
8583          (seq-min "Hello")
8584          ⇒ 72
8585
8586 -- Function: seq-max sequence
8587     This function returns the largest element of SEQUENCE.  The
8588     elements of SEQUENCE must be numbers or markers.
8589
8590          (seq-max [1 3 2])
8591          ⇒ 3
8592          (seq-max "Hello")
8593          ⇒ 111
8594
8595 -- Macro: seq-doseq (var sequence) body...
8596     This macro is like ‘dolist’ (*note dolist: Iteration.), except that
8597     SEQUENCE can be a list, vector or string.  This is primarily useful
8598     for side-effects.
8599
8600 -- Macro: seq-let var-sequence val-sequence body...
8601     This macro binds the variables defined in VAR-SEQUENCE to the
8602     values that are the corresponding elements of VAL-SEQUENCE.  This
8603     is known as “destructuring binding”.  The elements of VAR-SEQUENCE
8604     can themselves include sequences, allowing for nested
8605     destructuring.
8606
8607     The VAR-SEQUENCE sequence can also include the ‘&rest’ marker
8608     followed by a variable name to be bound to the rest of
8609     VAL-SEQUENCE.
8610
8611          (seq-let [first second] [1 2 3 4]
8612            (list first second))
8613          ⇒ (1 2)
8614          (seq-let (_ a _ b) '(1 2 3 4)
8615            (list a b))
8616          ⇒ (2 4)
8617          (seq-let [a [b [c]]] [1 [2 [3]]]
8618            (list a b c))
8619          ⇒ (1 2 3)
8620          (seq-let [a b &rest others] [1 2 3 4]
8621            others)
8622          ⇒ [3 4]
8623
8624     The ‘pcase’ patterns provide an alternative facility for
8625     destructuring binding, see *note Destructuring with pcase
8626     Patterns::.
8627
8628 -- Function: seq-random-elt sequence
8629     This function returns an element of SEQUENCE taken at random.
8630
8631          (seq-random-elt [1 2 3 4])
8632          ⇒ 3
8633          (seq-random-elt [1 2 3 4])
8634          ⇒ 2
8635          (seq-random-elt [1 2 3 4])
8636          ⇒ 4
8637          (seq-random-elt [1 2 3 4])
8638          ⇒ 2
8639          (seq-random-elt [1 2 3 4])
8640          ⇒ 1
8641
8642     If SEQUENCE is empty, this function signals an error.
8643
8644
8645File: elisp.info,  Node: Arrays,  Next: Array Functions,  Prev: Sequence Functions,  Up: Sequences Arrays Vectors
8646
86476.2 Arrays
8648==========
8649
8650An “array” object has slots that hold a number of other Lisp objects,
8651called the elements of the array.  Any element of an array may be
8652accessed in constant time.  In contrast, the time to access an element
8653of a list is proportional to the position of that element in the list.
8654
8655   Emacs defines four types of array, all one-dimensional: “strings”
8656(*note String Type::), “vectors” (*note Vector Type::), “bool-vectors”
8657(*note Bool-Vector Type::), and “char-tables” (*note Char-Table Type::).
8658Vectors and char-tables can hold elements of any type, but strings can
8659only hold characters, and bool-vectors can only hold ‘t’ and ‘nil’.
8660
8661   All four kinds of array share these characteristics:
8662
8663   • The first element of an array has index zero, the second element
8664     has index 1, and so on.  This is called “zero-origin” indexing.
8665     For example, an array of four elements has indices 0, 1, 2, and 3.
8666
8667   • The length of the array is fixed once you create it; you cannot
8668     change the length of an existing array.
8669
8670   • For purposes of evaluation, the array is a constant—i.e., it
8671     evaluates to itself.
8672
8673   • The elements of an array may be referenced or changed with the
8674     functions ‘aref’ and ‘aset’, respectively (*note Array
8675     Functions::).
8676
8677   When you create an array, other than a char-table, you must specify
8678its length.  You cannot specify the length of a char-table, because that
8679is determined by the range of character codes.
8680
8681   In principle, if you want an array of text characters, you could use
8682either a string or a vector.  In practice, we always choose strings for
8683such applications, for four reasons:
8684
8685   • They occupy one-fourth the space of a vector of the same elements.
8686
8687   • Strings are printed in a way that shows the contents more clearly
8688     as text.
8689
8690   • Strings can hold text properties.  *Note Text Properties::.
8691
8692   • Many of the specialized editing and I/O facilities of Emacs accept
8693     only strings.  For example, you cannot insert a vector of
8694     characters into a buffer the way you can insert a string.  *Note
8695     Strings and Characters::.
8696
8697   By contrast, for an array of keyboard input characters (such as a key
8698sequence), a vector may be necessary, because many keyboard input
8699characters are outside the range that will fit in a string.  *Note Key
8700Sequence Input::.
8701
8702
8703File: elisp.info,  Node: Array Functions,  Next: Vectors,  Prev: Arrays,  Up: Sequences Arrays Vectors
8704
87056.3 Functions that Operate on Arrays
8706====================================
8707
8708In this section, we describe the functions that accept all types of
8709arrays.
8710
8711 -- Function: arrayp object
8712     This function returns ‘t’ if OBJECT is an array (i.e., a vector, a
8713     string, a bool-vector or a char-table).
8714
8715          (arrayp [a])
8716               ⇒ t
8717          (arrayp "asdf")
8718               ⇒ t
8719          (arrayp (syntax-table))    ;; A char-table.
8720               ⇒ t
8721
8722 -- Function: aref arr index
8723     This function returns the INDEXth element of the array or record
8724     ARR.  The first element is at index zero.
8725
8726          (setq primes [2 3 5 7 11 13])
8727               ⇒ [2 3 5 7 11 13]
8728          (aref primes 4)
8729               ⇒ 11
8730          (aref "abcdefg" 1)
8731               ⇒ 98           ; ‘b’ is ASCII code 98.
8732
8733     See also the function ‘elt’, in *note Sequence Functions::.
8734
8735 -- Function: aset array index object
8736     This function sets the INDEXth element of ARRAY to be OBJECT.  It
8737     returns OBJECT.
8738
8739          (setq w (vector 'foo 'bar 'baz))
8740               ⇒ [foo bar baz]
8741          (aset w 0 'fu)
8742               ⇒ fu
8743          w
8744               ⇒ [fu bar baz]
8745
8746          ;; ‘copy-sequence’ copies the string to be modified later.
8747          (setq x (copy-sequence "asdfasfd"))
8748               ⇒ "asdfasfd"
8749          (aset x 3 ?Z)
8750               ⇒ 90
8751          x
8752               ⇒ "asdZasfd"
8753
8754     The ARRAY should be mutable.  *Note Mutability::.
8755
8756     If ARRAY is a string and OBJECT is not a character, a
8757     ‘wrong-type-argument’ error results.  The function converts a
8758     unibyte string to multibyte if necessary to insert a character.
8759
8760 -- Function: fillarray array object
8761     This function fills the array ARRAY with OBJECT, so that each
8762     element of ARRAY is OBJECT.  It returns ARRAY.
8763
8764          (setq a (copy-sequence [a b c d e f g]))
8765               ⇒ [a b c d e f g]
8766          (fillarray a 0)
8767               ⇒ [0 0 0 0 0 0 0]
8768          a
8769               ⇒ [0 0 0 0 0 0 0]
8770          (setq s (copy-sequence "When in the course"))
8771               ⇒ "When in the course"
8772          (fillarray s ?-)
8773               ⇒ "------------------"
8774
8775     If ARRAY is a string and OBJECT is not a character, a
8776     ‘wrong-type-argument’ error results.
8777
8778   The general sequence functions ‘copy-sequence’ and ‘length’ are often
8779useful for objects known to be arrays.  *Note Sequence Functions::.
8780
8781
8782File: elisp.info,  Node: Vectors,  Next: Vector Functions,  Prev: Array Functions,  Up: Sequences Arrays Vectors
8783
87846.4 Vectors
8785===========
8786
8787A “vector” is a general-purpose array whose elements can be any Lisp
8788objects.  (By contrast, the elements of a string can only be characters.
8789*Note Strings and Characters::.)  Vectors are used in Emacs for many
8790purposes: as key sequences (*note Key Sequences::), as symbol-lookup
8791tables (*note Creating Symbols::), as part of the representation of a
8792byte-compiled function (*note Byte Compilation::), and more.
8793
8794   Like other arrays, vectors use zero-origin indexing: the first
8795element has index 0.
8796
8797   Vectors are printed with square brackets surrounding the elements.
8798Thus, a vector whose elements are the symbols ‘a’, ‘b’ and ‘a’ is
8799printed as ‘[a b a]’.  You can write vectors in the same way in Lisp
8800input.
8801
8802   A vector, like a string or a number, is considered a constant for
8803evaluation: the result of evaluating it is the same vector.  This does
8804not evaluate or even examine the elements of the vector.  *Note
8805Self-Evaluating Forms::.  Vectors written with square brackets should
8806not be modified via ‘aset’ or other destructive operations.  *Note
8807Mutability::.
8808
8809   Here are examples illustrating these principles:
8810
8811     (setq avector [1 two '(three) "four" [five]])
8812          ⇒ [1 two '(three) "four" [five]]
8813     (eval avector)
8814          ⇒ [1 two '(three) "four" [five]]
8815     (eq avector (eval avector))
8816          ⇒ t
8817
8818
8819File: elisp.info,  Node: Vector Functions,  Next: Char-Tables,  Prev: Vectors,  Up: Sequences Arrays Vectors
8820
88216.5 Functions for Vectors
8822=========================
8823
8824Here are some functions that relate to vectors:
8825
8826 -- Function: vectorp object
8827     This function returns ‘t’ if OBJECT is a vector.
8828
8829          (vectorp [a])
8830               ⇒ t
8831          (vectorp "asdf")
8832               ⇒ nil
8833
8834 -- Function: vector &rest objects
8835     This function creates and returns a vector whose elements are the
8836     arguments, OBJECTS.
8837
8838          (vector 'foo 23 [bar baz] "rats")
8839               ⇒ [foo 23 [bar baz] "rats"]
8840          (vector)
8841               ⇒ []
8842
8843 -- Function: make-vector length object
8844     This function returns a new vector consisting of LENGTH elements,
8845     each initialized to OBJECT.
8846
8847          (setq sleepy (make-vector 9 'Z))
8848               ⇒ [Z Z Z Z Z Z Z Z Z]
8849
8850 -- Function: vconcat &rest sequences
8851     This function returns a new vector containing all the elements of
8852     SEQUENCES.  The arguments SEQUENCES may be proper lists, vectors,
8853     strings or bool-vectors.  If no SEQUENCES are given, the empty
8854     vector is returned.
8855
8856     The value is either the empty vector, or is a newly constructed
8857     nonempty vector that is not ‘eq’ to any existing vector.
8858
8859          (setq a (vconcat '(A B C) '(D E F)))
8860               ⇒ [A B C D E F]
8861          (eq a (vconcat a))
8862               ⇒ nil
8863          (vconcat)
8864               ⇒ []
8865          (vconcat [A B C] "aa" '(foo (6 7)))
8866               ⇒ [A B C 97 97 foo (6 7)]
8867
8868     The ‘vconcat’ function also allows byte-code function objects as
8869     arguments.  This is a special feature to make it easy to access the
8870     entire contents of a byte-code function object.  *Note Byte-Code
8871     Objects::.
8872
8873     For other concatenation functions, see ‘mapconcat’ in *note Mapping
8874     Functions::, ‘concat’ in *note Creating Strings::, and ‘append’ in
8875     *note Building Lists::.
8876
8877   The ‘append’ function also provides a way to convert a vector into a
8878list with the same elements:
8879
8880     (setq avector [1 two (quote (three)) "four" [five]])
8881          ⇒ [1 two '(three) "four" [five]]
8882     (append avector nil)
8883          ⇒ (1 two '(three) "four" [five])
8884
8885
8886File: elisp.info,  Node: Char-Tables,  Next: Bool-Vectors,  Prev: Vector Functions,  Up: Sequences Arrays Vectors
8887
88886.6 Char-Tables
8889===============
8890
8891A char-table is much like a vector, except that it is indexed by
8892character codes.  Any valid character code, without modifiers, can be
8893used as an index in a char-table.  You can access a char-table’s
8894elements with ‘aref’ and ‘aset’, as with any array.  In addition, a
8895char-table can have “extra slots” to hold additional data not associated
8896with particular character codes.  Like vectors, char-tables are
8897constants when evaluated, and can hold elements of any type.
8898
8899   Each char-table has a “subtype”, a symbol, which serves two purposes:
8900
8901   • The subtype provides an easy way to tell what the char-table is
8902     for.  For instance, display tables are char-tables with
8903     ‘display-table’ as the subtype, and syntax tables are char-tables
8904     with ‘syntax-table’ as the subtype.  The subtype can be queried
8905     using the function ‘char-table-subtype’, described below.
8906
8907   • The subtype controls the number of “extra slots” in the char-table.
8908     This number is specified by the subtype’s ‘char-table-extra-slots’
8909     symbol property (*note Symbol Properties::), whose value should be
8910     an integer between 0 and 10.  If the subtype has no such symbol
8911     property, the char-table has no extra slots.
8912
8913   A char-table can have a “parent”, which is another char-table.  If it
8914does, then whenever the char-table specifies ‘nil’ for a particular
8915character C, it inherits the value specified in the parent.  In other
8916words, ‘(aref CHAR-TABLE C)’ returns the value from the parent of
8917CHAR-TABLE if CHAR-TABLE itself specifies ‘nil’.
8918
8919   A char-table can also have a “default value”.  If so, then ‘(aref
8920CHAR-TABLE C)’ returns the default value whenever the char-table does
8921not specify any other non-‘nil’ value.
8922
8923 -- Function: make-char-table subtype &optional init
8924     Return a newly-created char-table, with subtype SUBTYPE (a symbol).
8925     Each element is initialized to INIT, which defaults to ‘nil’.  You
8926     cannot alter the subtype of a char-table after the char-table is
8927     created.
8928
8929     There is no argument to specify the length of the char-table,
8930     because all char-tables have room for any valid character code as
8931     an index.
8932
8933     If SUBTYPE has the ‘char-table-extra-slots’ symbol property, that
8934     specifies the number of extra slots in the char-table.  This should
8935     be an integer between 0 and 10; otherwise, ‘make-char-table’ raises
8936     an error.  If SUBTYPE has no ‘char-table-extra-slots’ symbol
8937     property (*note Property Lists::), the char-table has no extra
8938     slots.
8939
8940 -- Function: char-table-p object
8941     This function returns ‘t’ if OBJECT is a char-table, and ‘nil’
8942     otherwise.
8943
8944 -- Function: char-table-subtype char-table
8945     This function returns the subtype symbol of CHAR-TABLE.
8946
8947   There is no special function to access default values in a
8948char-table.  To do that, use ‘char-table-range’ (see below).
8949
8950 -- Function: char-table-parent char-table
8951     This function returns the parent of CHAR-TABLE.  The parent is
8952     always either ‘nil’ or another char-table.
8953
8954 -- Function: set-char-table-parent char-table new-parent
8955     This function sets the parent of CHAR-TABLE to NEW-PARENT.
8956
8957 -- Function: char-table-extra-slot char-table n
8958     This function returns the contents of extra slot N (zero based) of
8959     CHAR-TABLE.  The number of extra slots in a char-table is
8960     determined by its subtype.
8961
8962 -- Function: set-char-table-extra-slot char-table n value
8963     This function stores VALUE in extra slot N (zero based) of
8964     CHAR-TABLE.
8965
8966   A char-table can specify an element value for a single character
8967code; it can also specify a value for an entire character set.
8968
8969 -- Function: char-table-range char-table range
8970     This returns the value specified in CHAR-TABLE for a range of
8971     characters RANGE.  Here are the possibilities for RANGE:
8972
8973     ‘nil’
8974          Refers to the default value.
8975
8976     CHAR
8977          Refers to the element for character CHAR (supposing CHAR is a
8978          valid character code).
8979
8980     ‘(FROM . TO)’
8981          A cons cell refers to all the characters in the inclusive
8982          range ‘[FROM..TO]’.
8983
8984 -- Function: set-char-table-range char-table range value
8985     This function sets the value in CHAR-TABLE for a range of
8986     characters RANGE.  Here are the possibilities for RANGE:
8987
8988     ‘nil’
8989          Refers to the default value.
8990
8991     ‘t’
8992          Refers to the whole range of character codes.
8993
8994     CHAR
8995          Refers to the element for character CHAR (supposing CHAR is a
8996          valid character code).
8997
8998     ‘(FROM . TO)’
8999          A cons cell refers to all the characters in the inclusive
9000          range ‘[FROM..TO]’.
9001
9002 -- Function: map-char-table function char-table
9003     This function calls its argument FUNCTION for each element of
9004     CHAR-TABLE that has a non-‘nil’ value.  The call to FUNCTION is
9005     with two arguments, a key and a value.  The key is a possible RANGE
9006     argument for ‘char-table-range’—either a valid character or a cons
9007     cell ‘(FROM . TO)’, specifying a range of characters that share the
9008     same value.  The value is what ‘(char-table-range CHAR-TABLE KEY)’
9009     returns.
9010
9011     Overall, the key-value pairs passed to FUNCTION describe all the
9012     values stored in CHAR-TABLE.
9013
9014     The return value is always ‘nil’; to make calls to ‘map-char-table’
9015     useful, FUNCTION should have side effects.  For example, here is
9016     how to examine the elements of the syntax table:
9017
9018          (let (accumulator)
9019             (map-char-table
9020              (lambda (key value)
9021                (setq accumulator
9022                      (cons (list
9023                             (if (consp key)
9024                                 (list (car key) (cdr key))
9025                               key)
9026                             value)
9027                            accumulator)))
9028              (syntax-table))
9029             accumulator)
90309031          (((2597602 4194303) (2)) ((2597523 2597601) (3))
9032           ... (65379 (5 . 65378)) (65378 (4 . 65379)) (65377 (1))
9033           ... (12 (0)) (11 (3)) (10 (12)) (9 (0)) ((0 8) (3)))
9034
9035
9036File: elisp.info,  Node: Bool-Vectors,  Next: Rings,  Prev: Char-Tables,  Up: Sequences Arrays Vectors
9037
90386.7 Bool-vectors
9039================
9040
9041A bool-vector is much like a vector, except that it stores only the
9042values ‘t’ and ‘nil’.  If you try to store any non-‘nil’ value into an
9043element of the bool-vector, the effect is to store ‘t’ there.  As with
9044all arrays, bool-vector indices start from 0, and the length cannot be
9045changed once the bool-vector is created.  Bool-vectors are constants
9046when evaluated.
9047
9048   Several functions work specifically with bool-vectors; aside from
9049that, you manipulate them with same functions used for other kinds of
9050arrays.
9051
9052 -- Function: make-bool-vector length initial
9053     Return a new bool-vector of LENGTH elements, each one initialized
9054     to INITIAL.
9055
9056 -- Function: bool-vector &rest objects
9057     This function creates and returns a bool-vector whose elements are
9058     the arguments, OBJECTS.
9059
9060 -- Function: bool-vector-p object
9061     This returns ‘t’ if OBJECT is a bool-vector, and ‘nil’ otherwise.
9062
9063   There are also some bool-vector set operation functions, described
9064below:
9065
9066 -- Function: bool-vector-exclusive-or a b &optional c
9067     Return “bitwise exclusive or” of bool vectors A and B.  If optional
9068     argument C is given, the result of this operation is stored into C.
9069     All arguments should be bool vectors of the same length.
9070
9071 -- Function: bool-vector-union a b &optional c
9072     Return “bitwise or” of bool vectors A and B.  If optional argument
9073     C is given, the result of this operation is stored into C.  All
9074     arguments should be bool vectors of the same length.
9075
9076 -- Function: bool-vector-intersection a b &optional c
9077     Return “bitwise and” of bool vectors A and B.  If optional argument
9078     C is given, the result of this operation is stored into C.  All
9079     arguments should be bool vectors of the same length.
9080
9081 -- Function: bool-vector-set-difference a b &optional c
9082     Return “set difference” of bool vectors A and B.  If optional
9083     argument C is given, the result of this operation is stored into C.
9084     All arguments should be bool vectors of the same length.
9085
9086 -- Function: bool-vector-not a &optional b
9087     Return “set complement” of bool vector A.  If optional argument B
9088     is given, the result of this operation is stored into B.  All
9089     arguments should be bool vectors of the same length.
9090
9091 -- Function: bool-vector-subsetp a b
9092     Return ‘t’ if every ‘t’ value in A is also ‘t’ in B, ‘nil’
9093     otherwise.  All arguments should be bool vectors of the same
9094     length.
9095
9096 -- Function: bool-vector-count-consecutive a b i
9097     Return the number of consecutive elements in A equal B starting at
9098     I.  ‘a’ is a bool vector, B is ‘t’ or ‘nil’, and I is an index into
9099     ‘a’.
9100
9101 -- Function: bool-vector-count-population a
9102     Return the number of elements that are ‘t’ in bool vector A.
9103
9104   The printed form represents up to 8 boolean values as a single
9105character:
9106
9107     (bool-vector t nil t nil)
9108          ⇒ #&4"^E"
9109     (bool-vector)
9110          ⇒ #&0""
9111
9112   You can use ‘vconcat’ to print a bool-vector like other vectors:
9113
9114     (vconcat (bool-vector nil t nil t))
9115          ⇒ [nil t nil t]
9116
9117   Here is another example of creating, examining, and updating a
9118bool-vector:
9119
9120     (setq bv (make-bool-vector 5 t))
9121          ⇒ #&5"^_"
9122     (aref bv 1)
9123          ⇒ t
9124     (aset bv 3 nil)
9125          ⇒ nil
9126     bv
9127          ⇒ #&5"^W"
9128
9129These results make sense because the binary codes for control-_ and
9130control-W are 11111 and 10111, respectively.
9131
9132
9133File: elisp.info,  Node: Rings,  Prev: Bool-Vectors,  Up: Sequences Arrays Vectors
9134
91356.8 Managing a Fixed-Size Ring of Objects
9136=========================================
9137
9138A “ring” is a fixed-size data structure that supports insertion,
9139deletion, rotation, and modulo-indexed reference and traversal.  An
9140efficient ring data structure is implemented by the ‘ring’ package.  It
9141provides the functions listed in this section.
9142
9143   Note that several rings in Emacs, like the kill ring and the mark
9144ring, are actually implemented as simple lists, _not_ using the ‘ring’
9145package; thus the following functions won’t work on them.
9146
9147 -- Function: make-ring size
9148     This returns a new ring capable of holding SIZE objects.  SIZE
9149     should be an integer.
9150
9151 -- Function: ring-p object
9152     This returns ‘t’ if OBJECT is a ring, ‘nil’ otherwise.
9153
9154 -- Function: ring-size ring
9155     This returns the maximum capacity of the RING.
9156
9157 -- Function: ring-length ring
9158     This returns the number of objects that RING currently contains.
9159     The value will never exceed that returned by ‘ring-size’.
9160
9161 -- Function: ring-elements ring
9162     This returns a list of the objects in RING, in order, newest first.
9163
9164 -- Function: ring-copy ring
9165     This returns a new ring which is a copy of RING.  The new ring
9166     contains the same (‘eq’) objects as RING.
9167
9168 -- Function: ring-empty-p ring
9169     This returns ‘t’ if RING is empty, ‘nil’ otherwise.
9170
9171   The newest element in the ring always has index 0.  Higher indices
9172correspond to older elements.  Indices are computed modulo the ring
9173length.  Index −1 corresponds to the oldest element, −2 to the
9174next-oldest, and so forth.
9175
9176 -- Function: ring-ref ring index
9177     This returns the object in RING found at index INDEX.  INDEX may be
9178     negative or greater than the ring length.  If RING is empty,
9179     ‘ring-ref’ signals an error.
9180
9181 -- Function: ring-insert ring object
9182     This inserts OBJECT into RING, making it the newest element, and
9183     returns OBJECT.
9184
9185     If the ring is full, insertion removes the oldest element to make
9186     room for the new element.
9187
9188 -- Function: ring-remove ring &optional index
9189     Remove an object from RING, and return that object.  The argument
9190     INDEX specifies which item to remove; if it is ‘nil’, that means to
9191     remove the oldest item.  If RING is empty, ‘ring-remove’ signals an
9192     error.
9193
9194 -- Function: ring-insert-at-beginning ring object
9195     This inserts OBJECT into RING, treating it as the oldest element.
9196     The return value is not significant.
9197
9198     If the ring is full, this function removes the newest element to
9199     make room for the inserted element.
9200
9201 -- Function: ring-resize ring size
9202     Set the size of RING to SIZE.  If the new size is smaller, then the
9203     oldest items in the ring are discarded.
9204
9205   If you are careful not to exceed the ring size, you can use the ring
9206as a first-in-first-out queue.  For example:
9207
9208     (let ((fifo (make-ring 5)))
9209       (mapc (lambda (obj) (ring-insert fifo obj))
9210             '(0 one "two"))
9211       (list (ring-remove fifo) t
9212             (ring-remove fifo) t
9213             (ring-remove fifo)))
9214          ⇒ (0 t one t "two")
9215
9216
9217File: elisp.info,  Node: Records,  Next: Hash Tables,  Prev: Sequences Arrays Vectors,  Up: Top
9218
92197 Records
9220*********
9221
9222The purpose of records is to allow programmers to create objects with
9223new types that are not built into Emacs.  They are used as the
9224underlying representation of ‘cl-defstruct’ and ‘defclass’ instances.
9225
9226   Internally, a record object is much like a vector; its slots can be
9227accessed using ‘aref’ and it can be copied using ‘copy-sequence’.
9228However, the first slot is used to hold its type as returned by
9229‘type-of’.  Also, in the current implementation records can have at most
92304096 slots, whereas vectors can be much larger.  Like arrays, records
9231use zero-origin indexing: the first slot has index 0.
9232
9233   The type slot should be a symbol or a type descriptor.  If it’s a
9234type descriptor, the symbol naming its type will be returned; *note Type
9235Descriptors::.  Any other kind of object is returned as-is.
9236
9237   The printed representation of records is ‘#s’ followed by a list
9238specifying the contents.  The first list element must be the record
9239type.  The following elements are the record slots.
9240
9241   To avoid conflicts with other type names, Lisp programs that define
9242new types of records should normally use the naming conventions of the
9243package where these record types are introduced for the names of the
9244types.  Note that the names of the types which could possibly conflict
9245might not be known at the time the package defining a record type is
9246loaded; they could be loaded at some future point in time.
9247
9248   A record is considered a constant for evaluation: the result of
9249evaluating it is the same record.  This does not evaluate or even
9250examine the slots.  *Note Self-Evaluating Forms::.
9251
9252* Menu:
9253
9254* Record Functions::        Functions for records.
9255* Backward Compatibility::  Compatibility for cl-defstruct.
9256
9257
9258File: elisp.info,  Node: Record Functions,  Next: Backward Compatibility,  Up: Records
9259
92607.1 Record Functions
9261====================
9262
9263 -- Function: recordp object
9264     This function returns ‘t’ if OBJECT is a record.
9265
9266          (recordp #s(a))
9267               ⇒ t
9268
9269 -- Function: record type &rest objects
9270     This function creates and returns a record whose type is TYPE and
9271     remaining slots are the rest of the arguments, OBJECTS.
9272
9273          (record 'foo 23 [bar baz] "rats")
9274               ⇒ #s(foo 23 [bar baz] "rats")
9275
9276 -- Function: make-record type length object
9277     This function returns a new record with type TYPE and LENGTH more
9278     slots, each initialized to OBJECT.
9279
9280          (setq sleepy (make-record 'foo 9 'Z))
9281               ⇒ #s(foo Z Z Z Z Z Z Z Z Z)
9282
9283
9284File: elisp.info,  Node: Backward Compatibility,  Prev: Record Functions,  Up: Records
9285
92867.2 Backward Compatibility
9287==========================
9288
9289Code compiled with older versions of ‘cl-defstruct’ that doesn’t use
9290records may run into problems when used in a new Emacs.  To alleviate
9291this, Emacs detects when an old ‘cl-defstruct’ is used, and enables a
9292mode in which ‘type-of’ handles old struct objects as if they were
9293records.
9294
9295 -- Function: cl-old-struct-compat-mode arg
9296     If ARG is positive, enable backward compatibility with old-style
9297     structs.
9298
9299
9300File: elisp.info,  Node: Hash Tables,  Next: Symbols,  Prev: Records,  Up: Top
9301
93028 Hash Tables
9303*************
9304
9305A hash table is a very fast kind of lookup table, somewhat like an alist
9306(*note Association Lists::) in that it maps keys to corresponding
9307values.  It differs from an alist in these ways:
9308
9309   • Lookup in a hash table is extremely fast for large tables—in fact,
9310     the time required is essentially _independent_ of how many elements
9311     are stored in the table.  For smaller tables (a few tens of
9312     elements) alists may still be faster because hash tables have a
9313     more-or-less constant overhead.
9314
9315   • The correspondences in a hash table are in no particular order.
9316
9317   • There is no way to share structure between two hash tables, the way
9318     two alists can share a common tail.
9319
9320   Emacs Lisp provides a general-purpose hash table data type, along
9321with a series of functions for operating on them.  Hash tables have a
9322special printed representation, which consists of ‘#s’ followed by a
9323list specifying the hash table properties and contents.  *Note Creating
9324Hash::.  (Hash notation, the initial ‘#’ character used in the printed
9325representations of objects with no read representation, has nothing to
9326do with hash tables.  *Note Printed Representation::.)
9327
9328   Obarrays are also a kind of hash table, but they are a different type
9329of object and are used only for recording interned symbols (*note
9330Creating Symbols::).
9331
9332* Menu:
9333
9334* Creating Hash::       Functions to create hash tables.
9335* Hash Access::         Reading and writing the hash table contents.
9336* Defining Hash::       Defining new comparison methods.
9337* Other Hash::          Miscellaneous.
9338
9339
9340File: elisp.info,  Node: Creating Hash,  Next: Hash Access,  Up: Hash Tables
9341
93428.1 Creating Hash Tables
9343========================
9344
9345The principal function for creating a hash table is ‘make-hash-table’.
9346
9347 -- Function: make-hash-table &rest keyword-args
9348     This function creates a new hash table according to the specified
9349     arguments.  The arguments should consist of alternating keywords
9350     (particular symbols recognized specially) and values corresponding
9351     to them.
9352
9353     Several keywords make sense in ‘make-hash-table’, but the only two
9354     that you really need to know about are ‘:test’ and ‘:weakness’.
9355
9356     ‘:test TEST’
9357          This specifies the method of key lookup for this hash table.
9358          The default is ‘eql’; ‘eq’ and ‘equal’ are other alternatives:
9359
9360          ‘eql’
9361               Keys which are numbers are the same if they are ‘equal’,
9362               that is, if they are equal in value and either both are
9363               integers or both are floating point; otherwise, two
9364               distinct objects are never the same.
9365
9366          ‘eq’
9367               Any two distinct Lisp objects are different as keys.
9368
9369          ‘equal’
9370               Two Lisp objects are the same, as keys, if they are equal
9371               according to ‘equal’.
9372
9373          You can use ‘define-hash-table-test’ (*note Defining Hash::)
9374          to define additional possibilities for TEST.
9375
9376     ‘:weakness WEAK’
9377          The weakness of a hash table specifies whether the presence of
9378          a key or value in the hash table preserves it from garbage
9379          collection.
9380
9381          The value, WEAK, must be one of ‘nil’, ‘key’, ‘value’,
9382          ‘key-or-value’, ‘key-and-value’, or ‘t’ which is an alias for
9383          ‘key-and-value’.  If WEAK is ‘key’ then the hash table does
9384          not prevent its keys from being collected as garbage (if they
9385          are not referenced anywhere else); if a particular key does
9386          get collected, the corresponding association is removed from
9387          the hash table.
9388
9389          If WEAK is ‘value’, then the hash table does not prevent
9390          values from being collected as garbage (if they are not
9391          referenced anywhere else); if a particular value does get
9392          collected, the corresponding association is removed from the
9393          hash table.
9394
9395          If WEAK is ‘key-and-value’ or ‘t’, both the key and the value
9396          must be live in order to preserve the association.  Thus, the
9397          hash table does not protect either keys or values from garbage
9398          collection; if either one is collected as garbage, that
9399          removes the association.
9400
9401          If WEAK is ‘key-or-value’, either the key or the value can
9402          preserve the association.  Thus, associations are removed from
9403          the hash table when both their key and value would be
9404          collected as garbage (if not for references from weak hash
9405          tables).
9406
9407          The default for WEAK is ‘nil’, so that all keys and values
9408          referenced in the hash table are preserved from garbage
9409          collection.
9410
9411     ‘:size SIZE’
9412          This specifies a hint for how many associations you plan to
9413          store in the hash table.  If you know the approximate number,
9414          you can make things a little more efficient by specifying it
9415          this way.  If you specify too small a size, the hash table
9416          will grow automatically when necessary, but doing that takes
9417          some extra time.
9418
9419          The default size is 65.
9420
9421     ‘:rehash-size REHASH-SIZE’
9422          When you add an association to a hash table and the table is
9423          full, it grows automatically.  This value specifies how to
9424          make the hash table larger, at that time.
9425
9426          If REHASH-SIZE is an integer, it should be positive, and the
9427          hash table grows by adding approximately that much to the
9428          nominal size.  If REHASH-SIZE is floating point, it had better
9429          be greater than 1, and the hash table grows by multiplying the
9430          old size by approximately that number.
9431
9432          The default value is 1.5.
9433
9434     ‘:rehash-threshold THRESHOLD’
9435          This specifies the criterion for when the hash table is full
9436          (so it should be made larger).  The value, THRESHOLD, should
9437          be a positive floating-point number, no greater than 1.  The
9438          hash table is full whenever the actual number of entries
9439          exceeds the nominal size multiplied by an approximation to
9440          this value.  The default for THRESHOLD is 0.8125.
9441
9442   You can also create a new hash table using the printed representation
9443for hash tables.  The Lisp reader can read this printed representation,
9444provided each element in the specified hash table has a valid read
9445syntax (*note Printed Representation::).  For instance, the following
9446specifies a new hash table containing the keys ‘key1’ and ‘key2’ (both
9447symbols) associated with ‘val1’ (a symbol) and ‘300’ (a number)
9448respectively.
9449
9450     #s(hash-table size 30 data (key1 val1 key2 300))
9451
9452The printed representation for a hash table consists of ‘#s’ followed by
9453a list beginning with ‘hash-table’.  The rest of the list should consist
9454of zero or more property-value pairs specifying the hash table’s
9455properties and initial contents.  The properties and values are read
9456literally.  Valid property names are ‘size’, ‘test’, ‘weakness’,
9457‘rehash-size’, ‘rehash-threshold’, and ‘data’.  The ‘data’ property
9458should be a list of key-value pairs for the initial contents; the other
9459properties have the same meanings as the matching ‘make-hash-table’
9460keywords (‘:size’, ‘:test’, etc.), described above.
9461
9462   Note that you cannot specify a hash table whose initial contents
9463include objects that have no read syntax, such as buffers and frames.
9464Such objects may be added to the hash table after it is created.
9465
9466
9467File: elisp.info,  Node: Hash Access,  Next: Defining Hash,  Prev: Creating Hash,  Up: Hash Tables
9468
94698.2 Hash Table Access
9470=====================
9471
9472This section describes the functions for accessing and storing
9473associations in a hash table.  In general, any Lisp object can be used
9474as a hash key, unless the comparison method imposes limits.  Any Lisp
9475object can also be used as the value.
9476
9477 -- Function: gethash key table &optional default
9478     This function looks up KEY in TABLE, and returns its associated
9479     VALUE—or DEFAULT, if KEY has no association in TABLE.
9480
9481 -- Function: puthash key value table
9482     This function enters an association for KEY in TABLE, with value
9483     VALUE.  If KEY already has an association in TABLE, VALUE replaces
9484     the old associated value.
9485
9486 -- Function: remhash key table
9487     This function removes the association for KEY from TABLE, if there
9488     is one.  If KEY has no association, ‘remhash’ does nothing.
9489
9490     Common Lisp note: In Common Lisp, ‘remhash’ returns non-‘nil’ if it
9491     actually removed an association and ‘nil’ otherwise.  In Emacs
9492     Lisp, ‘remhash’ always returns ‘nil’.
9493
9494 -- Function: clrhash table
9495     This function removes all the associations from hash table TABLE,
9496     so that it becomes empty.  This is also called “clearing” the hash
9497     table.
9498
9499     Common Lisp note: In Common Lisp, ‘clrhash’ returns the empty
9500     TABLE.  In Emacs Lisp, it returns ‘nil’.
9501
9502 -- Function: maphash function table
9503     This function calls FUNCTION once for each of the associations in
9504     TABLE.  The function FUNCTION should accept two arguments—a KEY
9505     listed in TABLE, and its associated VALUE.  ‘maphash’ returns
9506     ‘nil’.
9507
9508
9509File: elisp.info,  Node: Defining Hash,  Next: Other Hash,  Prev: Hash Access,  Up: Hash Tables
9510
95118.3 Defining Hash Comparisons
9512=============================
9513
9514You can define new methods of key lookup by means of
9515‘define-hash-table-test’.  In order to use this feature, you need to
9516understand how hash tables work, and what a “hash code” means.
9517
9518   You can think of a hash table conceptually as a large array of many
9519slots, each capable of holding one association.  To look up a key,
9520‘gethash’ first computes an integer, the hash code, from the key.  It
9521can reduce this integer modulo the length of the array, to produce an
9522index in the array.  Then it looks in that slot, and if necessary in
9523other nearby slots, to see if it has found the key being sought.
9524
9525   Thus, to define a new method of key lookup, you need to specify both
9526a function to compute the hash code from a key, and a function to
9527compare two keys directly.  The two functions should be consistent with
9528each other: that is, two keys’ hash codes should be the same if the keys
9529compare as equal.  Also, since the two functions can be called at any
9530time (such as by the garbage collector), the functions should be free of
9531side effects and should return quickly, and their behavior should depend
9532on only on properties of the keys that do not change.
9533
9534 -- Function: define-hash-table-test name test-fn hash-fn
9535     This function defines a new hash table test, named NAME.
9536
9537     After defining NAME in this way, you can use it as the TEST
9538     argument in ‘make-hash-table’.  When you do that, the hash table
9539     will use TEST-FN to compare key values, and HASH-FN to compute a
9540     hash code from a key value.
9541
9542     The function TEST-FN should accept two arguments, two keys, and
9543     return non-‘nil’ if they are considered the same.
9544
9545     The function HASH-FN should accept one argument, a key, and return
9546     an integer that is the hash code of that key.  For good results,
9547     the function should use the whole range of fixnums for hash codes,
9548     including negative fixnums.
9549
9550     The specified functions are stored in the property list of NAME
9551     under the property ‘hash-table-test’; the property value’s form is
9552     ‘(TEST-FN HASH-FN)’.
9553
9554 -- Function: sxhash-equal obj
9555     This function returns a hash code for Lisp object OBJ.  This is an
9556     integer that reflects the contents of OBJ and the other Lisp
9557     objects it points to.
9558
9559     If two objects OBJ1 and OBJ2 are ‘equal’, then ‘(sxhash-equal
9560     OBJ1)’ and ‘(sxhash-equal OBJ2)’ are the same integer.
9561
9562     If the two objects are not ‘equal’, the values returned by
9563     ‘sxhash-equal’ are usually different, but not always; once in a
9564     rare while, by luck, you will encounter two distinct-looking
9565     objects that give the same result from ‘sxhash-equal’.
9566
9567     Common Lisp note: In Common Lisp a similar function is called
9568     ‘sxhash’.  Emacs provides this name as a compatibility alias for
9569     ‘sxhash-equal’.
9570
9571 -- Function: sxhash-eq obj
9572     This function returns a hash code for Lisp object OBJ.  Its result
9573     reflects identity of OBJ, but not its contents.
9574
9575     If two objects OBJ1 and OBJ2 are ‘eq’, then ‘(sxhash-eq OBJ1)’ and
9576     ‘(sxhash-eq OBJ2)’ are the same integer.
9577
9578 -- Function: sxhash-eql obj
9579     This function returns a hash code for Lisp object OBJ suitable for
9580     ‘eql’ comparison.  I.e.  it reflects identity of OBJ except for the
9581     case where the object is a bignum or a float number, in which case
9582     a hash code is generated for the value.
9583
9584     If two objects OBJ1 and OBJ2 are ‘eql’, then ‘(sxhash-eql OBJ1)’
9585     and ‘(sxhash-eql OBJ2)’ are the same integer.
9586
9587   This example creates a hash table whose keys are strings that are
9588compared case-insensitively.
9589
9590     (defun case-fold-string= (a b)
9591       (eq t (compare-strings a nil nil b nil nil t)))
9592     (defun case-fold-string-hash (a)
9593       (sxhash-equal (upcase a)))
9594
9595     (define-hash-table-test 'case-fold
9596       'case-fold-string= 'case-fold-string-hash)
9597
9598     (make-hash-table :test 'case-fold)
9599
9600   Here is how you could define a hash table test equivalent to the
9601predefined test value ‘equal’.  The keys can be any Lisp object, and
9602equal-looking objects are considered the same key.
9603
9604     (define-hash-table-test 'contents-hash 'equal 'sxhash-equal)
9605
9606     (make-hash-table :test 'contents-hash)
9607
9608   Lisp programs should _not_ rely on hash codes being preserved between
9609Emacs sessions, as the implementation of the hash functions uses some
9610details of the object storage that can change between sessions and
9611between different architectures.
9612
9613
9614File: elisp.info,  Node: Other Hash,  Prev: Defining Hash,  Up: Hash Tables
9615
96168.4 Other Hash Table Functions
9617==============================
9618
9619Here are some other functions for working with hash tables.
9620
9621 -- Function: hash-table-p table
9622     This returns non-‘nil’ if TABLE is a hash table object.
9623
9624 -- Function: copy-hash-table table
9625     This function creates and returns a copy of TABLE.  Only the table
9626     itself is copied—the keys and values are shared.
9627
9628 -- Function: hash-table-count table
9629     This function returns the actual number of entries in TABLE.
9630
9631 -- Function: hash-table-test table
9632     This returns the TEST value that was given when TABLE was created,
9633     to specify how to hash and compare keys.  See ‘make-hash-table’
9634     (*note Creating Hash::).
9635
9636 -- Function: hash-table-weakness table
9637     This function returns the WEAK value that was specified for hash
9638     table TABLE.
9639
9640 -- Function: hash-table-rehash-size table
9641     This returns the rehash size of TABLE.
9642
9643 -- Function: hash-table-rehash-threshold table
9644     This returns the rehash threshold of TABLE.
9645
9646 -- Function: hash-table-size table
9647     This returns the current nominal size of TABLE.
9648
9649
9650File: elisp.info,  Node: Symbols,  Next: Evaluation,  Prev: Hash Tables,  Up: Top
9651
96529 Symbols
9653*********
9654
9655A “symbol” is an object with a unique name.  This chapter describes
9656symbols, their components, their property lists, and how they are
9657created and interned.  Separate chapters describe the use of symbols as
9658variables and as function names; see *note Variables::, and *note
9659Functions::.  For the precise read syntax for symbols, see *note Symbol
9660Type::.
9661
9662   You can test whether an arbitrary Lisp object is a symbol with
9663‘symbolp’:
9664
9665 -- Function: symbolp object
9666     This function returns ‘t’ if OBJECT is a symbol, ‘nil’ otherwise.
9667
9668* Menu:
9669
9670* Symbol Components::        Symbols have names, values, function definitions
9671                               and property lists.
9672* Definitions::              A definition says how a symbol will be used.
9673* Creating Symbols::         How symbols are kept unique.
9674* Symbol Properties::        Each symbol has a property list
9675                               for recording miscellaneous information.
9676
9677
9678File: elisp.info,  Node: Symbol Components,  Next: Definitions,  Up: Symbols
9679
96809.1 Symbol Components
9681=====================
9682
9683Each symbol has four components (or “cells”), each of which references
9684another object:
9685
9686Print name
9687     The symbol’s name.
9688
9689Value
9690     The symbol’s current value as a variable.
9691
9692Function
9693     The symbol’s function definition.  It can also hold a symbol, a
9694     keymap, or a keyboard macro.
9695
9696Property list
9697     The symbol’s property list.
9698
9699The print name cell always holds a string, and cannot be changed.  Each
9700of the other three cells can be set to any Lisp object.
9701
9702   The print name cell holds the string that is the name of a symbol.
9703Since symbols are represented textually by their names, it is important
9704not to have two symbols with the same name.  The Lisp reader ensures
9705this: every time it reads a symbol, it looks for an existing symbol with
9706the specified name before it creates a new one.  To get a symbol’s name,
9707use the function ‘symbol-name’ (*note Creating Symbols::).
9708
9709   The value cell holds a symbol’s value as a variable, which is what
9710you get if the symbol itself is evaluated as a Lisp expression.  *Note
9711Variables::, for details about how values are set and retrieved,
9712including complications such as “local bindings” and “scoping rules”.
9713Most symbols can have any Lisp object as a value, but certain special
9714symbols have values that cannot be changed; these include ‘nil’ and ‘t’,
9715and any symbol whose name starts with ‘:’ (those are called “keywords”).
9716*Note Constant Variables::.
9717
9718   The function cell holds a symbol’s function definition.  Often, we
9719refer to “the function ‘foo’” when we really mean the function stored in
9720the function cell of ‘foo’; we make the distinction explicit only when
9721necessary.  Typically, the function cell is used to hold a function
9722(*note Functions::) or a macro (*note Macros::).  However, it can also
9723be used to hold a symbol (*note Function Indirection::), keyboard macro
9724(*note Keyboard Macros::), keymap (*note Keymaps::), or autoload object
9725(*note Autoloading::).  To get the contents of a symbol’s function cell,
9726use the function ‘symbol-function’ (*note Function Cells::).
9727
9728   The property list cell normally should hold a correctly formatted
9729property list.  To get a symbol’s property list, use the function
9730‘symbol-plist’.  *Note Symbol Properties::.
9731
9732   The function cell or the value cell may be “void”, which means that
9733the cell does not reference any object.  (This is not the same thing as
9734holding the symbol ‘void’, nor the same as holding the symbol ‘nil’.)
9735Examining a function or value cell that is void results in an error,
9736such as ‘Symbol's value as variable is void’.
9737
9738   Because each symbol has separate value and function cells, variables
9739names and function names do not conflict.  For example, the symbol
9740‘buffer-file-name’ has a value (the name of the file being visited in
9741the current buffer) as well as a function definition (a primitive
9742function that returns the name of the file):
9743
9744     buffer-file-name
9745          ⇒ "/gnu/elisp/symbols.texi"
9746     (symbol-function 'buffer-file-name)
9747          ⇒ #<subr buffer-file-name>
9748
9749
9750File: elisp.info,  Node: Definitions,  Next: Creating Symbols,  Prev: Symbol Components,  Up: Symbols
9751
97529.2 Defining Symbols
9753====================
9754
9755A “definition” is a special kind of Lisp expression that announces your
9756intention to use a symbol in a particular way.  It typically specifies a
9757value or meaning for the symbol for one kind of use, plus documentation
9758for its meaning when used in this way.  Thus, when you define a symbol
9759as a variable, you can supply an initial value for the variable, plus
9760documentation for the variable.
9761
9762   ‘defvar’ and ‘defconst’ are special forms that define a symbol as a
9763“global variable”—a variable that can be accessed at any point in a Lisp
9764program.  *Note Variables::, for details about variables.  To define a
9765customizable variable, use the ‘defcustom’ macro, which also calls
9766‘defvar’ as a subroutine (*note Customization::).
9767
9768   In principle, you can assign a variable value to any symbol with
9769‘setq’, whether or not it has first been defined as a variable.
9770However, you ought to write a variable definition for each global
9771variable that you want to use; otherwise, your Lisp program may not act
9772correctly if it is evaluated with lexical scoping enabled (*note
9773Variable Scoping::).
9774
9775   ‘defun’ defines a symbol as a function, creating a lambda expression
9776and storing it in the function cell of the symbol.  This lambda
9777expression thus becomes the function definition of the symbol.  (The
9778term “function definition”, meaning the contents of the function cell,
9779is derived from the idea that ‘defun’ gives the symbol its definition as
9780a function.)  ‘defsubst’ and ‘defalias’ are two other ways of defining a
9781function.  *Note Functions::.
9782
9783   ‘defmacro’ defines a symbol as a macro.  It creates a macro object
9784and stores it in the function cell of the symbol.  Note that a given
9785symbol can be a macro or a function, but not both at once, because both
9786macro and function definitions are kept in the function cell, and that
9787cell can hold only one Lisp object at any given time.  *Note Macros::.
9788
9789   As previously noted, Emacs Lisp allows the same symbol to be defined
9790both as a variable (e.g., with ‘defvar’) and as a function or macro
9791(e.g., with ‘defun’).  Such definitions do not conflict.
9792
9793   These definitions also act as guides for programming tools.  For
9794example, the ‘C-h f’ and ‘C-h v’ commands create help buffers containing
9795links to the relevant variable, function, or macro definitions.  *Note
9796(emacs)Name Help::.
9797
9798
9799File: elisp.info,  Node: Creating Symbols,  Next: Symbol Properties,  Prev: Definitions,  Up: Symbols
9800
98019.3 Creating and Interning Symbols
9802==================================
9803
9804To understand how symbols are created in GNU Emacs Lisp, you must know
9805how Lisp reads them.  Lisp must ensure that it finds the same symbol
9806every time it reads the same set of characters.  Failure to do so would
9807cause complete confusion.
9808
9809   When the Lisp reader encounters a symbol, it reads all the characters
9810of the name.  Then it hashes those characters to find an index in a
9811table called an “obarray”.  Hashing is an efficient method of looking
9812something up.  For example, instead of searching a telephone book cover
9813to cover when looking up Jan Jones, you start with the J’s and go from
9814there.  That is a simple version of hashing.  Each element of the
9815obarray is a “bucket” which holds all the symbols with a given hash
9816code; to look for a given name, it is sufficient to look through all the
9817symbols in the bucket for that name’s hash code.  (The same idea is used
9818for general Emacs hash tables, but they are a different data type; see
9819*note Hash Tables::.)
9820
9821   If a symbol with the desired name is found, the reader uses that
9822symbol.  If the obarray does not contain a symbol with that name, the
9823reader makes a new symbol and adds it to the obarray.  Finding or adding
9824a symbol with a certain name is called “interning” it, and the symbol is
9825then called an “interned symbol”.
9826
9827   Interning ensures that each obarray has just one symbol with any
9828particular name.  Other like-named symbols may exist, but not in the
9829same obarray.  Thus, the reader gets the same symbols for the same
9830names, as long as you keep reading with the same obarray.
9831
9832   Interning usually happens automatically in the reader, but sometimes
9833other programs need to do it.  For example, after the ‘M-x’ command
9834obtains the command name as a string using the minibuffer, it then
9835interns the string, to get the interned symbol with that name.
9836
9837   No obarray contains all symbols; in fact, some symbols are not in any
9838obarray.  They are called “uninterned symbols”.  An uninterned symbol
9839has the same four cells as other symbols; however, the only way to gain
9840access to it is by finding it in some other object or as the value of a
9841variable.
9842
9843   Creating an uninterned symbol is useful in generating Lisp code,
9844because an uninterned symbol used as a variable in the code you generate
9845cannot clash with any variables used in other Lisp programs.
9846
9847   In Emacs Lisp, an obarray is actually a vector.  Each element of the
9848vector is a bucket; its value is either an interned symbol whose name
9849hashes to that bucket, or 0 if the bucket is empty.  Each interned
9850symbol has an internal link (invisible to the user) to the next symbol
9851in the bucket.  Because these links are invisible, there is no way to
9852find all the symbols in an obarray except using ‘mapatoms’ (below).  The
9853order of symbols in a bucket is not significant.
9854
9855   In an empty obarray, every element is 0, so you can create an obarray
9856with ‘(make-vector LENGTH 0)’.  *This is the only valid way to create an
9857obarray.*  Prime numbers as lengths tend to result in good hashing;
9858lengths one less than a power of two are also good.
9859
9860   *Do not try to put symbols in an obarray yourself.*  This does not
9861work—only ‘intern’ can enter a symbol in an obarray properly.
9862
9863     Common Lisp note: Unlike Common Lisp, Emacs Lisp does not provide
9864     for interning a single symbol in several obarrays.
9865
9866   Most of the functions below take a name and sometimes an obarray as
9867arguments.  A ‘wrong-type-argument’ error is signaled if the name is not
9868a string, or if the obarray is not a vector.
9869
9870 -- Function: symbol-name symbol
9871     This function returns the string that is SYMBOL’s name.  For
9872     example:
9873
9874          (symbol-name 'foo)
9875               ⇒ "foo"
9876
9877     *Warning:* Changing the string by substituting characters does
9878     change the name of the symbol, but fails to update the obarray, so
9879     don’t do it!
9880
9881 -- Function: make-symbol name
9882     This function returns a newly-allocated, uninterned symbol whose
9883     name is NAME (which must be a string).  Its value and function
9884     definition are void, and its property list is ‘nil’.  In the
9885     example below, the value of ‘sym’ is not ‘eq’ to ‘foo’ because it
9886     is a distinct uninterned symbol whose name is also ‘foo’.
9887
9888          (setq sym (make-symbol "foo"))
9889               ⇒ foo
9890          (eq sym 'foo)
9891               ⇒ nil
9892
9893 -- Function: gensym &optional prefix
9894     This function returns a symbol using ‘make-symbol’, whose name is
9895     made by appending ‘gensym-counter’ to PREFIX.  The prefix defaults
9896     to ‘"g"’.
9897
9898 -- Function: intern name &optional obarray
9899     This function returns the interned symbol whose name is NAME.  If
9900     there is no such symbol in the obarray OBARRAY, ‘intern’ creates a
9901     new one, adds it to the obarray, and returns it.  If OBARRAY is
9902     omitted, the value of the global variable ‘obarray’ is used.
9903
9904          (setq sym (intern "foo"))
9905               ⇒ foo
9906          (eq sym 'foo)
9907               ⇒ t
9908
9909          (setq sym1 (intern "foo" other-obarray))
9910               ⇒ foo
9911          (eq sym1 'foo)
9912               ⇒ nil
9913
9914     Common Lisp note: In Common Lisp, you can intern an existing symbol
9915     in an obarray.  In Emacs Lisp, you cannot do this, because the
9916     argument to ‘intern’ must be a string, not a symbol.
9917
9918 -- Function: intern-soft name &optional obarray
9919     This function returns the symbol in OBARRAY whose name is NAME, or
9920     ‘nil’ if OBARRAY has no symbol with that name.  Therefore, you can
9921     use ‘intern-soft’ to test whether a symbol with a given name is
9922     already interned.  If OBARRAY is omitted, the value of the global
9923     variable ‘obarray’ is used.
9924
9925     The argument NAME may also be a symbol; in that case, the function
9926     returns NAME if NAME is interned in the specified obarray, and
9927     otherwise ‘nil’.
9928
9929          (intern-soft "frazzle")        ; No such symbol exists.
9930               ⇒ nil
9931          (make-symbol "frazzle")        ; Create an uninterned one.
9932               ⇒ frazzle
9933          (intern-soft "frazzle")        ; That one cannot be found.
9934               ⇒ nil
9935          (setq sym (intern "frazzle"))  ; Create an interned one.
9936               ⇒ frazzle
9937          (intern-soft "frazzle")        ; That one can be found!
9938               ⇒ frazzle
9939          (eq sym 'frazzle)              ; And it is the same one.
9940               ⇒ t
9941
9942 -- Variable: obarray
9943     This variable is the standard obarray for use by ‘intern’ and
9944     ‘read’.
9945
9946 -- Function: mapatoms function &optional obarray
9947     This function calls FUNCTION once with each symbol in the obarray
9948     OBARRAY.  Then it returns ‘nil’.  If OBARRAY is omitted, it
9949     defaults to the value of ‘obarray’, the standard obarray for
9950     ordinary symbols.
9951
9952          (setq count 0)
9953               ⇒ 0
9954          (defun count-syms (s)
9955            (setq count (1+ count)))
9956               ⇒ count-syms
9957          (mapatoms 'count-syms)
9958               ⇒ nil
9959          count
9960               ⇒ 1871
9961
9962     See ‘documentation’ in *note Accessing Documentation::, for another
9963     example using ‘mapatoms’.
9964
9965 -- Function: unintern symbol obarray
9966     This function deletes SYMBOL from the obarray OBARRAY.  If ‘symbol’
9967     is not actually in the obarray, ‘unintern’ does nothing.  If
9968     OBARRAY is ‘nil’, the current obarray is used.
9969
9970     If you provide a string instead of a symbol as SYMBOL, it stands
9971     for a symbol name.  Then ‘unintern’ deletes the symbol (if any) in
9972     the obarray which has that name.  If there is no such symbol,
9973     ‘unintern’ does nothing.
9974
9975     If ‘unintern’ does delete a symbol, it returns ‘t’.  Otherwise it
9976     returns ‘nil’.
9977
9978
9979File: elisp.info,  Node: Symbol Properties,  Prev: Creating Symbols,  Up: Symbols
9980
99819.4 Symbol Properties
9982=====================
9983
9984A symbol may possess any number of “symbol properties”, which can be
9985used to record miscellaneous information about the symbol.  For example,
9986when a symbol has a ‘risky-local-variable’ property with a non-‘nil’
9987value, that means the variable which the symbol names is a risky
9988file-local variable (*note File Local Variables::).
9989
9990   Each symbol’s properties and property values are stored in the
9991symbol’s property list cell (*note Symbol Components::), in the form of
9992a property list (*note Property Lists::).
9993
9994* Menu:
9995
9996* Symbol Plists::        Accessing symbol properties.
9997* Standard Properties::  Standard meanings of symbol properties.
9998
9999
10000File: elisp.info,  Node: Symbol Plists,  Next: Standard Properties,  Up: Symbol Properties
10001
100029.4.1 Accessing Symbol Properties
10003---------------------------------
10004
10005The following functions can be used to access symbol properties.
10006
10007 -- Function: get symbol property
10008     This function returns the value of the property named PROPERTY in
10009     SYMBOL’s property list.  If there is no such property, it returns
10010     ‘nil’.  Thus, there is no distinction between a value of ‘nil’ and
10011     the absence of the property.
10012
10013     The name PROPERTY is compared with the existing property names
10014     using ‘eq’, so any object is a legitimate property.
10015
10016     See ‘put’ for an example.
10017
10018 -- Function: put symbol property value
10019     This function puts VALUE onto SYMBOL’s property list under the
10020     property name PROPERTY, replacing any previous property value.  The
10021     ‘put’ function returns VALUE.
10022
10023          (put 'fly 'verb 'transitive)
10024               ⇒'transitive
10025          (put 'fly 'noun '(a buzzing little bug))
10026               ⇒ (a buzzing little bug)
10027          (get 'fly 'verb)
10028               ⇒ transitive
10029          (symbol-plist 'fly)
10030               ⇒ (verb transitive noun (a buzzing little bug))
10031
10032 -- Function: symbol-plist symbol
10033     This function returns the property list of SYMBOL.
10034
10035 -- Function: setplist symbol plist
10036     This function sets SYMBOL’s property list to PLIST.  Normally,
10037     PLIST should be a well-formed property list, but this is not
10038     enforced.  The return value is PLIST.
10039
10040          (setplist 'foo '(a 1 b (2 3) c nil))
10041               ⇒ (a 1 b (2 3) c nil)
10042          (symbol-plist 'foo)
10043               ⇒ (a 1 b (2 3) c nil)
10044
10045     For symbols in special obarrays, which are not used for ordinary
10046     purposes, it may make sense to use the property list cell in a
10047     nonstandard fashion; in fact, the abbrev mechanism does so (*note
10048     Abbrevs::).
10049
10050     You could define ‘put’ in terms of ‘setplist’ and ‘plist-put’, as
10051     follows:
10052
10053          (defun put (symbol prop value)
10054            (setplist symbol
10055                      (plist-put (symbol-plist symbol) prop value)))
10056
10057 -- Function: function-get symbol property &optional autoload
10058     This function is identical to ‘get’, except that if SYMBOL is the
10059     name of a function alias, it looks in the property list of the
10060     symbol naming the actual function.  *Note Defining Functions::.  If
10061     the optional argument AUTOLOAD is non-‘nil’, and SYMBOL is
10062     auto-loaded, this function will try to autoload it, since
10063     autoloading might set PROPERTY of SYMBOL.  If AUTOLOAD is the
10064     symbol ‘macro’, only try autoloading if SYMBOL is an auto-loaded
10065     macro.
10066
10067 -- Function: function-put function property value
10068     This function sets PROPERTY of FUNCTION to VALUE.  FUNCTION should
10069     be a symbol.  This function is preferred to calling ‘put’ for
10070     setting properties of a function, because it will allow us some day
10071     to implement remapping of old properties to new ones.
10072
10073
10074File: elisp.info,  Node: Standard Properties,  Prev: Symbol Plists,  Up: Symbol Properties
10075
100769.4.2 Standard Symbol Properties
10077--------------------------------
10078
10079Here, we list the symbol properties which are used for special purposes
10080in Emacs.  In the following table, whenever we say “the named function”,
10081that means the function whose name is the relevant symbol; similarly for
10082“the named variable” etc.
10083
10084‘:advertised-binding’
10085     This property value specifies the preferred key binding, when
10086     showing documentation, for the named function.  *Note Keys in
10087     Documentation::.
10088
10089‘char-table-extra-slots’
10090     The value, if non-‘nil’, specifies the number of extra slots in the
10091     named char-table type.  *Note Char-Tables::.
10092
10093‘customized-face’
10094‘face-defface-spec’
10095‘saved-face’
10096‘theme-face’
10097     These properties are used to record a face’s standard, saved,
10098     customized, and themed face specs.  Do not set them directly; they
10099     are managed by ‘defface’ and related functions.  *Note Defining
10100     Faces::.
10101
10102‘customized-value’
10103‘saved-value’
10104‘standard-value’
10105‘theme-value’
10106     These properties are used to record a customizable variable’s
10107     standard value, saved value, customized-but-unsaved value, and
10108     themed values.  Do not set them directly; they are managed by
10109     ‘defcustom’ and related functions.  *Note Variable Definitions::.
10110
10111‘disabled’
10112     If the value is non-‘nil’, the named function is disabled as a
10113     command.  *Note Disabling Commands::.
10114
10115‘face-documentation’
10116     The value stores the documentation string of the named face.  This
10117     is set automatically by ‘defface’.  *Note Defining Faces::.
10118
10119‘history-length’
10120     The value, if non-‘nil’, specifies the maximum minibuffer history
10121     length for the named history list variable.  *Note Minibuffer
10122     History::.
10123
10124‘interactive-form’
10125     The value is an interactive form for the named function.  Normally,
10126     you should not set this directly; use the ‘interactive’ special
10127     form instead.  *Note Interactive Call::.
10128
10129‘menu-enable’
10130     The value is an expression for determining whether the named menu
10131     item should be enabled in menus.  *Note Simple Menu Items::.
10132
10133‘mode-class’
10134     If the value is ‘special’, the named major mode is special.  *Note
10135     Major Mode Conventions::.
10136
10137‘permanent-local’
10138     If the value is non-‘nil’, the named variable is a buffer-local
10139     variable whose value should not be reset when changing major modes.
10140     *Note Creating Buffer-Local::.
10141
10142‘permanent-local-hook’
10143     If the value is non-‘nil’, the named function should not be deleted
10144     from the local value of a hook variable when changing major modes.
10145     *Note Setting Hooks::.
10146
10147‘pure’
10148     If the value is non-‘nil’, the named function is considered to be
10149     pure (*note What Is a Function::).  Calls with constant arguments
10150     can be evaluated at compile time.  This may shift run time errors
10151     to compile time.  Not to be confused with pure storage (*note Pure
10152     Storage::).
10153
10154‘risky-local-variable’
10155     If the value is non-‘nil’, the named variable is considered risky
10156     as a file-local variable.  *Note File Local Variables::.
10157
10158‘safe-function’
10159     If the value is non-‘nil’, the named function is considered
10160     generally safe for evaluation.  *Note Function Safety::.
10161
10162‘safe-local-eval-function’
10163     If the value is non-‘nil’, the named function is safe to call in
10164     file-local evaluation forms.  *Note File Local Variables::.
10165
10166‘safe-local-variable’
10167     The value specifies a function for determining safe file-local
10168     values for the named variable.  *Note File Local Variables::.
10169
10170‘side-effect-free’
10171     A non-‘nil’ value indicates that the named function is free of side
10172     effects (*note What Is a Function::), so the byte compiler may
10173     ignore a call whose value is unused.  If the property’s value is
10174     ‘error-free’, the byte compiler may even delete such unused calls.
10175     In addition to byte compiler optimizations, this property is also
10176     used for determining function safety (*note Function Safety::).
10177
10178‘undo-inhibit-region’
10179     If non-‘nil’, the named function prevents the ‘undo’ operation from
10180     being restricted to the active region, if ‘undo’ is invoked
10181     immediately after the function.  *Note Undo::.
10182
10183‘variable-documentation’
10184     If non-‘nil’, this specifies the named variable’s documentation
10185     string.  This is set automatically by ‘defvar’ and related
10186     functions.  *Note Defining Faces::.
10187
10188
10189File: elisp.info,  Node: Evaluation,  Next: Control Structures,  Prev: Symbols,  Up: Top
10190
1019110 Evaluation
10192*************
10193
10194The “evaluation” of expressions in Emacs Lisp is performed by the “Lisp
10195interpreter”—a program that receives a Lisp object as input and computes
10196its “value as an expression”.  How it does this depends on the data type
10197of the object, according to rules described in this chapter.  The
10198interpreter runs automatically to evaluate portions of your program, but
10199can also be called explicitly via the Lisp primitive function ‘eval’.
10200
10201* Menu:
10202
10203* Intro Eval::     Evaluation in the scheme of things.
10204* Forms::          How various sorts of objects are evaluated.
10205* Quoting::        Avoiding evaluation (to put constants in the program).
10206* Backquote::      Easier construction of list structure.
10207* Eval::           How to invoke the Lisp interpreter explicitly.
10208* Deferred Eval::  Deferred and lazy evaluation of forms.
10209
10210
10211File: elisp.info,  Node: Intro Eval,  Next: Forms,  Up: Evaluation
10212
1021310.1 Introduction to Evaluation
10214===============================
10215
10216The Lisp interpreter, or evaluator, is the part of Emacs that computes
10217the value of an expression that is given to it.  When a function written
10218in Lisp is called, the evaluator computes the value of the function by
10219evaluating the expressions in the function body.  Thus, running any Lisp
10220program really means running the Lisp interpreter.
10221
10222   A Lisp object that is intended for evaluation is called a “form” or
10223“expression”(1).  The fact that forms are data objects and not merely
10224text is one of the fundamental differences between Lisp-like languages
10225and typical programming languages.  Any object can be evaluated, but in
10226practice only numbers, symbols, lists and strings are evaluated very
10227often.
10228
10229   In subsequent sections, we will describe the details of what
10230evaluation means for each kind of form.
10231
10232   It is very common to read a Lisp form and then evaluate the form, but
10233reading and evaluation are separate activities, and either can be
10234performed alone.  Reading per se does not evaluate anything; it converts
10235the printed representation of a Lisp object to the object itself.  It is
10236up to the caller of ‘read’ to specify whether this object is a form to
10237be evaluated, or serves some entirely different purpose.  *Note Input
10238Functions::.
10239
10240   Evaluation is a recursive process, and evaluating a form often
10241involves evaluating parts within that form.  For instance, when you
10242evaluate a “function call” form such as ‘(car x)’, Emacs first evaluates
10243the argument (the subform ‘x’).  After evaluating the argument, Emacs
10244“executes” the function (‘car’), and if the function is written in Lisp,
10245execution works by evaluating the “body” of the function (in this
10246example, however, ‘car’ is not a Lisp function; it is a primitive
10247function implemented in C). *Note Functions::, for more information
10248about functions and function calls.
10249
10250   Evaluation takes place in a context called the “environment”, which
10251consists of the current values and bindings of all Lisp variables (*note
10252Variables::).(2)  Whenever a form refers to a variable without creating
10253a new binding for it, the variable evaluates to the value given by the
10254current environment.  Evaluating a form may also temporarily alter the
10255environment by binding variables (*note Local Variables::).
10256
10257   Evaluating a form may also make changes that persist; these changes
10258are called “side effects”.  An example of a form that produces a side
10259effect is ‘(setq foo 1)’.
10260
10261   Do not confuse evaluation with command key interpretation.  The
10262editor command loop translates keyboard input into a command (an
10263interactively callable function) using the active keymaps, and then uses
10264‘call-interactively’ to execute that command.  Executing the command
10265usually involves evaluation, if the command is written in Lisp; however,
10266this step is not considered a part of command key interpretation.  *Note
10267Command Loop::.
10268
10269   ---------- Footnotes ----------
10270
10271   (1) It is sometimes also referred to as an “S-expression” or “sexp”,
10272but we generally do not use this terminology in this manual.
10273
10274   (2) This definition of “environment” is specifically not intended to
10275include all the data that can affect the result of a program.
10276
10277
10278File: elisp.info,  Node: Forms,  Next: Quoting,  Prev: Intro Eval,  Up: Evaluation
10279
1028010.2 Kinds of Forms
10281===================
10282
10283A Lisp object that is intended to be evaluated is called a “form” (or an
10284“expression”).  How Emacs evaluates a form depends on its data type.
10285Emacs has three different kinds of form that are evaluated differently:
10286symbols, lists, and all other types.  This section describes all three
10287kinds, one by one, starting with the other types, which are
10288self-evaluating forms.
10289
10290* Menu:
10291
10292* Self-Evaluating Forms::   Forms that evaluate to themselves.
10293* Symbol Forms::            Symbols evaluate as variables.
10294* Classifying Lists::       How to distinguish various sorts of list forms.
10295* Function Indirection::    When a symbol appears as the car of a list,
10296                              we find the real function via the symbol.
10297* Function Forms::          Forms that call functions.
10298* Macro Forms::             Forms that call macros.
10299* Special Forms::           Special forms are idiosyncratic primitives,
10300                              most of them extremely important.
10301* Autoloading::             Functions set up to load files
10302                              containing their real definitions.
10303
10304
10305File: elisp.info,  Node: Self-Evaluating Forms,  Next: Symbol Forms,  Up: Forms
10306
1030710.2.1 Self-Evaluating Forms
10308----------------------------
10309
10310A “self-evaluating form” is any form that is not a list or symbol.
10311Self-evaluating forms evaluate to themselves: the result of evaluation
10312is the same object that was evaluated.  Thus, the number 25 evaluates to
1031325, and the string ‘"foo"’ evaluates to the string ‘"foo"’.  Likewise,
10314evaluating a vector does not cause evaluation of the elements of the
10315vector—it returns the same vector with its contents unchanged.
10316
10317     '123               ; A number, shown without evaluation.
10318          ⇒ 123
10319     123                ; Evaluated as usual—result is the same.
10320          ⇒ 123
10321     (eval '123)        ; Evaluated "by hand"—result is the same.
10322          ⇒ 123
10323     (eval (eval '123)) ; Evaluating twice changes nothing.
10324          ⇒ 123
10325
10326   A self-evaluating form yields a value that becomes part of the
10327program, and you should not try to modify it via ‘setcar’, ‘aset’ or
10328similar operations.  The Lisp interpreter might unify the constants
10329yielded by your program’s self-evaluating forms, so that these constants
10330might share structure.  *Note Mutability::.
10331
10332   It is common to write numbers, characters, strings, and even vectors
10333in Lisp code, taking advantage of the fact that they self-evaluate.
10334However, it is quite unusual to do this for types that lack a read
10335syntax, because there’s no way to write them textually.  It is possible
10336to construct Lisp expressions containing these types by means of a Lisp
10337program.  Here is an example:
10338
10339     ;; Build an expression containing a buffer object.
10340     (setq print-exp (list 'print (current-buffer)))
10341          ⇒ (print #<buffer eval.texi>)
10342     ;; Evaluate it.
10343     (eval print-exp)
10344          ⊣ #<buffer eval.texi>
10345          ⇒ #<buffer eval.texi>
10346
10347
10348File: elisp.info,  Node: Symbol Forms,  Next: Classifying Lists,  Prev: Self-Evaluating Forms,  Up: Forms
10349
1035010.2.2 Symbol Forms
10351-------------------
10352
10353When a symbol is evaluated, it is treated as a variable.  The result is
10354the variable’s value, if it has one.  If the symbol has no value as a
10355variable, the Lisp interpreter signals an error.  For more information
10356on the use of variables, see *note Variables::.
10357
10358   In the following example, we set the value of a symbol with ‘setq’.
10359Then we evaluate the symbol, and get back the value that ‘setq’ stored.
10360
10361     (setq a 123)
10362          ⇒ 123
10363     (eval 'a)
10364          ⇒ 123
10365     a
10366          ⇒ 123
10367
10368   The symbols ‘nil’ and ‘t’ are treated specially, so that the value of
10369‘nil’ is always ‘nil’, and the value of ‘t’ is always ‘t’; you cannot
10370set or bind them to any other values.  Thus, these two symbols act like
10371self-evaluating forms, even though ‘eval’ treats them like any other
10372symbol.  A symbol whose name starts with ‘:’ also self-evaluates in the
10373same way; likewise, its value ordinarily cannot be changed.  *Note
10374Constant Variables::.
10375
10376
10377File: elisp.info,  Node: Classifying Lists,  Next: Function Indirection,  Prev: Symbol Forms,  Up: Forms
10378
1037910.2.3 Classification of List Forms
10380-----------------------------------
10381
10382A form that is a nonempty list is either a function call, a macro call,
10383or a special form, according to its first element.  These three kinds of
10384forms are evaluated in different ways, described below.  The remaining
10385list elements constitute the “arguments” for the function, macro, or
10386special form.
10387
10388   The first step in evaluating a nonempty list is to examine its first
10389element.  This element alone determines what kind of form the list is
10390and how the rest of the list is to be processed.  The first element is
10391_not_ evaluated, as it would be in some Lisp dialects such as Scheme.
10392
10393
10394File: elisp.info,  Node: Function Indirection,  Next: Function Forms,  Prev: Classifying Lists,  Up: Forms
10395
1039610.2.4 Symbol Function Indirection
10397----------------------------------
10398
10399If the first element of the list is a symbol then evaluation examines
10400the symbol’s function cell, and uses its contents instead of the
10401original symbol.  If the contents are another symbol, this process,
10402called “symbol function indirection”, is repeated until it obtains a
10403non-symbol.  *Note Function Names::, for more information about symbol
10404function indirection.
10405
10406   One possible consequence of this process is an infinite loop, in the
10407event that a symbol’s function cell refers to the same symbol.
10408Otherwise, we eventually obtain a non-symbol, which ought to be a
10409function or other suitable object.
10410
10411   More precisely, we should now have a Lisp function (a lambda
10412expression), a byte-code function, a primitive function, a Lisp macro, a
10413special form, or an autoload object.  Each of these types is a case
10414described in one of the following sections.  If the object is not one of
10415these types, Emacs signals an ‘invalid-function’ error.
10416
10417   The following example illustrates the symbol indirection process.  We
10418use ‘fset’ to set the function cell of a symbol and ‘symbol-function’ to
10419get the function cell contents (*note Function Cells::).  Specifically,
10420we store the symbol ‘car’ into the function cell of ‘first’, and the
10421symbol ‘first’ into the function cell of ‘erste’.
10422
10423     ;; Build this function cell linkage:
10424     ;;   -------------       -----        -------        -------
10425     ;;  | #<subr car> | <-- | car |  <-- | first |  <-- | erste |
10426     ;;   -------------       -----        -------        -------
10427     (symbol-function 'car)
10428          ⇒ #<subr car>
10429     (fset 'first 'car)
10430          ⇒ car
10431     (fset 'erste 'first)
10432          ⇒ first
10433     (erste '(1 2 3))   ; Call the function referenced by ‘erste’.
10434          ⇒ 1
10435
10436   By contrast, the following example calls a function without any
10437symbol function indirection, because the first element is an anonymous
10438Lisp function, not a symbol.
10439
10440     ((lambda (arg) (erste arg))
10441      '(1 2 3))
10442          ⇒ 1
10443
10444Executing the function itself evaluates its body; this does involve
10445symbol function indirection when calling ‘erste’.
10446
10447   This form is rarely used and is now deprecated.  Instead, you should
10448write it as:
10449
10450     (funcall (lambda (arg) (erste arg))
10451              '(1 2 3))
10452   or just
10453     (let ((arg '(1 2 3))) (erste arg))
10454
10455   The built-in function ‘indirect-function’ provides an easy way to
10456perform symbol function indirection explicitly.
10457
10458 -- Function: indirect-function function &optional noerror
10459     This function returns the meaning of FUNCTION as a function.  If
10460     FUNCTION is a symbol, then it finds FUNCTION’s function definition
10461     and starts over with that value.  If FUNCTION is not a symbol, then
10462     it returns FUNCTION itself.
10463
10464     This function returns ‘nil’ if the final symbol is unbound.  It
10465     signals a ‘cyclic-function-indirection’ error if there is a loop in
10466     the chain of symbols.
10467
10468     The optional argument NOERROR is obsolete, kept for backward
10469     compatibility, and has no effect.
10470
10471     Here is how you could define ‘indirect-function’ in Lisp:
10472
10473          (defun indirect-function (function)
10474            (if (symbolp function)
10475                (indirect-function (symbol-function function))
10476              function))
10477
10478
10479File: elisp.info,  Node: Function Forms,  Next: Macro Forms,  Prev: Function Indirection,  Up: Forms
10480
1048110.2.5 Evaluation of Function Forms
10482-----------------------------------
10483
10484If the first element of a list being evaluated is a Lisp function
10485object, byte-code object or primitive function object, then that list is
10486a “function call”.  For example, here is a call to the function ‘+’:
10487
10488     (+ 1 x)
10489
10490   The first step in evaluating a function call is to evaluate the
10491remaining elements of the list from left to right.  The results are the
10492actual argument values, one value for each list element.  The next step
10493is to call the function with this list of arguments, effectively using
10494the function ‘apply’ (*note Calling Functions::).  If the function is
10495written in Lisp, the arguments are used to bind the argument variables
10496of the function (*note Lambda Expressions::); then the forms in the
10497function body are evaluated in order, and the value of the last body
10498form becomes the value of the function call.
10499
10500
10501File: elisp.info,  Node: Macro Forms,  Next: Special Forms,  Prev: Function Forms,  Up: Forms
10502
1050310.2.6 Lisp Macro Evaluation
10504----------------------------
10505
10506If the first element of a list being evaluated is a macro object, then
10507the list is a “macro call”.  When a macro call is evaluated, the
10508elements of the rest of the list are _not_ initially evaluated.
10509Instead, these elements themselves are used as the arguments of the
10510macro.  The macro definition computes a replacement form, called the
10511“expansion” of the macro, to be evaluated in place of the original form.
10512The expansion may be any sort of form: a self-evaluating constant, a
10513symbol, or a list.  If the expansion is itself a macro call, this
10514process of expansion repeats until some other sort of form results.
10515
10516   Ordinary evaluation of a macro call finishes by evaluating the
10517expansion.  However, the macro expansion is not necessarily evaluated
10518right away, or at all, because other programs also expand macro calls,
10519and they may or may not evaluate the expansions.
10520
10521   Normally, the argument expressions are not evaluated as part of
10522computing the macro expansion, but instead appear as part of the
10523expansion, so they are computed when the expansion is evaluated.
10524
10525   For example, given a macro defined as follows:
10526
10527     (defmacro cadr (x)
10528       (list 'car (list 'cdr x)))
10529
10530an expression such as ‘(cadr (assq 'handler list))’ is a macro call, and
10531its expansion is:
10532
10533     (car (cdr (assq 'handler list)))
10534
10535Note that the argument ‘(assq 'handler list)’ appears in the expansion.
10536
10537   *Note Macros::, for a complete description of Emacs Lisp macros.
10538
10539
10540File: elisp.info,  Node: Special Forms,  Next: Autoloading,  Prev: Macro Forms,  Up: Forms
10541
1054210.2.7 Special Forms
10543--------------------
10544
10545A “special form” is a primitive function specially marked so that its
10546arguments are not all evaluated.  Most special forms define control
10547structures or perform variable bindings—things which functions cannot
10548do.
10549
10550   Each special form has its own rules for which arguments are evaluated
10551and which are used without evaluation.  Whether a particular argument is
10552evaluated may depend on the results of evaluating other arguments.
10553
10554   If an expression’s first symbol is that of a special form, the
10555expression should follow the rules of that special form; otherwise,
10556Emacs’s behavior is not well-defined (though it will not crash).  For
10557example, ‘((lambda (x) x . 3) 4)’ contains a subexpression that begins
10558with ‘lambda’ but is not a well-formed ‘lambda’ expression, so Emacs may
10559signal an error, or may return 3 or 4 or ‘nil’, or may behave in other
10560ways.
10561
10562 -- Function: special-form-p object
10563     This predicate tests whether its argument is a special form, and
10564     returns ‘t’ if so, ‘nil’ otherwise.
10565
10566   Here is a list, in alphabetical order, of all of the special forms in
10567Emacs Lisp with a reference to where each is described.
10568
10569‘and’
10570     *note Combining Conditions::
10571
10572‘catch’
10573     *note Catch and Throw::
10574
10575‘cond’
10576     *note Conditionals::
10577
10578‘condition-case’
10579     *note Handling Errors::
10580
10581‘defconst’
10582     *note Defining Variables::
10583
10584‘defvar’
10585     *note Defining Variables::
10586
10587‘function’
10588     *note Anonymous Functions::
10589
10590‘if’
10591     *note Conditionals::
10592
10593‘interactive’
10594     *note Interactive Call::
10595
10596‘lambda’
10597     *note Lambda Expressions::
10598
10599‘let’
10600‘let*’
10601     *note Local Variables::
10602
10603‘or’
10604     *note Combining Conditions::
10605
10606‘prog1’
10607‘prog2’
10608‘progn’
10609     *note Sequencing::
10610
10611‘quote’
10612     *note Quoting::
10613
10614‘save-current-buffer’
10615     *note Current Buffer::
10616
10617‘save-excursion’
10618     *note Excursions::
10619
10620‘save-restriction’
10621     *note Narrowing::
10622
10623‘setq’
10624     *note Setting Variables::
10625
10626‘setq-default’
10627     *note Creating Buffer-Local::
10628
10629‘unwind-protect’
10630     *note Nonlocal Exits::
10631
10632‘while’
10633     *note Iteration::
10634
10635     Common Lisp note: Here are some comparisons of special forms in GNU
10636     Emacs Lisp and Common Lisp.  ‘setq’, ‘if’, and ‘catch’ are special
10637     forms in both Emacs Lisp and Common Lisp.  ‘save-excursion’ is a
10638     special form in Emacs Lisp, but doesn’t exist in Common Lisp.
10639     ‘throw’ is a special form in Common Lisp (because it must be able
10640     to throw multiple values), but it is a function in Emacs Lisp
10641     (which doesn’t have multiple values).
10642
10643
10644File: elisp.info,  Node: Autoloading,  Prev: Special Forms,  Up: Forms
10645
1064610.2.8 Autoloading
10647------------------
10648
10649The “autoload” feature allows you to call a function or macro whose
10650function definition has not yet been loaded into Emacs.  It specifies
10651which file contains the definition.  When an autoload object appears as
10652a symbol’s function definition, calling that symbol as a function
10653automatically loads the specified file; then it calls the real
10654definition loaded from that file.  The way to arrange for an autoload
10655object to appear as a symbol’s function definition is described in *note
10656Autoload::.
10657
10658
10659File: elisp.info,  Node: Quoting,  Next: Backquote,  Prev: Forms,  Up: Evaluation
10660
1066110.3 Quoting
10662============
10663
10664The special form ‘quote’ returns its single argument, as written,
10665without evaluating it.  This provides a way to include constant symbols
10666and lists, which are not self-evaluating objects, in a program.  (It is
10667not necessary to quote self-evaluating objects such as numbers, strings,
10668and vectors.)
10669
10670 -- Special Form: quote object
10671     This special form returns OBJECT, without evaluating it.  The
10672     returned value might be shared and should not be modified.  *Note
10673     Self-Evaluating Forms::.
10674
10675   Because ‘quote’ is used so often in programs, Lisp provides a
10676convenient read syntax for it.  An apostrophe character (‘'’) followed
10677by a Lisp object (in read syntax) expands to a list whose first element
10678is ‘quote’, and whose second element is the object.  Thus, the read
10679syntax ‘'x’ is an abbreviation for ‘(quote x)’.
10680
10681   Here are some examples of expressions that use ‘quote’:
10682
10683     (quote (+ 1 2))
10684          ⇒ (+ 1 2)
10685     (quote foo)
10686          ⇒ foo
10687     'foo
10688          ⇒ foo
10689     ''foo
10690          ⇒ 'foo
10691     '(quote foo)
10692          ⇒ 'foo
10693     ['foo]
10694          ⇒ ['foo]
10695
10696   Although the expressions ‘(list '+ 1 2)’ and ‘'(+ 1 2)’ both yield
10697lists equal to ‘(+ 1 2)’, the former yields a freshly-minted mutable
10698list whereas the latter yields a list built from conses that might be
10699shared and should not be modified.  *Note Self-Evaluating Forms::.
10700
10701   Other quoting constructs include ‘function’ (*note Anonymous
10702Functions::), which causes an anonymous lambda expression written in
10703Lisp to be compiled, and ‘`’ (*note Backquote::), which is used to quote
10704only part of a list, while computing and substituting other parts.
10705
10706
10707File: elisp.info,  Node: Backquote,  Next: Eval,  Prev: Quoting,  Up: Evaluation
10708
1070910.4 Backquote
10710==============
10711
10712“Backquote constructs” allow you to quote a list, but selectively
10713evaluate elements of that list.  In the simplest case, it is identical
10714to the special form ‘quote’ (described in the previous section; *note
10715Quoting::).  For example, these two forms yield identical results:
10716
10717     `(a list of (+ 2 3) elements)
10718          ⇒ (a list of (+ 2 3) elements)
10719     '(a list of (+ 2 3) elements)
10720          ⇒ (a list of (+ 2 3) elements)
10721
10722   The special marker ‘,’ inside of the argument to backquote indicates
10723a value that isn’t constant.  The Emacs Lisp evaluator evaluates the
10724argument of ‘,’, and puts the value in the list structure:
10725
10726     `(a list of ,(+ 2 3) elements)
10727          ⇒ (a list of 5 elements)
10728
10729Substitution with ‘,’ is allowed at deeper levels of the list structure
10730also.  For example:
10731
10732     `(1 2 (3 ,(+ 4 5)))
10733          ⇒ (1 2 (3 9))
10734
10735   You can also “splice” an evaluated value into the resulting list,
10736using the special marker ‘,@’.  The elements of the spliced list become
10737elements at the same level as the other elements of the resulting list.
10738The equivalent code without using ‘`’ is often unreadable.  Here are
10739some examples:
10740
10741     (setq some-list '(2 3))
10742          ⇒ (2 3)
10743     (cons 1 (append some-list '(4) some-list))
10744          ⇒ (1 2 3 4 2 3)
10745     `(1 ,@some-list 4 ,@some-list)
10746          ⇒ (1 2 3 4 2 3)
10747
10748     (setq list '(hack foo bar))
10749          ⇒ (hack foo bar)
10750     (cons 'use
10751       (cons 'the
10752         (cons 'words (append (cdr list) '(as elements)))))
10753          ⇒ (use the words foo bar as elements)
10754     `(use the words ,@(cdr list) as elements)
10755          ⇒ (use the words foo bar as elements)
10756
10757   If a subexpression of a backquote construct has no substitutions or
10758splices, it acts like ‘quote’ in that it yields conses, vectors and
10759strings that might be shared and should not be modified.  *Note
10760Self-Evaluating Forms::.
10761
10762
10763File: elisp.info,  Node: Eval,  Next: Deferred Eval,  Prev: Backquote,  Up: Evaluation
10764
1076510.5 Eval
10766=========
10767
10768Most often, forms are evaluated automatically, by virtue of their
10769occurrence in a program being run.  On rare occasions, you may need to
10770write code that evaluates a form that is computed at run time, such as
10771after reading a form from text being edited or getting one from a
10772property list.  On these occasions, use the ‘eval’ function.  Often
10773‘eval’ is not needed and something else should be used instead.  For
10774example, to get the value of a variable, while ‘eval’ works,
10775‘symbol-value’ is preferable; or rather than store expressions in a
10776property list that then need to go through ‘eval’, it is better to store
10777functions instead that are then passed to ‘funcall’.
10778
10779   The functions and variables described in this section evaluate forms,
10780specify limits to the evaluation process, or record recently returned
10781values.  Loading a file also does evaluation (*note Loading::).
10782
10783   It is generally cleaner and more flexible to store a function in a
10784data structure, and call it with ‘funcall’ or ‘apply’, than to store an
10785expression in the data structure and evaluate it.  Using functions
10786provides the ability to pass information to them as arguments.
10787
10788 -- Function: eval form &optional lexical
10789     This is the basic function for evaluating an expression.  It
10790     evaluates FORM in the current environment, and returns the result.
10791     The type of the FORM object determines how it is evaluated.  *Note
10792     Forms::.
10793
10794     The argument LEXICAL specifies the scoping rule for local variables
10795     (*note Variable Scoping::).  If it is omitted or ‘nil’, that means
10796     to evaluate FORM using the default dynamic scoping rule.  If it is
10797     ‘t’, that means to use the lexical scoping rule.  The value of
10798     LEXICAL can also be a non-empty alist specifying a particular
10799     “lexical environment” for lexical bindings; however, this feature
10800     is only useful for specialized purposes, such as in Emacs Lisp
10801     debuggers.  *Note Lexical Binding::.
10802
10803     Since ‘eval’ is a function, the argument expression that appears in
10804     a call to ‘eval’ is evaluated twice: once as preparation before
10805     ‘eval’ is called, and again by the ‘eval’ function itself.  Here is
10806     an example:
10807
10808          (setq foo 'bar)
10809               ⇒ bar
10810          (setq bar 'baz)
10811               ⇒ baz
10812          ;; Here ‘eval’ receives argument ‘foo’
10813          (eval 'foo)
10814               ⇒ bar
10815          ;; Here ‘eval’ receives argument ‘bar’, which is the value of ‘foo’
10816          (eval foo)
10817               ⇒ baz
10818
10819     The number of currently active calls to ‘eval’ is limited to
10820     ‘max-lisp-eval-depth’ (see below).
10821
10822 -- Command: eval-region start end &optional stream read-function
10823     This function evaluates the forms in the current buffer in the
10824     region defined by the positions START and END.  It reads forms from
10825     the region and calls ‘eval’ on them until the end of the region is
10826     reached, or until an error is signaled and not handled.
10827
10828     By default, ‘eval-region’ does not produce any output.  However, if
10829     STREAM is non-‘nil’, any output produced by output functions (*note
10830     Output Functions::), as well as the values that result from
10831     evaluating the expressions in the region are printed using STREAM.
10832     *Note Output Streams::.
10833
10834     If READ-FUNCTION is non-‘nil’, it should be a function, which is
10835     used instead of ‘read’ to read expressions one by one.  This
10836     function is called with one argument, the stream for reading input.
10837     You can also use the variable ‘load-read-function’ (*note How
10838     Programs Do Loading: Definition of load-read-function.) to specify
10839     this function, but it is more robust to use the READ-FUNCTION
10840     argument.
10841
10842     ‘eval-region’ does not move point.  It always returns ‘nil’.
10843
10844 -- Command: eval-buffer &optional buffer-or-name stream filename
10845          unibyte print
10846     This is similar to ‘eval-region’, but the arguments provide
10847     different optional features.  ‘eval-buffer’ operates on the entire
10848     accessible portion of buffer BUFFER-OR-NAME (*note
10849     (emacs)Narrowing::).  BUFFER-OR-NAME can be a buffer, a buffer name
10850     (a string), or ‘nil’ (or omitted), which means to use the current
10851     buffer.  STREAM is used as in ‘eval-region’, unless STREAM is ‘nil’
10852     and PRINT non-‘nil’.  In that case, values that result from
10853     evaluating the expressions are still discarded, but the output of
10854     the output functions is printed in the echo area.  FILENAME is the
10855     file name to use for ‘load-history’ (*note Unloading::), and
10856     defaults to ‘buffer-file-name’ (*note Buffer File Name::).  If
10857     UNIBYTE is non-‘nil’, ‘read’ converts strings to unibyte whenever
10858     possible.
10859
10860     ‘eval-current-buffer’ is an alias for this command.
10861
10862 -- User Option: max-lisp-eval-depth
10863     This variable defines the maximum depth allowed in calls to ‘eval’,
10864     ‘apply’, and ‘funcall’ before an error is signaled (with error
10865     message ‘"Lisp nesting exceeds max-lisp-eval-depth"’).
10866
10867     This limit, with the associated error when it is exceeded, is one
10868     way Emacs Lisp avoids infinite recursion on an ill-defined
10869     function.  If you increase the value of ‘max-lisp-eval-depth’ too
10870     much, such code can cause stack overflow instead.  On some systems,
10871     this overflow can be handled.  In that case, normal Lisp evaluation
10872     is interrupted and control is transferred back to the top level
10873     command loop (‘top-level’).  Note that there is no way to enter
10874     Emacs Lisp debugger in this situation.  *Note Error Debugging::.
10875
10876     The depth limit counts internal uses of ‘eval’, ‘apply’, and
10877     ‘funcall’, such as for calling the functions mentioned in Lisp
10878     expressions, and recursive evaluation of function call arguments
10879     and function body forms, as well as explicit calls in Lisp code.
10880
10881     The default value of this variable is 800.  If you set it to a
10882     value less than 100, Lisp will reset it to 100 if the given value
10883     is reached.  Entry to the Lisp debugger increases the value, if
10884     there is little room left, to make sure the debugger itself has
10885     room to execute.
10886
10887     ‘max-specpdl-size’ provides another limit on nesting.  *Note Local
10888     Variables: Definition of max-specpdl-size.
10889
10890 -- Variable: values
10891     The value of this variable is a list of the values returned by all
10892     the expressions that were read, evaluated, and printed from buffers
10893     (including the minibuffer) by the standard Emacs commands which do
10894     this.  (Note that this does _not_ include evaluation in ‘*ielm*’
10895     buffers, nor evaluation using ‘C-j’, ‘C-x C-e’, and similar
10896     evaluation commands in ‘lisp-interaction-mode’.)  The elements are
10897     ordered most recent first.
10898
10899          (setq x 1)
10900               ⇒ 1
10901          (list 'A (1+ 2) auto-save-default)
10902               ⇒ (A 3 t)
10903          values
10904               ⇒ ((A 3 t) 1 ...)
10905
10906     This variable is useful for referring back to values of forms
10907     recently evaluated.  It is generally a bad idea to print the value
10908     of ‘values’ itself, since this may be very long.  Instead, examine
10909     particular elements, like this:
10910
10911          ;; Refer to the most recent evaluation result.
10912          (nth 0 values)
10913               ⇒ (A 3 t)
10914          ;; That put a new element on,
10915          ;;   so all elements move back one.
10916          (nth 1 values)
10917               ⇒ (A 3 t)
10918          ;; This gets the element that was next-to-most-recent
10919          ;;   before this example.
10920          (nth 3 values)
10921               ⇒ 1
10922
10923
10924File: elisp.info,  Node: Deferred Eval,  Prev: Eval,  Up: Evaluation
10925
1092610.6 Deferred and Lazy Evaluation
10927=================================
10928
10929Sometimes it is useful to delay the evaluation of an expression, for
10930example if you want to avoid performing a time-consuming calculation if
10931it turns out that the result is not needed in the future of the program.
10932The ‘thunk’ library provides the following functions and macros to
10933support such “deferred evaluation”:
10934
10935 -- Macro: thunk-delay forms...
10936     Return a “thunk” for evaluating the FORMS.  A thunk is a closure
10937     (*note Closures::) that inherits the lexical environment of the
10938     ‘thunk-delay’ call.  Using this macro requires ‘lexical-binding’.
10939
10940 -- Function: thunk-force thunk
10941     Force THUNK to perform the evaluation of the forms specified in the
10942     ‘thunk-delay’ that created the thunk.  The result of the evaluation
10943     of the last form is returned.  The THUNK also “remembers” that it
10944     has been forced: Any further calls of ‘thunk-force’ with the same
10945     THUNK will just return the same result without evaluating the forms
10946     again.
10947
10948 -- Macro: thunk-let (bindings...) forms...
10949     This macro is analogous to ‘let’ but creates “lazy” variable
10950     bindings.  Any binding has the form ‘(SYMBOL VALUE-FORM)’.  Unlike
10951     ‘let’, the evaluation of any VALUE-FORM is deferred until the
10952     binding of the according SYMBOL is used for the first time when
10953     evaluating the FORMS.  Any VALUE-FORM is evaluated at most once.
10954     Using this macro requires ‘lexical-binding’.
10955
10956   Example:
10957
10958     (defun f (number)
10959       (thunk-let ((derived-number
10960                   (progn (message "Calculating 1 plus 2 times %d" number)
10961                          (1+ (* 2 number)))))
10962         (if (> number 10)
10963             derived-number
10964           number)))
10965
10966     (f 5)
10967     ⇒ 5
10968
10969     (f 12)
10970     ⊣ Calculating 1 plus 2 times 12
10971     ⇒ 25
10972
10973
10974   Because of the special nature of lazily bound variables, it is an
10975error to set them (e.g. with ‘setq’).
10976
10977 -- Macro: thunk-let* (bindings...) forms...
10978     This is like ‘thunk-let’ but any expression in BINDINGS is allowed
10979     to refer to preceding bindings in this ‘thunk-let*’ form.  Using
10980     this macro requires ‘lexical-binding’.
10981
10982     (thunk-let* ((x (prog2 (message "Calculating x...")
10983                         (+ 1 1)
10984                       (message "Finished calculating x")))
10985                  (y (prog2 (message "Calculating y...")
10986                         (+ x 1)
10987                       (message "Finished calculating y")))
10988                  (z (prog2 (message "Calculating z...")
10989                         (+ y 1)
10990                       (message "Finished calculating z")))
10991                  (a (prog2 (message "Calculating a...")
10992                         (+ z 1)
10993                       (message "Finished calculating a"))))
10994       (* z x))
10995
10996     ⊣ Calculating z...
10997     ⊣ Calculating y...
10998     ⊣ Calculating x...
10999     ⊣ Finished calculating x
11000     ⊣ Finished calculating y
11001     ⊣ Finished calculating z
11002     ⇒ 8
11003
11004
11005   ‘thunk-let’ and ‘thunk-let*’ use thunks implicitly: their expansion
11006creates helper symbols and binds them to thunks wrapping the binding
11007expressions.  All references to the original variables in the body FORMS
11008are then replaced by an expression that calls ‘thunk-force’ with the
11009according helper variable as the argument.  So, any code using
11010‘thunk-let’ or ‘thunk-let*’ could be rewritten to use thunks, but in
11011many cases using these macros results in nicer code than using thunks
11012explicitly.
11013
11014
11015File: elisp.info,  Node: Control Structures,  Next: Variables,  Prev: Evaluation,  Up: Top
11016
1101711 Control Structures
11018*********************
11019
11020A Lisp program consists of a set of “expressions”, or “forms” (*note
11021Forms::).  We control the order of execution of these forms by enclosing
11022them in “control structures”.  Control structures are special forms
11023which control when, whether, or how many times to execute the forms they
11024contain.
11025
11026   The simplest order of execution is sequential execution: first form
11027A, then form B, and so on.  This is what happens when you write several
11028forms in succession in the body of a function, or at top level in a file
11029of Lisp code—the forms are executed in the order written.  We call this
11030“textual order”.  For example, if a function body consists of two forms
11031A and B, evaluation of the function evaluates first A and then B.  The
11032result of evaluating B becomes the value of the function.
11033
11034   Explicit control structures make possible an order of execution other
11035than sequential.
11036
11037   Emacs Lisp provides several kinds of control structure, including
11038other varieties of sequencing, conditionals, iteration, and (controlled)
11039jumps—all discussed below.  The built-in control structures are special
11040forms since their subforms are not necessarily evaluated or not
11041evaluated sequentially.  You can use macros to define your own control
11042structure constructs (*note Macros::).
11043
11044* Menu:
11045
11046* Sequencing::             Evaluation in textual order.
11047* Conditionals::           ‘if’, ‘cond’, ‘when’, ‘unless’.
11048* Combining Conditions::   ‘and’, ‘or’, ‘not’, and friends.
11049* Pattern-Matching Conditional::  How to use ‘pcase’ and friends.
11050* Iteration::              ‘while’ loops.
11051* Generators::             Generic sequences and coroutines.
11052* Nonlocal Exits::         Jumping out of a sequence.
11053
11054
11055File: elisp.info,  Node: Sequencing,  Next: Conditionals,  Up: Control Structures
11056
1105711.1 Sequencing
11058===============
11059
11060Evaluating forms in the order they appear is the most common way control
11061passes from one form to another.  In some contexts, such as in a
11062function body, this happens automatically.  Elsewhere you must use a
11063control structure construct to do this: ‘progn’, the simplest control
11064construct of Lisp.
11065
11066   A ‘progn’ special form looks like this:
11067
11068     (progn A B C ...)
11069
11070and it says to execute the forms A, B, C, and so on, in that order.
11071These forms are called the “body” of the ‘progn’ form.  The value of the
11072last form in the body becomes the value of the entire ‘progn’.
11073‘(progn)’ returns ‘nil’.
11074
11075   In the early days of Lisp, ‘progn’ was the only way to execute two or
11076more forms in succession and use the value of the last of them.  But
11077programmers found they often needed to use a ‘progn’ in the body of a
11078function, where (at that time) only one form was allowed.  So the body
11079of a function was made into an implicit ‘progn’: several forms are
11080allowed just as in the body of an actual ‘progn’.  Many other control
11081structures likewise contain an implicit ‘progn’.  As a result, ‘progn’
11082is not used as much as it was many years ago.  It is needed now most
11083often inside an ‘unwind-protect’, ‘and’, ‘or’, or in the THEN-part of an
11084‘if’.
11085
11086 -- Special Form: progn forms...
11087     This special form evaluates all of the FORMS, in textual order,
11088     returning the result of the final form.
11089
11090          (progn (print "The first form")
11091                 (print "The second form")
11092                 (print "The third form"))
11093               ⊣ "The first form"
11094               ⊣ "The second form"
11095               ⊣ "The third form"
11096          ⇒ "The third form"
11097
11098   Two other constructs likewise evaluate a series of forms but return
11099different values:
11100
11101 -- Special Form: prog1 form1 forms...
11102     This special form evaluates FORM1 and all of the FORMS, in textual
11103     order, returning the result of FORM1.
11104
11105          (prog1 (print "The first form")
11106                 (print "The second form")
11107                 (print "The third form"))
11108               ⊣ "The first form"
11109               ⊣ "The second form"
11110               ⊣ "The third form"
11111          ⇒ "The first form"
11112
11113     Here is a way to remove the first element from a list in the
11114     variable ‘x’, then return the value of that former element:
11115
11116          (prog1 (car x) (setq x (cdr x)))
11117
11118 -- Special Form: prog2 form1 form2 forms...
11119     This special form evaluates FORM1, FORM2, and all of the following
11120     FORMS, in textual order, returning the result of FORM2.
11121
11122          (prog2 (print "The first form")
11123                 (print "The second form")
11124                 (print "The third form"))
11125               ⊣ "The first form"
11126               ⊣ "The second form"
11127               ⊣ "The third form"
11128          ⇒ "The second form"
11129
11130
11131File: elisp.info,  Node: Conditionals,  Next: Combining Conditions,  Prev: Sequencing,  Up: Control Structures
11132
1113311.2 Conditionals
11134=================
11135
11136Conditional control structures choose among alternatives.  Emacs Lisp
11137has five conditional forms: ‘if’, which is much the same as in other
11138languages; ‘when’ and ‘unless’, which are variants of ‘if’; ‘cond’,
11139which is a generalized case statement; and ‘pcase’, which is a
11140generalization of ‘cond’ (*note Pattern-Matching Conditional::).
11141
11142 -- Special Form: if condition then-form else-forms...
11143     ‘if’ chooses between the THEN-FORM and the ELSE-FORMS based on the
11144     value of CONDITION.  If the evaluated CONDITION is non-‘nil’,
11145     THEN-FORM is evaluated and the result returned.  Otherwise, the
11146     ELSE-FORMS are evaluated in textual order, and the value of the
11147     last one is returned.  (The ELSE part of ‘if’ is an example of an
11148     implicit ‘progn’.  *Note Sequencing::.)
11149
11150     If CONDITION has the value ‘nil’, and no ELSE-FORMS are given, ‘if’
11151     returns ‘nil’.
11152
11153     ‘if’ is a special form because the branch that is not selected is
11154     never evaluated—it is ignored.  Thus, in this example, ‘true’ is
11155     not printed because ‘print’ is never called:
11156
11157          (if nil
11158              (print 'true)
11159            'very-false)
11160          ⇒ very-false
11161
11162 -- Macro: when condition then-forms...
11163     This is a variant of ‘if’ where there are no ELSE-FORMS, and
11164     possibly several THEN-FORMS.  In particular,
11165
11166          (when CONDITION A B C)
11167
11168     is entirely equivalent to
11169
11170          (if CONDITION (progn A B C) nil)
11171
11172 -- Macro: unless condition forms...
11173     This is a variant of ‘if’ where there is no THEN-FORM:
11174
11175          (unless CONDITION A B C)
11176
11177     is entirely equivalent to
11178
11179          (if CONDITION nil
11180             A B C)
11181
11182 -- Special Form: cond clause...
11183     ‘cond’ chooses among an arbitrary number of alternatives.  Each
11184     CLAUSE in the ‘cond’ must be a list.  The CAR of this list is the
11185     CONDITION; the remaining elements, if any, the BODY-FORMS.  Thus, a
11186     clause looks like this:
11187
11188          (CONDITION BODY-FORMS...)
11189
11190     ‘cond’ tries the clauses in textual order, by evaluating the
11191     CONDITION of each clause.  If the value of CONDITION is non-‘nil’,
11192     the clause succeeds; then ‘cond’ evaluates its BODY-FORMS, and
11193     returns the value of the last of BODY-FORMS.  Any remaining clauses
11194     are ignored.
11195
11196     If the value of CONDITION is ‘nil’, the clause fails, so the ‘cond’
11197     moves on to the following clause, trying its CONDITION.
11198
11199     A clause may also look like this:
11200
11201          (CONDITION)
11202
11203     Then, if CONDITION is non-‘nil’ when tested, the ‘cond’ form
11204     returns the value of CONDITION.
11205
11206     If every CONDITION evaluates to ‘nil’, so that every clause fails,
11207     ‘cond’ returns ‘nil’.
11208
11209     The following example has four clauses, which test for the cases
11210     where the value of ‘x’ is a number, string, buffer and symbol,
11211     respectively:
11212
11213          (cond ((numberp x) x)
11214                ((stringp x) x)
11215                ((bufferp x)
11216                 (setq temporary-hack x) ; multiple body-forms
11217                 (buffer-name x))        ; in one clause
11218                ((symbolp x) (symbol-value x)))
11219
11220     Often we want to execute the last clause whenever none of the
11221     previous clauses was successful.  To do this, we use ‘t’ as the
11222     CONDITION of the last clause, like this: ‘(t BODY-FORMS)’.  The
11223     form ‘t’ evaluates to ‘t’, which is never ‘nil’, so this clause
11224     never fails, provided the ‘cond’ gets to it at all.  For example:
11225
11226          (setq a 5)
11227          (cond ((eq a 'hack) 'foo)
11228                (t "default"))
11229          ⇒ "default"
11230
11231     This ‘cond’ expression returns ‘foo’ if the value of ‘a’ is ‘hack’,
11232     and returns the string ‘"default"’ otherwise.
11233
11234   Any conditional construct can be expressed with ‘cond’ or with ‘if’.
11235Therefore, the choice between them is a matter of style.  For example:
11236
11237     (if A B C)
1123811239     (cond (A B) (t C))
11240
11241
11242File: elisp.info,  Node: Combining Conditions,  Next: Pattern-Matching Conditional,  Prev: Conditionals,  Up: Control Structures
11243
1124411.3 Constructs for Combining Conditions
11245========================================
11246
11247This section describes constructs that are often used together with ‘if’
11248and ‘cond’ to express complicated conditions.  The constructs ‘and’ and
11249‘or’ can also be used individually as kinds of multiple conditional
11250constructs.
11251
11252 -- Function: not condition
11253     This function tests for the falsehood of CONDITION.  It returns ‘t’
11254     if CONDITION is ‘nil’, and ‘nil’ otherwise.  The function ‘not’ is
11255     identical to ‘null’, and we recommend using the name ‘null’ if you
11256     are testing for an empty list.
11257
11258 -- Special Form: and conditions...
11259     The ‘and’ special form tests whether all the CONDITIONS are true.
11260     It works by evaluating the CONDITIONS one by one in the order
11261     written.
11262
11263     If any of the CONDITIONS evaluates to ‘nil’, then the result of the
11264     ‘and’ must be ‘nil’ regardless of the remaining CONDITIONS; so
11265     ‘and’ returns ‘nil’ right away, ignoring the remaining CONDITIONS.
11266
11267     If all the CONDITIONS turn out non-‘nil’, then the value of the
11268     last of them becomes the value of the ‘and’ form.  Just ‘(and)’,
11269     with no CONDITIONS, returns ‘t’, appropriate because all the
11270     CONDITIONS turned out non-‘nil’.  (Think about it; which one did
11271     not?)
11272
11273     Here is an example.  The first condition returns the integer 1,
11274     which is not ‘nil’.  Similarly, the second condition returns the
11275     integer 2, which is not ‘nil’.  The third condition is ‘nil’, so
11276     the remaining condition is never evaluated.
11277
11278          (and (print 1) (print 2) nil (print 3))
11279               ⊣ 1
11280               ⊣ 2
11281          ⇒ nil
11282
11283     Here is a more realistic example of using ‘and’:
11284
11285          (if (and (consp foo) (eq (car foo) 'x))
11286              (message "foo is a list starting with x"))
11287
11288     Note that ‘(car foo)’ is not executed if ‘(consp foo)’ returns
11289     ‘nil’, thus avoiding an error.
11290
11291     ‘and’ expressions can also be written using either ‘if’ or ‘cond’.
11292     Here’s how:
11293
11294          (and ARG1 ARG2 ARG3)
1129511296          (if ARG1 (if ARG2 ARG3))
1129711298          (cond (ARG1 (cond (ARG2 ARG3))))
11299
11300 -- Special Form: or conditions...
11301     The ‘or’ special form tests whether at least one of the CONDITIONS
11302     is true.  It works by evaluating all the CONDITIONS one by one in
11303     the order written.
11304
11305     If any of the CONDITIONS evaluates to a non-‘nil’ value, then the
11306     result of the ‘or’ must be non-‘nil’; so ‘or’ returns right away,
11307     ignoring the remaining CONDITIONS.  The value it returns is the
11308     non-‘nil’ value of the condition just evaluated.
11309
11310     If all the CONDITIONS turn out ‘nil’, then the ‘or’ expression
11311     returns ‘nil’.  Just ‘(or)’, with no CONDITIONS, returns ‘nil’,
11312     appropriate because all the CONDITIONS turned out ‘nil’.  (Think
11313     about it; which one did not?)
11314
11315     For example, this expression tests whether ‘x’ is either ‘nil’ or
11316     the integer zero:
11317
11318          (or (eq x nil) (eq x 0))
11319
11320     Like the ‘and’ construct, ‘or’ can be written in terms of ‘cond’.
11321     For example:
11322
11323          (or ARG1 ARG2 ARG3)
1132411325          (cond (ARG1)
11326                (ARG2)
11327                (ARG3))
11328
11329     You could almost write ‘or’ in terms of ‘if’, but not quite:
11330
11331          (if ARG1 ARG1
11332            (if ARG2 ARG2
11333              ARG3))
11334
11335     This is not completely equivalent because it can evaluate ARG1 or
11336     ARG2 twice.  By contrast, ‘(or ARG1 ARG2 ARG3)’ never evaluates any
11337     argument more than once.
11338
11339 -- Function: xor condition1 condition2
11340     This function returns the boolean exclusive-or of CONDITION1 and
11341     CONDITION2.  That is, ‘xor’ returns ‘nil’ if either both arguments
11342     are ‘nil’, or both are non-‘nil’.  Otherwise, it returns the value
11343     of that argument which is non-‘nil’.
11344
11345     Note that in contrast to ‘or’, both arguments are always evaluated.
11346
11347
11348File: elisp.info,  Node: Pattern-Matching Conditional,  Next: Iteration,  Prev: Combining Conditions,  Up: Control Structures
11349
1135011.4 Pattern-Matching Conditional
11351=================================
11352
11353Aside from the four basic conditional forms, Emacs Lisp also has a
11354pattern-matching conditional form, the ‘pcase’ macro, a hybrid of ‘cond’
11355and ‘cl-case’ (*note (cl)Conditionals::) that overcomes their
11356limitations and introduces the “pattern matching programming style”.
11357The limitations that ‘pcase’ overcomes are:
11358
11359   • The ‘cond’ form chooses among alternatives by evaluating the
11360     predicate CONDITION of each of its clauses (*note Conditionals::).
11361     The primary limitation is that variables let-bound in CONDITION are
11362     not available to the clause’s BODY-FORMS.
11363
11364     Another annoyance (more an inconvenience than a limitation) is that
11365     when a series of CONDITION predicates implement equality tests,
11366     there is a lot of repeated code.  (‘cl-case’ solves this
11367     inconvenience.)
11368
11369   • The ‘cl-case’ macro chooses among alternatives by evaluating the
11370     equality of its first argument against a set of specific values.
11371
11372     Its limitations are two-fold:
11373
11374       1. The equality tests use ‘eql’.
11375       2. The values must be known and written in advance.
11376
11377     These render ‘cl-case’ unsuitable for strings or compound data
11378     structures (e.g., lists or vectors).  (‘cond’ doesn’t have these
11379     limitations, but it has others, see above.)
11380
11381Conceptually, the ‘pcase’ macro borrows the first-arg focus of ‘cl-case’
11382and the clause-processing flow of ‘cond’, replacing CONDITION with a
11383generalization of the equality test which is a variant of “pattern
11384matching”, and adding facilities so that you can concisely express a
11385clause’s predicate, and arrange to share let-bindings between a clause’s
11386predicate and BODY-FORMS.
11387
11388   The concise expression of a predicate is known as a “pattern”.  When
11389the predicate, called on the value of the first arg, returns non-‘nil’,
11390we say that “the pattern matches the value” (or sometimes “the value
11391matches the pattern”).
11392
11393* Menu:
11394
11395* The ‘pcase’ macro: pcase Macro.  Includes examples and caveats.
11396* Extending ‘pcase’: Extending pcase.  Define new kinds of patterns.
11397* Backquote-Style Patterns: Backquote Patterns.  Structural patterns matching.
11398* Destructuring with pcase Patterns:: Using pcase patterns to extract subfields.
11399
11400
11401File: elisp.info,  Node: pcase Macro,  Next: Extending pcase,  Up: Pattern-Matching Conditional
11402
1140311.4.1 The ‘pcase’ macro
11404------------------------
11405
11406For background, *Note Pattern-Matching Conditional::.
11407
11408 -- Macro: pcase expression &rest clauses
11409     Each clause in CLAUSES has the form: ‘(PATTERN BODY-FORMS...)’.
11410
11411     Evaluate EXPRESSION to determine its value, EXPVAL.  Find the first
11412     clause in CLAUSES whose PATTERN matches EXPVAL and pass control to
11413     that clause’s BODY-FORMS.
11414
11415     If there is a match, the value of ‘pcase’ is the value of the last
11416     of BODY-FORMS in the successful clause.  Otherwise, ‘pcase’
11417     evaluates to ‘nil’.
11418
11419   Each PATTERN has to be a “pcase pattern”, which can use either one of
11420the core patterns defined below, or one of the patterns defined via
11421‘pcase-defmacro’ (*note Extending pcase::).
11422
11423   The rest of this subsection describes different forms of core
11424patterns, presents some examples, and concludes with important caveats
11425on using the let-binding facility provided by some pattern forms.  A
11426core pattern can have the following forms:
11427
11428‘_’
11429     Matches any EXPVAL.  This is also known as “don’t care” or
11430     “wildcard”.
11431
11432‘'VAL’
11433     Matches if EXPVAL equals VAL.  The comparison is done as if by
11434     ‘equal’ (*note Equality Predicates::).
11435
11436‘KEYWORD’
11437‘INTEGER’
11438‘STRING’
11439     Matches if EXPVAL equals the literal object.  This is a special
11440     case of ‘'VAL’, above, possible because literal objects of these
11441     types are self-quoting.
11442
11443‘SYMBOL’
11444     Matches any EXPVAL, and additionally let-binds SYMBOL to EXPVAL,
11445     such that this binding is available to BODY-FORMS (*note Dynamic
11446     Binding::).
11447
11448     If SYMBOL is part of a sequencing pattern SEQPAT (e.g., by using
11449     ‘and’, below), the binding is also available to the portion of
11450     SEQPAT following the appearance of SYMBOL.  This usage has some
11451     caveats, see *note caveats: pcase-symbol-caveats.
11452
11453     Two symbols to avoid are ‘t’, which behaves like ‘_’ (above) and is
11454     deprecated, and ‘nil’, which signals an error.  Likewise, it makes
11455     no sense to bind keyword symbols (*note Constant Variables::).
11456
11457‘(pred FUNCTION)’
11458     Matches if the predicate FUNCTION returns non-‘nil’ when called on
11459     EXPVAL.  the predicate FUNCTION can have one of the following
11460     forms:
11461
11462     function name (a symbol)
11463          Call the named function with one argument, EXPVAL.
11464
11465          Example: ‘integerp’
11466
11467     lambda expression
11468          Call the anonymous function with one argument, EXPVAL (*note
11469          Lambda Expressions::).
11470
11471          Example: ‘(lambda (n) (= 42 n))’
11472
11473     function call with N args
11474          Call the function (the first element of the function call)
11475          with N arguments (the other elements) and an additional N+1-th
11476          argument that is EXPVAL.
11477
11478          Example: ‘(= 42)’
11479          In this example, the function is ‘=’, N is one, and the actual
11480          function call becomes: ‘(= 42 EXPVAL)’.
11481
11482‘(app FUNCTION PATTERN)’
11483     Matches if FUNCTION called on EXPVAL returns a value that matches
11484     PATTERN.  FUNCTION can take one of the forms described for ‘pred’,
11485     above.  Unlike ‘pred’, however, ‘app’ tests the result against
11486     PATTERN, rather than against a boolean truth value.
11487
11488‘(guard BOOLEAN-EXPRESSION)’
11489     Matches if BOOLEAN-EXPRESSION evaluates to non-‘nil’.
11490
11491‘(let PATTERN EXPR)’
11492     Evaluates EXPR to get EXPRVAL and matches if EXPRVAL matches
11493     PATTERN.  (It is called ‘let’ because PATTERN can bind symbols to
11494     values using SYMBOL.)
11495
11496   A “sequencing pattern” (also known as SEQPAT) is a pattern that
11497processes its sub-pattern arguments in sequence.  There are two for
11498‘pcase’: ‘and’ and ‘or’.  They behave in a similar manner to the special
11499forms that share their name (*note Combining Conditions::), but instead
11500of processing values, they process sub-patterns.
11501
11502‘(and PATTERN1...)’
11503     Attempts to match PATTERN1..., in order, until one of them fails to
11504     match.  In that case, ‘and’ likewise fails to match, and the rest
11505     of the sub-patterns are not tested.  If all sub-patterns match,
11506     ‘and’ matches.
11507
11508‘(or PATTERN1 PATTERN2...)’
11509     Attempts to match PATTERN1, PATTERN2, ..., in order, until one of
11510     them succeeds.  In that case, ‘or’ likewise matches, and the rest
11511     of the sub-patterns are not tested.  (Note that there must be at
11512     least two sub-patterns.  Simply ‘(or PATTERN1)’ signals error.)
11513
11514     To present a consistent environment (*note Intro Eval::) to
11515     BODY-FORMS (thus avoiding an evaluation error on match), if any of
11516     the sub-patterns let-binds a set of symbols, they _must_ all bind
11517     the same set of symbols.
11518
11519‘(rx RX-EXPR...)’
11520     Matches strings against the regexp RX-EXPR..., using the ‘rx’
11521     regexp notation (*note Rx Notation::), as if by ‘string-match’.
11522
11523     In addition to the usual ‘rx’ syntax, RX-EXPR... can contain the
11524     following constructs:
11525
11526     ‘(let REF RX-EXPR...)’
11527          Bind the symbol REF to a submatch that matches RX-EXPR....
11528          REF is bound in BODY-FORMS to the string of the submatch or
11529          nil, but can also be used in ‘backref’.
11530
11531     ‘(backref REF)’
11532          Like the standard ‘backref’ construct, but REF can here also
11533          be a name introduced by a previous ‘(let REF ...)’ construct.
11534
11535Example: Advantage Over ‘cl-case’
11536---------------------------------
11537
11538Here’s an example that highlights some advantages ‘pcase’ has over
11539‘cl-case’ (*note (cl)Conditionals::).
11540
11541     (pcase (get-return-code x)
11542       ;; string
11543       ((and (pred stringp) msg)
11544        (message "%s" msg))
11545       ;; symbol
11546       ('success       (message "Done!"))
11547       ('would-block   (message "Sorry, can't do it now"))
11548       ('read-only     (message "The shmliblick is read-only"))
11549       ('access-denied (message "You do not have the needed rights"))
11550       ;; default
11551       (code           (message "Unknown return code %S" code)))
11552
11553With ‘cl-case’, you would need to explicitly declare a local variable
11554‘code’ to hold the return value of ‘get-return-code’.  Also ‘cl-case’ is
11555difficult to use with strings because it uses ‘eql’ for comparison.
11556
11557Example: Using ‘and’
11558--------------------
11559
11560A common idiom is to write a pattern starting with ‘and’, with one or
11561more SYMBOL sub-patterns providing bindings to the sub-patterns that
11562follow (as well as to the body forms).  For example, the following
11563pattern matches single-digit integers.
11564
11565     (and
11566       (pred integerp)
11567       n                     ; bind ‘n’ to EXPVAL
11568       (guard (<= -9 n 9)))
11569
11570First, ‘pred’ matches if ‘(integerp EXPVAL)’ evaluates to non-‘nil’.
11571Next, ‘n’ is a SYMBOL pattern that matches anything and binds ‘n’ to
11572EXPVAL.  Lastly, ‘guard’ matches if the boolean expression ‘(<= -9 n 9)’
11573(note the reference to ‘n’) evaluates to non-‘nil’.  If all these
11574sub-patterns match, ‘and’ matches.
11575
11576Example: Reformulation with ‘pcase’
11577-----------------------------------
11578
11579Here is another example that shows how to reformulate a simple matching
11580task from its traditional implementation (function ‘grok/traditional’)
11581to one using ‘pcase’ (function ‘grok/pcase’).  The docstring for both
11582these functions is: “If OBJ is a string of the form "key:NUMBER", return
11583NUMBER (a string).  Otherwise, return the list ("149" default).” First,
11584the traditional implementation (*note Regular Expressions::):
11585
11586     (defun grok/traditional (obj)
11587       (if (and (stringp obj)
11588                (string-match "^key:\\([[:digit:]]+\\)$" obj))
11589           (match-string 1 obj)
11590         (list "149" 'default)))
11591
11592     (grok/traditional "key:0")   ⇒ "0"
11593     (grok/traditional "key:149") ⇒ "149"
11594     (grok/traditional 'monolith) ⇒ ("149" default)
11595
11596The reformulation demonstrates SYMBOL binding as well as ‘or’, ‘and’,
11597‘pred’, ‘app’ and ‘let’.
11598
11599     (defun grok/pcase (obj)
11600       (pcase obj
11601         ((or                                     ; line 1
11602           (and                                   ; line 2
11603            (pred stringp)                        ; line 3
11604            (pred (string-match                   ; line 4
11605                   "^key:\\([[:digit:]]+\\)$"))   ; line 5
11606            (app (match-string 1)                 ; line 6
11607                 val))                            ; line 7
11608           (let val (list "149" 'default)))       ; line 8
11609          val)))                                  ; line 9
11610
11611     (grok/pcase "key:0")   ⇒ "0"
11612     (grok/pcase "key:149") ⇒ "149"
11613     (grok/pcase 'monolith) ⇒ ("149" default)
11614
11615The bulk of ‘grok/pcase’ is a single clause of a ‘pcase’ form, the
11616pattern on lines 1-8, the (single) body form on line 9.  The pattern is
11617‘or’, which tries to match in turn its argument sub-patterns, first
11618‘and’ (lines 2-7), then ‘let’ (line 8), until one of them succeeds.
11619
11620   As in the previous example (*note Example 1: pcase-example-1.), ‘and’
11621begins with a ‘pred’ sub-pattern to ensure the following sub-patterns
11622work with an object of the correct type (string, in this case).  If
11623‘(stringp EXPVAL)’ returns ‘nil’, ‘pred’ fails, and thus ‘and’ fails,
11624too.
11625
11626   The next ‘pred’ (lines 4-5) evaluates ‘(string-match RX EXPVAL)’ and
11627matches if the result is non-‘nil’, which means that EXPVAL has the
11628desired form: ‘key:NUMBER’.  Again, failing this, ‘pred’ fails and
11629‘and’, too.
11630
11631   Lastly (in this series of ‘and’ sub-patterns), ‘app’ evaluates
11632‘(match-string 1 EXPVAL)’ (line 6) to get a temporary value TMP (i.e.,
11633the “NUMBER” substring) and tries to match TMP against pattern ‘val’
11634(line 7).  Since that is a SYMBOL pattern, it matches unconditionally
11635and additionally binds ‘val’ to TMP.
11636
11637   Now that ‘app’ has matched, all ‘and’ sub-patterns have matched, and
11638so ‘and’ matches.  Likewise, once ‘and’ has matched, ‘or’ matches and
11639does not proceed to try sub-pattern ‘let’ (line 8).
11640
11641   Let’s consider the situation where ‘obj’ is not a string, or it is a
11642string but has the wrong form.  In this case, one of the ‘pred’ (lines
116433-5) fails to match, thus ‘and’ (line 2) fails to match, thus ‘or’ (line
116441) proceeds to try sub-pattern ‘let’ (line 8).
11645
11646   First, ‘let’ evaluates ‘(list "149" 'default)’ to get
11647‘("149" default)’, the EXPRVAL, and then tries to match EXPRVAL against
11648pattern ‘val’.  Since that is a SYMBOL pattern, it matches
11649unconditionally and additionally binds ‘val’ to EXPRVAL.  Now that ‘let’
11650has matched, ‘or’ matches.
11651
11652   Note how both ‘and’ and ‘let’ sub-patterns finish in the same way: by
11653trying (always successfully) to match against the SYMBOL pattern ‘val’,
11654in the process binding ‘val’.  Thus, ‘or’ always matches and control
11655always passes to the body form (line 9).  Because that is the last body
11656form in a successfully matched ‘pcase’ clause, it is the value of
11657‘pcase’ and likewise the return value of ‘grok/pcase’ (*note What Is a
11658Function::).
11659
11660Caveats for SYMBOL in Sequencing Patterns
11661-----------------------------------------
11662
11663The preceding examples all use sequencing patterns which include the
11664SYMBOL sub-pattern in some way.  Here are some important details about
11665that usage.
11666
11667  1. When SYMBOL occurs more than once in SEQPAT, the second and
11668     subsequent occurrences do not expand to re-binding, but instead
11669     expand to an equality test using ‘eq’.
11670
11671     The following example features a ‘pcase’ form with two clauses and
11672     two SEQPAT, A and B.  Both A and B first check that EXPVAL is a
11673     pair (using ‘pred’), and then bind symbols to the ‘car’ and ‘cdr’
11674     of EXPVAL (using one ‘app’ each).
11675
11676     For A, because symbol ‘st’ is mentioned twice, the second mention
11677     becomes an equality test using ‘eq’.  On the other hand, B uses two
11678     separate symbols, ‘s1’ and ‘s2’, both of which become independent
11679     bindings.
11680
11681          (defun grok (object)
11682            (pcase object
11683              ((and (pred consp)        ; seqpat A
11684                    (app car st)        ; first mention: st
11685                    (app cdr st))       ; second mention: st
11686               (list 'eq st))
11687              ((and (pred consp)        ; seqpat B
11688                    (app car s1)        ; first mention: s1
11689                    (app cdr s2))       ; first mention: s2
11690               (list 'not-eq s1 s2))))
11691
11692          (let ((s "yow!"))
11693            (grok (cons s s)))      ⇒ (eq "yow!")
11694          (grok (cons "yo!" "yo!")) ⇒ (not-eq "yo!" "yo!")
11695          (grok '(4 2))             ⇒ (not-eq 4 (2))
11696
11697  2. Side-effecting code referencing SYMBOL is undefined.  Avoid.  For
11698     example, here are two similar functions.  Both use ‘and’, SYMBOL
11699     and ‘guard’:
11700
11701          (defun square-double-digit-p/CLEAN (integer)
11702            (pcase (* integer integer)
11703              ((and n (guard (< 9 n 100))) (list 'yes n))
11704              (sorry (list 'no sorry))))
11705
11706          (square-double-digit-p/CLEAN 9) ⇒ (yes 81)
11707          (square-double-digit-p/CLEAN 3) ⇒ (no 9)
11708
11709          (defun square-double-digit-p/MAYBE (integer)
11710            (pcase (* integer integer)
11711              ((and n (guard (< 9 (incf n) 100))) (list 'yes n))
11712              (sorry (list 'no sorry))))
11713
11714          (square-double-digit-p/MAYBE 9) ⇒ (yes 81)
11715          (square-double-digit-p/MAYBE 3) ⇒ (yes 9)  ; WRONG!
11716
11717     The difference is in BOOLEAN-EXPRESSION in ‘guard’: ‘CLEAN’
11718     references ‘n’ simply and directly, while ‘MAYBE’ references ‘n’
11719     with a side-effect, in the expression ‘(incf n)’.  When ‘integer’
11720     is 3, here’s what happens:
11721
11722        • The first ‘n’ binds it to EXPVAL, i.e., the result of
11723          evaluating ‘(* 3 3)’, or 9.
11724
11725        • BOOLEAN-EXPRESSION is evaluated:
11726
11727               start:   (< 9 (incf n)        100)
11728               becomes: (< 9 (setq n (1+ n)) 100)
11729               becomes: (< 9 (setq n (1+ 9)) 100)
11730               becomes: (< 9 (setq n 10)     100)
11731                                                  ; side-effect here!
11732               becomes: (< 9       n         100) ; ‘n’ now bound to 10
11733               becomes: (< 9      10         100)
11734               becomes: t
11735
11736        • Because the result of the evaluation is non-‘nil’, ‘guard’
11737          matches, ‘and’ matches, and control passes to that clause’s
11738          body forms.
11739
11740     Aside from the mathematical incorrectness of asserting that 9 is a
11741     double-digit integer, there is another problem with ‘MAYBE’.  The
11742     body form references ‘n’ once more, yet we do not see the updated
11743     value—10—at all.  What happened to it?
11744
11745     To sum up, it’s best to avoid side-effecting references to SYMBOL
11746     patterns entirely, not only in BOOLEAN-EXPRESSION (in ‘guard’), but
11747     also in EXPR (in ‘let’) and FUNCTION (in ‘pred’ and ‘app’).
11748
11749  3. On match, the clause’s body forms can reference the set of symbols
11750     the pattern let-binds.  When SEQPAT is ‘and’, this set is the union
11751     of all the symbols each of its sub-patterns let-binds.  This makes
11752     sense because, for ‘and’ to match, all the sub-patterns must match.
11753
11754     When SEQPAT is ‘or’, things are different: ‘or’ matches at the
11755     first sub-pattern that matches; the rest of the sub-patterns are
11756     ignored.  It makes no sense for each sub-pattern to let-bind a
11757     different set of symbols because the body forms have no way to
11758     distinguish which sub-pattern matched and choose among the
11759     different sets.  For example, the following is invalid:
11760
11761          (require 'cl-lib)
11762          (pcase (read-number "Enter an integer: ")
11763            ((or (and (pred cl-evenp)
11764                      e-num)      ; bind ‘e-num’ to EXPVAL
11765                 o-num)           ; bind ‘o-num’ to EXPVAL
11766             (list e-num o-num)))
11767
11768          Enter an integer: 42
11769          error→ Symbol’s value as variable is void: o-num
11770          Enter an integer: 149
11771          error→ Symbol’s value as variable is void: e-num
11772
11773     Evaluating body form ‘(list e-num o-num)’ signals error.  To
11774     distinguish between sub-patterns, you can use another symbol,
11775     identical in name in all sub-patterns but differing in value.
11776     Reworking the above example:
11777
11778          (require 'cl-lib)
11779          (pcase (read-number "Enter an integer: ")
11780            ((and num                                ; line 1
11781                  (or (and (pred cl-evenp)           ; line 2
11782                           (let spin 'even))         ; line 3
11783                      (let spin 'odd)))              ; line 4
11784             (list spin num)))                       ; line 5
11785
11786          Enter an integer: 42
11787          ⇒ (even 42)
11788          Enter an integer: 149
11789          ⇒ (odd 149)
11790
11791     Line 1 “factors out” the EXPVAL binding with ‘and’ and SYMBOL (in
11792     this case, ‘num’).  On line 2, ‘or’ begins in the same way as
11793     before, but instead of binding different symbols, uses ‘let’ twice
11794     (lines 3-4) to bind the same symbol ‘spin’ in both sub-patterns.
11795     The value of ‘spin’ distinguishes the sub-patterns.  The body form
11796     references both symbols (line 5).
11797
11798
11799File: elisp.info,  Node: Extending pcase,  Next: Backquote Patterns,  Prev: pcase Macro,  Up: Pattern-Matching Conditional
11800
1180111.4.2 Extending ‘pcase’
11802------------------------
11803
11804The ‘pcase’ macro supports several kinds of patterns (*note
11805Pattern-Matching Conditional::).  You can add support for other kinds of
11806patterns using the ‘pcase-defmacro’ macro.
11807
11808 -- Macro: pcase-defmacro name args [doc] &rest body
11809     Define a new kind of pattern for ‘pcase’, to be invoked as
11810     ‘(NAME ACTUAL-ARGS)’.  The ‘pcase’ macro expands this into a
11811     function call that evaluates BODY, whose job it is to rewrite the
11812     invoked pattern into some other pattern, in an environment where
11813     ARGS are bound to ACTUAL-ARGS.
11814
11815     Additionally, arrange to display DOC along with the docstring of
11816     ‘pcase’.  By convention, DOC should use ‘EXPVAL’ to stand for the
11817     result of evaluating EXPRESSION (first arg to ‘pcase’).
11818
11819Typically, BODY rewrites the invoked pattern to use more basic patterns.
11820Although all patterns eventually reduce to core patterns, ‘body’ need
11821not use core patterns straight away.  The following example defines two
11822patterns, named ‘less-than’ and ‘integer-less-than’.
11823
11824     (pcase-defmacro less-than (n)
11825       "Matches if EXPVAL is a number less than N."
11826       `(pred (> ,n)))
11827
11828     (pcase-defmacro integer-less-than (n)
11829       "Matches if EXPVAL is an integer less than N."
11830       `(and (pred integerp)
11831             (less-than ,n)))
11832
11833Note that the docstrings mention ARGS (in this case, only one: ‘n’) in
11834the usual way, and also mention ‘EXPVAL’ by convention.  The first
11835rewrite (i.e., BODY for ‘less-than’) uses one core pattern: ‘pred’.  The
11836second uses two core patterns: ‘and’ and ‘pred’, as well as the
11837newly-defined pattern ‘less-than’.  Both use a single backquote
11838construct (*note Backquote::).
11839
11840
11841File: elisp.info,  Node: Backquote Patterns,  Next: Destructuring with pcase Patterns,  Prev: Extending pcase,  Up: Pattern-Matching Conditional
11842
1184311.4.3 Backquote-Style Patterns
11844-------------------------------
11845
11846This subsection describes “backquote-style patterns”, a set of builtin
11847patterns that eases structural matching.  For background, *note
11848Pattern-Matching Conditional::.
11849
11850   Backquote-style patterns are a powerful set of ‘pcase’ pattern
11851extensions (created using ‘pcase-defmacro’) that make it easy to match
11852EXPVAL against specifications of its _structure_.
11853
11854   For example, to match EXPVAL that must be a list of two elements
11855whose first element is a specific string and the second element is any
11856value, you can write a core pattern:
11857
11858     (and (pred listp)
11859          ls
11860          (guard (= 2 (length ls)))
11861          (guard (string= "first" (car ls)))
11862          (let second-elem (cadr ls)))
11863
11864or you can write the equivalent backquote-style pattern:
11865
11866     `("first" ,second-elem)
11867
11868The backquote-style pattern is more concise, resembles the structure of
11869EXPVAL, and avoids binding ‘ls’.
11870
11871   A backquote-style pattern has the form ‘`QPAT’ where QPAT can have
11872the following forms:
11873
11874‘(QPAT1 . QPAT2)’
11875     Matches if EXPVAL is a cons cell whose ‘car’ matches QPAT1 and
11876     whose ‘cdr’ matches QPAT2.  This readily generalizes to lists as in
11877     ‘(QPAT1 QPAT2 ...)’.
11878
11879‘[QPAT1 QPAT2 ... QPATM]’
11880     Matches if EXPVAL is a vector of length M whose ‘0’..‘(M-1)’th
11881     elements match QPAT1, QPAT2 ... QPATM, respectively.
11882
11883‘SYMBOL’
11884‘KEYWORD’
11885‘NUMBER’
11886‘STRING’
11887     Matches if the corresponding element of EXPVAL is ‘equal’ to the
11888     specified literal object.
11889
11890‘,PATTERN’
11891     Matches if the corresponding element of EXPVAL matches PATTERN.
11892     Note that PATTERN is any kind that ‘pcase’ supports.  (In the
11893     example above, ‘second-elem’ is a SYMBOL core pattern; it therefore
11894     matches anything, and let-binds ‘second-elem’.)
11895
11896   The “corresponding element” is the portion of EXPVAL that is in the
11897same structural position as the structural position of QPAT in the
11898backquote-style pattern.  (In the example above, the corresponding
11899element of ‘second-elem’ is the second element of EXPVAL.)
11900
11901   Here is an example of using ‘pcase’ to implement a simple interpreter
11902for a little expression language (note that this requires lexical
11903binding for the lambda expression in the ‘fn’ clause to properly capture
11904‘body’ and ‘arg’ (*note Lexical Binding::):
11905
11906     (defun evaluate (form env)
11907       (pcase form
11908         (`(add ,x ,y)       (+ (evaluate x env)
11909                                (evaluate y env)))
11910         (`(call ,fun ,arg)  (funcall (evaluate fun env)
11911                                      (evaluate arg env)))
11912         (`(fn ,arg ,body)   (lambda (val)
11913                               (evaluate body (cons (cons arg val)
11914                                                    env))))
11915         ((pred numberp)     form)
11916         ((pred symbolp)     (cdr (assq form env)))
11917         (_                  (error "Syntax error: %S" form))))
11918
11919The first three clauses use backquote-style patterns.  ‘`(add ,x ,y)’ is
11920a pattern that checks that ‘form’ is a three-element list starting with
11921the literal symbol ‘add’, then extracts the second and third elements
11922and binds them to symbols ‘x’ and ‘y’, respectively.  The clause body
11923evaluates ‘x’ and ‘y’ and adds the results.  Similarly, the ‘call’
11924clause implements a function call, and the ‘fn’ clause implements an
11925anonymous function definition.
11926
11927   The remaining clauses use core patterns.  ‘(pred numberp)’ matches if
11928‘form’ is a number.  On match, the body evaluates it.  ‘(pred symbolp)’
11929matches if ‘form’ is a symbol.  On match, the body looks up the symbol
11930in ‘env’ and returns its association.  Finally, ‘_’ is the catch-all
11931pattern that matches anything, so it’s suitable for reporting syntax
11932errors.
11933
11934   Here are some sample programs in this small language, including their
11935evaluation results:
11936
11937     (evaluate '(add 1 2) nil)                 ⇒ 3
11938     (evaluate '(add x y) '((x . 1) (y . 2)))  ⇒ 3
11939     (evaluate '(call (fn x (add 1 x)) 2) nil) ⇒ 3
11940     (evaluate '(sub 1 2) nil)                 ⇒ error
11941
11942
11943File: elisp.info,  Node: Destructuring with pcase Patterns,  Prev: Backquote Patterns,  Up: Pattern-Matching Conditional
11944
1194511.4.4 Destructuring with ‘pcase’ Patterns
11946------------------------------------------
11947
11948Pcase patterns not only express a condition on the form of the objects
11949they can match, but they can also extract sub-fields of those objects.
11950For example we can extract 2 elements from a list that is the value of
11951the variable ‘my-list’ with the following code:
11952
11953       (pcase my-list
11954         (`(add ,x ,y)  (message "Contains %S and %S" x y)))
11955
11956   This will not only extract ‘x’ and ‘y’ but will additionally test
11957that ‘my-list’ is a list containing exactly 3 elements and whose first
11958element is the symbol ‘add’.  If any of those tests fail, ‘pcase’ will
11959immediately return ‘nil’ without calling ‘message’.
11960
11961   Extraction of multiple values stored in an object is known as
11962“destructuring”.  Using ‘pcase’ patterns allows to perform
11963“destructuring binding”, which is similar to a local binding (*note
11964Local Variables::), but gives values to multiple elements of a variable
11965by extracting those values from an object of compatible structure.
11966
11967   The macros described in this section use ‘pcase’ patterns to perform
11968destructuring binding.  The condition of the object to be of compatible
11969structure means that the object must match the pattern, because only
11970then the object’s subfields can be extracted.  For example:
11971
11972       (pcase-let ((`(add ,x ,y) my-list))
11973         (message "Contains %S and %S" x y))
11974
11975does the same as the previous example, except that it directly tries to
11976extract ‘x’ and ‘y’ from ‘my-list’ without first verifying if ‘my-list’
11977is a list which has the right number of elements and has ‘add’ as its
11978first element.  The precise behavior when the object does not actually
11979match the pattern is undefined, although the body will not be silently
11980skipped: either an error is signaled or the body is run with some of the
11981variables potentially bound to arbitrary values like ‘nil’.
11982
11983   The pcase patterns that are useful for destructuring bindings are
11984generally those described in *note Backquote Patterns::, since they
11985express a specification of the structure of objects that will match.
11986
11987   For an alternative facility for destructuring binding, see *note
11988seq-let::.
11989
11990 -- Macro: pcase-let bindings body...
11991     Perform destructuring binding of variables according to BINDINGS,
11992     and then evaluate BODY.
11993
11994     BINDINGS is a list of bindings of the form ‘(PATTERN EXP)’, where
11995     EXP is an expression to evaluate and PATTERN is a ‘pcase’ pattern.
11996
11997     All EXPs are evaluated first, after which they are matched against
11998     their respective PATTERN, introducing new variable bindings that
11999     can then be used inside BODY.  The variable bindings are produced
12000     by destructuring binding of elements of PATTERN to the values of
12001     the corresponding elements of the evaluated EXP.
12002
12003 -- Macro: pcase-let* bindings body...
12004     Perform destructuring binding of variables according to BINDINGS,
12005     and then evaluate BODY.
12006
12007     BINDINGS is a list of bindings of the form ‘(PATTERN EXP)’, where
12008     EXP is an expression to evaluate and PATTERN is a ‘pcase’ pattern.
12009     The variable bindings are produced by destructuring binding of
12010     elements of PATTERN to the values of the corresponding elements of
12011     the evaluated EXP.
12012
12013     Unlike ‘pcase-let’, but similarly to ‘let*’, each EXP is matched
12014     against its corresponding PATTERN before processing the next
12015     element of BINDINGS, so the variable bindings introduced in each
12016     one of the BINDINGS are available in the EXPs of the BINDINGS that
12017     follow it, additionally to being available in BODY.
12018
12019 -- Macro: pcase-dolist (pattern list) body...
12020     Execute BODY once for each element of LIST, on each iteration
12021     performing a destructuring binding of variables in PATTERN to the
12022     values of the corresponding subfields of the element of LIST.  The
12023     bindings are performed as if by ‘pcase-let’.  When PATTERN is a
12024     simple variable, this ends up being equivalent to ‘dolist’ (*note
12025     Iteration::).
12026
12027
12028File: elisp.info,  Node: Iteration,  Next: Generators,  Prev: Pattern-Matching Conditional,  Up: Control Structures
12029
1203011.5 Iteration
12031==============
12032
12033Iteration means executing part of a program repetitively.  For example,
12034you might want to repeat some computation once for each element of a
12035list, or once for each integer from 0 to N.  You can do this in Emacs
12036Lisp with the special form ‘while’:
12037
12038 -- Special Form: while condition forms...
12039     ‘while’ first evaluates CONDITION.  If the result is non-‘nil’, it
12040     evaluates FORMS in textual order.  Then it reevaluates CONDITION,
12041     and if the result is non-‘nil’, it evaluates FORMS again.  This
12042     process repeats until CONDITION evaluates to ‘nil’.
12043
12044     There is no limit on the number of iterations that may occur.  The
12045     loop will continue until either CONDITION evaluates to ‘nil’ or
12046     until an error or ‘throw’ jumps out of it (*note Nonlocal Exits::).
12047
12048     The value of a ‘while’ form is always ‘nil’.
12049
12050          (setq num 0)
12051               ⇒ 0
12052          (while (< num 4)
12053            (princ (format "Iteration %d." num))
12054            (setq num (1+ num)))
12055               ⊣ Iteration 0.
12056               ⊣ Iteration 1.
12057               ⊣ Iteration 2.
12058               ⊣ Iteration 3.
12059               ⇒ nil
12060
12061     To write a repeat-until loop, which will execute something on each
12062     iteration and then do the end-test, put the body followed by the
12063     end-test in a ‘progn’ as the first argument of ‘while’, as shown
12064     here:
12065
12066          (while (progn
12067                   (forward-line 1)
12068                   (not (looking-at "^$"))))
12069
12070     This moves forward one line and continues moving by lines until it
12071     reaches an empty line.  It is peculiar in that the ‘while’ has no
12072     body, just the end test (which also does the real work of moving
12073     point).
12074
12075   The ‘dolist’ and ‘dotimes’ macros provide convenient ways to write
12076two common kinds of loops.
12077
12078 -- Macro: dolist (var list [result]) body...
12079     This construct executes BODY once for each element of LIST, binding
12080     the variable VAR locally to hold the current element.  Then it
12081     returns the value of evaluating RESULT, or ‘nil’ if RESULT is
12082     omitted.  For example, here is how you could use ‘dolist’ to define
12083     the ‘reverse’ function:
12084
12085          (defun reverse (list)
12086            (let (value)
12087              (dolist (elt list value)
12088                (setq value (cons elt value)))))
12089
12090 -- Macro: dotimes (var count [result]) body...
12091     This construct executes BODY once for each integer from 0
12092     (inclusive) to COUNT (exclusive), binding the variable VAR to the
12093     integer for the current iteration.  Then it returns the value of
12094     evaluating RESULT, or ‘nil’ if RESULT is omitted.  Use of RESULT is
12095     deprecated.  Here is an example of using ‘dotimes’ to do something
12096     100 times:
12097
12098          (dotimes (i 100)
12099            (insert "I will not obey absurd orders\n"))
12100
12101
12102File: elisp.info,  Node: Generators,  Next: Nonlocal Exits,  Prev: Iteration,  Up: Control Structures
12103
1210411.6 Generators
12105===============
12106
12107A “generator” is a function that produces a potentially-infinite stream
12108of values.  Each time the function produces a value, it suspends itself
12109and waits for a caller to request the next value.
12110
12111 -- Macro: iter-defun name args [doc] [declare] [interactive] body...
12112     ‘iter-defun’ defines a generator function.  A generator function
12113     has the same signature as a normal function, but works differently.
12114     Instead of executing BODY when called, a generator function returns
12115     an iterator object.  That iterator runs BODY to generate values,
12116     emitting a value and pausing where ‘iter-yield’ or
12117     ‘iter-yield-from’ appears.  When BODY returns normally, ‘iter-next’
12118     signals ‘iter-end-of-sequence’ with BODY’s result as its condition
12119     data.
12120
12121     Any kind of Lisp code is valid inside BODY, but ‘iter-yield’ and
12122     ‘iter-yield-from’ cannot appear inside ‘unwind-protect’ forms.
12123
12124 -- Macro: iter-lambda args [doc] [interactive] body...
12125     ‘iter-lambda’ produces an unnamed generator function that works
12126     just like a generator function produced with ‘iter-defun’.
12127
12128 -- Macro: iter-yield value
12129     When it appears inside a generator function, ‘iter-yield’ indicates
12130     that the current iterator should pause and return VALUE from
12131     ‘iter-next’.  ‘iter-yield’ evaluates to the ‘value’ parameter of
12132     next call to ‘iter-next’.
12133
12134 -- Macro: iter-yield-from iterator
12135     ‘iter-yield-from’ yields all the values that ITERATOR produces and
12136     evaluates to the value that ITERATOR’s generator function returns
12137     normally.  While it has control, ITERATOR receives values sent to
12138     the iterator using ‘iter-next’.
12139
12140   To use a generator function, first call it normally, producing a
12141“iterator” object.  An iterator is a specific instance of a generator.
12142Then use ‘iter-next’ to retrieve values from this iterator.  When there
12143are no more values to pull from an iterator, ‘iter-next’ raises an
12144‘iter-end-of-sequence’ condition with the iterator’s final value.
12145
12146   It’s important to note that generator function bodies only execute
12147inside calls to ‘iter-next’.  A call to a function defined with
12148‘iter-defun’ produces an iterator; you must drive this iterator with
12149‘iter-next’ for anything interesting to happen.  Each call to a
12150generator function produces a _different_ iterator, each with its own
12151state.
12152
12153 -- Function: iter-next iterator value
12154     Retrieve the next value from ITERATOR.  If there are no more values
12155     to be generated (because ITERATOR’s generator function returned),
12156     ‘iter-next’ signals the ‘iter-end-of-sequence’ condition; the data
12157     value associated with this condition is the value with which
12158     ITERATOR’s generator function returned.
12159
12160     VALUE is sent into the iterator and becomes the value to which
12161     ‘iter-yield’ evaluates.  VALUE is ignored for the first ‘iter-next’
12162     call to a given iterator, since at the start of ITERATOR’s
12163     generator function, the generator function is not evaluating any
12164     ‘iter-yield’ form.
12165
12166 -- Function: iter-close iterator
12167     If ITERATOR is suspended inside an ‘unwind-protect’’s ‘bodyform’
12168     and becomes unreachable, Emacs will eventually run unwind handlers
12169     after a garbage collection pass.  (Note that ‘iter-yield’ is
12170     illegal inside an ‘unwind-protect’’s ‘unwindforms’.)  To ensure
12171     that these handlers are run before then, use ‘iter-close’.
12172
12173   Some convenience functions are provided to make working with
12174iterators easier:
12175
12176 -- Macro: iter-do (var iterator) body ...
12177     Run BODY with VAR bound to each value that ITERATOR produces.
12178
12179   The Common Lisp loop facility also contains features for working with
12180iterators.  *Note (cl)Loop Facility::.
12181
12182   The following piece of code demonstrates some important principles of
12183working with iterators.
12184
12185     (require 'generator)
12186     (iter-defun my-iter (x)
12187       (iter-yield (1+ (iter-yield (1+ x))))
12188        ;; Return normally
12189       -1)
12190
12191     (let* ((iter (my-iter 5))
12192            (iter2 (my-iter 0)))
12193       ;; Prints 6
12194       (print (iter-next iter))
12195       ;; Prints 9
12196       (print (iter-next iter 8))
12197       ;; Prints 1; iter and iter2 have distinct states
12198       (print (iter-next iter2 nil))
12199
12200       ;; We expect the iter sequence to end now
12201       (condition-case x
12202           (iter-next iter)
12203         (iter-end-of-sequence
12204           ;; Prints -1, which my-iter returned normally
12205           (print (cdr x)))))
12206
12207
12208File: elisp.info,  Node: Nonlocal Exits,  Prev: Generators,  Up: Control Structures
12209
1221011.7 Nonlocal Exits
12211===================
12212
12213A “nonlocal exit” is a transfer of control from one point in a program
12214to another remote point.  Nonlocal exits can occur in Emacs Lisp as a
12215result of errors; you can also use them under explicit control.
12216Nonlocal exits unbind all variable bindings made by the constructs being
12217exited.
12218
12219* Menu:
12220
12221* Catch and Throw::     Nonlocal exits for the program’s own purposes.
12222* Examples of Catch::   Showing how such nonlocal exits can be written.
12223* Errors::              How errors are signaled and handled.
12224* Cleanups::            Arranging to run a cleanup form if an error happens.
12225
12226
12227File: elisp.info,  Node: Catch and Throw,  Next: Examples of Catch,  Up: Nonlocal Exits
12228
1222911.7.1 Explicit Nonlocal Exits: ‘catch’ and ‘throw’
12230---------------------------------------------------
12231
12232Most control constructs affect only the flow of control within the
12233construct itself.  The function ‘throw’ is the exception to this rule of
12234normal program execution: it performs a nonlocal exit on request.
12235(There are other exceptions, but they are for error handling only.)
12236‘throw’ is used inside a ‘catch’, and jumps back to that ‘catch’.  For
12237example:
12238
12239     (defun foo-outer ()
12240       (catch 'foo
12241         (foo-inner)))
12242
12243     (defun foo-inner ()
12244       ...
12245       (if x
12246           (throw 'foo t))
12247       ...)
12248
12249The ‘throw’ form, if executed, transfers control straight back to the
12250corresponding ‘catch’, which returns immediately.  The code following
12251the ‘throw’ is not executed.  The second argument of ‘throw’ is used as
12252the return value of the ‘catch’.
12253
12254   The function ‘throw’ finds the matching ‘catch’ based on the first
12255argument: it searches for a ‘catch’ whose first argument is ‘eq’ to the
12256one specified in the ‘throw’.  If there is more than one applicable
12257‘catch’, the innermost one takes precedence.  Thus, in the above
12258example, the ‘throw’ specifies ‘foo’, and the ‘catch’ in ‘foo-outer’
12259specifies the same symbol, so that ‘catch’ is the applicable one
12260(assuming there is no other matching ‘catch’ in between).
12261
12262   Executing ‘throw’ exits all Lisp constructs up to the matching
12263‘catch’, including function calls.  When binding constructs such as
12264‘let’ or function calls are exited in this way, the bindings are
12265unbound, just as they are when these constructs exit normally (*note
12266Local Variables::).  Likewise, ‘throw’ restores the buffer and position
12267saved by ‘save-excursion’ (*note Excursions::), and the narrowing status
12268saved by ‘save-restriction’.  It also runs any cleanups established with
12269the ‘unwind-protect’ special form when it exits that form (*note
12270Cleanups::).
12271
12272   The ‘throw’ need not appear lexically within the ‘catch’ that it
12273jumps to.  It can equally well be called from another function called
12274within the ‘catch’.  As long as the ‘throw’ takes place chronologically
12275after entry to the ‘catch’, and chronologically before exit from it, it
12276has access to that ‘catch’.  This is why ‘throw’ can be used in commands
12277such as ‘exit-recursive-edit’ that throw back to the editor command loop
12278(*note Recursive Editing::).
12279
12280     Common Lisp note: Most other versions of Lisp, including Common
12281     Lisp, have several ways of transferring control nonsequentially:
12282     ‘return’, ‘return-from’, and ‘go’, for example.  Emacs Lisp has
12283     only ‘throw’.  The ‘cl-lib’ library provides versions of some of
12284     these.  *Note (cl)Blocks and Exits::.
12285
12286 -- Special Form: catch tag body...
12287     ‘catch’ establishes a return point for the ‘throw’ function.  The
12288     return point is distinguished from other such return points by TAG,
12289     which may be any Lisp object except ‘nil’.  The argument TAG is
12290     evaluated normally before the return point is established.
12291
12292     With the return point in effect, ‘catch’ evaluates the forms of the
12293     BODY in textual order.  If the forms execute normally (without
12294     error or nonlocal exit) the value of the last body form is returned
12295     from the ‘catch’.
12296
12297     If a ‘throw’ is executed during the execution of BODY, specifying
12298     the same value TAG, the ‘catch’ form exits immediately; the value
12299     it returns is whatever was specified as the second argument of
12300     ‘throw’.
12301
12302 -- Function: throw tag value
12303     The purpose of ‘throw’ is to return from a return point previously
12304     established with ‘catch’.  The argument TAG is used to choose among
12305     the various existing return points; it must be ‘eq’ to the value
12306     specified in the ‘catch’.  If multiple return points match TAG, the
12307     innermost one is used.
12308
12309     The argument VALUE is used as the value to return from that
12310     ‘catch’.
12311
12312     If no return point is in effect with tag TAG, then a ‘no-catch’
12313     error is signaled with data ‘(TAG VALUE)’.
12314
12315
12316File: elisp.info,  Node: Examples of Catch,  Next: Errors,  Prev: Catch and Throw,  Up: Nonlocal Exits
12317
1231811.7.2 Examples of ‘catch’ and ‘throw’
12319--------------------------------------
12320
12321One way to use ‘catch’ and ‘throw’ is to exit from a doubly nested loop.
12322(In most languages, this would be done with a ‘goto’.)  Here we compute
12323‘(foo I J)’ for I and J varying from 0 to 9:
12324
12325     (defun search-foo ()
12326       (catch 'loop
12327         (let ((i 0))
12328           (while (< i 10)
12329             (let ((j 0))
12330               (while (< j 10)
12331                 (if (foo i j)
12332                     (throw 'loop (list i j)))
12333                 (setq j (1+ j))))
12334             (setq i (1+ i))))))
12335
12336If ‘foo’ ever returns non-‘nil’, we stop immediately and return a list
12337of I and J.  If ‘foo’ always returns ‘nil’, the ‘catch’ returns
12338normally, and the value is ‘nil’, since that is the result of the
12339‘while’.
12340
12341   Here are two tricky examples, slightly different, showing two return
12342points at once.  First, two return points with the same tag, ‘hack’:
12343
12344     (defun catch2 (tag)
12345       (catch tag
12346         (throw 'hack 'yes)))
12347     ⇒ catch2
12348
12349     (catch 'hack
12350       (print (catch2 'hack))
12351       'no)
12352     ⊣ yes
12353     ⇒ no
12354
12355Since both return points have tags that match the ‘throw’, it goes to
12356the inner one, the one established in ‘catch2’.  Therefore, ‘catch2’
12357returns normally with value ‘yes’, and this value is printed.  Finally
12358the second body form in the outer ‘catch’, which is ‘'no’, is evaluated
12359and returned from the outer ‘catch’.
12360
12361   Now let’s change the argument given to ‘catch2’:
12362
12363     (catch 'hack
12364       (print (catch2 'quux))
12365       'no)
12366     ⇒ yes
12367
12368We still have two return points, but this time only the outer one has
12369the tag ‘hack’; the inner one has the tag ‘quux’ instead.  Therefore,
12370‘throw’ makes the outer ‘catch’ return the value ‘yes’.  The function
12371‘print’ is never called, and the body-form ‘'no’ is never evaluated.
12372
12373
12374File: elisp.info,  Node: Errors,  Next: Cleanups,  Prev: Examples of Catch,  Up: Nonlocal Exits
12375
1237611.7.3 Errors
12377-------------
12378
12379When Emacs Lisp attempts to evaluate a form that, for some reason,
12380cannot be evaluated, it “signals” an “error”.
12381
12382   When an error is signaled, Emacs’s default reaction is to print an
12383error message and terminate execution of the current command.  This is
12384the right thing to do in most cases, such as if you type ‘C-f’ at the
12385end of the buffer.
12386
12387   In complicated programs, simple termination may not be what you want.
12388For example, the program may have made temporary changes in data
12389structures, or created temporary buffers that should be deleted before
12390the program is finished.  In such cases, you would use ‘unwind-protect’
12391to establish “cleanup expressions” to be evaluated in case of error.
12392(*Note Cleanups::.)  Occasionally, you may wish the program to continue
12393execution despite an error in a subroutine.  In these cases, you would
12394use ‘condition-case’ to establish “error handlers” to recover control in
12395case of error.
12396
12397   Resist the temptation to use error handling to transfer control from
12398one part of the program to another; use ‘catch’ and ‘throw’ instead.
12399*Note Catch and Throw::.
12400
12401* Menu:
12402
12403* Signaling Errors::      How to report an error.
12404* Processing of Errors::  What Emacs does when you report an error.
12405* Handling Errors::       How you can trap errors and continue execution.
12406* Error Symbols::         How errors are classified for trapping them.
12407
12408
12409File: elisp.info,  Node: Signaling Errors,  Next: Processing of Errors,  Up: Errors
12410
1241111.7.3.1 How to Signal an Error
12412...............................
12413
12414“Signaling” an error means beginning error processing.  Error processing
12415normally aborts all or part of the running program and returns to a
12416point that is set up to handle the error (*note Processing of Errors::).
12417Here we describe how to signal an error.
12418
12419   Most errors are signaled automatically within Lisp primitives which
12420you call for other purposes, such as if you try to take the CAR of an
12421integer or move forward a character at the end of the buffer.  You can
12422also signal errors explicitly with the functions ‘error’ and ‘signal’.
12423
12424   Quitting, which happens when the user types ‘C-g’, is not considered
12425an error, but it is handled almost like an error.  *Note Quitting::.
12426
12427   Every error specifies an error message, one way or another.  The
12428message should state what is wrong (“File does not exist”), not how
12429things ought to be (“File must exist”).  The convention in Emacs Lisp is
12430that error messages should start with a capital letter, but should not
12431end with any sort of punctuation.
12432
12433 -- Function: error format-string &rest args
12434     This function signals an error with an error message constructed by
12435     applying ‘format-message’ (*note Formatting Strings::) to
12436     FORMAT-STRING and ARGS.
12437
12438     These examples show typical uses of ‘error’:
12439
12440          (error "That is an error -- try something else")
12441               error→ That is an error -- try something else
12442
12443          (error "Invalid name `%s'" "A%%B")
12444               error→ Invalid name ‘A%%B’
12445
12446     ‘error’ works by calling ‘signal’ with two arguments: the error
12447     symbol ‘error’, and a list containing the string returned by
12448     ‘format-message’.
12449
12450     Typically grave accent and apostrophe in the format translate to
12451     matching curved quotes, e.g., "Missing `%s'" might result in
12452     "Missing ‘foo’".  *Note Text Quoting Style::, for how to influence
12453     or inhibit this translation.
12454
12455     *Warning:* If you want to use your own string as an error message
12456     verbatim, don’t just write ‘(error STRING)’.  If STRING STRING
12457     contains ‘%’, ‘`’, or ‘'’ it may be reformatted, with undesirable
12458     results.  Instead, use ‘(error "%s" STRING)’.
12459
12460 -- Function: signal error-symbol data
12461     This function signals an error named by ERROR-SYMBOL.  The argument
12462     DATA is a list of additional Lisp objects relevant to the
12463     circumstances of the error.
12464
12465     The argument ERROR-SYMBOL must be an “error symbol”—a symbol
12466     defined with ‘define-error’.  This is how Emacs Lisp classifies
12467     different sorts of errors.  *Note Error Symbols::, for a
12468     description of error symbols, error conditions and condition names.
12469
12470     If the error is not handled, the two arguments are used in printing
12471     the error message.  Normally, this error message is provided by the
12472     ‘error-message’ property of ERROR-SYMBOL.  If DATA is non-‘nil’,
12473     this is followed by a colon and a comma separated list of the
12474     unevaluated elements of DATA.  For ‘error’, the error message is
12475     the CAR of DATA (that must be a string).  Subcategories of
12476     ‘file-error’ are handled specially.
12477
12478     The number and significance of the objects in DATA depends on
12479     ERROR-SYMBOL.  For example, with a ‘wrong-type-argument’ error,
12480     there should be two objects in the list: a predicate that describes
12481     the type that was expected, and the object that failed to fit that
12482     type.
12483
12484     Both ERROR-SYMBOL and DATA are available to any error handlers that
12485     handle the error: ‘condition-case’ binds a local variable to a list
12486     of the form ‘(ERROR-SYMBOL . DATA)’ (*note Handling Errors::).
12487
12488     The function ‘signal’ never returns.
12489
12490          (signal 'wrong-number-of-arguments '(x y))
12491               error→ Wrong number of arguments: x, y
12492
12493          (signal 'no-such-error '("My unknown error condition"))
12494               error→ peculiar error: "My unknown error condition"
12495
12496 -- Function: user-error format-string &rest args
12497     This function behaves exactly like ‘error’, except that it uses the
12498     error symbol ‘user-error’ rather than ‘error’.  As the name
12499     suggests, this is intended to report errors on the part of the
12500     user, rather than errors in the code itself.  For example, if you
12501     try to use the command ‘Info-history-back’ (‘l’) to move back
12502     beyond the start of your Info browsing history, Emacs signals a
12503     ‘user-error’.  Such errors do not cause entry to the debugger, even
12504     when ‘debug-on-error’ is non-‘nil’.  *Note Error Debugging::.
12505
12506     Common Lisp note: Emacs Lisp has nothing like the Common Lisp
12507     concept of continuable errors.
12508
12509
12510File: elisp.info,  Node: Processing of Errors,  Next: Handling Errors,  Prev: Signaling Errors,  Up: Errors
12511
1251211.7.3.2 How Emacs Processes Errors
12513...................................
12514
12515When an error is signaled, ‘signal’ searches for an active “handler” for
12516the error.  A handler is a sequence of Lisp expressions designated to be
12517executed if an error happens in part of the Lisp program.  If the error
12518has an applicable handler, the handler is executed, and control resumes
12519following the handler.  The handler executes in the environment of the
12520‘condition-case’ that established it; all functions called within that
12521‘condition-case’ have already been exited, and the handler cannot return
12522to them.
12523
12524   If there is no applicable handler for the error, it terminates the
12525current command and returns control to the editor command loop.  (The
12526command loop has an implicit handler for all kinds of errors.)  The
12527command loop’s handler uses the error symbol and associated data to
12528print an error message.  You can use the variable
12529‘command-error-function’ to control how this is done:
12530
12531 -- Variable: command-error-function
12532     This variable, if non-‘nil’, specifies a function to use to handle
12533     errors that return control to the Emacs command loop.  The function
12534     should take three arguments: DATA, a list of the same form that
12535     ‘condition-case’ would bind to its variable; CONTEXT, a string
12536     describing the situation in which the error occurred, or (more
12537     often) ‘nil’; and CALLER, the Lisp function which called the
12538     primitive that signaled the error.
12539
12540   An error that has no explicit handler may call the Lisp debugger.
12541The debugger is enabled if the variable ‘debug-on-error’ (*note Error
12542Debugging::) is non-‘nil’.  Unlike error handlers, the debugger runs in
12543the environment of the error, so that you can examine values of
12544variables precisely as they were at the time of the error.
12545
12546
12547File: elisp.info,  Node: Handling Errors,  Next: Error Symbols,  Prev: Processing of Errors,  Up: Errors
12548
1254911.7.3.3 Writing Code to Handle Errors
12550......................................
12551
12552The usual effect of signaling an error is to terminate the command that
12553is running and return immediately to the Emacs editor command loop.  You
12554can arrange to trap errors occurring in a part of your program by
12555establishing an error handler, with the special form ‘condition-case’.
12556A simple example looks like this:
12557
12558     (condition-case nil
12559         (delete-file filename)
12560       (error nil))
12561
12562This deletes the file named FILENAME, catching any error and returning
12563‘nil’ if an error occurs.  (You can use the macro ‘ignore-errors’ for a
12564simple case like this; see below.)
12565
12566   The ‘condition-case’ construct is often used to trap errors that are
12567predictable, such as failure to open a file in a call to
12568‘insert-file-contents’.  It is also used to trap errors that are totally
12569unpredictable, such as when the program evaluates an expression read
12570from the user.
12571
12572   The second argument of ‘condition-case’ is called the “protected
12573form”.  (In the example above, the protected form is a call to
12574‘delete-file’.)  The error handlers go into effect when this form begins
12575execution and are deactivated when this form returns.  They remain in
12576effect for all the intervening time.  In particular, they are in effect
12577during the execution of functions called by this form, in their
12578subroutines, and so on.  This is a good thing, since, strictly speaking,
12579errors can be signaled only by Lisp primitives (including ‘signal’ and
12580‘error’) called by the protected form, not by the protected form itself.
12581
12582   The arguments after the protected form are handlers.  Each handler
12583lists one or more “condition names” (which are symbols) to specify which
12584errors it will handle.  The error symbol specified when an error is
12585signaled also defines a list of condition names.  A handler applies to
12586an error if they have any condition names in common.  In the example
12587above, there is one handler, and it specifies one condition name,
12588‘error’, which covers all errors.
12589
12590   The search for an applicable handler checks all the established
12591handlers starting with the most recently established one.  Thus, if two
12592nested ‘condition-case’ forms offer to handle the same error, the inner
12593of the two gets to handle it.
12594
12595   If an error is handled by some ‘condition-case’ form, this ordinarily
12596prevents the debugger from being run, even if ‘debug-on-error’ says this
12597error should invoke the debugger.
12598
12599   If you want to be able to debug errors that are caught by a
12600‘condition-case’, set the variable ‘debug-on-signal’ to a non-‘nil’
12601value.  You can also specify that a particular handler should let the
12602debugger run first, by writing ‘debug’ among the conditions, like this:
12603
12604     (condition-case nil
12605         (delete-file filename)
12606       ((debug error) nil))
12607
12608The effect of ‘debug’ here is only to prevent ‘condition-case’ from
12609suppressing the call to the debugger.  Any given error will invoke the
12610debugger only if ‘debug-on-error’ and the other usual filtering
12611mechanisms say it should.  *Note Error Debugging::.
12612
12613 -- Macro: condition-case-unless-debug var protected-form handlers...
12614     The macro ‘condition-case-unless-debug’ provides another way to
12615     handle debugging of such forms.  It behaves exactly like
12616     ‘condition-case’, unless the variable ‘debug-on-error’ is
12617     non-‘nil’, in which case it does not handle any errors at all.
12618
12619   Once Emacs decides that a certain handler handles the error, it
12620returns control to that handler.  To do so, Emacs unbinds all variable
12621bindings made by binding constructs that are being exited, and executes
12622the cleanups of all ‘unwind-protect’ forms that are being exited.  Once
12623control arrives at the handler, the body of the handler executes
12624normally.
12625
12626   After execution of the handler body, execution returns from the
12627‘condition-case’ form.  Because the protected form is exited completely
12628before execution of the handler, the handler cannot resume execution at
12629the point of the error, nor can it examine variable bindings that were
12630made within the protected form.  All it can do is clean up and proceed.
12631
12632   Error signaling and handling have some resemblance to ‘throw’ and
12633‘catch’ (*note Catch and Throw::), but they are entirely separate
12634facilities.  An error cannot be caught by a ‘catch’, and a ‘throw’
12635cannot be handled by an error handler (though using ‘throw’ when there
12636is no suitable ‘catch’ signals an error that can be handled).
12637
12638 -- Special Form: condition-case var protected-form handlers...
12639     This special form establishes the error handlers HANDLERS around
12640     the execution of PROTECTED-FORM.  If PROTECTED-FORM executes
12641     without error, the value it returns becomes the value of the
12642     ‘condition-case’ form; in this case, the ‘condition-case’ has no
12643     effect.  The ‘condition-case’ form makes a difference when an error
12644     occurs during PROTECTED-FORM.
12645
12646     Each of the HANDLERS is a list of the form ‘(CONDITIONS BODY...)’.
12647     Here CONDITIONS is an error condition name to be handled, or a list
12648     of condition names (which can include ‘debug’ to allow the debugger
12649     to run before the handler).  A condition name of ‘t’ matches any
12650     condition.  BODY is one or more Lisp expressions to be executed
12651     when this handler handles an error.  Here are examples of handlers:
12652
12653          (error nil)
12654
12655          (arith-error (message "Division by zero"))
12656
12657          ((arith-error file-error)
12658           (message
12659            "Either division by zero or failure to open a file"))
12660
12661     Each error that occurs has an “error symbol” that describes what
12662     kind of error it is, and which describes also a list of condition
12663     names (*note Error Symbols::).  Emacs searches all the active
12664     ‘condition-case’ forms for a handler that specifies one or more of
12665     these condition names; the innermost matching ‘condition-case’
12666     handles the error.  Within this ‘condition-case’, the first
12667     applicable handler handles the error.
12668
12669     After executing the body of the handler, the ‘condition-case’
12670     returns normally, using the value of the last form in the handler
12671     body as the overall value.
12672
12673     The argument VAR is a variable.  ‘condition-case’ does not bind
12674     this variable when executing the PROTECTED-FORM, only when it
12675     handles an error.  At that time, it binds VAR locally to an “error
12676     description”, which is a list giving the particulars of the error.
12677     The error description has the form ‘(ERROR-SYMBOL . DATA)’.  The
12678     handler can refer to this list to decide what to do.  For example,
12679     if the error is for failure opening a file, the file name is the
12680     second element of DATA—the third element of the error description.
12681
12682     If VAR is ‘nil’, that means no variable is bound.  Then the error
12683     symbol and associated data are not available to the handler.
12684
12685     Sometimes it is necessary to re-throw a signal caught by
12686     ‘condition-case’, for some outer-level handler to catch.  Here’s
12687     how to do that:
12688
12689            (signal (car err) (cdr err))
12690
12691     where ‘err’ is the error description variable, the first argument
12692     to ‘condition-case’ whose error condition you want to re-throw.
12693     *Note Definition of signal::.
12694
12695 -- Function: error-message-string error-descriptor
12696     This function returns the error message string for a given error
12697     descriptor.  It is useful if you want to handle an error by
12698     printing the usual error message for that error.  *Note Definition
12699     of signal::.
12700
12701   Here is an example of using ‘condition-case’ to handle the error that
12702results from dividing by zero.  The handler displays the error message
12703(but without a beep), then returns a very large number.
12704
12705     (defun safe-divide (dividend divisor)
12706       (condition-case err
12707           ;; Protected form.
12708           (/ dividend divisor)
12709         ;; The handler.
12710         (arith-error                        ; Condition.
12711          ;; Display the usual message for this error.
12712          (message "%s" (error-message-string err))
12713          1000000)))
12714     ⇒ safe-divide
12715
12716     (safe-divide 5 0)
12717          ⊣ Arithmetic error: (arith-error)
12718     ⇒ 1000000
12719
12720The handler specifies condition name ‘arith-error’ so that it will
12721handle only division-by-zero errors.  Other kinds of errors will not be
12722handled (by this ‘condition-case’).  Thus:
12723
12724     (safe-divide nil 3)
12725          error→ Wrong type argument: number-or-marker-p, nil
12726
12727   Here is a ‘condition-case’ that catches all kinds of errors,
12728including those from ‘error’:
12729
12730     (setq baz 34)
12731          ⇒ 34
12732
12733     (condition-case err
12734         (if (eq baz 35)
12735             t
12736           ;; This is a call to the function ‘error’.
12737           (error "Rats!  The variable %s was %s, not 35" 'baz baz))
12738       ;; This is the handler; it is not a form.
12739       (error (princ (format "The error was: %s" err))
12740              2))
12741     ⊣ The error was: (error "Rats!  The variable baz was 34, not 35")
12742     ⇒ 2
12743
12744 -- Macro: ignore-errors body...
12745     This construct executes BODY, ignoring any errors that occur during
12746     its execution.  If the execution is without error, ‘ignore-errors’
12747     returns the value of the last form in BODY; otherwise, it returns
12748     ‘nil’.
12749
12750     Here’s the example at the beginning of this subsection rewritten
12751     using ‘ignore-errors’:
12752
12753            (ignore-errors
12754             (delete-file filename))
12755
12756 -- Macro: ignore-error condition body...
12757     This macro is like ‘ignore-errors’, but will only ignore the
12758     specific error condition specified.
12759
12760            (ignore-error end-of-file
12761              (read ""))
12762
12763     CONDITION can also be a list of error conditions.
12764
12765 -- Macro: with-demoted-errors format body...
12766     This macro is like a milder version of ‘ignore-errors’.  Rather
12767     than suppressing errors altogether, it converts them into messages.
12768     It uses the string FORMAT to format the message.  FORMAT should
12769     contain a single ‘%’-sequence; e.g., ‘"Error: %S"’.  Use
12770     ‘with-demoted-errors’ around code that is not expected to signal
12771     errors, but should be robust if one does occur.  Note that this
12772     macro uses ‘condition-case-unless-debug’ rather than
12773     ‘condition-case’.
12774
12775
12776File: elisp.info,  Node: Error Symbols,  Prev: Handling Errors,  Up: Errors
12777
1277811.7.3.4 Error Symbols and Condition Names
12779..........................................
12780
12781When you signal an error, you specify an “error symbol” to specify the
12782kind of error you have in mind.  Each error has one and only one error
12783symbol to categorize it.  This is the finest classification of errors
12784defined by the Emacs Lisp language.
12785
12786   These narrow classifications are grouped into a hierarchy of wider
12787classes called “error conditions”, identified by “condition names”.  The
12788narrowest such classes belong to the error symbols themselves: each
12789error symbol is also a condition name.  There are also condition names
12790for more extensive classes, up to the condition name ‘error’ which takes
12791in all kinds of errors (but not ‘quit’).  Thus, each error has one or
12792more condition names: ‘error’, the error symbol if that is distinct from
12793‘error’, and perhaps some intermediate classifications.
12794
12795 -- Function: define-error name message &optional parent
12796     In order for a symbol to be an error symbol, it must be defined
12797     with ‘define-error’ which takes a parent condition (defaults to
12798     ‘error’).  This parent defines the conditions that this kind of
12799     error belongs to.  The transitive set of parents always includes
12800     the error symbol itself, and the symbol ‘error’.  Because quitting
12801     is not considered an error, the set of parents of ‘quit’ is just
12802     ‘(quit)’.
12803
12804   In addition to its parents, the error symbol has a MESSAGE which is a
12805string to be printed when that error is signaled but not handled.  If
12806that message is not valid, the error message ‘peculiar error’ is used.
12807*Note Definition of signal::.
12808
12809   Internally, the set of parents is stored in the ‘error-conditions’
12810property of the error symbol and the message is stored in the
12811‘error-message’ property of the error symbol.
12812
12813   Here is how we define a new error symbol, ‘new-error’:
12814
12815     (define-error 'new-error "A new error" 'my-own-errors)
12816
12817This error has several condition names: ‘new-error’, the narrowest
12818classification; ‘my-own-errors’, which we imagine is a wider
12819classification; and all the conditions of ‘my-own-errors’ which should
12820include ‘error’, which is the widest of all.
12821
12822   The error string should start with a capital letter but it should not
12823end with a period.  This is for consistency with the rest of Emacs.
12824
12825   Naturally, Emacs will never signal ‘new-error’ on its own; only an
12826explicit call to ‘signal’ (*note Definition of signal::) in your code
12827can do this:
12828
12829     (signal 'new-error '(x y))
12830          error→ A new error: x, y
12831
12832   This error can be handled through any of its condition names.  This
12833example handles ‘new-error’ and any other errors in the class
12834‘my-own-errors’:
12835
12836     (condition-case foo
12837         (bar nil t)
12838       (my-own-errors nil))
12839
12840   The significant way that errors are classified is by their condition
12841names—the names used to match errors with handlers.  An error symbol
12842serves only as a convenient way to specify the intended error message
12843and list of condition names.  It would be cumbersome to give ‘signal’ a
12844list of condition names rather than one error symbol.
12845
12846   By contrast, using only error symbols without condition names would
12847seriously decrease the power of ‘condition-case’.  Condition names make
12848it possible to categorize errors at various levels of generality when
12849you write an error handler.  Using error symbols alone would eliminate
12850all but the narrowest level of classification.
12851
12852   *Note Standard Errors::, for a list of the main error symbols and
12853their conditions.
12854
12855
12856File: elisp.info,  Node: Cleanups,  Prev: Errors,  Up: Nonlocal Exits
12857
1285811.7.4 Cleaning Up from Nonlocal Exits
12859--------------------------------------
12860
12861The ‘unwind-protect’ construct is essential whenever you temporarily put
12862a data structure in an inconsistent state; it permits you to make the
12863data consistent again in the event of an error or throw.  (Another more
12864specific cleanup construct that is used only for changes in buffer
12865contents is the atomic change group; *note Atomic Changes::.)
12866
12867 -- Special Form: unwind-protect body-form cleanup-forms...
12868     ‘unwind-protect’ executes BODY-FORM with a guarantee that the
12869     CLEANUP-FORMS will be evaluated if control leaves BODY-FORM, no
12870     matter how that happens.  BODY-FORM may complete normally, or
12871     execute a ‘throw’ out of the ‘unwind-protect’, or cause an error;
12872     in all cases, the CLEANUP-FORMS will be evaluated.
12873
12874     If BODY-FORM finishes normally, ‘unwind-protect’ returns the value
12875     of BODY-FORM, after it evaluates the CLEANUP-FORMS.  If BODY-FORM
12876     does not finish, ‘unwind-protect’ does not return any value in the
12877     normal sense.
12878
12879     Only BODY-FORM is protected by the ‘unwind-protect’.  If any of the
12880     CLEANUP-FORMS themselves exits nonlocally (via a ‘throw’ or an
12881     error), ‘unwind-protect’ is _not_ guaranteed to evaluate the rest
12882     of them.  If the failure of one of the CLEANUP-FORMS has the
12883     potential to cause trouble, then protect it with another
12884     ‘unwind-protect’ around that form.
12885
12886     The number of currently active ‘unwind-protect’ forms counts,
12887     together with the number of local variable bindings, against the
12888     limit ‘max-specpdl-size’ (*note Local Variables: Definition of
12889     max-specpdl-size.).
12890
12891   For example, here we make an invisible buffer for temporary use, and
12892make sure to kill it before finishing:
12893
12894     (let ((buffer (get-buffer-create " *temp*")))
12895       (with-current-buffer buffer
12896         (unwind-protect
12897             BODY-FORM
12898           (kill-buffer buffer))))
12899
12900You might think that we could just as well write ‘(kill-buffer
12901(current-buffer))’ and dispense with the variable ‘buffer’.  However,
12902the way shown above is safer, if BODY-FORM happens to get an error after
12903switching to a different buffer!  (Alternatively, you could write a
12904‘save-current-buffer’ around BODY-FORM, to ensure that the temporary
12905buffer becomes current again in time to kill it.)
12906
12907   Emacs includes a standard macro called ‘with-temp-buffer’ which
12908expands into more or less the code shown above (*note Current Buffer:
12909Definition of with-temp-buffer.).  Several of the macros defined in this
12910manual use ‘unwind-protect’ in this way.
12911
12912   Here is an actual example derived from an FTP package.  It creates a
12913process (*note Processes::) to try to establish a connection to a remote
12914machine.  As the function ‘ftp-login’ is highly susceptible to numerous
12915problems that the writer of the function cannot anticipate, it is
12916protected with a form that guarantees deletion of the process in the
12917event of failure.  Otherwise, Emacs might fill up with useless
12918subprocesses.
12919
12920     (let ((win nil))
12921       (unwind-protect
12922           (progn
12923             (setq process (ftp-setup-buffer host file))
12924             (if (setq win (ftp-login process host user password))
12925                 (message "Logged in")
12926               (error "Ftp login failed")))
12927         (or win (and process (delete-process process)))))
12928
12929   This example has a small bug: if the user types ‘C-g’ to quit, and
12930the quit happens immediately after the function ‘ftp-setup-buffer’
12931returns but before the variable ‘process’ is set, the process will not
12932be killed.  There is no easy way to fix this bug, but at least it is
12933very unlikely.
12934
12935
12936File: elisp.info,  Node: Variables,  Next: Functions,  Prev: Control Structures,  Up: Top
12937
1293812 Variables
12939************
12940
12941A “variable” is a name used in a program to stand for a value.  In Lisp,
12942each variable is represented by a Lisp symbol (*note Symbols::).  The
12943variable name is simply the symbol’s name, and the variable’s value is
12944stored in the symbol’s value cell(1).  *Note Symbol Components::.  In
12945Emacs Lisp, the use of a symbol as a variable is independent of its use
12946as a function name.
12947
12948   As previously noted in this manual, a Lisp program is represented
12949primarily by Lisp objects, and only secondarily as text.  The textual
12950form of a Lisp program is given by the read syntax of the Lisp objects
12951that constitute the program.  Hence, the textual form of a variable in a
12952Lisp program is written using the read syntax for the symbol
12953representing the variable.
12954
12955* Menu:
12956
12957* Global Variables::            Variable values that exist permanently, everywhere.
12958* Constant Variables::          Variables that never change.
12959* Local Variables::             Variable values that exist only temporarily.
12960* Void Variables::              Symbols that lack values.
12961* Defining Variables::          A definition says a symbol is used as a variable.
12962* Tips for Defining::           Things you should think about when you
12963                            define a variable.
12964* Accessing Variables::         Examining values of variables whose names
12965                            are known only at run time.
12966* Setting Variables::           Storing new values in variables.
12967* Watching Variables::          Running a function when a variable is changed.
12968* Variable Scoping::            How Lisp chooses among local and global values.
12969* Buffer-Local Variables::      Variable values in effect only in one buffer.
12970* File Local Variables::        Handling local variable lists in files.
12971* Directory Local Variables::   Local variables common to all files in a directory.
12972* Connection Local Variables::  Local variables common for remote connections.
12973* Variable Aliases::            Variables that are aliases for other variables.
12974* Variables with Restricted Values::  Non-constant variables whose value can
12975                                        _not_ be an arbitrary Lisp object.
12976* Generalized Variables::       Extending the concept of variables.
12977
12978   ---------- Footnotes ----------
12979
12980   (1) To be precise, under the default “dynamic scoping” rule, the
12981value cell always holds the variable’s current value, but this is not
12982the case under the “lexical scoping” rule.  *Note Variable Scoping::,
12983for details.
12984
12985
12986File: elisp.info,  Node: Global Variables,  Next: Constant Variables,  Up: Variables
12987
1298812.1 Global Variables
12989=====================
12990
12991The simplest way to use a variable is “globally”.  This means that the
12992variable has just one value at a time, and this value is in effect (at
12993least for the moment) throughout the Lisp system.  The value remains in
12994effect until you specify a new one.  When a new value replaces the old
12995one, no trace of the old value remains in the variable.
12996
12997   You specify a value for a symbol with ‘setq’.  For example,
12998
12999     (setq x '(a b))
13000
13001gives the variable ‘x’ the value ‘(a b)’.  Note that ‘setq’ is a special
13002form (*note Special Forms::); it does not evaluate its first argument,
13003the name of the variable, but it does evaluate the second argument, the
13004new value.
13005
13006   Once the variable has a value, you can refer to it by using the
13007symbol itself as an expression.  Thus,
13008
13009     x ⇒ (a b)
13010
13011assuming the ‘setq’ form shown above has already been executed.
13012
13013   If you do set the same variable again, the new value replaces the old
13014one:
13015
13016     x
13017          ⇒ (a b)
13018     (setq x 4)
13019          ⇒ 4
13020     x
13021          ⇒ 4
13022
13023
13024File: elisp.info,  Node: Constant Variables,  Next: Local Variables,  Prev: Global Variables,  Up: Variables
13025
1302612.2 Variables that Never Change
13027================================
13028
13029In Emacs Lisp, certain symbols normally evaluate to themselves.  These
13030include ‘nil’ and ‘t’, as well as any symbol whose name starts with ‘:’
13031(these are called “keywords”).  These symbols cannot be rebound, nor can
13032their values be changed.  Any attempt to set or bind ‘nil’ or ‘t’
13033signals a ‘setting-constant’ error.  The same is true for a keyword (a
13034symbol whose name starts with ‘:’), if it is interned in the standard
13035obarray, except that setting such a symbol to itself is not an error.
13036
13037     nil ≡ 'nil
13038          ⇒ nil
13039     (setq nil 500)
13040     error→ Attempt to set constant symbol: nil
13041
13042 -- Function: keywordp object
13043     function returns ‘t’ if OBJECT is a symbol whose name starts with
13044     ‘:’, interned in the standard obarray, and returns ‘nil’ otherwise.
13045
13046   These constants are fundamentally different from the constants
13047defined using the ‘defconst’ special form (*note Defining Variables::).
13048A ‘defconst’ form serves to inform human readers that you do not intend
13049to change the value of a variable, but Emacs does not raise an error if
13050you actually change it.
13051
13052   A small number of additional symbols are made read-only for various
13053practical reasons.  These include ‘enable-multibyte-characters’,
13054‘most-positive-fixnum’, ‘most-negative-fixnum’, and a few others.  Any
13055attempt to set or bind these also signals a ‘setting-constant’ error.
13056
13057
13058File: elisp.info,  Node: Local Variables,  Next: Void Variables,  Prev: Constant Variables,  Up: Variables
13059
1306012.3 Local Variables
13061====================
13062
13063Global variables have values that last until explicitly superseded with
13064new values.  Sometimes it is useful to give a variable a “local value”—a
13065value that takes effect only within a certain part of a Lisp program.
13066When a variable has a local value, we say that it is “locally bound” to
13067that value, and that it is a “local variable”.
13068
13069   For example, when a function is called, its argument variables
13070receive local values, which are the actual arguments supplied to the
13071function call; these local bindings take effect within the body of the
13072function.  To take another example, the ‘let’ special form explicitly
13073establishes local bindings for specific variables, which take effect
13074only within the body of the ‘let’ form.
13075
13076   We also speak of the “global binding”, which is where (conceptually)
13077the global value is kept.
13078
13079   Establishing a local binding saves away the variable’s previous value
13080(or lack of one).  We say that the previous value is “shadowed”.  Both
13081global and local values may be shadowed.  If a local binding is in
13082effect, using ‘setq’ on the local variable stores the specified value in
13083the local binding.  When that local binding is no longer in effect, the
13084previously shadowed value (or lack of one) comes back.
13085
13086   A variable can have more than one local binding at a time (e.g., if
13087there are nested ‘let’ forms that bind the variable).  The “current
13088binding” is the local binding that is actually in effect.  It determines
13089the value returned by evaluating the variable symbol, and it is the
13090binding acted on by ‘setq’.
13091
13092   For most purposes, you can think of the current binding as the
13093innermost local binding, or the global binding if there is no local
13094binding.  To be more precise, a rule called the “scoping rule”
13095determines where in a program a local binding takes effect.  The default
13096scoping rule in Emacs Lisp is called “dynamic scoping”, which simply
13097states that the current binding at any given point in the execution of a
13098program is the most recently-created binding for that variable that
13099still exists.  For details about dynamic scoping, and an alternative
13100scoping rule called “lexical scoping”, *Note Variable Scoping::.
13101
13102   The special forms ‘let’ and ‘let*’ exist to create local bindings:
13103
13104 -- Special Form: let (bindings...) forms...
13105     This special form sets up local bindings for a certain set of
13106     variables, as specified by BINDINGS, and then evaluates all of the
13107     FORMS in textual order.  Its return value is the value of the last
13108     form in FORMS.  The local bindings set up by ‘let’ will be in
13109     effect only within the body of FORMS.
13110
13111     Each of the BINDINGS is either (i) a symbol, in which case that
13112     symbol is locally bound to ‘nil’; or (ii) a list of the form
13113     ‘(SYMBOL VALUE-FORM)’, in which case SYMBOL is locally bound to the
13114     result of evaluating VALUE-FORM.  If VALUE-FORM is omitted, ‘nil’
13115     is used.
13116
13117     All of the VALUE-FORMs in BINDINGS are evaluated in the order they
13118     appear and _before_ binding any of the symbols to them.  Here is an
13119     example of this: ‘z’ is bound to the old value of ‘y’, which is 2,
13120     not the new value of ‘y’, which is 1.
13121
13122          (setq y 2)
13123               ⇒ 2
13124
13125          (let ((y 1)
13126                (z y))
13127            (list y z))
13128               ⇒ (1 2)
13129
13130     On the other hand, the order of _bindings_ is unspecified: in the
13131     following example, either 1 or 2 might be printed.
13132
13133          (let ((x 1)
13134                (x 2))
13135            (print x))
13136
13137     Therefore, avoid binding a variable more than once in a single
13138     ‘let’ form.
13139
13140 -- Special Form: let* (bindings...) forms...
13141     This special form is like ‘let’, but it binds each variable right
13142     after computing its local value, before computing the local value
13143     for the next variable.  Therefore, an expression in BINDINGS can
13144     refer to the preceding symbols bound in this ‘let*’ form.  Compare
13145     the following example with the example above for ‘let’.
13146
13147          (setq y 2)
13148               ⇒ 2
13149
13150          (let* ((y 1)
13151                 (z y))    ; Use the just-established value of ‘y’.
13152            (list y z))
13153               ⇒ (1 1)
13154
13155 -- Special Form: letrec (bindings...) forms...
13156     This special form is like ‘let*’, but all the variables are bound
13157     before any of the local values are computed.  The values are then
13158     assigned to the locally bound variables.  This is only useful when
13159     lexical binding is in effect, and you want to create closures that
13160     refer to bindings that would otherwise not yet be in effect when
13161     using ‘let*’.
13162
13163     For instance, here’s a closure that removes itself from a hook
13164     after being run once:
13165
13166          (letrec ((hookfun (lambda ()
13167                              (message "Run once")
13168                              (remove-hook 'post-command-hook hookfun))))
13169            (add-hook 'post-command-hook hookfun))
13170
13171   Here is a complete list of the other facilities that create local
13172bindings:
13173
13174   • Function calls (*note Functions::).
13175
13176   • Macro calls (*note Macros::).
13177
13178   • ‘condition-case’ (*note Errors::).
13179
13180   Variables can also have buffer-local bindings (*note Buffer-Local
13181Variables::); a few variables have terminal-local bindings (*note
13182Multiple Terminals::).  These kinds of bindings work somewhat like
13183ordinary local bindings, but they are localized depending on where you
13184are in Emacs.
13185
13186 -- User Option: max-specpdl-size
13187     This variable defines the limit on the total number of local
13188     variable bindings and ‘unwind-protect’ cleanups (see *note Cleaning
13189     Up from Nonlocal Exits: Cleanups.) that are allowed before Emacs
13190     signals an error (with data ‘"Variable binding depth exceeds
13191     max-specpdl-size"’).
13192
13193     This limit, with the associated error when it is exceeded, is one
13194     way that Lisp avoids infinite recursion on an ill-defined function.
13195     ‘max-lisp-eval-depth’ provides another limit on depth of nesting.
13196     *Note Eval: Definition of max-lisp-eval-depth.
13197
13198     The default value is 1600.  Entry to the Lisp debugger increases
13199     the value, if there is little room left, to make sure the debugger
13200     itself has room to execute.
13201
13202
13203File: elisp.info,  Node: Void Variables,  Next: Defining Variables,  Prev: Local Variables,  Up: Variables
13204
1320512.4 When a Variable is Void
13206============================
13207
13208We say that a variable is void if its symbol has an unassigned value
13209cell (*note Symbol Components::).
13210
13211   Under Emacs Lisp’s default dynamic scoping rule (*note Variable
13212Scoping::), the value cell stores the variable’s current (local or
13213global) value.  Note that an unassigned value cell is _not_ the same as
13214having ‘nil’ in the value cell.  The symbol ‘nil’ is a Lisp object and
13215can be the value of a variable, just as any other object can be; but it
13216is still a value.  If a variable is void, trying to evaluate the
13217variable signals a ‘void-variable’ error, instead of returning a value.
13218
13219   Under the optional lexical scoping rule, the value cell only holds
13220the variable’s global value—the value outside of any lexical binding
13221construct.  When a variable is lexically bound, the local value is
13222determined by the lexical environment; hence, variables can have local
13223values even if their symbols’ value cells are unassigned.
13224
13225 -- Function: makunbound symbol
13226     This function empties out the value cell of SYMBOL, making the
13227     variable void.  It returns SYMBOL.
13228
13229     If SYMBOL has a dynamic local binding, ‘makunbound’ voids the
13230     current binding, and this voidness lasts only as long as the local
13231     binding is in effect.  Afterwards, the previously shadowed local or
13232     global binding is reexposed; then the variable will no longer be
13233     void, unless the reexposed binding is void too.
13234
13235     Here are some examples (assuming dynamic binding is in effect):
13236
13237          (setq x 1)               ; Put a value in the global binding.
13238               ⇒ 1
13239          (let ((x 2))             ; Locally bind it.
13240            (makunbound 'x)        ; Void the local binding.
13241            x)
13242          error→ Symbol's value as variable is void: x
13243          x                        ; The global binding is unchanged.
13244               ⇒ 1
13245
13246          (let ((x 2))             ; Locally bind it.
13247            (let ((x 3))           ; And again.
13248              (makunbound 'x)      ; Void the innermost-local binding.
13249              x))                  ; And refer: it’s void.
13250          error→ Symbol's value as variable is void: x
13251
13252          (let ((x 2))
13253            (let ((x 3))
13254              (makunbound 'x))     ; Void inner binding, then remove it.
13255            x)                     ; Now outer ‘let’ binding is visible.
13256               ⇒ 2
13257
13258 -- Function: boundp variable
13259     This function returns ‘t’ if VARIABLE (a symbol) is not void, and
13260     ‘nil’ if it is void.
13261
13262     Here are some examples (assuming dynamic binding is in effect):
13263
13264          (boundp 'abracadabra)          ; Starts out void.
13265               ⇒ nil
13266          (let ((abracadabra 5))         ; Locally bind it.
13267            (boundp 'abracadabra))
13268               ⇒ t
13269          (boundp 'abracadabra)          ; Still globally void.
13270               ⇒ nil
13271          (setq abracadabra 5)           ; Make it globally nonvoid.
13272               ⇒ 5
13273          (boundp 'abracadabra)
13274               ⇒ t
13275
13276
13277File: elisp.info,  Node: Defining Variables,  Next: Tips for Defining,  Prev: Void Variables,  Up: Variables
13278
1327912.5 Defining Global Variables
13280==============================
13281
13282A “variable definition” is a construct that announces your intention to
13283use a symbol as a global variable.  It uses the special forms ‘defvar’
13284or ‘defconst’, which are documented below.
13285
13286   A variable definition serves three purposes.  First, it informs
13287people who read the code that the symbol is _intended_ to be used a
13288certain way (as a variable).  Second, it informs the Lisp system of
13289this, optionally supplying an initial value and a documentation string.
13290Third, it provides information to programming tools such as ‘etags’,
13291allowing them to find where the variable was defined.
13292
13293   The difference between ‘defconst’ and ‘defvar’ is mainly a matter of
13294intent, serving to inform human readers of whether the value should ever
13295change.  Emacs Lisp does not actually prevent you from changing the
13296value of a variable defined with ‘defconst’.  One notable difference
13297between the two forms is that ‘defconst’ unconditionally initializes the
13298variable, whereas ‘defvar’ initializes it only if it is originally void.
13299
13300   To define a customizable variable, you should use ‘defcustom’ (which
13301calls ‘defvar’ as a subroutine).  *Note Variable Definitions::.
13302
13303 -- Special Form: defvar symbol [value [doc-string]]
13304     This special form defines SYMBOL as a variable.  Note that SYMBOL
13305     is not evaluated; the symbol to be defined should appear explicitly
13306     in the ‘defvar’ form.  The variable is marked as “special”, meaning
13307     that it should always be dynamically bound (*note Variable
13308     Scoping::).
13309
13310     If VALUE is specified, and SYMBOL is void (i.e., it has no
13311     dynamically bound value; *note Void Variables::), then VALUE is
13312     evaluated and SYMBOL is set to the result.  But if SYMBOL is not
13313     void, VALUE is not evaluated, and SYMBOL’s value is left unchanged.
13314     If VALUE is omitted, the value of SYMBOL is not changed in any
13315     case.
13316
13317     Note that specifying a value, even ‘nil’, marks the variable as
13318     special permanently.  Whereas if VALUE is omitted then the variable
13319     is only marked special locally (i.e. within the current lexical
13320     scope, or file if at the top-level).  This can be useful for
13321     suppressing byte compilation warnings, see *note Compiler Errors::.
13322
13323     If SYMBOL has a buffer-local binding in the current buffer,
13324     ‘defvar’ acts on the default value, which is buffer-independent,
13325     rather than the buffer-local binding.  It sets the default value if
13326     the default value is void.  *Note Buffer-Local Variables::.
13327
13328     If SYMBOL is already lexically bound (e.g., if the ‘defvar’ form
13329     occurs in a ‘let’ form with lexical binding enabled), then ‘defvar’
13330     sets the dynamic value.  The lexical binding remains in effect
13331     until its binding construct exits.  *Note Variable Scoping::.
13332
13333     When you evaluate a top-level ‘defvar’ form with ‘C-M-x’ in Emacs
13334     Lisp mode (‘eval-defun’), a special feature of ‘eval-defun’
13335     arranges to set the variable unconditionally, without testing
13336     whether its value is void.
13337
13338     If the DOC-STRING argument is supplied, it specifies the
13339     documentation string for the variable (stored in the symbol’s
13340     ‘variable-documentation’ property).  *Note Documentation::.
13341
13342     Here are some examples.  This form defines ‘foo’ but does not
13343     initialize it:
13344
13345          (defvar foo)
13346               ⇒ foo
13347
13348     This example initializes the value of ‘bar’ to ‘23’, and gives it a
13349     documentation string:
13350
13351          (defvar bar 23
13352            "The normal weight of a bar.")
13353               ⇒ bar
13354
13355     The ‘defvar’ form returns SYMBOL, but it is normally used at top
13356     level in a file where its value does not matter.
13357
13358     For a more elaborate example of using ‘defvar’ without a value, see
13359     *note Local defvar example::.
13360
13361 -- Special Form: defconst symbol value [doc-string]
13362     This special form defines SYMBOL as a value and initializes it.  It
13363     informs a person reading your code that SYMBOL has a standard
13364     global value, established here, that should not be changed by the
13365     user or by other programs.  Note that SYMBOL is not evaluated; the
13366     symbol to be defined must appear explicitly in the ‘defconst’.
13367
13368     The ‘defconst’ form, like ‘defvar’, marks the variable as
13369     “special”, meaning that it should always be dynamically bound
13370     (*note Variable Scoping::).  In addition, it marks the variable as
13371     risky (*note File Local Variables::).
13372
13373     ‘defconst’ always evaluates VALUE, and sets the value of SYMBOL to
13374     the result.  If SYMBOL does have a buffer-local binding in the
13375     current buffer, ‘defconst’ sets the default value, not the
13376     buffer-local value.  (But you should not be making buffer-local
13377     bindings for a symbol that is defined with ‘defconst’.)
13378
13379     An example of the use of ‘defconst’ is Emacs’s definition of
13380     ‘float-pi’—the mathematical constant pi, which ought not to be
13381     changed by anyone (attempts by the Indiana State Legislature
13382     notwithstanding).  As the second form illustrates, however,
13383     ‘defconst’ is only advisory.
13384
13385          (defconst float-pi 3.141592653589793 "The value of Pi.")
13386               ⇒ float-pi
13387          (setq float-pi 3)
13388               ⇒ float-pi
13389          float-pi
13390               ⇒ 3
13391
13392   *Warning:* If you use a ‘defconst’ or ‘defvar’ special form while the
13393variable has a local binding (made with ‘let’, or a function argument),
13394it sets the local binding rather than the global binding.  This is not
13395what you usually want.  To prevent this, use these special forms at top
13396level in a file, where normally no local binding is in effect, and make
13397sure to load the file before making a local binding for the variable.
13398
13399
13400File: elisp.info,  Node: Tips for Defining,  Next: Accessing Variables,  Prev: Defining Variables,  Up: Variables
13401
1340212.6 Tips for Defining Variables Robustly
13403=========================================
13404
13405When you define a variable whose value is a function, or a list of
13406functions, use a name that ends in ‘-function’ or ‘-functions’,
13407respectively.
13408
13409   There are several other variable name conventions; here is a complete
13410list:
13411
13412‘...-hook’
13413     The variable is a normal hook (*note Hooks::).
13414
13415‘...-function’
13416     The value is a function.
13417
13418‘...-functions’
13419     The value is a list of functions.
13420
13421‘...-form’
13422     The value is a form (an expression).
13423
13424‘...-forms’
13425     The value is a list of forms (expressions).
13426
13427‘...-predicate’
13428     The value is a predicate—a function of one argument that returns
13429     non-‘nil’ for success and ‘nil’ for failure.
13430
13431‘...-flag’
13432     The value is significant only as to whether it is ‘nil’ or not.
13433     Since such variables often end up acquiring more values over time,
13434     this convention is not strongly recommended.
13435
13436‘...-program’
13437     The value is a program name.
13438
13439‘...-command’
13440     The value is a whole shell command.
13441
13442‘...-switches’
13443     The value specifies options for a command.
13444
13445‘PREFIX--...’
13446     The variable is intended for internal use and is defined in the
13447     file ‘PREFIX.el’.  (Emacs code contributed before 2018 may follow
13448     other conventions, which are being phased out.)
13449
13450‘...-internal’
13451     The variable is intended for internal use and is defined in C code.
13452     (Emacs code contributed before 2018 may follow other conventions,
13453     which are being phased out.)
13454
13455   When you define a variable, always consider whether you should mark
13456it as safe or risky; see *note File Local Variables::.
13457
13458   When defining and initializing a variable that holds a complicated
13459value (such as a keymap with bindings in it), it’s best to put the
13460entire computation of the value into the ‘defvar’, like this:
13461
13462     (defvar my-mode-map
13463       (let ((map (make-sparse-keymap)))
13464         (define-key map "\C-c\C-a" 'my-command)
13465         ...
13466         map)
13467       DOCSTRING)
13468
13469This method has several benefits.  First, if the user quits while
13470loading the file, the variable is either still uninitialized or
13471initialized properly, never in-between.  If it is still uninitialized,
13472reloading the file will initialize it properly.  Second, reloading the
13473file once the variable is initialized will not alter it; that is
13474important if the user has run hooks to alter part of the contents (such
13475as, to rebind keys).  Third, evaluating the ‘defvar’ form with ‘C-M-x’
13476will reinitialize the map completely.
13477
13478   Putting so much code in the ‘defvar’ form has one disadvantage: it
13479puts the documentation string far away from the line which names the
13480variable.  Here’s a safe way to avoid that:
13481
13482     (defvar my-mode-map nil
13483       DOCSTRING)
13484     (unless my-mode-map
13485       (let ((map (make-sparse-keymap)))
13486         (define-key map "\C-c\C-a" 'my-command)
13487         ...
13488         (setq my-mode-map map)))
13489
13490This has all the same advantages as putting the initialization inside
13491the ‘defvar’, except that you must type ‘C-M-x’ twice, once on each
13492form, if you do want to reinitialize the variable.
13493
13494
13495File: elisp.info,  Node: Accessing Variables,  Next: Setting Variables,  Prev: Tips for Defining,  Up: Variables
13496
1349712.7 Accessing Variable Values
13498==============================
13499
13500The usual way to reference a variable is to write the symbol which names
13501it.  *Note Symbol Forms::.
13502
13503   Occasionally, you may want to reference a variable which is only
13504determined at run time.  In that case, you cannot specify the variable
13505name in the text of the program.  You can use the ‘symbol-value’
13506function to extract the value.
13507
13508 -- Function: symbol-value symbol
13509     This function returns the value stored in SYMBOL’s value cell.
13510     This is where the variable’s current (dynamic) value is stored.  If
13511     the variable has no local binding, this is simply its global value.
13512     If the variable is void, a ‘void-variable’ error is signaled.
13513
13514     If the variable is lexically bound, the value reported by
13515     ‘symbol-value’ is not necessarily the same as the variable’s
13516     lexical value, which is determined by the lexical environment
13517     rather than the symbol’s value cell.  *Note Variable Scoping::.
13518
13519          (setq abracadabra 5)
13520               ⇒ 5
13521          (setq foo 9)
13522               ⇒ 9
13523
13524          ;; Here the symbol ‘abracadabra’
13525          ;;   is the symbol whose value is examined.
13526          (let ((abracadabra 'foo))
13527            (symbol-value 'abracadabra))
13528               ⇒ foo
13529
13530          ;; Here, the value of ‘abracadabra’,
13531          ;;   which is ‘foo’,
13532          ;;   is the symbol whose value is examined.
13533          (let ((abracadabra 'foo))
13534            (symbol-value abracadabra))
13535               ⇒ 9
13536
13537          (symbol-value 'abracadabra)
13538               ⇒ 5
13539
13540
13541File: elisp.info,  Node: Setting Variables,  Next: Watching Variables,  Prev: Accessing Variables,  Up: Variables
13542
1354312.8 Setting Variable Values
13544============================
13545
13546The usual way to change the value of a variable is with the special form
13547‘setq’.  When you need to compute the choice of variable at run time,
13548use the function ‘set’.
13549
13550 -- Special Form: setq [symbol form]...
13551     This special form is the most common method of changing a
13552     variable’s value.  Each SYMBOL is given a new value, which is the
13553     result of evaluating the corresponding FORM.  The current binding
13554     of the symbol is changed.
13555
13556     ‘setq’ does not evaluate SYMBOL; it sets the symbol that you write.
13557     We say that this argument is “automatically quoted”.  The ‘q’ in
13558     ‘setq’ stands for “quoted”.
13559
13560     The value of the ‘setq’ form is the value of the last FORM.
13561
13562          (setq x (1+ 2))
13563               ⇒ 3
13564          x                   ; ‘x’ now has a global value.
13565               ⇒ 3
13566          (let ((x 5))
13567            (setq x 6)        ; The local binding of ‘x’ is set.
13568            x)
13569               ⇒ 6
13570          x                   ; The global value is unchanged.
13571               ⇒ 3
13572
13573     Note that the first FORM is evaluated, then the first SYMBOL is
13574     set, then the second FORM is evaluated, then the second SYMBOL is
13575     set, and so on:
13576
13577          (setq x 10          ; Notice that ‘x’ is set before
13578                y (1+ x))     ;   the value of ‘y’ is computed.
13579               ⇒ 11
13580
13581 -- Function: set symbol value
13582     This function puts VALUE in the value cell of SYMBOL.  Since it is
13583     a function rather than a special form, the expression written for
13584     SYMBOL is evaluated to obtain the symbol to set.  The return value
13585     is VALUE.
13586
13587     When dynamic variable binding is in effect (the default), ‘set’ has
13588     the same effect as ‘setq’, apart from the fact that ‘set’ evaluates
13589     its SYMBOL argument whereas ‘setq’ does not.  But when a variable
13590     is lexically bound, ‘set’ affects its _dynamic_ value, whereas
13591     ‘setq’ affects its current (lexical) value.  *Note Variable
13592     Scoping::.
13593
13594          (set one 1)
13595          error→ Symbol's value as variable is void: one
13596          (set 'one 1)
13597               ⇒ 1
13598          (set 'two 'one)
13599               ⇒ one
13600          (set two 2)         ; ‘two’ evaluates to symbol ‘one’.
13601               ⇒ 2
13602          one                 ; So it is ‘one’ that was set.
13603               ⇒ 2
13604          (let ((one 1))      ; This binding of ‘one’ is set,
13605            (set 'one 3)      ;   not the global value.
13606            one)
13607               ⇒ 3
13608          one
13609               ⇒ 2
13610
13611     If SYMBOL is not actually a symbol, a ‘wrong-type-argument’ error
13612     is signaled.
13613
13614          (set '(x y) 'z)
13615          error→ Wrong type argument: symbolp, (x y)
13616
13617
13618File: elisp.info,  Node: Watching Variables,  Next: Variable Scoping,  Prev: Setting Variables,  Up: Variables
13619
1362012.9 Running a function when a variable is changed.
13621===================================================
13622
13623It is sometimes useful to take some action when a variable changes its
13624value.  The “variable watchpoint” facility provides the means to do so.
13625Some possible uses for this feature include keeping display in sync with
13626variable settings, and invoking the debugger to track down unexpected
13627changes to variables (*note Variable Debugging::).
13628
13629   The following functions may be used to manipulate and query the watch
13630functions for a variable.
13631
13632 -- Function: add-variable-watcher symbol watch-function
13633     This function arranges for WATCH-FUNCTION to be called whenever
13634     SYMBOL is modified.  Modifications through aliases (*note Variable
13635     Aliases::) will have the same effect.
13636
13637     WATCH-FUNCTION will be called, just before changing the value of
13638     SYMBOL, with 4 arguments: SYMBOL, NEWVAL, OPERATION, and WHERE.
13639     SYMBOL is the variable being changed.  NEWVAL is the value it will
13640     be changed to.  (The old value is available to WATCH-FUNCTION as
13641     the value of SYMBOL, since it was not yet changed to NEWVAL.)
13642     OPERATION is a symbol representing the kind of change, one of:
13643     ‘set’, ‘let’, ‘unlet’, ‘makunbound’, or ‘defvaralias’.  WHERE is a
13644     buffer if the buffer-local value of the variable is being changed,
13645     ‘nil’ otherwise.
13646
13647 -- Function: remove-variable-watcher symbol watch-function
13648     This function removes WATCH-FUNCTION from SYMBOL’s list of
13649     watchers.
13650
13651 -- Function: get-variable-watchers symbol
13652     This function returns the list of SYMBOL’s active watcher
13653     functions.
13654
1365512.9.1 Limitations
13656------------------
13657
13658There are a couple of ways in which a variable could be modified (or at
13659least appear to be modified) without triggering a watchpoint.
13660
13661   Since watchpoints are attached to symbols, modification to the
13662objects contained within variables (e.g., by a list modification
13663function *note Modifying Lists::) is not caught by this mechanism.
13664
13665   Additionally, C code can modify the value of variables directly,
13666bypassing the watchpoint mechanism.
13667
13668   A minor limitation of this feature, again because it targets symbols,
13669is that only variables of dynamic scope may be watched.  This poses
13670little difficulty, since modifications to lexical variables can be
13671discovered easily by inspecting the code within the scope of the
13672variable (unlike dynamic variables, which can be modified by any code at
13673all, *note Variable Scoping::).
13674
13675
13676File: elisp.info,  Node: Variable Scoping,  Next: Buffer-Local Variables,  Prev: Watching Variables,  Up: Variables
13677
1367812.10 Scoping Rules for Variable Bindings
13679=========================================
13680
13681When you create a local binding for a variable, that binding takes
13682effect only within a limited portion of the program (*note Local
13683Variables::).  This section describes exactly what this means.
13684
13685   Each local binding has a certain “scope” and “extent”.  “Scope”
13686refers to _where_ in the textual source code the binding can be
13687accessed.  “Extent” refers to _when_, as the program is executing, the
13688binding exists.
13689
13690   By default, the local bindings that Emacs creates are “dynamic
13691bindings”.  Such a binding has “dynamic scope”, meaning that any part of
13692the program can potentially access the variable binding.  It also has
13693“dynamic extent”, meaning that the binding lasts only while the binding
13694construct (such as the body of a ‘let’ form) is being executed.
13695
13696   Emacs can optionally create “lexical bindings”.  A lexical binding
13697has “lexical scope”, meaning that any reference to the variable must be
13698located textually within the binding construct(1).  It also has
13699“indefinite extent”, meaning that under some circumstances the binding
13700can live on even after the binding construct has finished executing, by
13701means of special objects called “closures”.
13702
13703   The following subsections describe dynamic binding and lexical
13704binding in greater detail, and how to enable lexical binding in Emacs
13705Lisp programs.
13706
13707* Menu:
13708
13709* Dynamic Binding::         The default for binding local variables in Emacs.
13710* Dynamic Binding Tips::    Avoiding problems with dynamic binding.
13711* Lexical Binding::         A different type of local variable binding.
13712* Using Lexical Binding::   How to enable lexical binding.
13713
13714   ---------- Footnotes ----------
13715
13716   (1) With some exceptions; for instance, a lexical binding can also be
13717accessed from the Lisp debugger.
13718
13719
13720File: elisp.info,  Node: Dynamic Binding,  Next: Dynamic Binding Tips,  Up: Variable Scoping
13721
1372212.10.1 Dynamic Binding
13723-----------------------
13724
13725By default, the local variable bindings made by Emacs are dynamic
13726bindings.  When a variable is dynamically bound, its current binding at
13727any point in the execution of the Lisp program is simply the most
13728recently-created dynamic local binding for that symbol, or the global
13729binding if there is no such local binding.
13730
13731   Dynamic bindings have dynamic scope and extent, as shown by the
13732following example:
13733
13734     (defvar x -99)  ; ‘x’ receives an initial value of −99.
13735
13736     (defun getx ()
13737       x)            ; ‘x’ is used free in this function.
13738
13739     (let ((x 1))    ; ‘x’ is dynamically bound.
13740       (getx))
13741          ⇒ 1
13742
13743     ;; After the ‘let’ form finishes, ‘x’ reverts to its
13744     ;; previous value, which is −99.
13745
13746     (getx)
13747          ⇒ -99
13748
13749The function ‘getx’ refers to ‘x’.  This is a “free” reference, in the
13750sense that there is no binding for ‘x’ within that ‘defun’ construct
13751itself.  When we call ‘getx’ from within a ‘let’ form in which ‘x’ is
13752(dynamically) bound, it retrieves the local value (i.e., 1).  But when
13753we call ‘getx’ outside the ‘let’ form, it retrieves the global value
13754(i.e., −99).
13755
13756   Here is another example, which illustrates setting a dynamically
13757bound variable using ‘setq’:
13758
13759     (defvar x -99)      ; ‘x’ receives an initial value of −99.
13760
13761     (defun addx ()
13762       (setq x (1+ x)))  ; Add 1 to ‘x’ and return its new value.
13763
13764     (let ((x 1))
13765       (addx)
13766       (addx))
13767          ⇒ 3           ; The two ‘addx’ calls add to ‘x’ twice.
13768
13769     ;; After the ‘let’ form finishes, ‘x’ reverts to its
13770     ;; previous value, which is −99.
13771
13772     (addx)
13773          ⇒ -98
13774
13775   Dynamic binding is implemented in Emacs Lisp in a simple way.  Each
13776symbol has a value cell, which specifies its current dynamic value (or
13777absence of value).  *Note Symbol Components::.  When a symbol is given a
13778dynamic local binding, Emacs records the contents of the value cell (or
13779absence thereof) in a stack, and stores the new local value in the value
13780cell.  When the binding construct finishes executing, Emacs pops the old
13781value off the stack, and puts it in the value cell.
13782
13783
13784File: elisp.info,  Node: Dynamic Binding Tips,  Next: Lexical Binding,  Prev: Dynamic Binding,  Up: Variable Scoping
13785
1378612.10.2 Proper Use of Dynamic Binding
13787-------------------------------------
13788
13789Dynamic binding is a powerful feature, as it allows programs to refer to
13790variables that are not defined within their local textual scope.
13791However, if used without restraint, this can also make programs hard to
13792understand.  There are two clean ways to use this technique:
13793
13794   • If a variable has no global definition, use it as a local variable
13795     only within a binding construct, such as the body of the ‘let’ form
13796     where the variable was bound.  If this convention is followed
13797     consistently throughout a program, the value of the variable will
13798     not affect, nor be affected by, any uses of the same variable
13799     symbol elsewhere in the program.
13800
13801   • Otherwise, define the variable with ‘defvar’, ‘defconst’ (*note
13802     Defining Variables::), or ‘defcustom’ (*note Variable
13803     Definitions::).  Usually, the definition should be at top-level in
13804     an Emacs Lisp file.  As far as possible, it should include a
13805     documentation string which explains the meaning and purpose of the
13806     variable.  You should also choose the variable’s name to avoid name
13807     conflicts (*note Coding Conventions::).
13808
13809     Then you can bind the variable anywhere in a program, knowing
13810     reliably what the effect will be.  Wherever you encounter the
13811     variable, it will be easy to refer back to the definition, e.g.,
13812     via the ‘C-h v’ command (provided the variable definition has been
13813     loaded into Emacs).  *Note (emacs)Name Help::.
13814
13815     For example, it is common to use local bindings for customizable
13816     variables like ‘case-fold-search’:
13817
13818          (defun search-for-abc ()
13819            "Search for the string \"abc\", ignoring case differences."
13820            (let ((case-fold-search t))
13821              (re-search-forward "abc")))
13822
13823
13824File: elisp.info,  Node: Lexical Binding,  Next: Using Lexical Binding,  Prev: Dynamic Binding Tips,  Up: Variable Scoping
13825
1382612.10.3 Lexical Binding
13827-----------------------
13828
13829Lexical binding was introduced to Emacs, as an optional feature, in
13830version 24.1.  We expect its importance to increase with time.  Lexical
13831binding opens up many more opportunities for optimization, so programs
13832using it are likely to run faster in future Emacs versions.  Lexical
13833binding is also more compatible with concurrency, which was added to
13834Emacs in version 26.1.
13835
13836   A lexically-bound variable has “lexical scope”, meaning that any
13837reference to the variable must be located textually within the binding
13838construct.  Here is an example (*note Using Lexical Binding::, for how
13839to actually enable lexical binding):
13840
13841     (let ((x 1))    ; ‘x’ is lexically bound.
13842       (+ x 3))
13843          ⇒ 4
13844
13845     (defun getx ()
13846       x)            ; ‘x’ is used free in this function.
13847
13848     (let ((x 1))    ; ‘x’ is lexically bound.
13849       (getx))
13850     error→ Symbol's value as variable is void: x
13851
13852Here, the variable ‘x’ has no global value.  When it is lexically bound
13853within a ‘let’ form, it can be used in the textual confines of that
13854‘let’ form.  But it can _not_ be used from within a ‘getx’ function
13855called from the ‘let’ form, since the function definition of ‘getx’
13856occurs outside the ‘let’ form itself.
13857
13858   Here is how lexical binding works.  Each binding construct defines a
13859“lexical environment”, specifying the variables that are bound within
13860the construct and their local values.  When the Lisp evaluator wants the
13861current value of a variable, it looks first in the lexical environment;
13862if the variable is not specified in there, it looks in the symbol’s
13863value cell, where the dynamic value is stored.
13864
13865   (Internally, the lexical environment is an alist of symbol-value
13866pairs, with the final element in the alist being the symbol ‘t’ rather
13867than a cons cell.  Such an alist can be passed as the second argument to
13868the ‘eval’ function, in order to specify a lexical environment in which
13869to evaluate a form.  *Note Eval::.  Most Emacs Lisp programs, however,
13870should not interact directly with lexical environments in this way; only
13871specialized programs like debuggers.)
13872
13873   Lexical bindings have indefinite extent.  Even after a binding
13874construct has finished executing, its lexical environment can be “kept
13875around” in Lisp objects called “closures”.  A closure is created when
13876you define a named or anonymous function with lexical binding enabled.
13877*Note Closures::, for details.
13878
13879   When a closure is called as a function, any lexical variable
13880references within its definition use the retained lexical environment.
13881Here is an example:
13882
13883     (defvar my-ticker nil)   ; We will use this dynamically bound
13884                              ; variable to store a closure.
13885
13886     (let ((x 0))             ; ‘x’ is lexically bound.
13887       (setq my-ticker (lambda ()
13888                         (setq x (1+ x)))))
13889         ⇒ (closure ((x . 0) t) ()
13890               (setq x (1+ x)))
13891
13892     (funcall my-ticker)
13893         ⇒ 1
13894
13895     (funcall my-ticker)
13896         ⇒ 2
13897
13898     (funcall my-ticker)
13899         ⇒ 3
13900
13901     x                        ; Note that ‘x’ has no global value.
13902     error→ Symbol's value as variable is void: x
13903
13904The ‘let’ binding defines a lexical environment in which the variable
13905‘x’ is locally bound to 0.  Within this binding construct, we define a
13906lambda expression which increments ‘x’ by one and returns the
13907incremented value.  This lambda expression is automatically turned into
13908a closure, in which the lexical environment lives on even after the
13909‘let’ binding construct has exited.  Each time we evaluate the closure,
13910it increments ‘x’, using the binding of ‘x’ in that lexical environment.
13911
13912   Note that unlike dynamic variables which are tied to the symbol
13913object itself, the relationship between lexical variables and symbols is
13914only present in the interpreter (or compiler).  Therefore, functions
13915which take a symbol argument (like ‘symbol-value’, ‘boundp’, and ‘set’)
13916can only retrieve or modify a variable’s dynamic binding (i.e., the
13917contents of its symbol’s value cell).
13918
13919
13920File: elisp.info,  Node: Using Lexical Binding,  Prev: Lexical Binding,  Up: Variable Scoping
13921
1392212.10.4 Using Lexical Binding
13923-----------------------------
13924
13925When loading an Emacs Lisp file or evaluating a Lisp buffer, lexical
13926binding is enabled if the buffer-local variable ‘lexical-binding’ is
13927non-‘nil’:
13928
13929 -- Variable: lexical-binding
13930     If this buffer-local variable is non-‘nil’, Emacs Lisp files and
13931     buffers are evaluated using lexical binding instead of dynamic
13932     binding.  (However, special variables are still dynamically bound;
13933     see below.)  If ‘nil’, dynamic binding is used for all local
13934     variables.  This variable is typically set for a whole Emacs Lisp
13935     file, as a file local variable (*note File Local Variables::).
13936     Note that unlike other such variables, this one must be set in the
13937     first line of a file.
13938
13939When evaluating Emacs Lisp code directly using an ‘eval’ call, lexical
13940binding is enabled if the LEXICAL argument to ‘eval’ is non-‘nil’.
13941*Note Eval::.
13942
13943   Lexical binding is also enabled in Lisp Interaction and IELM mode,
13944used in the ‘*scratch*’ and ‘*ielm*’ buffers, and also when evaluating
13945expressions via ‘M-:’ (‘eval-expression’) and when processing the
13946‘--eval’ command-line options of Emacs (*note (emacs)Action Arguments::)
13947and ‘emacsclient’ (*note (emacs)emacsclient Options::).
13948
13949   Even when lexical binding is enabled, certain variables will continue
13950to be dynamically bound.  These are called “special variables”.  Every
13951variable that has been defined with ‘defvar’, ‘defcustom’ or ‘defconst’
13952is a special variable (*note Defining Variables::).  All other variables
13953are subject to lexical binding.
13954
13955   Using ‘defvar’ without a value, it is possible to bind a variable
13956dynamically just in one file, or in just one part of a file while still
13957binding it lexically elsewhere.  For example:
13958
13959     (let (_)
13960       (defvar x)      ; Let-bindings of ‘x’ will be dynamic within this let.
13961       (let ((x -99))  ; This is a dynamic binding of ‘x’.
13962         (defun get-dynamic-x ()
13963           x)))
13964
13965     (let ((x 'lexical)) ; This is a lexical binding of ‘x’.
13966       (defun get-lexical-x ()
13967         x))
13968
13969     (let (_)
13970       (defvar x)
13971       (let ((x 'dynamic))
13972         (list (get-lexical-x)
13973               (get-dynamic-x))))
13974         ⇒ (lexical dynamic)
13975
13976 -- Function: special-variable-p symbol
13977     This function returns non-‘nil’ if SYMBOL is a special variable
13978     (i.e., it has a ‘defvar’, ‘defcustom’, or ‘defconst’ variable
13979     definition).  Otherwise, the return value is ‘nil’.
13980
13981     Note that since this is a function, it can only return non-‘nil’
13982     for variables which are permanently special, but not for those that
13983     are only special in the current lexical scope.
13984
13985   The use of a special variable as a formal argument in a function is
13986discouraged.  Doing so gives rise to unspecified behavior when lexical
13987binding mode is enabled (it may use lexical binding sometimes, and
13988dynamic binding other times).
13989
13990   Converting an Emacs Lisp program to lexical binding is easy.  First,
13991add a file-local variable setting of ‘lexical-binding’ to ‘t’ in the
13992header line of the Emacs Lisp source file (*note File Local
13993Variables::).  Second, check that every variable in the program which
13994needs to be dynamically bound has a variable definition, so that it is
13995not inadvertently bound lexically.
13996
13997   A simple way to find out which variables need a variable definition
13998is to byte-compile the source file.  *Note Byte Compilation::.  If a
13999non-special variable is used outside of a ‘let’ form, the byte-compiler
14000will warn about reference or assignment to a free variable.  If a
14001non-special variable is bound but not used within a ‘let’ form, the
14002byte-compiler will warn about an unused lexical variable.  The
14003byte-compiler will also issue a warning if you use a special variable as
14004a function argument.
14005
14006   (To silence byte-compiler warnings about unused variables, just use a
14007variable name that starts with an underscore.  The byte-compiler
14008interprets this as an indication that this is a variable known not to be
14009used.)
14010
14011
14012File: elisp.info,  Node: Buffer-Local Variables,  Next: File Local Variables,  Prev: Variable Scoping,  Up: Variables
14013
1401412.11 Buffer-Local Variables
14015============================
14016
14017Global and local variable bindings are found in most programming
14018languages in one form or another.  Emacs, however, also supports
14019additional, unusual kinds of variable binding, such as “buffer-local”
14020bindings, which apply only in one buffer.  Having different values for a
14021variable in different buffers is an important customization method.
14022(Variables can also have bindings that are local to each terminal.
14023*Note Multiple Terminals::.)
14024
14025* Menu:
14026
14027* Intro to Buffer-Local::       Introduction and concepts.
14028* Creating Buffer-Local::       Creating and destroying buffer-local bindings.
14029* Default Value::               The default value is seen in buffers
14030                                 that don’t have their own buffer-local values.
14031
14032
14033File: elisp.info,  Node: Intro to Buffer-Local,  Next: Creating Buffer-Local,  Up: Buffer-Local Variables
14034
1403512.11.1 Introduction to Buffer-Local Variables
14036----------------------------------------------
14037
14038A buffer-local variable has a buffer-local binding associated with a
14039particular buffer.  The binding is in effect when that buffer is
14040current; otherwise, it is not in effect.  If you set the variable while
14041a buffer-local binding is in effect, the new value goes in that binding,
14042so its other bindings are unchanged.  This means that the change is
14043visible only in the buffer where you made it.
14044
14045   The variable’s ordinary binding, which is not associated with any
14046specific buffer, is called the “default binding”.  In most cases, this
14047is the global binding.
14048
14049   A variable can have buffer-local bindings in some buffers but not in
14050other buffers.  The default binding is shared by all the buffers that
14051don’t have their own bindings for the variable.  (This includes all
14052newly-created buffers.)  If you set the variable in a buffer that does
14053not have a buffer-local binding for it, this sets the default binding,
14054so the new value is visible in all the buffers that see the default
14055binding.
14056
14057   The most common use of buffer-local bindings is for major modes to
14058change variables that control the behavior of commands.  For example, C
14059mode and Lisp mode both set the variable ‘paragraph-start’ to specify
14060that only blank lines separate paragraphs.  They do this by making the
14061variable buffer-local in the buffer that is being put into C mode or
14062Lisp mode, and then setting it to the new value for that mode.  *Note
14063Major Modes::.
14064
14065   The usual way to make a buffer-local binding is with
14066‘make-local-variable’, which is what major mode commands typically use.
14067This affects just the current buffer; all other buffers (including those
14068yet to be created) will continue to share the default value unless they
14069are explicitly given their own buffer-local bindings.
14070
14071   A more powerful operation is to mark the variable as “automatically
14072buffer-local” by calling ‘make-variable-buffer-local’.  You can think of
14073this as making the variable local in all buffers, even those yet to be
14074created.  More precisely, the effect is that setting the variable
14075automatically makes the variable local to the current buffer if it is
14076not already so.  All buffers start out by sharing the default value of
14077the variable as usual, but setting the variable creates a buffer-local
14078binding for the current buffer.  The new value is stored in the
14079buffer-local binding, leaving the default binding untouched.  This means
14080that the default value cannot be changed with ‘setq’ in any buffer; the
14081only way to change it is with ‘setq-default’.
14082
14083   *Warning:* When a variable has buffer-local bindings in one or more
14084buffers, ‘let’ rebinds the binding that’s currently in effect.  For
14085instance, if the current buffer has a buffer-local value, ‘let’
14086temporarily rebinds that.  If no buffer-local bindings are in effect,
14087‘let’ rebinds the default value.  If inside the ‘let’ you then change to
14088a different current buffer in which a different binding is in effect,
14089you won’t see the ‘let’ binding any more.  And if you exit the ‘let’
14090while still in the other buffer, you won’t see the unbinding occur
14091(though it will occur properly).  Here is an example to illustrate:
14092
14093     (setq foo 'g)
14094     (set-buffer "a")
14095     (make-local-variable 'foo)
14096     (setq foo 'a)
14097     (let ((foo 'temp))
14098       ;; foo ⇒ 'temp  ; let binding in buffer ‘a’
14099       (set-buffer "b")
14100       ;; foo ⇒ 'g     ; the global value since foo is not local in ‘b’
14101       BODY...)
14102     foo ⇒ 'g        ; exiting restored the local value in buffer ‘a’,
14103                      ; but we don’t see that in buffer ‘b’
14104     (set-buffer "a") ; verify the local value was restored
14105     foo ⇒ 'a
14106
14107Note that references to ‘foo’ in BODY access the buffer-local binding of
14108buffer ‘b’.
14109
14110   When a file specifies local variable values, these become
14111buffer-local values when you visit the file.  *Note (emacs)File
14112Variables::.
14113
14114   A buffer-local variable cannot be made terminal-local (*note Multiple
14115Terminals::).
14116
14117
14118File: elisp.info,  Node: Creating Buffer-Local,  Next: Default Value,  Prev: Intro to Buffer-Local,  Up: Buffer-Local Variables
14119
1412012.11.2 Creating and Deleting Buffer-Local Bindings
14121---------------------------------------------------
14122
14123 -- Command: make-local-variable variable
14124     This function creates a buffer-local binding in the current buffer
14125     for VARIABLE (a symbol).  Other buffers are not affected.  The
14126     value returned is VARIABLE.
14127
14128     The buffer-local value of VARIABLE starts out as the same value
14129     VARIABLE previously had.  If VARIABLE was void, it remains void.
14130
14131          ;; In buffer ‘b1’:
14132          (setq foo 5)                ; Affects all buffers.
14133               ⇒ 5
14134          (make-local-variable 'foo)  ; Now it is local in ‘b1’.
14135               ⇒ foo
14136          foo                         ; That did not change
14137               ⇒ 5                   ;   the value.
14138          (setq foo 6)                ; Change the value
14139               ⇒ 6                   ;   in ‘b1’.
14140          foo
14141               ⇒ 6
14142
14143          ;; In buffer ‘b2’, the value hasn’t changed.
14144          (with-current-buffer "b2"
14145            foo)
14146               ⇒ 5
14147
14148     Making a variable buffer-local within a ‘let’-binding for that
14149     variable does not work reliably, unless the buffer in which you do
14150     this is not current either on entry to or exit from the ‘let’.
14151     This is because ‘let’ does not distinguish between different kinds
14152     of bindings; it knows only which variable the binding was made for.
14153
14154     It is an error to make a constant or a read-only variable
14155     buffer-local.  *Note Constant Variables::.
14156
14157     If the variable is terminal-local (*note Multiple Terminals::),
14158     this function signals an error.  Such variables cannot have
14159     buffer-local bindings as well.
14160
14161     *Warning:* do not use ‘make-local-variable’ for a hook variable.
14162     The hook variables are automatically made buffer-local as needed if
14163     you use the LOCAL argument to ‘add-hook’ or ‘remove-hook’.
14164
14165 -- Macro: setq-local &rest pairs
14166     PAIRS is a list of variable and value pairs.  This macro creates a
14167     buffer-local binding in the current buffer for each of the
14168     variables, and gives them a buffer-local value.  It is equivalent
14169     to calling ‘make-local-variable’ followed by ‘setq’ for each of the
14170     variables.  The variables should be unquoted symbols.
14171
14172          (setq-local var1 "value1"
14173                      var2 "value2")
14174
14175 -- Command: make-variable-buffer-local variable
14176     This function marks VARIABLE (a symbol) automatically buffer-local,
14177     so that any subsequent attempt to set it will make it local to the
14178     current buffer at the time.  Unlike ‘make-local-variable’, with
14179     which it is often confused, this cannot be undone, and affects the
14180     behavior of the variable in all buffers.
14181
14182     A peculiar wrinkle of this feature is that binding the variable
14183     (with ‘let’ or other binding constructs) does not create a
14184     buffer-local binding for it.  Only setting the variable (with ‘set’
14185     or ‘setq’), while the variable does not have a ‘let’-style binding
14186     that was made in the current buffer, does so.
14187
14188     If VARIABLE does not have a default value, then calling this
14189     command will give it a default value of ‘nil’.  If VARIABLE already
14190     has a default value, that value remains unchanged.  Subsequently
14191     calling ‘makunbound’ on VARIABLE will result in a void buffer-local
14192     value and leave the default value unaffected.
14193
14194     The value returned is VARIABLE.
14195
14196     It is an error to make a constant or a read-only variable
14197     buffer-local.  *Note Constant Variables::.
14198
14199     *Warning:* Don’t assume that you should use
14200     ‘make-variable-buffer-local’ for user-option variables, simply
14201     because users _might_ want to customize them differently in
14202     different buffers.  Users can make any variable local, when they
14203     wish to.  It is better to leave the choice to them.
14204
14205     The time to use ‘make-variable-buffer-local’ is when it is crucial
14206     that no two buffers ever share the same binding.  For example, when
14207     a variable is used for internal purposes in a Lisp program which
14208     depends on having separate values in separate buffers, then using
14209     ‘make-variable-buffer-local’ can be the best solution.
14210
14211 -- Macro: defvar-local variable value &optional docstring
14212     This macro defines VARIABLE as a variable with initial value VALUE
14213     and DOCSTRING, and marks it as automatically buffer-local.  It is
14214     equivalent to calling ‘defvar’ followed by
14215     ‘make-variable-buffer-local’.  VARIABLE should be an unquoted
14216     symbol.
14217
14218 -- Function: local-variable-p variable &optional buffer
14219     This returns ‘t’ if VARIABLE is buffer-local in buffer BUFFER
14220     (which defaults to the current buffer); otherwise, ‘nil’.
14221
14222 -- Function: local-variable-if-set-p variable &optional buffer
14223     This returns ‘t’ if VARIABLE either has a buffer-local value in
14224     buffer BUFFER, or is automatically buffer-local.  Otherwise, it
14225     returns ‘nil’.  If omitted or ‘nil’, BUFFER defaults to the current
14226     buffer.
14227
14228 -- Function: buffer-local-value variable buffer
14229     This function returns the buffer-local binding of VARIABLE (a
14230     symbol) in buffer BUFFER.  If VARIABLE does not have a buffer-local
14231     binding in buffer BUFFER, it returns the default value (*note
14232     Default Value::) of VARIABLE instead.
14233
14234 -- Function: buffer-local-variables &optional buffer
14235     This function returns a list describing the buffer-local variables
14236     in buffer BUFFER.  (If BUFFER is omitted, the current buffer is
14237     used.)  Normally, each list element has the form ‘(SYM . VAL)’,
14238     where SYM is a buffer-local variable (a symbol) and VAL is its
14239     buffer-local value.  But when a variable’s buffer-local binding in
14240     BUFFER is void, its list element is just SYM.
14241
14242          (make-local-variable 'foobar)
14243          (makunbound 'foobar)
14244          (make-local-variable 'bind-me)
14245          (setq bind-me 69)
14246          (setq lcl (buffer-local-variables))
14247              ;; First, built-in variables local in all buffers:
14248          ⇒ ((mark-active . nil)
14249              (buffer-undo-list . nil)
14250              (mode-name . "Fundamental")
14251              ...
14252              ;; Next, non-built-in buffer-local variables.
14253              ;; This one is buffer-local and void:
14254              foobar
14255              ;; This one is buffer-local and nonvoid:
14256              (bind-me . 69))
14257
14258     Note that storing new values into the CDRs of cons cells in this
14259     list does _not_ change the buffer-local values of the variables.
14260
14261 -- Command: kill-local-variable variable
14262     This function deletes the buffer-local binding (if any) for
14263     VARIABLE (a symbol) in the current buffer.  As a result, the
14264     default binding of VARIABLE becomes visible in this buffer.  This
14265     typically results in a change in the value of VARIABLE, since the
14266     default value is usually different from the buffer-local value just
14267     eliminated.
14268
14269     If you kill the buffer-local binding of a variable that
14270     automatically becomes buffer-local when set, this makes the default
14271     value visible in the current buffer.  However, if you set the
14272     variable again, that will once again create a buffer-local binding
14273     for it.
14274
14275     ‘kill-local-variable’ returns VARIABLE.
14276
14277     This function is a command because it is sometimes useful to kill
14278     one buffer-local variable interactively, just as it is useful to
14279     create buffer-local variables interactively.
14280
14281 -- Function: kill-all-local-variables
14282     This function eliminates all the buffer-local variable bindings of
14283     the current buffer except for variables marked as permanent and
14284     local hook functions that have a non-‘nil’ ‘permanent-local-hook’
14285     property (*note Setting Hooks::).  As a result, the buffer will see
14286     the default values of most variables.
14287
14288     This function also resets certain other information pertaining to
14289     the buffer: it sets the local keymap to ‘nil’, the syntax table to
14290     the value of ‘(standard-syntax-table)’, the case table to
14291     ‘(standard-case-table)’, and the abbrev table to the value of
14292     ‘fundamental-mode-abbrev-table’.
14293
14294     The very first thing this function does is run the normal hook
14295     ‘change-major-mode-hook’ (see below).
14296
14297     Every major mode command begins by calling this function, which has
14298     the effect of switching to Fundamental mode and erasing most of the
14299     effects of the previous major mode.  To ensure that this does its
14300     job, the variables that major modes set should not be marked
14301     permanent.
14302
14303     ‘kill-all-local-variables’ returns ‘nil’.
14304
14305 -- Variable: change-major-mode-hook
14306     The function ‘kill-all-local-variables’ runs this normal hook
14307     before it does anything else.  This gives major modes a way to
14308     arrange for something special to be done if the user switches to a
14309     different major mode.  It is also useful for buffer-specific minor
14310     modes that should be forgotten if the user changes the major mode.
14311
14312     For best results, make this variable buffer-local, so that it will
14313     disappear after doing its job and will not interfere with the
14314     subsequent major mode.  *Note Hooks::.
14315
14316   A buffer-local variable is “permanent” if the variable name (a
14317symbol) has a ‘permanent-local’ property that is non-‘nil’.  Such
14318variables are unaffected by ‘kill-all-local-variables’, and their local
14319bindings are therefore not cleared by changing major modes.  Permanent
14320locals are appropriate for data pertaining to where the file came from
14321or how to save it, rather than with how to edit the contents.
14322
14323
14324File: elisp.info,  Node: Default Value,  Prev: Creating Buffer-Local,  Up: Buffer-Local Variables
14325
1432612.11.3 The Default Value of a Buffer-Local Variable
14327----------------------------------------------------
14328
14329The global value of a variable with buffer-local bindings is also called
14330the “default” value, because it is the value that is in effect whenever
14331neither the current buffer nor the selected frame has its own binding
14332for the variable.
14333
14334   The functions ‘default-value’ and ‘setq-default’ access and change a
14335variable’s default value regardless of whether the current buffer has a
14336buffer-local binding.  For example, you could use ‘setq-default’ to
14337change the default setting of ‘paragraph-start’ for most buffers; and
14338this would work even when you are in a C or Lisp mode buffer that has a
14339buffer-local value for this variable.
14340
14341   The special forms ‘defvar’ and ‘defconst’ also set the default value
14342(if they set the variable at all), rather than any buffer-local value.
14343
14344 -- Function: default-value symbol
14345     This function returns SYMBOL’s default value.  This is the value
14346     that is seen in buffers and frames that do not have their own
14347     values for this variable.  If SYMBOL is not buffer-local, this is
14348     equivalent to ‘symbol-value’ (*note Accessing Variables::).
14349
14350 -- Function: default-boundp symbol
14351     The function ‘default-boundp’ tells you whether SYMBOL’s default
14352     value is nonvoid.  If ‘(default-boundp 'foo)’ returns ‘nil’, then
14353     ‘(default-value 'foo)’ would get an error.
14354
14355     ‘default-boundp’ is to ‘default-value’ as ‘boundp’ is to
14356     ‘symbol-value’.
14357
14358 -- Special Form: setq-default [symbol form]...
14359     This special form gives each SYMBOL a new default value, which is
14360     the result of evaluating the corresponding FORM.  It does not
14361     evaluate SYMBOL, but does evaluate FORM.  The value of the
14362     ‘setq-default’ form is the value of the last FORM.
14363
14364     If a SYMBOL is not buffer-local for the current buffer, and is not
14365     marked automatically buffer-local, ‘setq-default’ has the same
14366     effect as ‘setq’.  If SYMBOL is buffer-local for the current
14367     buffer, then this changes the value that other buffers will see (as
14368     long as they don’t have a buffer-local value), but not the value
14369     that the current buffer sees.
14370
14371          ;; In buffer ‘foo’:
14372          (make-local-variable 'buffer-local)
14373               ⇒ buffer-local
14374          (setq buffer-local 'value-in-foo)
14375               ⇒ value-in-foo
14376          (setq-default buffer-local 'new-default)
14377               ⇒ new-default
14378          buffer-local
14379               ⇒ value-in-foo
14380          (default-value 'buffer-local)
14381               ⇒ new-default
14382
14383          ;; In (the new) buffer ‘bar’:
14384          buffer-local
14385               ⇒ new-default
14386          (default-value 'buffer-local)
14387               ⇒ new-default
14388          (setq buffer-local 'another-default)
14389               ⇒ another-default
14390          (default-value 'buffer-local)
14391               ⇒ another-default
14392
14393          ;; Back in buffer ‘foo’:
14394          buffer-local
14395               ⇒ value-in-foo
14396          (default-value 'buffer-local)
14397               ⇒ another-default
14398
14399 -- Function: set-default symbol value
14400     This function is like ‘setq-default’, except that SYMBOL is an
14401     ordinary evaluated argument.
14402
14403          (set-default (car '(a b c)) 23)
14404               ⇒ 23
14405          (default-value 'a)
14406               ⇒ 23
14407
14408   A variable can be let-bound (*note Local Variables::) to a value.
14409This makes its global value shadowed by the binding; ‘default-value’
14410will then return the value from that binding, not the global value, and
14411‘set-default’ will be prevented from setting the global value (it will
14412change the let-bound value instead).  The following two functions allow
14413to reference the global value even if it’s shadowed by a let-binding.
14414
14415 -- Function: default-toplevel-value symbol
14416     This function returns the “top-level” default value of SYMBOL,
14417     which is its value outside of any let-binding.
14418
14419     (defvar variable 'global-value)
14420         ⇒ variable
14421     (let ((variable 'let-binding))
14422       (default-value 'variable))
14423         ⇒ let-binding
14424     (let ((variable 'let-binding))
14425       (default-toplevel-value 'variable))
14426         ⇒ global-value
14427
14428 -- Function: set-default-toplevel-value symbol value
14429     This function sets the top-level default value of SYMBOL to the
14430     specified VALUE.  This comes in handy when you want to set the
14431     global value of SYMBOL regardless of whether your code runs in the
14432     context of SYMBOL’s let-binding.
14433
14434
14435File: elisp.info,  Node: File Local Variables,  Next: Directory Local Variables,  Prev: Buffer-Local Variables,  Up: Variables
14436
1443712.12 File Local Variables
14438==========================
14439
14440A file can specify local variable values; Emacs uses these to create
14441buffer-local bindings for those variables in the buffer visiting that
14442file.  *Note Local Variables in Files: (emacs)File Variables, for basic
14443information about file-local variables.  This section describes the
14444functions and variables that affect how file-local variables are
14445processed.
14446
14447   If a file-local variable could specify an arbitrary function or Lisp
14448expression that would be called later, visiting a file could take over
14449your Emacs.  Emacs protects against this by automatically setting only
14450those file-local variables whose specified values are known to be safe.
14451Other file-local variables are set only if the user agrees.
14452
14453   For additional safety, ‘read-circle’ is temporarily bound to ‘nil’
14454when Emacs reads file-local variables (*note Input Functions::).  This
14455prevents the Lisp reader from recognizing circular and shared Lisp
14456structures (*note Circular Objects::).
14457
14458 -- User Option: enable-local-variables
14459     This variable controls whether to process file-local variables.
14460     The possible values are:
14461
14462     ‘t’ (the default)
14463          Set the safe variables, and query (once) about any unsafe
14464          variables.
14465     ‘:safe’
14466          Set only the safe variables and do not query.
14467     ‘:all’
14468          Set all the variables and do not query.
14469     ‘nil’
14470          Don’t set any variables.
14471     anything else
14472          Query (once) about all the variables.
14473
14474 -- Variable: inhibit-local-variables-regexps
14475     This is a list of regular expressions.  If a file has a name
14476     matching an element of this list, then it is not scanned for any
14477     form of file-local variable.  For examples of why you might want to
14478     use this, *note Auto Major Mode::.
14479
14480 -- Function: hack-local-variables &optional handle-mode
14481     This function parses, and binds or evaluates as appropriate, any
14482     local variables specified by the contents of the current buffer.
14483     The variable ‘enable-local-variables’ has its effect here.
14484     However, this function does not look for the ‘mode:’ local variable
14485     in the ‘-*-’ line.  ‘set-auto-mode’ does that, also taking
14486     ‘enable-local-variables’ into account (*note Auto Major Mode::).
14487
14488     This function works by walking the alist stored in
14489     ‘file-local-variables-alist’ and applying each local variable in
14490     turn.  It calls ‘before-hack-local-variables-hook’ and
14491     ‘hack-local-variables-hook’ before and after applying the
14492     variables, respectively.  It only calls the before-hook if the
14493     alist is non-‘nil’; it always calls the other hook.  This function
14494     ignores a ‘mode’ element if it specifies the same major mode as the
14495     buffer already has.
14496
14497     If the optional argument HANDLE-MODE is ‘t’, then all this function
14498     does is return a symbol specifying the major mode, if the ‘-*-’
14499     line or the local variables list specifies one, and ‘nil’
14500     otherwise.  It does not set the mode or any other file-local
14501     variable.  If HANDLE-MODE has any value other than ‘nil’ or ‘t’,
14502     any settings of ‘mode’ in the ‘-*-’ line or the local variables
14503     list are ignored, and the other settings are applied.  If
14504     HANDLE-MODE is ‘nil’, all the file local variables are set.
14505
14506 -- Variable: file-local-variables-alist
14507     This buffer-local variable holds the alist of file-local variable
14508     settings.  Each element of the alist is of the form
14509     ‘(VAR . VALUE)’, where VAR is a symbol of the local variable and
14510     VALUE is its value.  When Emacs visits a file, it first collects
14511     all the file-local variables into this alist, and then the
14512     ‘hack-local-variables’ function applies them one by one.
14513
14514 -- Variable: before-hack-local-variables-hook
14515     Emacs calls this hook immediately before applying file-local
14516     variables stored in ‘file-local-variables-alist’.
14517
14518 -- Variable: hack-local-variables-hook
14519     Emacs calls this hook immediately after it finishes applying
14520     file-local variables stored in ‘file-local-variables-alist’.
14521
14522   You can specify safe values for a variable with a
14523‘safe-local-variable’ property.  The property has to be a function of
14524one argument; any value is safe if the function returns non-‘nil’ given
14525that value.  Many commonly-encountered file variables have
14526‘safe-local-variable’ properties; these include ‘fill-column’,
14527‘fill-prefix’, and ‘indent-tabs-mode’.  For boolean-valued variables
14528that are safe, use ‘booleanp’ as the property value.
14529
14530   If you want to define ‘safe-local-variable’ properties for variables
14531defined in C source code, add the names and the properties of those
14532variables to the list in the “Safe local variables” section of
14533files.el’.
14534
14535   When defining a user option using ‘defcustom’, you can set its
14536‘safe-local-variable’ property by adding the arguments ‘:safe FUNCTION’
14537to ‘defcustom’ (*note Variable Definitions::).  However, a safety
14538predicate defined using ‘:safe’ will only be known once the package that
14539contains the ‘defcustom’ is loaded, which is often too late.  As an
14540alternative, you can use the autoload cookie (*note Autoload::) to
14541assign the option its safety predicate, like this:
14542
14543     ;;;###autoload (put 'VAR 'safe-local-variable 'PRED)
14544
14545The safe value definitions specified with ‘autoload’ are copied into the
14546package’s autoloads file (‘loaddefs.el’ for most packages bundled with
14547Emacs), and are known to Emacs since the beginning of a session.
14548
14549 -- User Option: safe-local-variable-values
14550     This variable provides another way to mark some variable values as
14551     safe.  It is a list of cons cells ‘(VAR . VAL)’, where VAR is a
14552     variable name and VAL is a value which is safe for that variable.
14553
14554     When Emacs asks the user whether or not to obey a set of file-local
14555     variable specifications, the user can choose to mark them as safe.
14556     Doing so adds those variable/value pairs to
14557     ‘safe-local-variable-values’, and saves it to the user’s custom
14558     file.
14559
14560 -- Function: safe-local-variable-p sym val
14561     This function returns non-‘nil’ if it is safe to give SYM the value
14562     VAL, based on the above criteria.
14563
14564   Some variables are considered “risky”.  If a variable is risky, it is
14565never entered automatically into ‘safe-local-variable-values’; Emacs
14566always queries before setting a risky variable, unless the user
14567explicitly allows a value by customizing ‘safe-local-variable-values’
14568directly.
14569
14570   Any variable whose name has a non-‘nil’ ‘risky-local-variable’
14571property is considered risky.  When you define a user option using
14572‘defcustom’, you can set its ‘risky-local-variable’ property by adding
14573the arguments ‘:risky VALUE’ to ‘defcustom’ (*note Variable
14574Definitions::).  In addition, any variable whose name ends in any of
14575‘-command’, ‘-frame-alist’, ‘-function’, ‘-functions’, ‘-hook’,
14576‘-hooks’, ‘-form’, ‘-forms’, ‘-map’, ‘-map-alist’, ‘-mode-alist’,
14577‘-program’, or ‘-predicate’ is automatically considered risky.  The
14578variables ‘font-lock-keywords’, ‘font-lock-keywords’ followed by a
14579digit, and ‘font-lock-syntactic-keywords’ are also considered risky.
14580
14581 -- Function: risky-local-variable-p sym
14582     This function returns non-‘nil’ if SYM is a risky variable, based
14583     on the above criteria.
14584
14585 -- Variable: ignored-local-variables
14586     This variable holds a list of variables that should not be given
14587     local values by files.  Any value specified for one of these
14588     variables is completely ignored.
14589
14590   The ‘Eval:’ “variable” is also a potential loophole, so Emacs
14591normally asks for confirmation before handling it.
14592
14593 -- User Option: enable-local-eval
14594     This variable controls processing of ‘Eval:’ in ‘-*-’ lines or
14595     local variables lists in files being visited.  A value of ‘t’ means
14596     process them unconditionally; ‘nil’ means ignore them; anything
14597     else means ask the user what to do for each file.  The default
14598     value is ‘maybe’.
14599
14600 -- User Option: safe-local-eval-forms
14601     This variable holds a list of expressions that are safe to evaluate
14602     when found in the ‘Eval:’ “variable” in a file local variables
14603     list.
14604
14605   If the expression is a function call and the function has a
14606‘safe-local-eval-function’ property, the property value determines
14607whether the expression is safe to evaluate.  The property value can be a
14608predicate to call to test the expression, a list of such predicates
14609(it’s safe if any predicate succeeds), or ‘t’ (always safe provided the
14610arguments are constant).
14611
14612   Text properties are also potential loopholes, since their values
14613could include functions to call.  So Emacs discards all text properties
14614from string values specified for file-local variables.
14615
14616
14617File: elisp.info,  Node: Directory Local Variables,  Next: Connection Local Variables,  Prev: File Local Variables,  Up: Variables
14618
1461912.13 Directory Local Variables
14620===============================
14621
14622A directory can specify local variable values common to all files in
14623that directory; Emacs uses these to create buffer-local bindings for
14624those variables in buffers visiting any file in that directory.  This is
14625useful when the files in the directory belong to some “project” and
14626therefore share the same local variables.
14627
14628   There are two different methods for specifying directory local
14629variables: by putting them in a special file, or by defining a “project
14630class” for that directory.
14631
14632 -- Constant: dir-locals-file
14633     This constant is the name of the file where Emacs expects to find
14634     the directory-local variables.  The name of the file is
14635.dir-locals.el’(1).  A file by that name in a directory causes
14636     Emacs to apply its settings to any file in that directory or any of
14637     its subdirectories (optionally, you can exclude subdirectories; see
14638     below).  If some of the subdirectories have their own
14639.dir-locals.el’ files, Emacs uses the settings from the deepest
14640     file it finds starting from the file’s directory and moving up the
14641     directory tree.  This constant is also used to derive the name of a
14642     second dir-locals file ‘.dir-locals-2.el’.  If this second
14643     dir-locals file is present, then that is loaded in addition to
14644.dir-locals.el’.  This is useful when ‘.dir-locals.el’ is under
14645     version control in a shared repository and cannot be used for
14646     personal customizations.  The file specifies local variables as a
14647     specially formatted list; see *note Per-directory Local Variables:
14648     (emacs)Directory Variables, for more details.
14649
14650 -- Function: hack-dir-local-variables
14651     This function reads the ‘.dir-locals.el’ file and stores the
14652     directory-local variables in ‘file-local-variables-alist’ that is
14653     local to the buffer visiting any file in the directory, without
14654     applying them.  It also stores the directory-local settings in
14655     ‘dir-locals-class-alist’, where it defines a special class for the
14656     directory in which ‘.dir-locals.el’ file was found.  This function
14657     works by calling ‘dir-locals-set-class-variables’ and
14658     ‘dir-locals-set-directory-class’, described below.
14659
14660 -- Function: hack-dir-local-variables-non-file-buffer
14661     This function looks for directory-local variables, and immediately
14662     applies them in the current buffer.  It is intended to be called in
14663     the mode commands for non-file buffers, such as Dired buffers, to
14664     let them obey directory-local variable settings.  For non-file
14665     buffers, Emacs looks for directory-local variables in
14666     ‘default-directory’ and its parent directories.
14667
14668 -- Function: dir-locals-set-class-variables class variables
14669     This function defines a set of variable settings for the named
14670     CLASS, which is a symbol.  You can later assign the class to one or
14671     more directories, and Emacs will apply those variable settings to
14672     all files in those directories.  The list in VARIABLES can be of
14673     one of the two forms: ‘(MAJOR-MODE . ALIST)’ or ‘(DIRECTORY .
14674     LIST)’.  With the first form, if the file’s buffer turns on a mode
14675     that is derived from MAJOR-MODE, then all the variables in the
14676     associated ALIST are applied; ALIST should be of the form ‘(NAME .
14677     VALUE)’.  A special value ‘nil’ for MAJOR-MODE means the settings
14678     are applicable to any mode.  In ALIST, you can use a special NAME:
14679     ‘subdirs’.  If the associated value is ‘nil’, the alist is only
14680     applied to files in the relevant directory, not to those in any
14681     subdirectories.
14682
14683     With the second form of VARIABLES, if DIRECTORY is the initial
14684     substring of the file’s directory, then LIST is applied recursively
14685     by following the above rules; LIST should be of one of the two
14686     forms accepted by this function in VARIABLES.
14687
14688 -- Function: dir-locals-set-directory-class directory class &optional
14689          mtime
14690     This function assigns CLASS to all the files in ‘directory’ and its
14691     subdirectories.  Thereafter, all the variable settings specified
14692     for CLASS will be applied to any visited file in DIRECTORY and its
14693     children.  CLASS must have been already defined by
14694     ‘dir-locals-set-class-variables’.
14695
14696     Emacs uses this function internally when it loads directory
14697     variables from a ‘.dir-locals.el’ file.  In that case, the optional
14698     argument MTIME holds the file modification time (as returned by
14699     ‘file-attributes’).  Emacs uses this time to check stored local
14700     variables are still valid.  If you are assigning a class directly,
14701     not via a file, this argument should be ‘nil’.
14702
14703 -- Variable: dir-locals-class-alist
14704     This alist holds the class symbols and the associated variable
14705     settings.  It is updated by ‘dir-locals-set-class-variables’.
14706
14707 -- Variable: dir-locals-directory-cache
14708     This alist holds directory names, their assigned class names, and
14709     modification times of the associated directory local variables file
14710     (if there is one).  The function ‘dir-locals-set-directory-class’
14711     updates this list.
14712
14713 -- Variable: enable-dir-local-variables
14714     If ‘nil’, directory-local variables are ignored.  This variable may
14715     be useful for modes that want to ignore directory-locals while
14716     still respecting file-local variables (*note File Local
14717     Variables::).
14718
14719   ---------- Footnotes ----------
14720
14721   (1) The MS-DOS version of Emacs uses ‘_dir-locals.el’ instead, due to
14722limitations of the DOS filesystems.
14723
14724
14725File: elisp.info,  Node: Connection Local Variables,  Next: Variable Aliases,  Prev: Directory Local Variables,  Up: Variables
14726
1472712.14 Connection Local Variables
14728================================
14729
14730Connection-local variables provide a general mechanism for different
14731variable settings in buffers with a remote connection.  They are bound
14732and set depending on the remote connection a buffer is dedicated to.
14733
14734 -- Function: connection-local-set-profile-variables profile variables
14735     This function defines a set of variable settings for the connection
14736     PROFILE, which is a symbol.  You can later assign the connection
14737     profile to one or more remote connections, and Emacs will apply
14738     those variable settings to all process buffers for those
14739     connections.  The list in VARIABLES is an alist of the form
14740     ‘(NAME . VALUE)’.  Example:
14741
14742          (connection-local-set-profile-variables
14743            'remote-bash
14744            '((shell-file-name . "/bin/bash")
14745              (shell-command-switch . "-c")
14746              (shell-interactive-switch . "-i")
14747              (shell-login-switch . "-l")))
14748
14749          (connection-local-set-profile-variables
14750            'remote-ksh
14751            '((shell-file-name . "/bin/ksh")
14752              (shell-command-switch . "-c")
14753              (shell-interactive-switch . "-i")
14754              (shell-login-switch . "-l")))
14755
14756          (connection-local-set-profile-variables
14757            'remote-null-device
14758            '((null-device . "/dev/null")))
14759
14760 -- Variable: connection-local-profile-alist
14761     This alist holds the connection profile symbols and the associated
14762     variable settings.  It is updated by
14763     ‘connection-local-set-profile-variables’.
14764
14765 -- Function: connection-local-set-profiles criteria &rest profiles
14766     This function assigns PROFILES, which are symbols, to all remote
14767     connections identified by CRITERIA.  CRITERIA is a plist
14768     identifying a connection and the application using this connection.
14769     Property names might be ‘:application’, ‘:protocol’, ‘:user’ and
14770     ‘:machine’.  The property value of ‘:application’ is a symbol, all
14771     other property values are strings.  All properties are optional; if
14772     CRITERIA is ‘nil’, it always applies.  Example:
14773
14774          (connection-local-set-profiles
14775            '(:application 'tramp :protocol "ssh" :machine "localhost")
14776            'remote-bash 'remote-null-device)
14777
14778          (connection-local-set-profiles
14779            '(:application 'tramp :protocol "sudo"
14780              :user "root" :machine "localhost")
14781            'remote-ksh 'remote-null-device)
14782
14783     If CRITERIA is ‘nil’, it applies for all remote connections.
14784     Therefore, the example above would be equivalent to
14785
14786          (connection-local-set-profiles
14787            '(:application 'tramp :protocol "ssh" :machine "localhost")
14788            'remote-bash)
14789
14790          (connection-local-set-profiles
14791            '(:application 'tramp :protocol "sudo"
14792              :user "root" :machine "localhost")
14793            'remote-ksh)
14794
14795          (connection-local-set-profiles
14796            nil 'remote-null-device)
14797
14798     Any connection profile of PROFILES must have been already defined
14799     by ‘connection-local-set-profile-variables’.
14800
14801 -- Variable: connection-local-criteria-alist
14802     This alist contains connection criteria and their assigned profile
14803     names.  The function ‘connection-local-set-profiles’ updates this
14804     list.
14805
14806 -- Function: hack-connection-local-variables criteria
14807     This function collects applicable connection-local variables
14808     associated with CRITERIA in ‘connection-local-variables-alist’,
14809     without applying them.  Example:
14810
14811          (hack-connection-local-variables
14812            '(:application 'tramp :protocol "ssh" :machine "localhost"))
14813
14814          connection-local-variables-alist
14815               ⇒ ((null-device . "/dev/null")
14816                  (shell-login-switch . "-l")
14817                  (shell-interactive-switch . "-i")
14818                  (shell-command-switch . "-c")
14819                  (shell-file-name . "/bin/bash"))
14820
14821 -- Function: hack-connection-local-variables-apply criteria
14822     This function looks for connection-local variables according to
14823     CRITERIA, and immediately applies them in the current buffer.
14824
14825 -- Macro: with-connection-local-variables &rest body
14826     All connection-local variables, which are specified by
14827     ‘default-directory’, are applied.
14828
14829     After that, BODY is executed, and the connection-local variables
14830     are unwound.  Example:
14831
14832          (connection-local-set-profile-variables
14833            'remote-perl
14834            '((perl-command-name . "/usr/local/bin/perl")
14835              (perl-command-switch . "-e %s")))
14836
14837          (connection-local-set-profiles
14838            '(:application 'tramp :protocol "ssh" :machine "remotehost")
14839            'remote-perl)
14840
14841          (let ((default-directory "/ssh:remotehost:/working/dir/"))
14842            (with-connection-local-variables
14843              do something useful))
14844
14845 -- Variable: enable-connection-local-variables
14846     If ‘nil’, connection-local variables are ignored.  This variable
14847     shall be changed temporarily only in special modes.
14848
14849
14850File: elisp.info,  Node: Variable Aliases,  Next: Variables with Restricted Values,  Prev: Connection Local Variables,  Up: Variables
14851
1485212.15 Variable Aliases
14853======================
14854
14855It is sometimes useful to make two variables synonyms, so that both
14856variables always have the same value, and changing either one also
14857changes the other.  Whenever you change the name of a variable—either
14858because you realize its old name was not well chosen, or because its
14859meaning has partly changed—it can be useful to keep the old name as an
14860_alias_ of the new one for compatibility.  You can do this with
14861‘defvaralias’.
14862
14863 -- Function: defvaralias new-alias base-variable &optional docstring
14864     This function defines the symbol NEW-ALIAS as a variable alias for
14865     symbol BASE-VARIABLE.  This means that retrieving the value of
14866     NEW-ALIAS returns the value of BASE-VARIABLE, and changing the
14867     value of NEW-ALIAS changes the value of BASE-VARIABLE.  The two
14868     aliased variable names always share the same value and the same
14869     bindings.
14870
14871     If the DOCSTRING argument is non-‘nil’, it specifies the
14872     documentation for NEW-ALIAS; otherwise, the alias gets the same
14873     documentation as BASE-VARIABLE has, if any, unless BASE-VARIABLE is
14874     itself an alias, in which case NEW-ALIAS gets the documentation of
14875     the variable at the end of the chain of aliases.
14876
14877     This function returns BASE-VARIABLE.
14878
14879   Variable aliases are convenient for replacing an old name for a
14880variable with a new name.  ‘make-obsolete-variable’ declares that the
14881old name is obsolete and therefore that it may be removed at some stage
14882in the future.
14883
14884 -- Function: make-obsolete-variable obsolete-name current-name when
14885          &optional access-type
14886     This function makes the byte compiler warn that the variable
14887     OBSOLETE-NAME is obsolete.  If CURRENT-NAME is a symbol, it is the
14888     variable’s new name; then the warning message says to use
14889     CURRENT-NAME instead of OBSOLETE-NAME.  If CURRENT-NAME is a
14890     string, this is the message and there is no replacement variable.
14891     WHEN should be a string indicating when the variable was first made
14892     obsolete (usually a version number string).
14893
14894     The optional argument ACCESS-TYPE, if non-‘nil’, should specify the
14895     kind of access that will trigger obsolescence warnings; it can be
14896     either ‘get’ or ‘set’.
14897
14898   You can make two variables synonyms and declare one obsolete at the
14899same time using the macro ‘define-obsolete-variable-alias’.
14900
14901 -- Macro: define-obsolete-variable-alias obsolete-name current-name
14902          &optional when docstring
14903     This macro marks the variable OBSOLETE-NAME as obsolete and also
14904     makes it an alias for the variable CURRENT-NAME.  It is equivalent
14905     to the following:
14906
14907          (defvaralias OBSOLETE-NAME CURRENT-NAME DOCSTRING)
14908          (make-obsolete-variable OBSOLETE-NAME CURRENT-NAME WHEN)
14909
14910 -- Function: indirect-variable variable
14911     This function returns the variable at the end of the chain of
14912     aliases of VARIABLE.  If VARIABLE is not a symbol, or if VARIABLE
14913     is not defined as an alias, the function returns VARIABLE.
14914
14915     This function signals a ‘cyclic-variable-indirection’ error if
14916     there is a loop in the chain of symbols.
14917
14918     (defvaralias 'foo 'bar)
14919     (indirect-variable 'foo)
14920          ⇒ bar
14921     (indirect-variable 'bar)
14922          ⇒ bar
14923     (setq bar 2)
14924     bar
14925          ⇒ 2
14926     foo
14927          ⇒ 2
14928     (setq foo 0)
14929     bar
14930          ⇒ 0
14931     foo
14932          ⇒ 0
14933
14934
14935File: elisp.info,  Node: Variables with Restricted Values,  Next: Generalized Variables,  Prev: Variable Aliases,  Up: Variables
14936
1493712.16 Variables with Restricted Values
14938======================================
14939
14940Ordinary Lisp variables can be assigned any value that is a valid Lisp
14941object.  However, certain Lisp variables are not defined in Lisp, but in
14942C.  Most of these variables are defined in the C code using
14943‘DEFVAR_LISP’.  Like variables defined in Lisp, these can take on any
14944value.  However, some variables are defined using ‘DEFVAR_INT’ or
14945‘DEFVAR_BOOL’.  *Note Writing Emacs Primitives: Defining Lisp variables
14946in C, in particular the description of functions of the type
14947‘syms_of_FILENAME’, for a brief discussion of the C implementation.
14948
14949   Variables of type ‘DEFVAR_BOOL’ can only take on the values ‘nil’ or
14950‘t’.  Attempting to assign them any other value will set them to ‘t’:
14951
14952     (let ((display-hourglass 5))
14953       display-hourglass)
14954          ⇒ t
14955
14956 -- Variable: byte-boolean-vars
14957     This variable holds a list of all variables of type ‘DEFVAR_BOOL’.
14958
14959   Variables of type ‘DEFVAR_INT’ can take on only integer values.
14960Attempting to assign them any other value will result in an error:
14961
14962     (setq undo-limit 1000.0)
14963     error→ Wrong type argument: integerp, 1000.0
14964
14965
14966File: elisp.info,  Node: Generalized Variables,  Prev: Variables with Restricted Values,  Up: Variables
14967
1496812.17 Generalized Variables
14969===========================
14970
14971A “generalized variable” or “place form” is one of the many places in
14972Lisp memory where values can be stored using the ‘setf’ macro (*note
14973Setting Generalized Variables::).  The simplest place form is a regular
14974Lisp variable.  But the CARs and CDRs of lists, elements of arrays,
14975properties of symbols, and many other locations are also places where
14976Lisp values get stored.
14977
14978   Generalized variables are analogous to lvalues in the C language,
14979where ‘x = a[i]’ gets an element from an array and ‘a[i] = x’ stores an
14980element using the same notation.  Just as certain forms like ‘a[i]’ can
14981be lvalues in C, there is a set of forms that can be generalized
14982variables in Lisp.
14983
14984* Menu:
14985
14986* Setting Generalized Variables::   The ‘setf’ macro.
14987* Adding Generalized Variables::    Defining new ‘setf’ forms.
14988
14989
14990File: elisp.info,  Node: Setting Generalized Variables,  Next: Adding Generalized Variables,  Up: Generalized Variables
14991
1499212.17.1 The ‘setf’ Macro
14993------------------------
14994
14995The ‘setf’ macro is the most basic way to operate on generalized
14996variables.  The ‘setf’ form is like ‘setq’, except that it accepts
14997arbitrary place forms on the left side rather than just symbols.  For
14998example, ‘(setf (car a) b)’ sets the car of ‘a’ to ‘b’, doing the same
14999operation as ‘(setcar a b)’, but without you having to use two separate
15000functions for setting and accessing this type of place.
15001
15002 -- Macro: setf [place form]...
15003     This macro evaluates FORM and stores it in PLACE, which must be a
15004     valid generalized variable form.  If there are several PLACE and
15005     FORM pairs, the assignments are done sequentially just as with
15006     ‘setq’.  ‘setf’ returns the value of the last FORM.
15007
15008   The following Lisp forms are the forms in Emacs that will work as
15009generalized variables, and so may appear in the PLACE argument of
15010‘setf’:
15011
15012   • A symbol.  In other words, ‘(setf x y)’ is exactly equivalent to
15013     ‘(setq x y)’, and ‘setq’ itself is strictly speaking redundant
15014     given that ‘setf’ exists.  Most programmers will continue to prefer
15015     ‘setq’ for setting simple variables, though, for stylistic and
15016     historical reasons.  The macro ‘(setf x y)’ actually expands to
15017     ‘(setq x y)’, so there is no performance penalty for using it in
15018     compiled code.
15019
15020   • A call to any of the following standard Lisp functions:
15021
15022          aref      cddr      symbol-function
15023          car       elt       symbol-plist
15024          caar      get       symbol-value
15025          cadr      gethash
15026          cdr       nth
15027          cdar      nthcdr
15028
15029   • A call to any of the following Emacs-specific functions:
15030
15031          alist-get                     process-get
15032          frame-parameter               process-sentinel
15033          terminal-parameter            window-buffer
15034          keymap-parent                 window-display-table
15035          match-data                    window-dedicated-p
15036          overlay-get                   window-hscroll
15037          overlay-start                 window-parameter
15038          overlay-end                   window-point
15039          process-buffer                window-start
15040          process-filter                default-value
15041
15042‘setf’ signals an error if you pass a PLACE form that it does not know
15043how to handle.
15044
15045   Note that for ‘nthcdr’, the list argument of the function must itself
15046be a valid PLACE form.  For example, ‘(setf (nthcdr 0 foo) 7)’ will set
15047‘foo’ itself to 7.
15048
15049   The macros ‘push’ (*note List Variables::) and ‘pop’ (*note List
15050Elements::) can manipulate generalized variables, not just lists.  ‘(pop
15051PLACE)’ removes and returns the first element of the list stored in
15052PLACE.  It is analogous to ‘(prog1 (car PLACE) (setf PLACE (cdr
15053PLACE)))’, except that it takes care to evaluate all subforms only once.
15054‘(push X PLACE)’ inserts X at the front of the list stored in PLACE.  It
15055is analogous to ‘(setf PLACE (cons X PLACE))’, except for evaluation of
15056the subforms.  Note that ‘push’ and ‘pop’ on an ‘nthcdr’ place can be
15057used to insert or delete at any position in a list.
15058
15059   The ‘cl-lib’ library defines various extensions for generalized
15060variables, including additional ‘setf’ places.  *Note (cl)Generalized
15061Variables::.
15062
15063
15064File: elisp.info,  Node: Adding Generalized Variables,  Prev: Setting Generalized Variables,  Up: Generalized Variables
15065
1506612.17.2 Defining new ‘setf’ forms
15067---------------------------------
15068
15069This section describes how to define new forms that ‘setf’ can operate
15070on.
15071
15072 -- Macro: gv-define-simple-setter name setter &optional fix-return
15073     This macro enables you to easily define ‘setf’ methods for simple
15074     cases.  NAME is the name of a function, macro, or special form.
15075     You can use this macro whenever NAME has a directly corresponding
15076     SETTER function that updates it, e.g., ‘(gv-define-simple-setter
15077     car setcar)’.
15078
15079     This macro translates a call of the form
15080
15081          (setf (NAME ARGS...) VALUE)
15082
15083     into
15084          (SETTER ARGS... VALUE)
15085
15086     Such a ‘setf’ call is documented to return VALUE.  This is no
15087     problem with, e.g., ‘car’ and ‘setcar’, because ‘setcar’ returns
15088     the value that it set.  If your SETTER function does not return
15089     VALUE, use a non-‘nil’ value for the FIX-RETURN argument of
15090     ‘gv-define-simple-setter’.  This expands into something equivalent
15091     to
15092          (let ((temp VALUE))
15093            (SETTER ARGS... temp)
15094            temp)
15095     so ensuring that it returns the correct result.
15096
15097 -- Macro: gv-define-setter name arglist &rest body
15098     This macro allows for more complex ‘setf’ expansions than the
15099     previous form.  You may need to use this form, for example, if
15100     there is no simple setter function to call, or if there is one but
15101     it requires different arguments to the place form.
15102
15103     This macro expands the form ‘(setf (NAME ARGS...) VALUE)’ by first
15104     binding the ‘setf’ argument forms ‘(VALUE ARGS...)’ according to
15105     ARGLIST, and then executing BODY.  BODY should return a Lisp form
15106     that does the assignment, and finally returns the value that was
15107     set.  An example of using this macro is:
15108
15109          (gv-define-setter caar (val x) `(setcar (car ,x) ,val))
15110
15111 -- Macro: gv-define-expander name handler
15112     For more control over the expansion, the ‘gv-define-expander’ macro
15113     can be used.  For instance, a settable ‘substring’ could be
15114     implemented this way:
15115
15116          (gv-define-expander substring
15117            (lambda (do place from &optional to)
15118              (gv-letplace (getter setter) place
15119                (macroexp-let2* nil ((start from) (end to))
15120                  (funcall do `(substring ,getter ,start ,end)
15121                           (lambda (v)
15122                             (funcall setter `(cl--set-substring
15123                                               ,getter ,start ,end ,v))))))))
15124
15125 -- Macro: gv-letplace (getter setter) place &rest body
15126     The macro ‘gv-letplace’ can be useful in defining macros that
15127     perform similarly to ‘setf’; for example, the ‘incf’ macro of
15128     Common Lisp could be implemented this way:
15129
15130          (defmacro incf (place &optional n)
15131            (gv-letplace (getter setter) place
15132              (macroexp-let2 nil v (or n 1)
15133                (funcall setter `(+ ,v ,getter)))))
15134
15135     GETTER will be bound to a copyable expression that returns the
15136     value of PLACE.  SETTER will be bound to a function that takes an
15137     expression V and returns a new expression that sets PLACE to V.
15138     BODY should return a Emacs Lisp expression manipulating PLACE via
15139     GETTER and SETTER.
15140
15141   Consult the source file ‘gv.el’ for more details.
15142
15143     Common Lisp note: Common Lisp defines another way to specify the
15144     ‘setf’ behavior of a function, namely ‘setf’ functions, whose names
15145     are lists ‘(setf NAME)’ rather than symbols.  For example, ‘(defun
15146     (setf foo) ...)’ defines the function that is used when ‘setf’ is
15147     applied to ‘foo’.  Emacs does not support this.  It is a
15148     compile-time error to use ‘setf’ on a form that has not already had
15149     an appropriate expansion defined.  In Common Lisp, this is not an
15150     error since the function ‘(setf FUNC)’ might be defined later.
15151
15152
15153File: elisp.info,  Node: Functions,  Next: Macros,  Prev: Variables,  Up: Top
15154
1515513 Functions
15156************
15157
15158A Lisp program is composed mainly of Lisp functions.  This chapter
15159explains what functions are, how they accept arguments, and how to
15160define them.
15161
15162* Menu:
15163
15164* What Is a Function::          Lisp functions vs. primitives; terminology.
15165* Lambda Expressions::          How functions are expressed as Lisp objects.
15166* Function Names::              A symbol can serve as the name of a function.
15167* Defining Functions::          Lisp expressions for defining functions.
15168* Calling Functions::           How to use an existing function.
15169* Mapping Functions::           Applying a function to each element of a list, etc.
15170* Anonymous Functions::         Lambda expressions are functions with no names.
15171* Generic Functions::           Polymorphism, Emacs-style.
15172* Function Cells::              Accessing or setting the function definition
15173                            of a symbol.
15174* Closures::                    Functions that enclose a lexical environment.
15175* Advising Functions::          Adding to the definition of a function.
15176* Obsolete Functions::          Declaring functions obsolete.
15177* Inline Functions::            Functions that the compiler will expand inline.
15178* Declare Form::                Adding additional information about a function.
15179* Declaring Functions::         Telling the compiler that a function is defined.
15180* Function Safety::             Determining whether a function is safe to call.
15181* Related Topics::              Cross-references to specific Lisp primitives
15182                            that have a special bearing on how functions work.
15183
15184
15185File: elisp.info,  Node: What Is a Function,  Next: Lambda Expressions,  Up: Functions
15186
1518713.1 What Is a Function?
15188========================
15189
15190In a general sense, a function is a rule for carrying out a computation
15191given input values called “arguments”.  The result of the computation is
15192called the “value” or “return value” of the function.  The computation
15193can also have side effects, such as lasting changes in the values of
15194variables or the contents of data structures (*note Definition of side
15195effect::).  A “pure function” is a function which, in addition to having
15196no side effects, always returns the same value for the same combination
15197of arguments, regardless of external factors such as machine type or
15198system state.
15199
15200   In most computer languages, every function has a name.  But in Lisp,
15201a function in the strictest sense has no name: it is an object which can
15202_optionally_ be associated with a symbol (e.g., ‘car’) that serves as
15203the function name.  *Note Function Names::.  When a function has been
15204given a name, we usually also refer to that symbol as a “function”
15205(e.g., we refer to “the function ‘car’”).  In this manual, the
15206distinction between a function name and the function object itself is
15207usually unimportant, but we will take note wherever it is relevant.
15208
15209   Certain function-like objects, called “special forms” and “macros”,
15210also accept arguments to carry out computations.  However, as explained
15211below, these are not considered functions in Emacs Lisp.
15212
15213   Here are important terms for functions and function-like objects:
15214
15215“lambda expression”
15216     A function (in the strict sense, i.e., a function object) which is
15217     written in Lisp.  These are described in the following section.
15218     *Note Lambda Expressions::.
15219
15220“primitive”
15221     A function which is callable from Lisp but is actually written in
15222     C.  Primitives are also called “built-in functions”, or “subrs”.
15223     Examples include functions like ‘car’ and ‘append’.  In addition,
15224     all special forms (see below) are also considered primitives.
15225
15226     Usually, a function is implemented as a primitive because it is a
15227     fundamental part of Lisp (e.g., ‘car’), or because it provides a
15228     low-level interface to operating system services, or because it
15229     needs to run fast.  Unlike functions defined in Lisp, primitives
15230     can be modified or added only by changing the C sources and
15231     recompiling Emacs.  See *note Writing Emacs Primitives::.
15232
15233“special form”
15234     A primitive that is like a function but does not evaluate all of
15235     its arguments in the usual way.  It may evaluate only some of the
15236     arguments, or may evaluate them in an unusual order, or several
15237     times.  Examples include ‘if’, ‘and’, and ‘while’.  *Note Special
15238     Forms::.
15239
15240“macro”
15241     A construct defined in Lisp, which differs from a function in that
15242     it translates a Lisp expression into another expression which is to
15243     be evaluated instead of the original expression.  Macros enable
15244     Lisp programmers to do the sorts of things that special forms can
15245     do.  *Note Macros::.
15246
15247“command”
15248     An object which can be invoked via the ‘command-execute’ primitive,
15249     usually due to the user typing in a key sequence “bound” to that
15250     command.  *Note Interactive Call::.  A command is usually a
15251     function; if the function is written in Lisp, it is made into a
15252     command by an ‘interactive’ form in the function definition (*note
15253     Defining Commands::).  Commands that are functions can also be
15254     called from Lisp expressions, just like other functions.
15255
15256     Keyboard macros (strings and vectors) are commands also, even
15257     though they are not functions.  *Note Keyboard Macros::.  We say
15258     that a symbol is a command if its function cell contains a command
15259     (*note Symbol Components::); such a “named command” can be invoked
15260     with ‘M-x’.
15261
15262“closure”
15263     A function object that is much like a lambda expression, except
15264     that it also encloses an environment of lexical variable bindings.
15265     *Note Closures::.
15266
15267“byte-code function”
15268     A function that has been compiled by the byte compiler.  *Note
15269     Byte-Code Type::.
15270
15271“autoload object”
15272     A place-holder for a real function.  If the autoload object is
15273     called, Emacs loads the file containing the definition of the real
15274     function, and then calls the real function.  *Note Autoload::.
15275
15276   You can use the function ‘functionp’ to test if an object is a
15277function:
15278
15279 -- Function: functionp object
15280     This function returns ‘t’ if OBJECT is any kind of function, i.e.,
15281     can be passed to ‘funcall’.  Note that ‘functionp’ returns ‘t’ for
15282     symbols that are function names, and returns ‘nil’ for special
15283     forms.
15284
15285   It is also possible to find out how many arguments an arbitrary
15286function expects:
15287
15288 -- Function: func-arity function
15289     This function provides information about the argument list of the
15290     specified FUNCTION.  The returned value is a cons cell of the form
15291     ‘(MIN . MAX)’, where MIN is the minimum number of arguments, and
15292     MAX is either the maximum number of arguments, or the symbol ‘many’
15293     for functions with ‘&rest’ arguments, or the symbol ‘unevalled’ if
15294     FUNCTION is a special form.
15295
15296     Note that this function might return inaccurate results in some
15297     situations, such as the following:
15298
15299        − Functions defined using ‘apply-partially’ (*note
15300          apply-partially: Calling Functions.).
15301
15302        − Functions that are advised using ‘advice-add’ (*note Advising
15303          Named Functions::).
15304
15305        − Functions that determine the argument list dynamically, as
15306          part of their code.
15307
15308Unlike ‘functionp’, the next three functions do _not_ treat a symbol as
15309its function definition.
15310
15311 -- Function: subrp object
15312     This function returns ‘t’ if OBJECT is a built-in function (i.e., a
15313     Lisp primitive).
15314
15315          (subrp 'message)            ; ‘message’ is a symbol,
15316               ⇒ nil                 ;   not a subr object.
15317          (subrp (symbol-function 'message))
15318               ⇒ t
15319
15320 -- Function: byte-code-function-p object
15321     This function returns ‘t’ if OBJECT is a byte-code function.  For
15322     example:
15323
15324          (byte-code-function-p (symbol-function 'next-line))
15325               ⇒ t
15326
15327 -- Function: subr-arity subr
15328     This works like ‘func-arity’, but only for built-in functions and
15329     without symbol indirection.  It signals an error for non-built-in
15330     functions.  We recommend to use ‘func-arity’ instead.
15331
15332
15333File: elisp.info,  Node: Lambda Expressions,  Next: Function Names,  Prev: What Is a Function,  Up: Functions
15334
1533513.2 Lambda Expressions
15336=======================
15337
15338A lambda expression is a function object written in Lisp.  Here is an
15339example:
15340
15341     (lambda (x)
15342       "Return the hyperbolic cosine of X."
15343       (* 0.5 (+ (exp x) (exp (- x)))))
15344
15345In Emacs Lisp, such a list is a valid expression which evaluates to a
15346function object.
15347
15348   A lambda expression, by itself, has no name; it is an “anonymous
15349function”.  Although lambda expressions can be used this way (*note
15350Anonymous Functions::), they are more commonly associated with symbols
15351to make “named functions” (*note Function Names::).  Before going into
15352these details, the following subsections describe the components of a
15353lambda expression and what they do.
15354
15355* Menu:
15356
15357* Lambda Components::           The parts of a lambda expression.
15358* Simple Lambda::               A simple example.
15359* Argument List::               Details and special features of argument lists.
15360* Function Documentation::      How to put documentation in a function.
15361
15362
15363File: elisp.info,  Node: Lambda Components,  Next: Simple Lambda,  Up: Lambda Expressions
15364
1536513.2.1 Components of a Lambda Expression
15366----------------------------------------
15367
15368A lambda expression is a list that looks like this:
15369
15370     (lambda (ARG-VARIABLES...)
15371       [DOCUMENTATION-STRING]
15372       [INTERACTIVE-DECLARATION]
15373       BODY-FORMS...)
15374
15375   The first element of a lambda expression is always the symbol
15376‘lambda’.  This indicates that the list represents a function.  The
15377reason functions are defined to start with ‘lambda’ is so that other
15378lists, intended for other uses, will not accidentally be valid as
15379functions.
15380
15381   The second element is a list of symbols—the argument variable names
15382(*note Argument List::).  This is called the “lambda list”.  When a Lisp
15383function is called, the argument values are matched up against the
15384variables in the lambda list, which are given local bindings with the
15385values provided.  *Note Local Variables::.
15386
15387   The documentation string is a Lisp string object placed within the
15388function definition to describe the function for the Emacs help
15389facilities.  *Note Function Documentation::.
15390
15391   The interactive declaration is a list of the form ‘(interactive
15392CODE-STRING)’.  This declares how to provide arguments if the function
15393is used interactively.  Functions with this declaration are called
15394“commands”; they can be called using ‘M-x’ or bound to a key.  Functions
15395not intended to be called in this way should not have interactive
15396declarations.  *Note Defining Commands::, for how to write an
15397interactive declaration.
15398
15399   The rest of the elements are the “body” of the function: the Lisp
15400code to do the work of the function (or, as a Lisp programmer would say,
15401“a list of Lisp forms to evaluate”).  The value returned by the function
15402is the value returned by the last element of the body.
15403
15404
15405File: elisp.info,  Node: Simple Lambda,  Next: Argument List,  Prev: Lambda Components,  Up: Lambda Expressions
15406
1540713.2.2 A Simple Lambda Expression Example
15408-----------------------------------------
15409
15410Consider the following example:
15411
15412     (lambda (a b c) (+ a b c))
15413
15414We can call this function by passing it to ‘funcall’, like this:
15415
15416     (funcall (lambda (a b c) (+ a b c))
15417              1 2 3)
15418
15419This call evaluates the body of the lambda expression with the variable
15420‘a’ bound to 1, ‘b’ bound to 2, and ‘c’ bound to 3.  Evaluation of the
15421body adds these three numbers, producing the result 6; therefore, this
15422call to the function returns the value 6.
15423
15424   Note that the arguments can be the results of other function calls,
15425as in this example:
15426
15427     (funcall (lambda (a b c) (+ a b c))
15428              1 (* 2 3) (- 5 4))
15429
15430This evaluates the arguments ‘1’, ‘(* 2 3)’, and ‘(- 5 4)’ from left to
15431right.  Then it applies the lambda expression to the argument values 1,
154326 and 1 to produce the value 8.
15433
15434   As these examples show, you can use a form with a lambda expression
15435as its CAR to make local variables and give them values.  In the old
15436days of Lisp, this technique was the only way to bind and initialize
15437local variables.  But nowadays, it is clearer to use the special form
15438‘let’ for this purpose (*note Local Variables::).  Lambda expressions
15439are mainly used as anonymous functions for passing as arguments to other
15440functions (*note Anonymous Functions::), or stored as symbol function
15441definitions to produce named functions (*note Function Names::).
15442
15443
15444File: elisp.info,  Node: Argument List,  Next: Function Documentation,  Prev: Simple Lambda,  Up: Lambda Expressions
15445
1544613.2.3 Features of Argument Lists
15447---------------------------------
15448
15449Our simple sample function, ‘(lambda (a b c) (+ a b c))’, specifies
15450three argument variables, so it must be called with three arguments: if
15451you try to call it with only two arguments or four arguments, you get a
15452‘wrong-number-of-arguments’ error (*note Errors::).
15453
15454   It is often convenient to write a function that allows certain
15455arguments to be omitted.  For example, the function ‘substring’ accepts
15456three arguments—a string, the start index and the end index—but the
15457third argument defaults to the LENGTH of the string if you omit it.  It
15458is also convenient for certain functions to accept an indefinite number
15459of arguments, as the functions ‘list’ and ‘+’ do.
15460
15461   To specify optional arguments that may be omitted when a function is
15462called, simply include the keyword ‘&optional’ before the optional
15463arguments.  To specify a list of zero or more extra arguments, include
15464the keyword ‘&rest’ before one final argument.
15465
15466   Thus, the complete syntax for an argument list is as follows:
15467
15468     (REQUIRED-VARS...
15469      [&optional [OPTIONAL-VARS...]]
15470      [&rest [REST-VAR]])
15471
15472The square brackets indicate that the ‘&optional’ and ‘&rest’ clauses,
15473and the variables that follow them, are optional.
15474
15475   A call to the function requires one actual argument for each of the
15476REQUIRED-VARS.  There may be actual arguments for zero or more of the
15477OPTIONAL-VARS, and there cannot be any actual arguments beyond that
15478unless the lambda list uses ‘&rest’.  In that case, there may be any
15479number of extra actual arguments.
15480
15481   If actual arguments for the optional and rest variables are omitted,
15482then they always default to ‘nil’.  There is no way for the function to
15483distinguish between an explicit argument of ‘nil’ and an omitted
15484argument.  However, the body of the function is free to consider ‘nil’
15485an abbreviation for some other meaningful value.  This is what
15486‘substring’ does; ‘nil’ as the third argument to ‘substring’ means to
15487use the length of the string supplied.
15488
15489     Common Lisp note: Common Lisp allows the function to specify what
15490     default value to use when an optional argument is omitted; Emacs
15491     Lisp always uses ‘nil’.  Emacs Lisp does not support ‘supplied-p’
15492     variables that tell you whether an argument was explicitly passed.
15493
15494   For example, an argument list that looks like this:
15495
15496     (a b &optional c d &rest e)
15497
15498binds ‘a’ and ‘b’ to the first two actual arguments, which are required.
15499If one or two more arguments are provided, ‘c’ and ‘d’ are bound to them
15500respectively; any arguments after the first four are collected into a
15501list and ‘e’ is bound to that list.  Thus, if there are only two
15502arguments, ‘c’, ‘d’ and ‘e’ are ‘nil’; if two or three arguments, ‘d’
15503and ‘e’ are ‘nil’; if four arguments or fewer, ‘e’ is ‘nil’.  Note that
15504exactly five arguments with an explicit ‘nil’ argument provided for ‘e’
15505will cause that ‘nil’ argument to be passed as a list with one element,
15506‘(nil)’, as with any other single value for ‘e’.
15507
15508   There is no way to have required arguments following optional ones—it
15509would not make sense.  To see why this must be so, suppose that ‘c’ in
15510the example were optional and ‘d’ were required.  Suppose three actual
15511arguments are given; which variable would the third argument be for?
15512Would it be used for the C, or for D?  One can argue for both
15513possibilities.  Similarly, it makes no sense to have any more arguments
15514(either required or optional) after a ‘&rest’ argument.
15515
15516   Here are some examples of argument lists and proper calls:
15517
15518     (funcall (lambda (n) (1+ n))        ; One required:
15519              1)                         ; requires exactly one argument.
15520          ⇒ 2
15521     (funcall (lambda (n &optional n1)   ; One required and one optional:
15522                (if n1 (+ n n1) (1+ n))) ; 1 or 2 arguments.
15523              1 2)
15524          ⇒ 3
15525     (funcall (lambda (n &rest ns)       ; One required and one rest:
15526                (+ n (apply '+ ns)))     ; 1 or more arguments.
15527              1 2 3 4 5)
15528          ⇒ 15
15529
15530
15531File: elisp.info,  Node: Function Documentation,  Prev: Argument List,  Up: Lambda Expressions
15532
1553313.2.4 Documentation Strings of Functions
15534-----------------------------------------
15535
15536A lambda expression may optionally have a “documentation string” just
15537after the lambda list.  This string does not affect execution of the
15538function; it is a kind of comment, but a systematized comment which
15539actually appears inside the Lisp world and can be used by the Emacs help
15540facilities.  *Note Documentation::, for how the documentation string is
15541accessed.
15542
15543   It is a good idea to provide documentation strings for all the
15544functions in your program, even those that are called only from within
15545your program.  Documentation strings are like comments, except that they
15546are easier to access.
15547
15548   The first line of the documentation string should stand on its own,
15549because ‘apropos’ displays just this first line.  It should consist of
15550one or two complete sentences that summarize the function’s purpose.
15551
15552   The start of the documentation string is usually indented in the
15553source file, but since these spaces come before the starting
15554double-quote, they are not part of the string.  Some people make a
15555practice of indenting any additional lines of the string so that the
15556text lines up in the program source.  _That is a mistake._  The
15557indentation of the following lines is inside the string; what looks nice
15558in the source code will look ugly when displayed by the help commands.
15559
15560   You may wonder how the documentation string could be optional, since
15561there are required components of the function that follow it (the body).
15562Since evaluation of a string returns that string, without any side
15563effects, it has no effect if it is not the last form in the body.  Thus,
15564in practice, there is no confusion between the first form of the body
15565and the documentation string; if the only body form is a string then it
15566serves both as the return value and as the documentation.
15567
15568   The last line of the documentation string can specify calling
15569conventions different from the actual function arguments.  Write text
15570like this:
15571
15572     \(fn ARGLIST)
15573
15574following a blank line, at the beginning of the line, with no newline
15575following it inside the documentation string.  (The ‘\’ is used to avoid
15576confusing the Emacs motion commands.)  The calling convention specified
15577in this way appears in help messages in place of the one derived from
15578the actual arguments of the function.
15579
15580   This feature is particularly useful for macro definitions, since the
15581arguments written in a macro definition often do not correspond to the
15582way users think of the parts of the macro call.
15583
15584   Do not use this feature if you want to deprecate the calling
15585convention and favor the one you advertise by the above specification.
15586Instead, use the ‘advertised-calling-convention’ declaration (*note
15587Declare Form::) or ‘set-advertised-calling-convention’ (*note Obsolete
15588Functions::), because these two will cause the byte compiler emit a
15589warning message when it compiles Lisp programs which use the deprecated
15590calling convention.
15591
15592
15593File: elisp.info,  Node: Function Names,  Next: Defining Functions,  Prev: Lambda Expressions,  Up: Functions
15594
1559513.3 Naming a Function
15596======================
15597
15598A symbol can serve as the name of a function.  This happens when the
15599symbol’s “function cell” (*note Symbol Components::) contains a function
15600object (e.g., a lambda expression).  Then the symbol itself becomes a
15601valid, callable function, equivalent to the function object in its
15602function cell.
15603
15604   The contents of the function cell are also called the symbol’s
15605“function definition”.  The procedure of using a symbol’s function
15606definition in place of the symbol is called “symbol function
15607indirection”; see *note Function Indirection::.  If you have not given a
15608symbol a function definition, its function cell is said to be “void”,
15609and it cannot be used as a function.
15610
15611   In practice, nearly all functions have names, and are referred to by
15612their names.  You can create a named Lisp function by defining a lambda
15613expression and putting it in a function cell (*note Function Cells::).
15614However, it is more common to use the ‘defun’ special form, described in
15615the next section.  *Note Defining Functions::.
15616
15617   We give functions names because it is convenient to refer to them by
15618their names in Lisp expressions.  Also, a named Lisp function can easily
15619refer to itself—it can be recursive.  Furthermore, primitives can only
15620be referred to textually by their names, since primitive function
15621objects (*note Primitive Function Type::) have no read syntax.
15622
15623   A function need not have a unique name.  A given function object
15624_usually_ appears in the function cell of only one symbol, but this is
15625just a convention.  It is easy to store it in several symbols using
15626‘fset’; then each of the symbols is a valid name for the same function.
15627
15628   Note that a symbol used as a function name may also be used as a
15629variable; these two uses of a symbol are independent and do not
15630conflict.  (This is not the case in some dialects of Lisp, like Scheme.)
15631
15632   By convention, if a function’s symbol consists of two names separated
15633by ‘--’, the function is intended for internal use and the first part
15634names the file defining the function.  For example, a function named
15635‘vc-git--rev-parse’ is an internal function defined in ‘vc-git.el’.
15636Internal-use functions written in C have names ending in ‘-internal’,
15637e.g., ‘bury-buffer-internal’.  Emacs code contributed before 2018 may
15638follow other internal-use naming conventions, which are being phased
15639out.
15640
15641
15642File: elisp.info,  Node: Defining Functions,  Next: Calling Functions,  Prev: Function Names,  Up: Functions
15643
1564413.4 Defining Functions
15645=======================
15646
15647We usually give a name to a function when it is first created.  This is
15648called “defining a function”, and we usually do it with the ‘defun’
15649macro.  This section also describes other ways to define a function.
15650
15651 -- Macro: defun name args [doc] [declare] [interactive] body...
15652     ‘defun’ is the usual way to define new Lisp functions.  It defines
15653     the symbol NAME as a function with argument list ARGS (*note
15654     Argument List::) and body forms given by BODY.  Neither NAME nor
15655     ARGS should be quoted.
15656
15657     DOC, if present, should be a string specifying the function’s
15658     documentation string (*note Function Documentation::).  DECLARE, if
15659     present, should be a ‘declare’ form specifying function metadata
15660     (*note Declare Form::).  INTERACTIVE, if present, should be an
15661     ‘interactive’ form specifying how the function is to be called
15662     interactively (*note Interactive Call::).
15663
15664     The return value of ‘defun’ is undefined.
15665
15666     Here are some examples:
15667
15668          (defun foo () 5)
15669          (foo)
15670               ⇒ 5
15671
15672          (defun bar (a &optional b &rest c)
15673              (list a b c))
15674          (bar 1 2 3 4 5)
15675               ⇒ (1 2 (3 4 5))
15676          (bar 1)
15677               ⇒ (1 nil nil)
15678          (bar)
15679          error→ Wrong number of arguments.
15680
15681          (defun capitalize-backwards ()
15682            "Upcase the last letter of the word at point."
15683            (interactive)
15684            (backward-word 1)
15685            (forward-word 1)
15686            (backward-char 1)
15687            (capitalize-word 1))
15688
15689     Be careful not to redefine existing functions unintentionally.
15690     ‘defun’ redefines even primitive functions such as ‘car’ without
15691     any hesitation or notification.  Emacs does not prevent you from
15692     doing this, because redefining a function is sometimes done
15693     deliberately, and there is no way to distinguish deliberate
15694     redefinition from unintentional redefinition.
15695
15696 -- Function: defalias name definition &optional doc
15697     This function defines the symbol NAME as a function, with
15698     definition DEFINITION (which can be any valid Lisp function).  Its
15699     return value is _undefined_.
15700
15701     If DOC is non-‘nil’, it becomes the function documentation of NAME.
15702     Otherwise, any documentation provided by DEFINITION is used.
15703
15704     Internally, ‘defalias’ normally uses ‘fset’ to set the definition.
15705     If NAME has a ‘defalias-fset-function’ property, however, the
15706     associated value is used as a function to call in place of ‘fset’.
15707
15708     The proper place to use ‘defalias’ is where a specific function
15709     name is being defined—especially where that name appears explicitly
15710     in the source file being loaded.  This is because ‘defalias’
15711     records which file defined the function, just like ‘defun’ (*note
15712     Unloading::).
15713
15714     By contrast, in programs that manipulate function definitions for
15715     other purposes, it is better to use ‘fset’, which does not keep
15716     such records.  *Note Function Cells::.
15717
15718   You cannot create a new primitive function with ‘defun’ or
15719‘defalias’, but you can use them to change the function definition of
15720any symbol, even one such as ‘car’ or ‘x-popup-menu’ whose normal
15721definition is a primitive.  However, this is risky: for instance, it is
15722next to impossible to redefine ‘car’ without breaking Lisp completely.
15723Redefining an obscure function such as ‘x-popup-menu’ is less dangerous,
15724but it still may not work as you expect.  If there are calls to the
15725primitive from C code, they call the primitive’s C definition directly,
15726so changing the symbol’s definition will have no effect on them.
15727
15728   See also ‘defsubst’, which defines a function like ‘defun’ and tells
15729the Lisp compiler to perform inline expansion on it.  *Note Inline
15730Functions::.
15731
15732   To undefine a function name, use ‘fmakunbound’.  *Note Function
15733Cells::.
15734
15735
15736File: elisp.info,  Node: Calling Functions,  Next: Mapping Functions,  Prev: Defining Functions,  Up: Functions
15737
1573813.5 Calling Functions
15739======================
15740
15741Defining functions is only half the battle.  Functions don’t do anything
15742until you “call” them, i.e., tell them to run.  Calling a function is
15743also known as “invocation”.
15744
15745   The most common way of invoking a function is by evaluating a list.
15746For example, evaluating the list ‘(concat "a" "b")’ calls the function
15747‘concat’ with arguments ‘"a"’ and ‘"b"’.  *Note Evaluation::, for a
15748description of evaluation.
15749
15750   When you write a list as an expression in your program, you specify
15751which function to call, and how many arguments to give it, in the text
15752of the program.  Usually that’s just what you want.  Occasionally you
15753need to compute at run time which function to call.  To do that, use the
15754function ‘funcall’.  When you also need to determine at run time how
15755many arguments to pass, use ‘apply’.
15756
15757 -- Function: funcall function &rest arguments
15758     ‘funcall’ calls FUNCTION with ARGUMENTS, and returns whatever
15759     FUNCTION returns.
15760
15761     Since ‘funcall’ is a function, all of its arguments, including
15762     FUNCTION, are evaluated before ‘funcall’ is called.  This means
15763     that you can use any expression to obtain the function to be
15764     called.  It also means that ‘funcall’ does not see the expressions
15765     you write for the ARGUMENTS, only their values.  These values are
15766     _not_ evaluated a second time in the act of calling FUNCTION; the
15767     operation of ‘funcall’ is like the normal procedure for calling a
15768     function, once its arguments have already been evaluated.
15769
15770     The argument FUNCTION must be either a Lisp function or a primitive
15771     function.  Special forms and macros are not allowed, because they
15772     make sense only when given the unevaluated argument expressions.
15773     ‘funcall’ cannot provide these because, as we saw above, it never
15774     knows them in the first place.
15775
15776     If you need to use ‘funcall’ to call a command and make it behave
15777     as if invoked interactively, use ‘funcall-interactively’ (*note
15778     Interactive Call::).
15779
15780          (setq f 'list)
15781               ⇒ list
15782          (funcall f 'x 'y 'z)
15783               ⇒ (x y z)
15784          (funcall f 'x 'y '(z))
15785               ⇒ (x y (z))
15786          (funcall 'and t nil)
15787          error→ Invalid function: #<subr and>
15788
15789     Compare these examples with the examples of ‘apply’.
15790
15791 -- Function: apply function &rest arguments
15792     ‘apply’ calls FUNCTION with ARGUMENTS, just like ‘funcall’ but with
15793     one difference: the last of ARGUMENTS is a list of objects, which
15794     are passed to FUNCTION as separate arguments, rather than a single
15795     list.  We say that ‘apply’ “spreads” this list so that each
15796     individual element becomes an argument.
15797
15798     ‘apply’ returns the result of calling FUNCTION.  As with ‘funcall’,
15799     FUNCTION must either be a Lisp function or a primitive function;
15800     special forms and macros do not make sense in ‘apply’.
15801
15802          (setq f 'list)
15803               ⇒ list
15804          (apply f 'x 'y 'z)
15805          error→ Wrong type argument: listp, z
15806          (apply '+ 1 2 '(3 4))
15807               ⇒ 10
15808          (apply '+ '(1 2 3 4))
15809               ⇒ 10
15810
15811          (apply 'append '((a b c) nil (x y z) nil))
15812               ⇒ (a b c x y z)
15813
15814     For an interesting example of using ‘apply’, see *note Definition
15815     of mapcar::.
15816
15817   Sometimes it is useful to fix some of the function’s arguments at
15818certain values, and leave the rest of arguments for when the function is
15819actually called.  The act of fixing some of the function’s arguments is
15820called “partial application” of the function(1).  The result is a new
15821function that accepts the rest of arguments and calls the original
15822function with all the arguments combined.
15823
15824   Here’s how to do partial application in Emacs Lisp:
15825
15826 -- Function: apply-partially func &rest args
15827     This function returns a new function which, when called, will call
15828     FUNC with the list of arguments composed from ARGS and additional
15829     arguments specified at the time of the call.  If FUNC accepts N
15830     arguments, then a call to ‘apply-partially’ with ‘M < N’ arguments
15831     will produce a new function of ‘N - M’ arguments.
15832
15833     Here’s how we could define the built-in function ‘1+’, if it didn’t
15834     exist, using ‘apply-partially’ and ‘+’, another built-in function:
15835
15836          (defalias '1+ (apply-partially '+ 1)
15837            "Increment argument by one.")
15838          (1+ 10)
15839               ⇒ 11
15840
15841   It is common for Lisp functions to accept functions as arguments or
15842find them in data structures (especially in hook variables and property
15843lists) and call them using ‘funcall’ or ‘apply’.  Functions that accept
15844function arguments are often called “functionals”.
15845
15846   Sometimes, when you call a functional, it is useful to supply a no-op
15847function as the argument.  Here are two different kinds of no-op
15848function:
15849
15850 -- Function: identity argument
15851     This function returns ARGUMENT and has no side effects.
15852
15853 -- Function: ignore &rest arguments
15854     This function ignores any ARGUMENTS and returns ‘nil’.
15855
15856   Some functions are user-visible “commands”, which can be called
15857interactively (usually by a key sequence).  It is possible to invoke
15858such a command exactly as though it was called interactively, by using
15859the ‘call-interactively’ function.  *Note Interactive Call::.
15860
15861   ---------- Footnotes ----------
15862
15863   (1) This is related to, but different from “currying”, which
15864transforms a function that takes multiple arguments in such a way that
15865it can be called as a chain of functions, each one with a single
15866argument.
15867
15868
15869File: elisp.info,  Node: Mapping Functions,  Next: Anonymous Functions,  Prev: Calling Functions,  Up: Functions
15870
1587113.6 Mapping Functions
15872======================
15873
15874A “mapping function” applies a given function (_not_ a special form or
15875macro) to each element of a list or other collection.  Emacs Lisp has
15876several such functions; this section describes ‘mapcar’, ‘mapc’,
15877‘mapconcat’, and ‘mapcan’, which map over a list.  *Note Definition of
15878mapatoms::, for the function ‘mapatoms’ which maps over the symbols in
15879an obarray.  *Note Definition of maphash::, for the function ‘maphash’
15880which maps over key/value associations in a hash table.
15881
15882   These mapping functions do not allow char-tables because a char-table
15883is a sparse array whose nominal range of indices is very large.  To map
15884over a char-table in a way that deals properly with its sparse nature,
15885use the function ‘map-char-table’ (*note Char-Tables::).
15886
15887 -- Function: mapcar function sequence
15888     ‘mapcar’ applies FUNCTION to each element of SEQUENCE in turn, and
15889     returns a list of the results.
15890
15891     The argument SEQUENCE can be any kind of sequence except a
15892     char-table; that is, a list, a vector, a bool-vector, or a string.
15893     The result is always a list.  The length of the result is the same
15894     as the length of SEQUENCE.  For example:
15895
15896          (mapcar 'car '((a b) (c d) (e f)))
15897               ⇒ (a c e)
15898          (mapcar '1+ [1 2 3])
15899               ⇒ (2 3 4)
15900          (mapcar 'string "abc")
15901               ⇒ ("a" "b" "c")
15902
15903          ;; Call each function in ‘my-hooks’.
15904          (mapcar 'funcall my-hooks)
15905
15906          (defun mapcar* (function &rest args)
15907            "Apply FUNCTION to successive cars of all ARGS.
15908          Return the list of results."
15909            ;; If no list is exhausted,
15910            (if (not (memq nil args))
15911                ;; apply function to CARs.
15912                (cons (apply function (mapcar 'car args))
15913                      (apply 'mapcar* function
15914                             ;; Recurse for rest of elements.
15915                             (mapcar 'cdr args)))))
15916
15917          (mapcar* 'cons '(a b c) '(1 2 3 4))
15918               ⇒ ((a . 1) (b . 2) (c . 3))
15919
15920 -- Function: mapcan function sequence
15921     This function applies FUNCTION to each element of SEQUENCE, like
15922     ‘mapcar’, but instead of collecting the results into a list, it
15923     returns a single list with all the elements of the results (which
15924     must be lists), by altering the results (using ‘nconc’; *note
15925     Rearrangement::).  Like with ‘mapcar’, SEQUENCE can be of any type
15926     except a char-table.
15927
15928          ;; Contrast this:
15929          (mapcar 'list '(a b c d))
15930               ⇒ ((a) (b) (c) (d))
15931          ;; with this:
15932          (mapcan 'list '(a b c d))
15933               ⇒ (a b c d)
15934
15935 -- Function: mapc function sequence
15936     ‘mapc’ is like ‘mapcar’ except that FUNCTION is used for
15937     side-effects only—the values it returns are ignored, not collected
15938     into a list.  ‘mapc’ always returns SEQUENCE.
15939
15940 -- Function: mapconcat function sequence separator
15941     ‘mapconcat’ applies FUNCTION to each element of SEQUENCE; the
15942     results, which must be sequences of characters (strings, vectors,
15943     or lists), are concatenated into a single string return value.
15944     Between each pair of result sequences, ‘mapconcat’ inserts the
15945     characters from SEPARATOR, which also must be a string, or a vector
15946     or list of characters.  *Note Sequences Arrays Vectors::.
15947
15948     The argument FUNCTION must be a function that can take one argument
15949     and returns a sequence of characters: a string, a vector, or a
15950     list.  The argument SEQUENCE can be any kind of sequence except a
15951     char-table; that is, a list, a vector, a bool-vector, or a string.
15952
15953          (mapconcat 'symbol-name
15954                     '(The cat in the hat)
15955                     " ")
15956               ⇒ "The cat in the hat"
15957
15958          (mapconcat (lambda (x) (format "%c" (1+ x)))
15959                     "HAL-8000"
15960                     "")
15961               ⇒ "IBM.9111"
15962
15963
15964File: elisp.info,  Node: Anonymous Functions,  Next: Generic Functions,  Prev: Mapping Functions,  Up: Functions
15965
1596613.7 Anonymous Functions
15967========================
15968
15969Although functions are usually defined with ‘defun’ and given names at
15970the same time, it is sometimes convenient to use an explicit lambda
15971expression—an “anonymous function”.  Anonymous functions are valid
15972wherever function names are.  They are often assigned as variable
15973values, or as arguments to functions; for instance, you might pass one
15974as the FUNCTION argument to ‘mapcar’, which applies that function to
15975each element of a list (*note Mapping Functions::).  *Note
15976describe-symbols example::, for a realistic example of this.
15977
15978   When defining a lambda expression that is to be used as an anonymous
15979function, you can in principle use any method to construct the list.
15980But typically you should use the ‘lambda’ macro, or the ‘function’
15981special form, or the ‘#'’ read syntax:
15982
15983 -- Macro: lambda args [doc] [interactive] body...
15984     This macro returns an anonymous function with argument list ARGS,
15985     documentation string DOC (if any), interactive spec INTERACTIVE (if
15986     any), and body forms given by BODY.
15987
15988     Under dynamic binding, this macro effectively makes ‘lambda’ forms
15989     self-quoting: evaluating a form whose CAR is ‘lambda’ yields the
15990     form itself:
15991
15992          (lambda (x) (* x x))
15993               ⇒ (lambda (x) (* x x))
15994
15995     Note that when evaluating under lexical binding the result is a
15996     closure object (*note Closures::).
15997
15998     The ‘lambda’ form has one other effect: it tells the Emacs
15999     evaluator and byte-compiler that its argument is a function, by
16000     using ‘function’ as a subroutine (see below).
16001
16002 -- Special Form: function function-object
16003     This special form returns FUNCTION-OBJECT without evaluating it.
16004     In this, it is similar to ‘quote’ (*note Quoting::).  But unlike
16005     ‘quote’, it also serves as a note to the Emacs evaluator and
16006     byte-compiler that FUNCTION-OBJECT is intended to be used as a
16007     function.  Assuming FUNCTION-OBJECT is a valid lambda expression,
16008     this has two effects:
16009
16010        • When the code is byte-compiled, FUNCTION-OBJECT is compiled
16011          into a byte-code function object (*note Byte Compilation::).
16012
16013        • When lexical binding is enabled, FUNCTION-OBJECT is converted
16014          into a closure.  *Note Closures::.
16015
16016     When FUNCTION-OBJECT is a symbol and the code is byte compiled, the
16017     byte-compiler will warn if that function is not defined or might
16018     not be known at run time.
16019
16020   The read syntax ‘#'’ is a short-hand for using ‘function’.  The
16021following forms are all equivalent:
16022
16023     (lambda (x) (* x x))
16024     (function (lambda (x) (* x x)))
16025     #'(lambda (x) (* x x))
16026
16027   In the following example, we define a ‘change-property’ function that
16028takes a function as its third argument, followed by a ‘double-property’
16029function that makes use of ‘change-property’ by passing it an anonymous
16030function:
16031
16032     (defun change-property (symbol prop function)
16033       (let ((value (get symbol prop)))
16034         (put symbol prop (funcall function value))))
16035
16036     (defun double-property (symbol prop)
16037       (change-property symbol prop (lambda (x) (* 2 x))))
16038
16039Note that we do not quote the ‘lambda’ form.
16040
16041   If you compile the above code, the anonymous function is also
16042compiled.  This would not happen if, say, you had constructed the
16043anonymous function by quoting it as a list:
16044
16045     (defun double-property (symbol prop)
16046       (change-property symbol prop '(lambda (x) (* 2 x))))
16047
16048In that case, the anonymous function is kept as a lambda expression in
16049the compiled code.  The byte-compiler cannot assume this list is a
16050function, even though it looks like one, since it does not know that
16051‘change-property’ intends to use it as a function.
16052
16053
16054File: elisp.info,  Node: Generic Functions,  Next: Function Cells,  Prev: Anonymous Functions,  Up: Functions
16055
1605613.8 Generic Functions
16057======================
16058
16059Functions defined using ‘defun’ have a hard-coded set of assumptions
16060about the types and expected values of their arguments.  For example, a
16061function that was designed to handle values of its argument that are
16062either numbers or lists of numbers will fail or signal an error if
16063called with a value of any other type, such as a vector or a string.
16064This happens because the implementation of the function is not prepared
16065to deal with types other than those assumed during the design.
16066
16067   By contrast, object-oriented programs use “polymorphic functions”: a
16068set of specialized functions having the same name, each one of which was
16069written for a certain specific set of argument types.  Which of the
16070functions is actually called is decided at run time based on the types
16071of the actual arguments.
16072
16073   Emacs provides support for polymorphism.  Like other Lisp
16074environments, notably Common Lisp and its Common Lisp Object System
16075(CLOS), this support is based on “generic functions”.  The Emacs generic
16076functions closely follow CLOS, including use of similar names, so if you
16077have experience with CLOS, the rest of this section will sound very
16078familiar.
16079
16080   A generic function specifies an abstract operation, by defining its
16081name and list of arguments, but (usually) no implementation.  The actual
16082implementation for several specific classes of arguments is provided by
16083“methods”, which should be defined separately.  Each method that
16084implements a generic function has the same name as the generic function,
16085but the method’s definition indicates what kinds of arguments it can
16086handle by “specializing” the arguments defined by the generic function.
16087These “argument specializers” can be more or less specific; for example,
16088a ‘string’ type is more specific than a more general type, such as
16089‘sequence’.
16090
16091   Note that, unlike in message-based OO languages, such as C++ and
16092Simula, methods that implement generic functions don’t belong to a
16093class, they belong to the generic function they implement.
16094
16095   When a generic function is invoked, it selects the applicable methods
16096by comparing the actual arguments passed by the caller with the argument
16097specializers of each method.  A method is applicable if the actual
16098arguments of the call are compatible with the method’s specializers.  If
16099more than one method is applicable, they are combined using certain
16100rules, described below, and the combination then handles the call.
16101
16102 -- Macro: cl-defgeneric name arguments [documentation]
16103          [options-and-methods...] &rest body
16104     This macro defines a generic function with the specified NAME and
16105     ARGUMENTS.  If BODY is present, it provides the default
16106     implementation.  If DOCUMENTATION is present (it should always be),
16107     it specifies the documentation string for the generic function, in
16108     the form ‘(:documentation DOCSTRING)’.  The optional
16109     OPTIONS-AND-METHODS can be one of the following forms:
16110
16111     ‘(declare DECLARATIONS)’
16112          A declare form, as described in *note Declare Form::.
16113     ‘(:argument-precedence-order &rest ARGS)’
16114          This form affects the sorting order for combining applicable
16115          methods.  Normally, when two methods are compared during
16116          combination, method arguments are examined left to right, and
16117          the first method whose argument specializer is more specific
16118          will come before the other one.  The order defined by this
16119          form overrides that, and the arguments are examined according
16120          to their order in this form, and not left to right.
16121     ‘(:method [QUALIFIERS...] args &rest body)’
16122          This form defines a method like ‘cl-defmethod’ does.
16123
16124 -- Macro: cl-defmethod name [qualifier] arguments [&context (expr
16125          spec)...] &rest [docstring] body
16126     This macro defines a particular implementation for the generic
16127     function called NAME.  The implementation code is given by BODY.
16128     If present, DOCSTRING is the documentation string for the method.
16129     The ARGUMENTS list, which must be identical in all the methods that
16130     implement a generic function, and must match the argument list of
16131     that function, provides argument specializers of the form ‘(ARG
16132     SPEC)’, where ARG is the argument name as specified in the
16133     ‘cl-defgeneric’ call, and SPEC is one of the following specializer
16134     forms:
16135
16136     ‘TYPE’
16137          This specializer requires the argument to be of the given
16138          TYPE, one of the types from the type hierarchy described
16139          below.
16140     ‘(eql OBJECT)’
16141          This specializer requires the argument be ‘eql’ to the given
16142          OBJECT.
16143     ‘(head OBJECT)’
16144          The argument must be a cons cell whose ‘car’ is ‘eql’ to
16145          OBJECT.
16146     ‘STRUCT-TYPE’
16147          The argument must be an instance of a class named STRUCT-TYPE
16148          defined with ‘cl-defstruct’ (*note (cl)Structures::), or of
16149          one of its child classes.
16150
16151     Method definitions can make use of a new argument-list keyword,
16152     ‘&context’, which introduces extra specializers that test the
16153     environment at the time the method is run.  This keyword should
16154     appear after the list of required arguments, but before any ‘&rest’
16155     or ‘&optional’ keywords.  The ‘&context’ specializers look much
16156     like regular argument specializers—(EXPR SPEC)—except that EXPR is
16157     an expression to be evaluated in the current context, and the SPEC
16158     is a value to compare against.  For example, ‘&context
16159     (overwrite-mode (eql t))’ will make the method applicable only when
16160     ‘overwrite-mode’ is turned on.  The ‘&context’ keyword can be
16161     followed by any number of context specializers.  Because the
16162     context specializers are not part of the generic function’s
16163     argument signature, they may be omitted in methods that don’t
16164     require them.
16165
16166     The type specializer, ‘(ARG TYPE)’, can specify one of the “system
16167     types” in the following list.  When a parent type is specified, an
16168     argument whose type is any of its more specific child types, as
16169     well as grand-children, grand-grand-children, etc.  will also be
16170     compatible.
16171
16172     ‘integer’
16173          Parent type: ‘number’.
16174     ‘number’
16175     ‘null’
16176          Parent type: ‘symbol’
16177     ‘symbol’
16178     ‘string’
16179          Parent type: ‘array’.
16180     ‘array’
16181          Parent type: ‘sequence’.
16182     ‘cons’
16183          Parent type: ‘list’.
16184     ‘list’
16185          Parent type: ‘sequence’.
16186     ‘marker’
16187     ‘overlay’
16188     ‘float’
16189          Parent type: ‘number’.
16190     ‘window-configuration’
16191     ‘process’
16192     ‘window’
16193     ‘subr’
16194     ‘compiled-function’
16195     ‘buffer’
16196     ‘char-table’
16197          Parent type: ‘array’.
16198     ‘bool-vector’
16199          Parent type: ‘array’.
16200     ‘vector’
16201          Parent type: ‘array’.
16202     ‘frame’
16203     ‘hash-table’
16204     ‘font-spec’
16205     ‘font-entity’
16206     ‘font-object’
16207
16208     The optional QUALIFIER allows combining several applicable methods.
16209     If it is not present, the defined method is a “primary” method,
16210     responsible for providing the primary implementation of the generic
16211     function for the specialized arguments.  You can also define
16212     “auxiliary methods”, by using one of the following values as
16213     QUALIFIER:
16214
16215     ‘:before’
16216          This auxiliary method will run before the primary method.
16217          More accurately, all the ‘:before’ methods will run before the
16218          primary, in the most-specific-first order.
16219     ‘:after’
16220          This auxiliary method will run after the primary method.  More
16221          accurately, all such methods will run after the primary, in
16222          the most-specific-last order.
16223     ‘:around’
16224          This auxiliary method will run _instead_ of the primary
16225          method.  The most specific of such methods will be run before
16226          any other method.  Such methods normally use
16227          ‘cl-call-next-method’, described below, to invoke the other
16228          auxiliary or primary methods.
16229     ‘:extra STRING’
16230          This allows you to add more methods, distinguished by STRING,
16231          for the same specializers and qualifiers.
16232
16233     Functions defined using ‘cl-defmethod’ cannot be made interactive,
16234     i.e. commands (*note Defining Commands::), by adding the
16235     ‘interactive’ form to them.  If you need a polymorphic command, we
16236     recommend defining a normal command that calls a polymorphic
16237     function defined via ‘cl-defgeneric’ and ‘cl-defmethod’.
16238
16239   Each time a generic function is called, it builds the “effective
16240method” which will handle this invocation by combining the applicable
16241methods defined for the function.  The process of finding the applicable
16242methods and producing the effective method is called “dispatch”.  The
16243applicable methods are those all of whose specializers are compatible
16244with the actual arguments of the call.  Since all of the arguments must
16245be compatible with the specializers, they all determine whether a method
16246is applicable.  Methods that explicitly specialize more than one
16247argument are called “multiple-dispatch methods”.
16248
16249   The applicable methods are sorted into the order in which they will
16250be combined.  The method whose left-most argument specializer is the
16251most specific one will come first in the order.  (Specifying
16252‘:argument-precedence-order’ as part of ‘cl-defmethod’ overrides that,
16253as described above.)  If the method body calls ‘cl-call-next-method’,
16254the next most-specific method will run.  If there are applicable
16255‘:around’ methods, the most-specific of them will run first; it should
16256call ‘cl-call-next-method’ to run any of the less specific ‘:around’
16257methods.  Next, the ‘:before’ methods run in the order of their
16258specificity, followed by the primary method, and lastly the ‘:after’
16259methods in the reverse order of their specificity.
16260
16261 -- Function: cl-call-next-method &rest args
16262     When invoked from within the lexical body of a primary or an
16263     ‘:around’ auxiliary method, call the next applicable method for the
16264     same generic function.  Normally, it is called with no arguments,
16265     which means to call the next applicable method with the same
16266     arguments that the calling method was invoked.  Otherwise, the
16267     specified arguments are used instead.
16268
16269 -- Function: cl-next-method-p
16270     This function, when called from within the lexical body of a
16271     primary or an ‘:around’ auxiliary method, returns non-‘nil’ if
16272     there is a next method to call.
16273
16274
16275File: elisp.info,  Node: Function Cells,  Next: Closures,  Prev: Generic Functions,  Up: Functions
16276
1627713.9 Accessing Function Cell Contents
16278=====================================
16279
16280The “function definition” of a symbol is the object stored in the
16281function cell of the symbol.  The functions described here access, test,
16282and set the function cell of symbols.
16283
16284   See also the function ‘indirect-function’.  *Note Definition of
16285indirect-function::.
16286
16287 -- Function: symbol-function symbol
16288     This returns the object in the function cell of SYMBOL.  It does
16289     not check that the returned object is a legitimate function.
16290
16291     If the function cell is void, the return value is ‘nil’.  To
16292     distinguish between a function cell that is void and one set to
16293     ‘nil’, use ‘fboundp’ (see below).
16294
16295          (defun bar (n) (+ n 2))
16296          (symbol-function 'bar)
16297               ⇒ (lambda (n) (+ n 2))
16298          (fset 'baz 'bar)
16299               ⇒ bar
16300          (symbol-function 'baz)
16301               ⇒ bar
16302
16303   If you have never given a symbol any function definition, we say that
16304that symbol’s function cell is “void”.  In other words, the function
16305cell does not have any Lisp object in it.  If you try to call the symbol
16306as a function, Emacs signals a ‘void-function’ error.
16307
16308   Note that void is not the same as ‘nil’ or the symbol ‘void’.  The
16309symbols ‘nil’ and ‘void’ are Lisp objects, and can be stored into a
16310function cell just as any other object can be (and they can be valid
16311functions if you define them in turn with ‘defun’).  A void function
16312cell contains no object whatsoever.
16313
16314   You can test the voidness of a symbol’s function definition with
16315‘fboundp’.  After you have given a symbol a function definition, you can
16316make it void once more using ‘fmakunbound’.
16317
16318 -- Function: fboundp symbol
16319     This function returns ‘t’ if the symbol has an object in its
16320     function cell, ‘nil’ otherwise.  It does not check that the object
16321     is a legitimate function.
16322
16323 -- Function: fmakunbound symbol
16324     This function makes SYMBOL’s function cell void, so that a
16325     subsequent attempt to access this cell will cause a ‘void-function’
16326     error.  It returns SYMBOL.  (See also ‘makunbound’, in *note Void
16327     Variables::.)
16328
16329          (defun foo (x) x)
16330          (foo 1)
16331               ⇒1
16332          (fmakunbound 'foo)
16333               ⇒ foo
16334          (foo 1)
16335          error→ Symbol's function definition is void: foo
16336
16337 -- Function: fset symbol definition
16338     This function stores DEFINITION in the function cell of SYMBOL.
16339     The result is DEFINITION.  Normally DEFINITION should be a function
16340     or the name of a function, but this is not checked.  The argument
16341     SYMBOL is an ordinary evaluated argument.
16342
16343     The primary use of this function is as a subroutine by constructs
16344     that define or alter functions, like ‘defun’ or ‘advice-add’ (*note
16345     Advising Functions::).  You can also use it to give a symbol a
16346     function definition that is not a function, e.g., a keyboard macro
16347     (*note Keyboard Macros::):
16348
16349          ;; Define a named keyboard macro.
16350          (fset 'kill-two-lines "\^u2\^k")
16351               ⇒ "\^u2\^k"
16352
16353     It you wish to use ‘fset’ to make an alternate name for a function,
16354     consider using ‘defalias’ instead.  *Note Definition of defalias::.
16355
16356
16357File: elisp.info,  Node: Closures,  Next: Advising Functions,  Prev: Function Cells,  Up: Functions
16358
1635913.10 Closures
16360==============
16361
16362As explained in *note Variable Scoping::, Emacs can optionally enable
16363lexical binding of variables.  When lexical binding is enabled, any
16364named function that you create (e.g., with ‘defun’), as well as any
16365anonymous function that you create using the ‘lambda’ macro or the
16366‘function’ special form or the ‘#'’ syntax (*note Anonymous
16367Functions::), is automatically converted into a “closure”.
16368
16369   A closure is a function that also carries a record of the lexical
16370environment that existed when the function was defined.  When it is
16371invoked, any lexical variable references within its definition use the
16372retained lexical environment.  In all other respects, closures behave
16373much like ordinary functions; in particular, they can be called in the
16374same way as ordinary functions.
16375
16376   *Note Lexical Binding::, for an example of using a closure.
16377
16378   Currently, an Emacs Lisp closure object is represented by a list with
16379the symbol ‘closure’ as the first element, a list representing the
16380lexical environment as the second element, and the argument list and
16381body forms as the remaining elements:
16382
16383     ;; lexical binding is enabled.
16384     (lambda (x) (* x x))
16385          ⇒ (closure (t) (x) (* x x))
16386
16387However, the fact that the internal structure of a closure is exposed to
16388the rest of the Lisp world is considered an internal implementation
16389detail.  For this reason, we recommend against directly examining or
16390altering the structure of closure objects.
16391
16392
16393File: elisp.info,  Node: Advising Functions,  Next: Obsolete Functions,  Prev: Closures,  Up: Functions
16394
1639513.11 Advising Emacs Lisp Functions
16396===================================
16397
16398When you need to modify a function defined in another library, or when
16399you need to modify a hook like ‘FOO-function’, a process filter, or
16400basically any variable or object field which holds a function value, you
16401can use the appropriate setter function, such as ‘fset’ or ‘defun’ for
16402named functions, ‘setq’ for hook variables, or ‘set-process-filter’ for
16403process filters, but those are often too blunt, completely throwing away
16404the previous value.
16405
16406   The “advice” feature lets you add to the existing definition of a
16407function, by “advising the function”.  This is a cleaner method than
16408redefining the whole function.
16409
16410   Emacs’s advice system provides two sets of primitives for that: the
16411core set, for function values held in variables and object fields (with
16412the corresponding primitives being ‘add-function’ and ‘remove-function’)
16413and another set layered on top of it for named functions (with the main
16414primitives being ‘advice-add’ and ‘advice-remove’).
16415
16416   As a trivial example, here’s how to add advice that’ll modify the
16417return value of a function every time it’s called:
16418
16419     (defun my-double (x)
16420       (* x 2))
16421     (defun my-increase (x)
16422       (+ x 1))
16423     (advice-add 'my-double :filter-return #'my-increase)
16424
16425   After adding this advice, if you call ‘my-double’ with ‘3’, the
16426return value will be ‘7’.  To remove this advice, say
16427
16428     (advice-remove 'my-double #'my-increase)
16429
16430   A more advanced example would be to trace the calls to the process
16431filter of a process PROC:
16432
16433     (defun my-tracing-function (proc string)
16434       (message "Proc %S received %S" proc string))
16435
16436     (add-function :before (process-filter PROC) #'my-tracing-function)
16437
16438   This will cause the process’s output to be passed to
16439‘my-tracing-function’ before being passed to the original process
16440filter.  ‘my-tracing-function’ receives the same arguments as the
16441original function.  When you’re done with it, you can revert to the
16442untraced behavior with:
16443
16444     (remove-function (process-filter PROC) #'my-tracing-function)
16445
16446   Similarly, if you want to trace the execution of the function named
16447‘display-buffer’, you could use:
16448
16449     (defun his-tracing-function (orig-fun &rest args)
16450       (message "display-buffer called with args %S" args)
16451       (let ((res (apply orig-fun args)))
16452         (message "display-buffer returned %S" res)
16453         res))
16454
16455     (advice-add 'display-buffer :around #'his-tracing-function)
16456
16457   Here, ‘his-tracing-function’ is called instead of the original
16458function and receives the original function (additionally to that
16459function’s arguments) as argument, so it can call it if and when it
16460needs to.  When you’re tired of seeing this output, you can revert to
16461the untraced behavior with:
16462
16463     (advice-remove 'display-buffer #'his-tracing-function)
16464
16465   The arguments ‘:before’ and ‘:around’ used in the above examples
16466specify how the two functions are composed, since there are many
16467different ways to do it.  The added function is also called a piece of
16468_advice_.
16469
16470* Menu:
16471
16472* Core Advising Primitives::    Primitives to manipulate advice.
16473* Advising Named Functions::    Advising named functions.
16474* Advice Combinators::          Ways to compose advice.
16475* Porting Old Advice::          Adapting code using the old defadvice.
16476
16477
16478File: elisp.info,  Node: Core Advising Primitives,  Next: Advising Named Functions,  Up: Advising Functions
16479
1648013.11.1 Primitives to manipulate advices
16481----------------------------------------
16482
16483 -- Macro: add-function where place function &optional props
16484     This macro is the handy way to add the advice FUNCTION to the
16485     function stored in PLACE (*note Generalized Variables::).
16486
16487     WHERE determines how FUNCTION is composed with the existing
16488     function, e.g., whether FUNCTION should be called before, or after
16489     the original function.  *Note Advice Combinators::, for the list of
16490     available ways to compose the two functions.
16491
16492     When modifying a variable (whose name will usually end with
16493     ‘-function’), you can choose whether FUNCTION is used globally or
16494     only in the current buffer: if PLACE is just a symbol, then
16495     FUNCTION is added to the global value of PLACE.  Whereas if PLACE
16496     is of the form ‘(local SYMBOL)’, where SYMBOL is an expression
16497     which returns the variable name, then FUNCTION will only be added
16498     in the current buffer.  Finally, if you want to modify a lexical
16499     variable, you will have to use ‘(var VARIABLE)’.
16500
16501     Every function added with ‘add-function’ can be accompanied by an
16502     association list of properties PROPS.  Currently only two of those
16503     properties have a special meaning:
16504
16505     ‘name’
16506          This gives a name to the advice, which ‘remove-function’ can
16507          use to identify which function to remove.  Typically used when
16508          FUNCTION is an anonymous function.
16509
16510     ‘depth’
16511          This specifies how to order the advice, should several pieces
16512          of advice be present.  By default, the depth is 0.  A depth of
16513          100 indicates that this piece of advice should be kept as deep
16514          as possible, whereas a depth of −100 indicates that it should
16515          stay as the outermost piece.  When two pieces of advice
16516          specify the same depth, the most recently added one will be
16517          outermost.
16518
16519          For ‘:before’ advice, being outermost means that this advice
16520          will be run first, before any other advice, whereas being
16521          innermost means that it will run right before the original
16522          function, with no other advice run between itself and the
16523          original function.  Similarly, for ‘:after’ advice innermost
16524          means that it will run right after the original function, with
16525          no other advice run in between, whereas outermost means that
16526          it will be run right at the end after all other advice.  An
16527          innermost ‘:override’ piece of advice will only override the
16528          original function and other pieces of advice will apply to it,
16529          whereas an outermost ‘:override’ piece of advice will override
16530          not only the original function but all other advice applied to
16531          it as well.
16532
16533     If FUNCTION is not interactive, then the combined function will
16534     inherit the interactive spec, if any, of the original function.
16535     Else, the combined function will be interactive and will use the
16536     interactive spec of FUNCTION.  One exception: if the interactive
16537     spec of FUNCTION is a function (i.e., a ‘lambda’ expression or an
16538     ‘fbound’ symbol rather than an expression or a string), then the
16539     interactive spec of the combined function will be a call to that
16540     function with as sole argument the interactive spec of the original
16541     function.  To interpret the spec received as argument, use
16542     ‘advice-eval-interactive-spec’.
16543
16544     Note: The interactive spec of FUNCTION will apply to the combined
16545     function and should hence obey the calling convention of the
16546     combined function rather than that of FUNCTION.  In many cases, it
16547     makes no difference since they are identical, but it does matter
16548     for ‘:around’, ‘:filter-args’, and ‘:filter-return’, where FUNCTION
16549     receives different arguments than the original function stored in
16550     PLACE.
16551
16552 -- Macro: remove-function place function
16553     This macro removes FUNCTION from the function stored in PLACE.
16554     This only works if FUNCTION was added to PLACE using
16555     ‘add-function’.
16556
16557     FUNCTION is compared with functions added to PLACE using ‘equal’,
16558     to try and make it work also with lambda expressions.  It is
16559     additionally compared also with the ‘name’ property of the
16560     functions added to PLACE, which can be more reliable than comparing
16561     lambda expressions using ‘equal’.
16562
16563 -- Function: advice-function-member-p advice function-def
16564     Return non-‘nil’ if ADVICE is already in FUNCTION-DEF.  Like for
16565     ‘remove-function’ above, instead of ADVICE being the actual
16566     function, it can also be the ‘name’ of the piece of advice.
16567
16568 -- Function: advice-function-mapc f function-def
16569     Call the function F for every piece of advice that was added to
16570     FUNCTION-DEF.  F is called with two arguments: the advice function
16571     and its properties.
16572
16573 -- Function: advice-eval-interactive-spec spec
16574     Evaluate the interactive SPEC just like an interactive call to a
16575     function with such a spec would, and then return the corresponding
16576     list of arguments that was built.  E.g.,
16577     ‘(advice-eval-interactive-spec "r\nP")’ will return a list of three
16578     elements, containing the boundaries of the region and the current
16579     prefix argument.
16580
16581     For instance, if you want to make the ‘C-x m’ (‘compose-mail’)
16582     command prompt for a ‘From:’ header, you could say something like
16583     this:
16584
16585          (defun my-compose-mail-advice (orig &rest args)
16586            "Read From: address interactively."
16587            (interactive
16588             (lambda (spec)
16589               (let* ((user-mail-address
16590                       (completing-read "From: "
16591                                        '("one.address@example.net"
16592                                          "alternative.address@example.net")))
16593                      (from (message-make-from user-full-name
16594                                               user-mail-address))
16595                      (spec (advice-eval-interactive-spec spec)))
16596                 ;; Put the From header into the OTHER-HEADERS argument.
16597                 (push (cons 'From from) (nth 2 spec))
16598                 spec)))
16599            (apply orig args))
16600
16601          (advice-add 'compose-mail :around #'my-compose-mail-advice)
16602
16603
16604File: elisp.info,  Node: Advising Named Functions,  Next: Advice Combinators,  Prev: Core Advising Primitives,  Up: Advising Functions
16605
1660613.11.2 Advising Named Functions
16607--------------------------------
16608
16609A common use of advice is for named functions and macros.  You could
16610just use ‘add-function’ as in:
16611
16612     (add-function :around (symbol-function 'FUN) #'his-tracing-function)
16613
16614   But you should use ‘advice-add’ and ‘advice-remove’ for that instead.
16615This separate set of functions to manipulate pieces of advice applied to
16616named functions, offers the following extra features compared to
16617‘add-function’: they know how to deal with macros and autoloaded
16618functions, they let ‘describe-function’ preserve the original docstring
16619as well as document the added advice, and they let you add and remove
16620advice before a function is even defined.
16621
16622   ‘advice-add’ can be useful for altering the behavior of existing
16623calls to an existing function without having to redefine the whole
16624function.  However, it can be a source of bugs, since existing callers
16625to the function may assume the old behavior, and work incorrectly when
16626the behavior is changed by advice.  Advice can also cause confusion in
16627debugging, if the person doing the debugging does not notice or remember
16628that the function has been modified by advice.
16629
16630   For these reasons, advice should be reserved for the cases where you
16631cannot modify a function’s behavior in any other way.  If it is possible
16632to do the same thing via a hook, that is preferable (*note Hooks::).  If
16633you simply want to change what a particular key does, it may be better
16634to write a new command, and remap the old command’s key bindings to the
16635new one (*note Remapping Commands::).
16636
16637   If you are writing code for release, for others to use, try to avoid
16638including advice in it.  If the function you want to advise has no hook
16639to do the job, please talk with the Emacs developers about adding a
16640suitable hook.  Especially, Emacs’s own source files should not put
16641advice on functions in Emacs.  (There are currently a few exceptions to
16642this convention, but we aim to correct them.)  It is generally cleaner
16643to create a new hook in ‘foo’, and make ‘bar’ use the hook, than to have
16644‘bar’ put advice in ‘foo’.
16645
16646   Special forms (*note Special Forms::) cannot be advised, however
16647macros can be advised, in much the same way as functions.  Of course,
16648this will not affect code that has already been macro-expanded, so you
16649need to make sure the advice is installed before the macro is expanded.
16650
16651   It is possible to advise a primitive (*note What Is a Function::),
16652but one should typically _not_ do so, for two reasons.  Firstly, some
16653primitives are used by the advice mechanism, and advising them could
16654cause an infinite recursion.  Secondly, many primitives are called
16655directly from C, and such calls ignore advice; hence, one ends up in a
16656confusing situation where some calls (occurring from Lisp code) obey the
16657advice and other calls (from C code) do not.
16658
16659 -- Macro: define-advice symbol (where lambda-list &optional name depth)
16660          &rest body
16661     This macro defines a piece of advice and adds it to the function
16662     named SYMBOL.  The advice is an anonymous function if NAME is ‘nil’
16663     or a function named ‘symbol@name’.  See ‘advice-add’ for
16664     explanation of other arguments.
16665
16666 -- Function: advice-add symbol where function &optional props
16667     Add the advice FUNCTION to the named function SYMBOL.  WHERE and
16668     PROPS have the same meaning as for ‘add-function’ (*note Core
16669     Advising Primitives::).
16670
16671 -- Function: advice-remove symbol function
16672     Remove the advice FUNCTION from the named function SYMBOL.
16673     FUNCTION can also be the ‘name’ of a piece of advice.
16674
16675 -- Function: advice-member-p function symbol
16676     Return non-‘nil’ if the advice FUNCTION is already in the named
16677     function SYMBOL.  FUNCTION can also be the ‘name’ of a piece of
16678     advice.
16679
16680 -- Function: advice-mapc function symbol
16681     Call FUNCTION for every piece of advice that was added to the named
16682     function SYMBOL.  FUNCTION is called with two arguments: the advice
16683     function and its properties.
16684
16685
16686File: elisp.info,  Node: Advice Combinators,  Next: Porting Old Advice,  Prev: Advising Named Functions,  Up: Advising Functions
16687
1668813.11.3 Ways to compose advice
16689------------------------------
16690
16691Here are the different possible values for the WHERE argument of
16692‘add-function’ and ‘advice-add’, specifying how the advice FUNCTION and
16693the original function should be composed.
16694
16695‘:before’
16696     Call FUNCTION before the old function.  Both functions receive the
16697     same arguments, and the return value of the composition is the
16698     return value of the old function.  More specifically, the
16699     composition of the two functions behaves like:
16700          (lambda (&rest r) (apply FUNCTION r) (apply OLDFUN r))
16701     ‘(add-function :before FUNVAR FUNCTION)’ is comparable for
16702     single-function hooks to ‘(add-hook 'HOOKVAR FUNCTION)’ for normal
16703     hooks.
16704
16705‘:after’
16706     Call FUNCTION after the old function.  Both functions receive the
16707     same arguments, and the return value of the composition is the
16708     return value of the old function.  More specifically, the
16709     composition of the two functions behaves like:
16710          (lambda (&rest r) (prog1 (apply OLDFUN r) (apply FUNCTION r)))
16711     ‘(add-function :after FUNVAR FUNCTION)’ is comparable for
16712     single-function hooks to ‘(add-hook 'HOOKVAR FUNCTION 'append)’ for
16713     normal hooks.
16714
16715‘:override’
16716     This completely replaces the old function with the new one.  The
16717     old function can of course be recovered if you later call
16718     ‘remove-function’.
16719
16720‘:around’
16721     Call FUNCTION instead of the old function, but provide the old
16722     function as an extra argument to FUNCTION.  This is the most
16723     flexible composition.  For example, it lets you call the old
16724     function with different arguments, or many times, or within a
16725     let-binding, or you can sometimes delegate the work to the old
16726     function and sometimes override it completely.  More specifically,
16727     the composition of the two functions behaves like:
16728          (lambda (&rest r) (apply FUNCTION OLDFUN r))
16729
16730‘:before-while’
16731     Call FUNCTION before the old function and don’t call the old
16732     function if FUNCTION returns ‘nil’.  Both functions receive the
16733     same arguments, and the return value of the composition is the
16734     return value of the old function.  More specifically, the
16735     composition of the two functions behaves like:
16736          (lambda (&rest r) (and (apply FUNCTION r) (apply OLDFUN r)))
16737     ‘(add-function :before-while FUNVAR FUNCTION)’ is comparable for
16738     single-function hooks to ‘(add-hook 'HOOKVAR FUNCTION)’ when
16739     HOOKVAR is run via ‘run-hook-with-args-until-failure’.
16740
16741‘:before-until’
16742     Call FUNCTION before the old function and only call the old
16743     function if FUNCTION returns ‘nil’.  More specifically, the
16744     composition of the two functions behaves like:
16745          (lambda (&rest r) (or (apply FUNCTION r) (apply OLDFUN r)))
16746     ‘(add-function :before-until FUNVAR FUNCTION)’ is comparable for
16747     single-function hooks to ‘(add-hook 'HOOKVAR FUNCTION)’ when
16748     HOOKVAR is run via ‘run-hook-with-args-until-success’.
16749
16750‘:after-while’
16751     Call FUNCTION after the old function and only if the old function
16752     returned non-‘nil’.  Both functions receive the same arguments, and
16753     the return value of the composition is the return value of
16754     FUNCTION.  More specifically, the composition of the two functions
16755     behaves like:
16756          (lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r)))
16757     ‘(add-function :after-while FUNVAR FUNCTION)’ is comparable for
16758     single-function hooks to ‘(add-hook 'HOOKVAR FUNCTION 'append)’
16759     when HOOKVAR is run via ‘run-hook-with-args-until-failure’.
16760
16761‘:after-until’
16762     Call FUNCTION after the old function and only if the old function
16763     returned ‘nil’.  More specifically, the composition of the two
16764     functions behaves like:
16765          (lambda (&rest r) (or  (apply OLDFUN r) (apply FUNCTION r)))
16766     ‘(add-function :after-until FUNVAR FUNCTION)’ is comparable for
16767     single-function hooks to ‘(add-hook 'HOOKVAR FUNCTION 'append)’
16768     when HOOKVAR is run via ‘run-hook-with-args-until-success’.
16769
16770‘:filter-args’
16771     Call FUNCTION first and use the result (which should be a list) as
16772     the new arguments to pass to the old function.  More specifically,
16773     the composition of the two functions behaves like:
16774          (lambda (&rest r) (apply OLDFUN (funcall FUNCTION r)))
16775
16776‘:filter-return’
16777     Call the old function first and pass the result to FUNCTION.  More
16778     specifically, the composition of the two functions behaves like:
16779          (lambda (&rest r) (funcall FUNCTION (apply OLDFUN r)))
16780
16781
16782File: elisp.info,  Node: Porting Old Advice,  Prev: Advice Combinators,  Up: Advising Functions
16783
1678413.11.4 Adapting code using the old defadvice
16785---------------------------------------------
16786
16787A lot of code uses the old ‘defadvice’ mechanism, which is largely made
16788obsolete by the new ‘advice-add’, whose implementation and semantics is
16789significantly simpler.
16790
16791   An old piece of advice such as:
16792
16793     (defadvice previous-line (before next-line-at-end
16794                                      (&optional arg try-vscroll))
16795       "Insert an empty line when moving up from the top line."
16796       (if (and next-line-add-newlines (= arg 1)
16797                (save-excursion (beginning-of-line) (bobp)))
16798           (progn
16799             (beginning-of-line)
16800             (newline))))
16801
16802   could be translated in the new advice mechanism into a plain
16803function:
16804
16805     (defun previous-line--next-line-at-end (&optional arg try-vscroll)
16806       "Insert an empty line when moving up from the top line."
16807       (if (and next-line-add-newlines (= arg 1)
16808                (save-excursion (beginning-of-line) (bobp)))
16809           (progn
16810             (beginning-of-line)
16811             (newline))))
16812
16813   Obviously, this does not actually modify ‘previous-line’.  For that
16814the old advice needed:
16815     (ad-activate 'previous-line)
16816   whereas the new advice mechanism needs:
16817     (advice-add 'previous-line :before #'previous-line--next-line-at-end)
16818
16819   Note that ‘ad-activate’ had a global effect: it activated all pieces
16820of advice enabled for that specified function.  If you wanted to only
16821activate or deactivate a particular piece, you needed to _enable_ or
16822_disable_ it with ‘ad-enable-advice’ and ‘ad-disable-advice’.  The new
16823mechanism does away with this distinction.
16824
16825   Around advice such as:
16826
16827     (defadvice foo (around foo-around)
16828       "Ignore case in `foo'."
16829       (let ((case-fold-search t))
16830         ad-do-it))
16831     (ad-activate 'foo)
16832
16833   could translate into:
16834
16835     (defun foo--foo-around (orig-fun &rest args)
16836       "Ignore case in `foo'."
16837       (let ((case-fold-search t))
16838         (apply orig-fun args)))
16839     (advice-add 'foo :around #'foo--foo-around)
16840
16841   Regarding the advice’s _class_, note that the new ‘:before’ is not
16842quite equivalent to the old ‘before’, because in the old advice you
16843could modify the function’s arguments (e.g., with ‘ad-set-arg’), and
16844that would affect the argument values seen by the original function,
16845whereas in the new ‘:before’, modifying an argument via ‘setq’ in the
16846advice has no effect on the arguments seen by the original function.
16847When porting ‘before’ advice which relied on this behavior, you’ll need
16848to turn it into new ‘:around’ or ‘:filter-args’ advice instead.
16849
16850   Similarly old ‘after’ advice could modify the returned value by
16851changing ‘ad-return-value’, whereas new ‘:after’ advice cannot, so when
16852porting such old ‘after’ advice, you’ll need to turn it into new
16853‘:around’ or ‘:filter-return’ advice instead.
16854
16855
16856File: elisp.info,  Node: Obsolete Functions,  Next: Inline Functions,  Prev: Advising Functions,  Up: Functions
16857
1685813.12 Declaring Functions Obsolete
16859==================================
16860
16861You can mark a named function as “obsolete”, meaning that it may be
16862removed at some point in the future.  This causes Emacs to warn that the
16863function is obsolete whenever it byte-compiles code containing that
16864function, and whenever it displays the documentation for that function.
16865In all other respects, an obsolete function behaves like any other
16866function.
16867
16868   The easiest way to mark a function as obsolete is to put a ‘(declare
16869(obsolete ...))’ form in the function’s ‘defun’ definition.  *Note
16870Declare Form::.  Alternatively, you can use the ‘make-obsolete’
16871function, described below.
16872
16873   A macro (*note Macros::) can also be marked obsolete with
16874‘make-obsolete’; this has the same effects as for a function.  An alias
16875for a function or macro can also be marked as obsolete; this makes the
16876alias itself obsolete, not the function or macro which it resolves to.
16877
16878 -- Function: make-obsolete obsolete-name current-name when
16879     This function marks OBSOLETE-NAME as obsolete.  OBSOLETE-NAME
16880     should be a symbol naming a function or macro, or an alias for a
16881     function or macro.
16882
16883     If CURRENT-NAME is a symbol, the warning message says to use
16884     CURRENT-NAME instead of OBSOLETE-NAME.  CURRENT-NAME does not need
16885     to be an alias for OBSOLETE-NAME; it can be a different function
16886     with similar functionality.  CURRENT-NAME can also be a string,
16887     which serves as the warning message.  The message should begin in
16888     lower case, and end with a period.  It can also be ‘nil’, in which
16889     case the warning message provides no additional details.
16890
16891     The argument WHEN should be a string indicating when the function
16892     was first made obsolete—for example, a date or a release number.
16893
16894 -- Macro: define-obsolete-function-alias obsolete-name current-name
16895          when &optional doc
16896     This convenience macro marks the function OBSOLETE-NAME obsolete
16897     and also defines it as an alias for the function CURRENT-NAME.  It
16898     is equivalent to the following:
16899
16900          (defalias OBSOLETE-NAME CURRENT-NAME DOC)
16901          (make-obsolete OBSOLETE-NAME CURRENT-NAME WHEN)
16902
16903   In addition, you can mark a particular calling convention for a
16904function as obsolete:
16905
16906 -- Function: set-advertised-calling-convention function signature when
16907     This function specifies the argument list SIGNATURE as the correct
16908     way to call FUNCTION.  This causes the Emacs byte compiler to issue
16909     a warning whenever it comes across an Emacs Lisp program that calls
16910     FUNCTION any other way (however, it will still allow the code to be
16911     byte compiled).  WHEN should be a string indicating when the
16912     variable was first made obsolete (usually a version number string).
16913
16914     For instance, in old versions of Emacs the ‘sit-for’ function
16915     accepted three arguments, like this
16916
16917            (sit-for seconds milliseconds nodisp)
16918
16919     However, calling ‘sit-for’ this way is considered obsolete (*note
16920     Waiting::).  The old calling convention is deprecated like this:
16921
16922          (set-advertised-calling-convention
16923            'sit-for '(seconds &optional nodisp) "22.1")
16924
16925
16926File: elisp.info,  Node: Inline Functions,  Next: Declare Form,  Prev: Obsolete Functions,  Up: Functions
16927
1692813.13 Inline Functions
16929======================
16930
16931An “inline function” is a function that works just like an ordinary
16932function, except for one thing: when you byte-compile a call to the
16933function (*note Byte Compilation::), the function’s definition is
16934expanded into the caller.
16935
16936   The simple way to define an inline function, is to write ‘defsubst’
16937instead of ‘defun’.  The rest of the definition looks just the same, but
16938using ‘defsubst’ says to make it inline for byte compilation.
16939
16940 -- Macro: defsubst name args [doc] [declare] [interactive] body...
16941     This macro defines an inline function.  Its syntax is exactly the
16942     same as ‘defun’ (*note Defining Functions::).
16943
16944   Making a function inline often makes its function calls run faster.
16945But it also has disadvantages.  For one thing, it reduces flexibility;
16946if you change the definition of the function, calls already inlined
16947still use the old definition until you recompile them.
16948
16949   Another disadvantage is that making a large function inline can
16950increase the size of compiled code both in files and in memory.  Since
16951the speed advantage of inline functions is greatest for small functions,
16952you generally should not make large functions inline.
16953
16954   Also, inline functions do not behave well with respect to debugging,
16955tracing, and advising (*note Advising Functions::).  Since ease of
16956debugging and the flexibility of redefining functions are important
16957features of Emacs, you should not make a function inline, even if it’s
16958small, unless its speed is really crucial, and you’ve timed the code to
16959verify that using ‘defun’ actually has performance problems.
16960
16961   After an inline function is defined, its inline expansion can be
16962performed later on in the same file, just like macros.
16963
16964   It’s possible to use ‘defmacro’ to define a macro to expand into the
16965same code that an inline function would execute (*note Macros::).  But
16966the macro would be limited to direct use in expressions—a macro cannot
16967be called with ‘apply’, ‘mapcar’ and so on.  Also, it takes some work to
16968convert an ordinary function into a macro.  To convert it into an inline
16969function is easy; just replace ‘defun’ with ‘defsubst’.  Since each
16970argument of an inline function is evaluated exactly once, you needn’t
16971worry about how many times the body uses the arguments, as you do for
16972macros.
16973
16974   Alternatively, you can define a function by providing the code which
16975will inline it as a compiler macro.  The following macros make this
16976possible.
16977
16978 -- Macro: define-inline name args [doc] [declare] body...
16979     Define a function NAME by providing code that does its inlining, as
16980     a compiler macro.  The function will accept the argument list ARGS
16981     and will have the specified BODY.
16982
16983     If present, DOC should be the function’s documentation string
16984     (*note Function Documentation::); DECLARE, if present, should be a
16985     ‘declare’ form (*note Declare Form::) specifying the function’s
16986     metadata.
16987
16988   Functions defined via ‘define-inline’ have several advantages with
16989respect to macros defined by ‘defsubst’ or ‘defmacro’:
16990
16991   − They can be passed to ‘mapcar’ (*note Mapping Functions::).
16992
16993   − They are more efficient.
16994
16995   − They can be used as “place forms” to store values (*note
16996     Generalized Variables::).
16997
16998   − They behave in a more predictable way than ‘cl-defsubst’ (*note
16999     (cl)Argument Lists::).
17000
17001   Like ‘defmacro’, a function inlined with ‘define-inline’ inherits the
17002scoping rules, either dynamic or lexical, from the call site.  *Note
17003Variable Scoping::.
17004
17005   The following macros should be used in the body of a function defined
17006by ‘define-inline’.
17007
17008 -- Macro: inline-quote expression
17009     Quote EXPRESSION for ‘define-inline’.  This is similar to the
17010     backquote (*note Backquote::), but quotes code and accepts only
17011     ‘,’, not ‘,@’.
17012
17013 -- Macro: inline-letevals (bindings...) body...
17014     This is similar to ‘let’ (*note Local Variables::): it sets up
17015     local variables as specified by BINDINGS, and then evaluates BODY
17016     with those bindings in effect.  Each element of BINDINGS should be
17017     either a symbol or a list of the form ‘(VAR EXPR)’; the result is
17018     to evaluate EXPR and bind VAR to the result.  The tail of BINDINGS
17019     can be either ‘nil’ or a symbol which should hold a list of
17020     arguments, in which case each argument is evaluated, and the symbol
17021     is bound to the resulting list.
17022
17023 -- Macro: inline-const-p expression
17024     Return non-‘nil’ if the value of EXPRESSION is already known.
17025
17026 -- Macro: inline-const-val expression
17027     Return the value of EXPRESSION.
17028
17029 -- Macro: inline-error format &rest args
17030     Signal an error, formatting ARGS according to FORMAT.
17031
17032   Here’s an example of using ‘define-inline’:
17033
17034     (define-inline myaccessor (obj)
17035       (inline-letevals (obj)
17036         (inline-quote (if (foo-p ,obj) (aref (cdr ,obj) 3) (aref ,obj 2)))))
17037
17038This is equivalent to
17039
17040     (defsubst myaccessor (obj)
17041       (if (foo-p obj) (aref (cdr obj) 3) (aref obj 2)))
17042
17043
17044File: elisp.info,  Node: Declare Form,  Next: Declaring Functions,  Prev: Inline Functions,  Up: Functions
17045
1704613.14 The ‘declare’ Form
17047========================
17048
17049‘declare’ is a special macro which can be used to add meta properties to
17050a function or macro: for example, marking it as obsolete, or giving its
17051forms a special <TAB> indentation convention in Emacs Lisp mode.
17052
17053 -- Macro: declare specs...
17054     This macro ignores its arguments and evaluates to ‘nil’; it has no
17055     run-time effect.  However, when a ‘declare’ form occurs in the
17056     DECLARE argument of a ‘defun’ or ‘defsubst’ function definition
17057     (*note Defining Functions::) or a ‘defmacro’ macro definition
17058     (*note Defining Macros::), it appends the properties specified by
17059     SPECS to the function or macro.  This work is specially performed
17060     by ‘defun’, ‘defsubst’, and ‘defmacro’.
17061
17062     Each element in SPECS should have the form ‘(PROPERTY ARGS...)’,
17063     which should not be quoted.  These have the following effects:
17064
17065     ‘(advertised-calling-convention SIGNATURE WHEN)’
17066          This acts like a call to ‘set-advertised-calling-convention’
17067          (*note Obsolete Functions::); SIGNATURE specifies the correct
17068          argument list for calling the function or macro, and WHEN
17069          should be a string indicating when the old argument list was
17070          first made obsolete.
17071
17072     ‘(debug EDEBUG-FORM-SPEC)’
17073          This is valid for macros only.  When stepping through the
17074          macro with Edebug, use EDEBUG-FORM-SPEC.  *Note Instrumenting
17075          Macro Calls::.
17076
17077     ‘(doc-string N)’
17078          This is used when defining a function or macro which itself
17079          will be used to define entities like functions, macros, or
17080          variables.  It indicates that the Nth argument, if any, should
17081          be considered as a documentation string.
17082
17083     ‘(indent INDENT-SPEC)’
17084          Indent calls to this function or macro according to
17085          INDENT-SPEC.  This is typically used for macros, though it
17086          works for functions too.  *Note Indenting Macros::.
17087
17088     ‘(interactive-only VALUE)’
17089          Set the function’s ‘interactive-only’ property to VALUE.
17090          *Note The interactive-only property::.
17091
17092     ‘(obsolete CURRENT-NAME WHEN)’
17093          Mark the function or macro as obsolete, similar to a call to
17094          ‘make-obsolete’ (*note Obsolete Functions::).  CURRENT-NAME
17095          should be a symbol (in which case the warning message says to
17096          use that instead), a string (specifying the warning message),
17097          or ‘nil’ (in which case the warning message gives no extra
17098          details).  WHEN should be a string indicating when the
17099          function or macro was first made obsolete.
17100
17101     ‘(compiler-macro EXPANDER)’
17102          This can only be used for functions, and tells the compiler to
17103          use EXPANDER as an optimization function.  When encountering a
17104          call to the function, of the form ‘(FUNCTION ARGS...)’, the
17105          macro expander will call EXPANDER with that form as well as
17106          with ARGS..., and EXPANDER can either return a new expression
17107          to use instead of the function call, or it can return just the
17108          form unchanged, to indicate that the function call should be
17109          left alone.  EXPANDER can be a symbol, or it can be a form
17110          ‘(lambda (ARG) BODY)’ in which case ARG will hold the original
17111          function call expression, and the (unevaluated) arguments to
17112          the function can be accessed using the function’s formal
17113          arguments.
17114
17115     ‘(gv-expander EXPANDER)’
17116          Declare EXPANDER to be the function to handle calls to the
17117          macro (or function) as a generalized variable, similarly to
17118          ‘gv-define-expander’.  EXPANDER can be a symbol or it can be
17119          of the form ‘(lambda (ARG) BODY)’ in which case that function
17120          will additionally have access to the macro (or function)’s
17121          arguments.
17122
17123     ‘(gv-setter SETTER)’
17124          Declare SETTER to be the function to handle calls to the macro
17125          (or function) as a generalized variable.  SETTER can be a
17126          symbol in which case it will be passed to
17127          ‘gv-define-simple-setter’, or it can be of the form ‘(lambda
17128          (ARG) BODY)’ in which case that function will additionally
17129          have access to the macro (or function)’s arguments and it will
17130          be passed to ‘gv-define-setter’.
17131
17132
17133File: elisp.info,  Node: Declaring Functions,  Next: Function Safety,  Prev: Declare Form,  Up: Functions
17134
1713513.15 Telling the Compiler that a Function is Defined
17136=====================================================
17137
17138Byte-compiling a file often produces warnings about functions that the
17139compiler doesn’t know about (*note Compiler Errors::).  Sometimes this
17140indicates a real problem, but usually the functions in question are
17141defined in other files which would be loaded if that code is run.  For
17142example, byte-compiling ‘simple.el’ used to warn:
17143
17144     simple.el:8727:1:Warning: the function ‘shell-mode’ is not known to be
17145         defined.
17146
17147   In fact, ‘shell-mode’ is used only in a function that executes
17148‘(require 'shell)’ before calling ‘shell-mode’, so ‘shell-mode’ will be
17149defined properly at run-time.  When you know that such a warning does
17150not indicate a real problem, it is good to suppress the warning.  That
17151makes new warnings which might mean real problems more visible.  You do
17152that with ‘declare-function’.
17153
17154   All you need to do is add a ‘declare-function’ statement before the
17155first use of the function in question:
17156
17157     (declare-function shell-mode "shell" ())
17158
17159   This says that ‘shell-mode’ is defined in ‘shell.el’ (the ‘.el’ can
17160be omitted).  The compiler takes for granted that that file really
17161defines the function, and does not check.
17162
17163   The optional third argument specifies the argument list of
17164‘shell-mode’.  In this case, it takes no arguments (‘nil’ is different
17165from not specifying a value).  In other cases, this might be something
17166like ‘(file &optional overwrite)’.  You don’t have to specify the
17167argument list, but if you do the byte compiler can check that the calls
17168match the declaration.
17169
17170 -- Macro: declare-function function file &optional arglist fileonly
17171     Tell the byte compiler to assume that FUNCTION is defined in the
17172     file FILE.  The optional third argument ARGLIST is either ‘t’,
17173     meaning the argument list is unspecified, or a list of formal
17174     parameters in the same style as ‘defun’.  An omitted ARGLIST
17175     defaults to ‘t’, not ‘nil’; this is atypical behavior for omitted
17176     arguments, and it means that to supply a fourth but not third
17177     argument one must specify ‘t’ for the third-argument placeholder
17178     instead of the usual ‘nil’.  The optional fourth argument FILEONLY
17179     non-‘nil’ means check only that FILE exists, not that it actually
17180     defines FUNCTION.
17181
17182   To verify that these functions really are declared where
17183‘declare-function’ says they are, use ‘check-declare-file’ to check all
17184‘declare-function’ calls in one source file, or use
17185‘check-declare-directory’ check all the files in and under a certain
17186directory.
17187
17188   These commands find the file that ought to contain a function’s
17189definition using ‘locate-library’; if that finds no file, they expand
17190the definition file name relative to the directory of the file that
17191contains the ‘declare-function’ call.
17192
17193   You can also say that a function is a primitive by specifying a file
17194name ending in ‘.c’ or ‘.m’.  This is useful only when you call a
17195primitive that is defined only on certain systems.  Most primitives are
17196always defined, so they will never give you a warning.
17197
17198   Sometimes a file will optionally use functions from an external
17199package.  If you prefix the filename in the ‘declare-function’ statement
17200with ‘ext:’, then it will be checked if it is found, otherwise skipped
17201without error.
17202
17203   There are some function definitions that ‘check-declare’ does not
17204understand (e.g., ‘defstruct’ and some other macros).  In such cases,
17205you can pass a non-‘nil’ FILEONLY argument to ‘declare-function’,
17206meaning to only check that the file exists, not that it actually defines
17207the function.  Note that to do this without having to specify an
17208argument list, you should set the ARGLIST argument to ‘t’ (because ‘nil’
17209means an empty argument list, as opposed to an unspecified one).
17210
17211
17212File: elisp.info,  Node: Function Safety,  Next: Related Topics,  Prev: Declaring Functions,  Up: Functions
17213
1721413.16 Determining whether a Function is Safe to Call
17215====================================================
17216
17217Some major modes, such as SES, call functions that are stored in user
17218files.  (*note (ses)Top::, for more information on SES.)  User files
17219sometimes have poor pedigrees—you can get a spreadsheet from someone
17220you’ve just met, or you can get one through email from someone you’ve
17221never met.  So it is risky to call a function whose source code is
17222stored in a user file until you have determined that it is safe.
17223
17224 -- Function: unsafep form &optional unsafep-vars
17225     Returns ‘nil’ if FORM is a “safe” Lisp expression, or returns a
17226     list that describes why it might be unsafe.  The argument
17227     UNSAFEP-VARS is a list of symbols known to have temporary bindings
17228     at this point; it is mainly used for internal recursive calls.  The
17229     current buffer is an implicit argument, which provides a list of
17230     buffer-local bindings.
17231
17232   Being quick and simple, ‘unsafep’ does a very light analysis and
17233rejects many Lisp expressions that are actually safe.  There are no
17234known cases where ‘unsafep’ returns ‘nil’ for an unsafe expression.
17235However, a safe Lisp expression can return a string with a ‘display’
17236property, containing an associated Lisp expression to be executed after
17237the string is inserted into a buffer.  This associated expression can be
17238a virus.  In order to be safe, you must delete properties from all
17239strings calculated by user code before inserting them into buffers.
17240
17241
17242File: elisp.info,  Node: Related Topics,  Prev: Function Safety,  Up: Functions
17243
1724413.17 Other Topics Related to Functions
17245=======================================
17246
17247Here is a table of several functions that do things related to function
17248calling and function definitions.  They are documented elsewhere, but we
17249provide cross references here.
17250
17251‘apply’
17252     See *note Calling Functions::.
17253
17254‘autoload’
17255     See *note Autoload::.
17256
17257‘call-interactively’
17258     See *note Interactive Call::.
17259
17260‘called-interactively-p’
17261     See *note Distinguish Interactive::.
17262
17263‘commandp’
17264     See *note Interactive Call::.
17265
17266‘documentation’
17267     See *note Accessing Documentation::.
17268
17269‘eval’
17270     See *note Eval::.
17271
17272‘funcall’
17273     See *note Calling Functions::.
17274
17275‘function’
17276     See *note Anonymous Functions::.
17277
17278‘ignore’
17279     See *note Calling Functions::.
17280
17281‘indirect-function’
17282     See *note Function Indirection::.
17283
17284‘interactive’
17285     See *note Using Interactive::.
17286
17287‘interactive-p’
17288     See *note Distinguish Interactive::.
17289
17290‘mapatoms’
17291     See *note Creating Symbols::.
17292
17293‘mapcar’
17294     See *note Mapping Functions::.
17295
17296‘map-char-table’
17297     See *note Char-Tables::.
17298
17299‘mapconcat’
17300     See *note Mapping Functions::.
17301
17302‘undefined’
17303     See *note Functions for Key Lookup::.
17304
17305
17306File: elisp.info,  Node: Macros,  Next: Customization,  Prev: Functions,  Up: Top
17307
1730814 Macros
17309*********
17310
17311“Macros” enable you to define new control constructs and other language
17312features.  A macro is defined much like a function, but instead of
17313telling how to compute a value, it tells how to compute another Lisp
17314expression which will in turn compute the value.  We call this
17315expression the “expansion” of the macro.
17316
17317   Macros can do this because they operate on the unevaluated
17318expressions for the arguments, not on the argument values as functions
17319do.  They can therefore construct an expansion containing these argument
17320expressions or parts of them.
17321
17322   If you are using a macro to do something an ordinary function could
17323do, just for the sake of speed, consider using an inline function
17324instead.  *Note Inline Functions::.
17325
17326* Menu:
17327
17328* Simple Macro::            A basic example.
17329* Expansion::               How, when and why macros are expanded.
17330* Compiling Macros::        How macros are expanded by the compiler.
17331* Defining Macros::         How to write a macro definition.
17332* Problems with Macros::    Don’t evaluate the macro arguments too many times.
17333                              Don’t hide the user’s variables.
17334* Indenting Macros::        Specifying how to indent macro calls.
17335
17336
17337File: elisp.info,  Node: Simple Macro,  Next: Expansion,  Up: Macros
17338
1733914.1 A Simple Example of a Macro
17340================================
17341
17342Suppose we would like to define a Lisp construct to increment a variable
17343value, much like the ‘++’ operator in C.  We would like to write ‘(inc
17344x)’ and have the effect of ‘(setq x (1+ x))’.  Here’s a macro definition
17345that does the job:
17346
17347     (defmacro inc (var)
17348        (list 'setq var (list '1+ var)))
17349
17350   When this is called with ‘(inc x)’, the argument VAR is the symbol
17351‘x’—_not_ the _value_ of ‘x’, as it would be in a function.  The body of
17352the macro uses this to construct the expansion, which is ‘(setq x (1+
17353x))’.  Once the macro definition returns this expansion, Lisp proceeds
17354to evaluate it, thus incrementing ‘x’.
17355
17356 -- Function: macrop object
17357     This predicate tests whether its argument is a macro, and returns
17358     ‘t’ if so, ‘nil’ otherwise.
17359
17360
17361File: elisp.info,  Node: Expansion,  Next: Compiling Macros,  Prev: Simple Macro,  Up: Macros
17362
1736314.2 Expansion of a Macro Call
17364==============================
17365
17366A macro call looks just like a function call in that it is a list which
17367starts with the name of the macro.  The rest of the elements of the list
17368are the arguments of the macro.
17369
17370   Evaluation of the macro call begins like evaluation of a function
17371call except for one crucial difference: the macro arguments are the
17372actual expressions appearing in the macro call.  They are not evaluated
17373before they are given to the macro definition.  By contrast, the
17374arguments of a function are results of evaluating the elements of the
17375function call list.
17376
17377   Having obtained the arguments, Lisp invokes the macro definition just
17378as a function is invoked.  The argument variables of the macro are bound
17379to the argument values from the macro call, or to a list of them in the
17380case of a ‘&rest’ argument.  And the macro body executes and returns its
17381value just as a function body does.
17382
17383   The second crucial difference between macros and functions is that
17384the value returned by the macro body is an alternate Lisp expression,
17385also known as the “expansion” of the macro.  The Lisp interpreter
17386proceeds to evaluate the expansion as soon as it comes back from the
17387macro.
17388
17389   Since the expansion is evaluated in the normal manner, it may contain
17390calls to other macros.  It may even be a call to the same macro, though
17391this is unusual.
17392
17393   Note that Emacs tries to expand macros when loading an uncompiled
17394Lisp file.  This is not always possible, but if it is, it speeds up
17395subsequent execution.  *Note How Programs Do Loading::.
17396
17397   You can see the expansion of a given macro call by calling
17398‘macroexpand’.
17399
17400 -- Function: macroexpand form &optional environment
17401     This function expands FORM, if it is a macro call.  If the result
17402     is another macro call, it is expanded in turn, until something
17403     which is not a macro call results.  That is the value returned by
17404     ‘macroexpand’.  If FORM is not a macro call to begin with, it is
17405     returned as given.
17406
17407     Note that ‘macroexpand’ does not look at the subexpressions of FORM
17408     (although some macro definitions may do so).  Even if they are
17409     macro calls themselves, ‘macroexpand’ does not expand them.
17410
17411     The function ‘macroexpand’ does not expand calls to inline
17412     functions.  Normally there is no need for that, since a call to an
17413     inline function is no harder to understand than a call to an
17414     ordinary function.
17415
17416     If ENVIRONMENT is provided, it specifies an alist of macro
17417     definitions that shadow the currently defined macros.  Byte
17418     compilation uses this feature.
17419
17420          (defmacro inc (var)
17421              (list 'setq var (list '1+ var)))
17422
17423          (macroexpand '(inc r))
17424               ⇒ (setq r (1+ r))
17425
17426          (defmacro inc2 (var1 var2)
17427              (list 'progn (list 'inc var1) (list 'inc var2)))
17428
17429          (macroexpand '(inc2 r s))
17430               ⇒ (progn (inc r) (inc s))  ; ‘inc’ not expanded here.
17431
17432 -- Function: macroexpand-all form &optional environment
17433     ‘macroexpand-all’ expands macros like ‘macroexpand’, but will look
17434     for and expand all macros in FORM, not just at the top-level.  If
17435     no macros are expanded, the return value is ‘eq’ to FORM.
17436
17437     Repeating the example used for ‘macroexpand’ above with
17438     ‘macroexpand-all’, we see that ‘macroexpand-all’ _does_ expand the
17439     embedded calls to ‘inc’:
17440
17441          (macroexpand-all '(inc2 r s))
17442               ⇒ (progn (setq r (1+ r)) (setq s (1+ s)))
17443
17444 -- Function: macroexpand-1 form &optional environment
17445     This function expands macros like ‘macroexpand’, but it only
17446     performs one step of the expansion: if the result is another macro
17447     call, ‘macroexpand-1’ will not expand it.
17448
17449
17450File: elisp.info,  Node: Compiling Macros,  Next: Defining Macros,  Prev: Expansion,  Up: Macros
17451
1745214.3 Macros and Byte Compilation
17453================================
17454
17455You might ask why we take the trouble to compute an expansion for a
17456macro and then evaluate the expansion.  Why not have the macro body
17457produce the desired results directly?  The reason has to do with
17458compilation.
17459
17460   When a macro call appears in a Lisp program being compiled, the Lisp
17461compiler calls the macro definition just as the interpreter would, and
17462receives an expansion.  But instead of evaluating this expansion, it
17463compiles the expansion as if it had appeared directly in the program.
17464As a result, the compiled code produces the value and side effects
17465intended for the macro, but executes at full compiled speed.  This would
17466not work if the macro body computed the value and side effects
17467itself—they would be computed at compile time, which is not useful.
17468
17469   In order for compilation of macro calls to work, the macros must
17470already be defined in Lisp when the calls to them are compiled.  The
17471compiler has a special feature to help you do this: if a file being
17472compiled contains a ‘defmacro’ form, the macro is defined temporarily
17473for the rest of the compilation of that file.
17474
17475   Byte-compiling a file also executes any ‘require’ calls at top-level
17476in the file, so you can ensure that necessary macro definitions are
17477available during compilation by requiring the files that define them
17478(*note Named Features::).  To avoid loading the macro definition files
17479when someone _runs_ the compiled program, write ‘eval-when-compile’
17480around the ‘require’ calls (*note Eval During Compile::).
17481
17482
17483File: elisp.info,  Node: Defining Macros,  Next: Problems with Macros,  Prev: Compiling Macros,  Up: Macros
17484
1748514.4 Defining Macros
17486====================
17487
17488A Lisp macro object is a list whose CAR is ‘macro’, and whose CDR is a
17489function.  Expansion of the macro works by applying the function (with
17490‘apply’) to the list of _unevaluated_ arguments from the macro call.
17491
17492   It is possible to use an anonymous Lisp macro just like an anonymous
17493function, but this is never done, because it does not make sense to pass
17494an anonymous macro to functionals such as ‘mapcar’.  In practice, all
17495Lisp macros have names, and they are almost always defined with the
17496‘defmacro’ macro.
17497
17498 -- Macro: defmacro name args [doc] [declare] body...
17499     ‘defmacro’ defines the symbol NAME (which should not be quoted) as
17500     a macro that looks like this:
17501
17502          (macro lambda ARGS . BODY)
17503
17504     (Note that the CDR of this list is a lambda expression.)  This
17505     macro object is stored in the function cell of NAME.  The meaning
17506     of ARGS is the same as in a function, and the keywords ‘&rest’ and
17507     ‘&optional’ may be used (*note Argument List::).  Neither NAME nor
17508     ARGS should be quoted.  The return value of ‘defmacro’ is
17509     undefined.
17510
17511     DOC, if present, should be a string specifying the macro’s
17512     documentation string.  DECLARE, if present, should be a ‘declare’
17513     form specifying metadata for the macro (*note Declare Form::).
17514     Note that macros cannot have interactive declarations, since they
17515     cannot be called interactively.
17516
17517   Macros often need to construct large list structures from a mixture
17518of constants and nonconstant parts.  To make this easier, use the ‘`’
17519syntax (*note Backquote::).  For example:
17520
17521          (defmacro t-becomes-nil (variable)
17522            `(if (eq ,variable t)
17523                 (setq ,variable nil)))
17524
17525          (t-becomes-nil foo)
17526               ≡ (if (eq foo t) (setq foo nil))
17527
17528
17529File: elisp.info,  Node: Problems with Macros,  Next: Indenting Macros,  Prev: Defining Macros,  Up: Macros
17530
1753114.5 Common Problems Using Macros
17532=================================
17533
17534Macro expansion can have counterintuitive consequences.  This section
17535describes some important consequences that can lead to trouble, and
17536rules to follow to avoid trouble.
17537
17538* Menu:
17539
17540* Wrong Time::             Do the work in the expansion, not in the macro.
17541* Argument Evaluation::    The expansion should evaluate each macro arg once.
17542* Surprising Local Vars::  Local variable bindings in the expansion
17543                              require special care.
17544* Eval During Expansion::  Don’t evaluate them; put them in the expansion.
17545* Repeated Expansion::     Avoid depending on how many times expansion is done.
17546
17547
17548File: elisp.info,  Node: Wrong Time,  Next: Argument Evaluation,  Up: Problems with Macros
17549
1755014.5.1 Wrong Time
17551-----------------
17552
17553The most common problem in writing macros is doing some of the real work
17554prematurely—while expanding the macro, rather than in the expansion
17555itself.  For instance, one real package had this macro definition:
17556
17557     (defmacro my-set-buffer-multibyte (arg)
17558       (if (fboundp 'set-buffer-multibyte)
17559           (set-buffer-multibyte arg)))
17560
17561   With this erroneous macro definition, the program worked fine when
17562interpreted but failed when compiled.  This macro definition called
17563‘set-buffer-multibyte’ during compilation, which was wrong, and then did
17564nothing when the compiled package was run.  The definition that the
17565programmer really wanted was this:
17566
17567     (defmacro my-set-buffer-multibyte (arg)
17568       (if (fboundp 'set-buffer-multibyte)
17569           `(set-buffer-multibyte ,arg)))
17570
17571This macro expands, if appropriate, into a call to
17572‘set-buffer-multibyte’ that will be executed when the compiled program
17573is actually run.
17574
17575
17576File: elisp.info,  Node: Argument Evaluation,  Next: Surprising Local Vars,  Prev: Wrong Time,  Up: Problems with Macros
17577
1757814.5.2 Evaluating Macro Arguments Repeatedly
17579--------------------------------------------
17580
17581When defining a macro you must pay attention to the number of times the
17582arguments will be evaluated when the expansion is executed.  The
17583following macro (used to facilitate iteration) illustrates the problem.
17584This macro allows us to write a for-loop construct.
17585
17586     (defmacro for (var from init to final do &rest body)
17587       "Execute a simple \"for\" loop.
17588     For example, (for i from 1 to 10 do (print i))."
17589       (list 'let (list (list var init))
17590             (cons 'while
17591                   (cons (list '<= var final)
17592                         (append body (list (list 'inc var)))))))
17593
17594     (for i from 1 to 3 do
17595        (setq square (* i i))
17596        (princ (format "\n%d %d" i square)))
1759717598     (let ((i 1))
17599       (while (<= i 3)
17600         (setq square (* i i))
17601         (princ (format "\n%d %d" i square))
17602         (inc i)))
17603
17604          ⊣1       1
17605          ⊣2       4
17606          ⊣3       9
17607     ⇒ nil
17608
17609The arguments ‘from’, ‘to’, and ‘do’ in this macro are syntactic sugar;
17610they are entirely ignored.  The idea is that you will write noise words
17611(such as ‘from’, ‘to’, and ‘do’) in those positions in the macro call.
17612
17613   Here’s an equivalent definition simplified through use of backquote:
17614
17615     (defmacro for (var from init to final do &rest body)
17616       "Execute a simple \"for\" loop.
17617     For example, (for i from 1 to 10 do (print i))."
17618       `(let ((,var ,init))
17619          (while (<= ,var ,final)
17620            ,@body
17621            (inc ,var))))
17622
17623   Both forms of this definition (with backquote and without) suffer
17624from the defect that FINAL is evaluated on every iteration.  If FINAL is
17625a constant, this is not a problem.  If it is a more complex form, say
17626‘(long-complex-calculation x)’, this can slow down the execution
17627significantly.  If FINAL has side effects, executing it more than once
17628is probably incorrect.
17629
17630   A well-designed macro definition takes steps to avoid this problem by
17631producing an expansion that evaluates the argument expressions exactly
17632once unless repeated evaluation is part of the intended purpose of the
17633macro.  Here is a correct expansion for the ‘for’ macro:
17634
17635     (let ((i 1)
17636           (max 3))
17637       (while (<= i max)
17638         (setq square (* i i))
17639         (princ (format "%d      %d" i square))
17640         (inc i)))
17641
17642   Here is a macro definition that creates this expansion:
17643
17644     (defmacro for (var from init to final do &rest body)
17645       "Execute a simple for loop: (for i from 1 to 10 do (print i))."
17646       `(let ((,var ,init)
17647              (max ,final))
17648          (while (<= ,var max)
17649            ,@body
17650            (inc ,var))))
17651
17652   Unfortunately, this fix introduces another problem, described in the
17653following section.
17654
17655
17656File: elisp.info,  Node: Surprising Local Vars,  Next: Eval During Expansion,  Prev: Argument Evaluation,  Up: Problems with Macros
17657
1765814.5.3 Local Variables in Macro Expansions
17659------------------------------------------
17660
17661In the previous section, the definition of ‘for’ was fixed as follows to
17662make the expansion evaluate the macro arguments the proper number of
17663times:
17664
17665     (defmacro for (var from init to final do &rest body)
17666       "Execute a simple for loop: (for i from 1 to 10 do (print i))."
17667       `(let ((,var ,init)
17668              (max ,final))
17669          (while (<= ,var max)
17670            ,@body
17671            (inc ,var))))
17672
17673   The new definition of ‘for’ has a new problem: it introduces a local
17674variable named ‘max’ which the user does not expect.  This causes
17675trouble in examples such as the following:
17676
17677     (let ((max 0))
17678       (for x from 0 to 10 do
17679         (let ((this (frob x)))
17680           (if (< max this)
17681               (setq max this)))))
17682
17683The references to ‘max’ inside the body of the ‘for’, which are supposed
17684to refer to the user’s binding of ‘max’, really access the binding made
17685by ‘for’.
17686
17687   The way to correct this is to use an uninterned symbol instead of
17688‘max’ (*note Creating Symbols::).  The uninterned symbol can be bound
17689and referred to just like any other symbol, but since it is created by
17690‘for’, we know that it cannot already appear in the user’s program.
17691Since it is not interned, there is no way the user can put it into the
17692program later.  It will never appear anywhere except where put by ‘for’.
17693Here is a definition of ‘for’ that works this way:
17694
17695     (defmacro for (var from init to final do &rest body)
17696       "Execute a simple for loop: (for i from 1 to 10 do (print i))."
17697       (let ((tempvar (make-symbol "max")))
17698         `(let ((,var ,init)
17699                (,tempvar ,final))
17700            (while (<= ,var ,tempvar)
17701              ,@body
17702              (inc ,var)))))
17703
17704This creates an uninterned symbol named ‘max’ and puts it in the
17705expansion instead of the usual interned symbol ‘max’ that appears in
17706expressions ordinarily.
17707
17708
17709File: elisp.info,  Node: Eval During Expansion,  Next: Repeated Expansion,  Prev: Surprising Local Vars,  Up: Problems with Macros
17710
1771114.5.4 Evaluating Macro Arguments in Expansion
17712----------------------------------------------
17713
17714Another problem can happen if the macro definition itself evaluates any
17715of the macro argument expressions, such as by calling ‘eval’ (*note
17716Eval::).  If the argument is supposed to refer to the user’s variables,
17717you may have trouble if the user happens to use a variable with the same
17718name as one of the macro arguments.  Inside the macro body, the macro
17719argument binding is the most local binding of this variable, so any
17720references inside the form being evaluated do refer to it.  Here is an
17721example:
17722
17723     (defmacro foo (a)
17724       (list 'setq (eval a) t))
17725     (setq x 'b)
17726     (foo x) ↦ (setq b t)
17727          ⇒ t                  ; and ‘b’ has been set.
17728     ;; but
17729     (setq a 'c)
17730     (foo a) ↦ (setq a t)
17731          ⇒ t                  ; but this set ‘a’, not ‘c’.
17732
17733
17734   It makes a difference whether the user’s variable is named ‘a’ or
17735‘x’, because ‘a’ conflicts with the macro argument variable ‘a’.
17736
17737   Another problem with calling ‘eval’ in a macro definition is that it
17738probably won’t do what you intend in a compiled program.  The byte
17739compiler runs macro definitions while compiling the program, when the
17740program’s own computations (which you might have wished to access with
17741‘eval’) don’t occur and its local variable bindings don’t exist.
17742
17743   To avoid these problems, *don’t evaluate an argument expression while
17744computing the macro expansion*.  Instead, substitute the expression into
17745the macro expansion, so that its value will be computed as part of
17746executing the expansion.  This is how the other examples in this chapter
17747work.
17748
17749
17750File: elisp.info,  Node: Repeated Expansion,  Prev: Eval During Expansion,  Up: Problems with Macros
17751
1775214.5.5 How Many Times is the Macro Expanded?
17753--------------------------------------------
17754
17755Occasionally problems result from the fact that a macro call is expanded
17756each time it is evaluated in an interpreted function, but is expanded
17757only once (during compilation) for a compiled function.  If the macro
17758definition has side effects, they will work differently depending on how
17759many times the macro is expanded.
17760
17761   Therefore, you should avoid side effects in computation of the macro
17762expansion, unless you really know what you are doing.
17763
17764   One special kind of side effect can’t be avoided: constructing Lisp
17765objects.  Almost all macro expansions include constructed lists; that is
17766the whole point of most macros.  This is usually safe; there is just one
17767case where you must be careful: when the object you construct is part of
17768a quoted constant in the macro expansion.
17769
17770   If the macro is expanded just once, in compilation, then the object
17771is constructed just once, during compilation.  But in interpreted
17772execution, the macro is expanded each time the macro call runs, and this
17773means a new object is constructed each time.
17774
17775   In most clean Lisp code, this difference won’t matter.  It can matter
17776only if you perform side-effects on the objects constructed by the macro
17777definition.  Thus, to avoid trouble, *avoid side effects on objects
17778constructed by macro definitions*.  Here is an example of how such side
17779effects can get you into trouble:
17780
17781     (defmacro empty-object ()
17782       (list 'quote (cons nil nil)))
17783
17784     (defun initialize (condition)
17785       (let ((object (empty-object)))
17786         (if condition
17787             (setcar object condition))
17788         object))
17789
17790If ‘initialize’ is interpreted, a new list ‘(nil)’ is constructed each
17791time ‘initialize’ is called.  Thus, no side effect survives between
17792calls.  If ‘initialize’ is compiled, then the macro ‘empty-object’ is
17793expanded during compilation, producing a single constant ‘(nil)’ that is
17794reused and altered each time ‘initialize’ is called.
17795
17796   One way to avoid pathological cases like this is to think of
17797‘empty-object’ as a funny kind of constant, not as a memory allocation
17798construct.  You wouldn’t use ‘setcar’ on a constant such as ‘'(nil)’, so
17799naturally you won’t use it on ‘(empty-object)’ either.
17800
17801
17802File: elisp.info,  Node: Indenting Macros,  Prev: Problems with Macros,  Up: Macros
17803
1780414.6 Indenting Macros
17805=====================
17806
17807Within a macro definition, you can use the ‘declare’ form (*note
17808Defining Macros::) to specify how <TAB> should indent calls to the
17809macro.  An indentation specification is written like this:
17810
17811     (declare (indent INDENT-SPEC))
17812
17813This results in the ‘lisp-indent-function’ property being set on the
17814macro name.
17815
17816Here are the possibilities for INDENT-SPEC:
17817
17818‘nil’
17819     This is the same as no property—use the standard indentation
17820     pattern.
17821‘defun’
17822     Handle this function like a ‘def’ construct: treat the second line
17823     as the start of a “body”.
17824an integer, NUMBER
17825     The first NUMBER arguments of the function are “distinguished”
17826     arguments; the rest are considered the body of the expression.  A
17827     line in the expression is indented according to whether the first
17828     argument on it is distinguished or not.  If the argument is part of
17829     the body, the line is indented ‘lisp-body-indent’ more columns than
17830     the open-parenthesis starting the containing expression.  If the
17831     argument is distinguished and is either the first or second
17832     argument, it is indented _twice_ that many extra columns.  If the
17833     argument is distinguished and not the first or second argument, the
17834     line uses the standard pattern.
17835a symbol, SYMBOL
17836     SYMBOL should be a function name; that function is called to
17837     calculate the indentation of a line within this expression.  The
17838     function receives two arguments:
17839
17840     POS
17841          The position at which the line being indented begins.
17842     STATE
17843          The value returned by ‘parse-partial-sexp’ (a Lisp primitive
17844          for indentation and nesting computation) when it parses up to
17845          the beginning of this line.
17846
17847     It should return either a number, which is the number of columns of
17848     indentation for that line, or a list whose car is such a number.
17849     The difference between returning a number and returning a list is
17850     that a number says that all following lines at the same nesting
17851     level should be indented just like this one; a list says that
17852     following lines might call for different indentations.  This makes
17853     a difference when the indentation is being computed by ‘C-M-q’; if
17854     the value is a number, ‘C-M-q’ need not recalculate indentation for
17855     the following lines until the end of the list.
17856
17857
17858File: elisp.info,  Node: Customization,  Next: Loading,  Prev: Macros,  Up: Top
17859
1786015 Customization Settings
17861*************************
17862
17863Users of Emacs can customize variables and faces without writing Lisp
17864code, by using the Customize interface.  *Note (emacs)Easy
17865Customization::.  This chapter describes how to define “customization
17866items” that users can interact with through the Customize interface.
17867
17868   Customization items include customizable variables, which are defined
17869with the ‘defcustom’ macro (*note Variable Definitions::); customizable
17870faces, which are defined with ‘defface’ (described separately in *note
17871Defining Faces::); and “customization groups”, defined with ‘defgroup’
17872(*note Group Definitions::), which act as containers for groups of
17873related customization items.
17874
17875* Menu:
17876
17877* Common Keywords::         Common keyword arguments for all kinds of
17878                             customization declarations.
17879* Group Definitions::       Writing customization group definitions.
17880* Variable Definitions::    Declaring user options.
17881* Customization Types::     Specifying the type of a user option.
17882* Applying Customizations:: Functions to apply customization settings.
17883* Custom Themes::           Writing Custom themes.
17884
17885
17886File: elisp.info,  Node: Common Keywords,  Next: Group Definitions,  Up: Customization
17887
1788815.1 Common Item Keywords
17889=========================
17890
17891The customization declarations that we will describe in the next few
17892sections—‘defcustom’, ‘defgroup’, etc.—all accept keyword arguments
17893(*note Constant Variables::) for specifying various information.  This
17894section describes keywords that apply to all types of customization
17895declarations.
17896
17897   All of these keywords, except ‘:tag’, can be used more than once in a
17898given item.  Each use of the keyword has an independent effect.  The
17899keyword ‘:tag’ is an exception because any given item can only display
17900one name.
17901
17902‘:tag LABEL’
17903     Use LABEL, a string, instead of the item’s name, to label the item
17904     in customization menus and buffers.  *Don’t use a tag which is
17905     substantially different from the item’s real name; that would cause
17906     confusion.*
17907
17908‘:group GROUP’
17909     Put this customization item in group GROUP.  If this keyword is
17910     missing from a customization item, it’ll be placed in the same
17911     group that was last defined (in the current file).
17912
17913     When you use ‘:group’ in a ‘defgroup’, it makes the new group a
17914     subgroup of GROUP.
17915
17916     If you use this keyword more than once, you can put a single item
17917     into more than one group.  Displaying any of those groups will show
17918     this item.  Please don’t overdo this, since the result would be
17919     annoying.
17920
17921‘:link LINK-DATA’
17922     Include an external link after the documentation string for this
17923     item.  This is a sentence containing a button that references some
17924     other documentation.
17925
17926     There are several alternatives you can use for LINK-DATA:
17927
17928     ‘(custom-manual INFO-NODE)’
17929          Link to an Info node; INFO-NODE is a string which specifies
17930          the node name, as in ‘"(emacs)Top"’.  The link appears as
17931          ‘[Manual]’ in the customization buffer and enters the built-in
17932          Info reader on INFO-NODE.
17933
17934     ‘(info-link INFO-NODE)’
17935          Like ‘custom-manual’ except that the link appears in the
17936          customization buffer with the Info node name.
17937
17938     ‘(url-link URL)’
17939          Link to a web page; URL is a string which specifies the URL.
17940          The link appears in the customization buffer as URL and
17941          invokes the WWW browser specified by
17942          ‘browse-url-browser-function’.
17943
17944     ‘(emacs-commentary-link LIBRARY)’
17945          Link to the commentary section of a library; LIBRARY is a
17946          string which specifies the library name.  *Note Library
17947          Headers::.
17948
17949     ‘(emacs-library-link LIBRARY)’
17950          Link to an Emacs Lisp library file; LIBRARY is a string which
17951          specifies the library name.
17952
17953     ‘(file-link FILE)’
17954          Link to a file; FILE is a string which specifies the name of
17955          the file to visit with ‘find-file’ when the user invokes this
17956          link.
17957
17958     ‘(function-link FUNCTION)’
17959          Link to the documentation of a function; FUNCTION is a string
17960          which specifies the name of the function to describe with
17961          ‘describe-function’ when the user invokes this link.
17962
17963     ‘(variable-link VARIABLE)’
17964          Link to the documentation of a variable; VARIABLE is a string
17965          which specifies the name of the variable to describe with
17966          ‘describe-variable’ when the user invokes this link.
17967
17968     ‘(custom-group-link GROUP)’
17969          Link to another customization group.  Invoking it creates a
17970          new customization buffer for GROUP.
17971
17972     You can specify the text to use in the customization buffer by
17973     adding ‘:tag NAME’ after the first element of the LINK-DATA; for
17974     example, ‘(info-link :tag "foo" "(emacs)Top")’ makes a link to the
17975     Emacs manual which appears in the buffer as ‘foo’.
17976
17977     You can use this keyword more than once, to add multiple links.
17978
17979‘:load FILE’
17980     Load file FILE (a string) before displaying this customization item
17981     (*note Loading::).  Loading is done with ‘load’, and only if the
17982     file is not already loaded.
17983
17984‘:require FEATURE’
17985     Execute ‘(require 'FEATURE)’ when your saved customizations set the
17986     value of this item.  FEATURE should be a symbol.
17987
17988     The most common reason to use ‘:require’ is when a variable enables
17989     a feature such as a minor mode, and just setting the variable won’t
17990     have any effect unless the code which implements the mode is
17991     loaded.
17992
17993‘:version VERSION’
17994     This keyword specifies that the item was first introduced in Emacs
17995     version VERSION, or that its default value was changed in that
17996     version.  The value VERSION must be a string.
17997
17998‘:package-version '(PACKAGE . VERSION)’
17999     This keyword specifies that the item was first introduced in
18000     PACKAGE version VERSION, or that its meaning or default value was
18001     changed in that version.  This keyword takes priority over
18002     ‘:version’.
18003
18004     PACKAGE should be the official name of the package, as a symbol
18005     (e.g., ‘MH-E’).  VERSION should be a string.  If the package
18006     PACKAGE is released as part of Emacs, PACKAGE and VERSION should
18007     appear in the value of ‘customize-package-emacs-version-alist’.
18008
18009   Packages distributed as part of Emacs that use the ‘:package-version’
18010keyword must also update the ‘customize-package-emacs-version-alist’
18011variable.
18012
18013 -- Variable: customize-package-emacs-version-alist
18014     This alist provides a mapping for the versions of Emacs that are
18015     associated with versions of a package listed in the
18016     ‘:package-version’ keyword.  Its elements are:
18017
18018          (PACKAGE (PVERSION . EVERSION)...)
18019
18020     For each PACKAGE, which is a symbol, there are one or more elements
18021     that contain a package version PVERSION with an associated Emacs
18022     version EVERSION.  These versions are strings.  For example, the
18023     MH-E package updates this alist with the following:
18024
18025          (add-to-list 'customize-package-emacs-version-alist
18026                       '(MH-E ("6.0" . "22.1") ("6.1" . "22.1") ("7.0" . "22.1")
18027                              ("7.1" . "22.1") ("7.2" . "22.1") ("7.3" . "22.1")
18028                              ("7.4" . "22.1") ("8.0" . "22.1")))
18029
18030     The value of PACKAGE needs to be unique and it needs to match the
18031     PACKAGE value appearing in the ‘:package-version’ keyword.  Since
18032     the user might see the value in an error message, a good choice is
18033     the official name of the package, such as MH-E or Gnus.
18034
18035
18036File: elisp.info,  Node: Group Definitions,  Next: Variable Definitions,  Prev: Common Keywords,  Up: Customization
18037
1803815.2 Defining Customization Groups
18039==================================
18040
18041Each Emacs Lisp package should have one main customization group which
18042contains all the options, faces and other groups in the package.  If the
18043package has a small number of options and faces, use just one group and
18044put everything in it.  When there are more than twenty or so options and
18045faces, then you should structure them into subgroups, and put the
18046subgroups under the package’s main customization group.  It is OK to put
18047some of the options and faces in the package’s main group alongside the
18048subgroups.
18049
18050   The package’s main or only group should be a member of one or more of
18051the standard customization groups.  (To display the full list of them,
18052use ‘M-x customize’.)  Choose one or more of them (but not too many),
18053and add your group to each of them using the ‘:group’ keyword.
18054
18055   The way to declare new customization groups is with ‘defgroup’.
18056
18057 -- Macro: defgroup group members doc [keyword value]...
18058     Declare GROUP as a customization group containing MEMBERS.  Do not
18059     quote the symbol GROUP.  The argument DOC specifies the
18060     documentation string for the group.
18061
18062     The argument MEMBERS is a list specifying an initial set of
18063     customization items to be members of the group.  However, most
18064     often MEMBERS is ‘nil’, and you specify the group’s members by
18065     using the ‘:group’ keyword when defining those members.
18066
18067     If you want to specify group members through MEMBERS, each element
18068     should have the form ‘(NAME WIDGET)’.  Here NAME is a symbol, and
18069     WIDGET is a widget type for editing that symbol.  Useful widgets
18070     are ‘custom-variable’ for a variable, ‘custom-face’ for a face, and
18071     ‘custom-group’ for a group.
18072
18073     When you introduce a new group into Emacs, use the ‘:version’
18074     keyword in the ‘defgroup’; then you need not use it for the
18075     individual members of the group.
18076
18077     In addition to the common keywords (*note Common Keywords::), you
18078     can also use this keyword in ‘defgroup’:
18079
18080     ‘:prefix PREFIX’
18081          If the name of an item in the group starts with PREFIX, and
18082          the customizable variable ‘custom-unlispify-remove-prefixes’
18083          is non-‘nil’, the item’s tag will omit PREFIX.  A group can
18084          have any number of prefixes.
18085
18086     The variables and subgroups of a group are stored in the
18087     ‘custom-group’ property of the group’s symbol.  *Note Symbol
18088     Plists::.  The value of that property is a list of pairs whose
18089     ‘car’ is the variable or subgroup symbol and the ‘cdr’ is either
18090     ‘custom-variable’ or ‘custom-group’.
18091
18092 -- User Option: custom-unlispify-remove-prefixes
18093     If this variable is non-‘nil’, the prefixes specified by a group’s
18094     ‘:prefix’ keyword are omitted from tag names, whenever the user
18095     customizes the group.
18096
18097     The default value is ‘nil’, i.e., the prefix-discarding feature is
18098     disabled.  This is because discarding prefixes often leads to
18099     confusing names for options and faces.
18100
18101
18102File: elisp.info,  Node: Variable Definitions,  Next: Customization Types,  Prev: Group Definitions,  Up: Customization
18103
1810415.3 Defining Customization Variables
18105=====================================
18106
18107“Customizable variables”, also called “user options”, are global Lisp
18108variables whose values can be set through the Customize interface.
18109Unlike other global variables, which are defined with ‘defvar’ (*note
18110Defining Variables::), customizable variables are defined using the
18111‘defcustom’ macro.  In addition to calling ‘defvar’ as a subroutine,
18112‘defcustom’ states how the variable should be displayed in the Customize
18113interface, the values it is allowed to take, etc.
18114
18115 -- Macro: defcustom option standard doc [keyword value]...
18116     This macro declares OPTION as a user option (i.e., a customizable
18117     variable).  You should not quote OPTION.
18118
18119     The argument STANDARD is an expression that specifies the standard
18120     value for OPTION.  Evaluating the ‘defcustom’ form evaluates
18121     STANDARD, but does not necessarily bind the option to that value.
18122     If OPTION already has a default value, it is left unchanged.  If
18123     the user has already saved a customization for OPTION, the user’s
18124     customized value is installed as the default value.  Otherwise, the
18125     result of evaluating STANDARD is installed as the default value.
18126
18127     Like ‘defvar’, this macro marks ‘option’ as a special variable,
18128     meaning that it should always be dynamically bound.  If OPTION is
18129     already lexically bound, that lexical binding remains in effect
18130     until the binding construct exits.  *Note Variable Scoping::.
18131
18132     The expression STANDARD can be evaluated at various other times,
18133     too—whenever the customization facility needs to know OPTION’s
18134     standard value.  So be sure to use an expression which is harmless
18135     to evaluate at any time.
18136
18137     The argument DOC specifies the documentation string for the
18138     variable.
18139
18140     If a ‘defcustom’ does not specify any ‘:group’, the last group
18141     defined with ‘defgroup’ in the same file will be used.  This way,
18142     most ‘defcustom’ do not need an explicit ‘:group’.
18143
18144     When you evaluate a ‘defcustom’ form with ‘C-M-x’ in Emacs Lisp
18145     mode (‘eval-defun’), a special feature of ‘eval-defun’ arranges to
18146     set the variable unconditionally, without testing whether its value
18147     is void.  (The same feature applies to ‘defvar’, *note Defining
18148     Variables::.)  Using ‘eval-defun’ on a defcustom that is already
18149     defined calls the ‘:set’ function (see below), if there is one.
18150
18151     If you put a ‘defcustom’ in a pre-loaded Emacs Lisp file (*note
18152     Building Emacs::), the standard value installed at dump time might
18153     be incorrect, e.g., because another variable that it depends on has
18154     not been assigned the right value yet.  In that case, use
18155     ‘custom-reevaluate-setting’, described below, to re-evaluate the
18156     standard value after Emacs starts up.
18157
18158   In addition to the keywords listed in *note Common Keywords::, this
18159macro accepts the following keywords:
18160
18161‘:type TYPE’
18162     Use TYPE as the data type for this option.  It specifies which
18163     values are legitimate, and how to display the value (*note
18164     Customization Types::).  Every ‘defcustom’ should specify a value
18165     for this keyword.
18166
18167‘:options VALUE-LIST’
18168     Specify the list of reasonable values for use in this option.  The
18169     user is not restricted to using only these values, but they are
18170     offered as convenient alternatives.
18171
18172     This is meaningful only for certain types, currently including
18173     ‘hook’, ‘plist’ and ‘alist’.  See the definition of the individual
18174     types for a description of how to use ‘:options’.
18175
18176‘:set SETFUNCTION’
18177     Specify SETFUNCTION as the way to change the value of this option
18178     when using the Customize interface.  The function SETFUNCTION
18179     should take two arguments, a symbol (the option name) and the new
18180     value, and should do whatever is necessary to update the value
18181     properly for this option (which may not mean simply setting the
18182     option as a Lisp variable); preferably, though, it should not
18183     modify its value argument destructively.  The default for
18184     SETFUNCTION is ‘set-default’.
18185
18186     If you specify this keyword, the variable’s documentation string
18187     should describe how to do the same job in hand-written Lisp code.
18188
18189‘:get GETFUNCTION’
18190     Specify GETFUNCTION as the way to extract the value of this option.
18191     The function GETFUNCTION should take one argument, a symbol, and
18192     should return whatever customize should use as the current value
18193     for that symbol (which need not be the symbol’s Lisp value).  The
18194     default is ‘default-value’.
18195
18196     You have to really understand the workings of Custom to use ‘:get’
18197     correctly.  It is meant for values that are treated in Custom as
18198     variables but are not actually stored in Lisp variables.  It is
18199     almost surely a mistake to specify GETFUNCTION for a value that
18200     really is stored in a Lisp variable.
18201
18202‘:initialize FUNCTION’
18203     FUNCTION should be a function used to initialize the variable when
18204     the ‘defcustom’ is evaluated.  It should take two arguments, the
18205     option name (a symbol) and the value.  Here are some predefined
18206     functions meant for use in this way:
18207
18208     ‘custom-initialize-set’
18209          Use the variable’s ‘:set’ function to initialize the variable,
18210          but do not reinitialize it if it is already non-void.
18211
18212     ‘custom-initialize-default’
18213          Like ‘custom-initialize-set’, but use the function
18214          ‘set-default’ to set the variable, instead of the variable’s
18215          ‘:set’ function.  This is the usual choice for a variable
18216          whose ‘:set’ function enables or disables a minor mode; with
18217          this choice, defining the variable will not call the minor
18218          mode function, but customizing the variable will do so.
18219
18220     ‘custom-initialize-reset’
18221          Always use the ‘:set’ function to initialize the variable.  If
18222          the variable is already non-void, reset it by calling the
18223          ‘:set’ function using the current value (returned by the
18224          ‘:get’ method).  This is the default ‘:initialize’ function.
18225
18226     ‘custom-initialize-changed’
18227          Use the ‘:set’ function to initialize the variable, if it is
18228          already set or has been customized; otherwise, just use
18229          ‘set-default’.
18230
18231     ‘custom-initialize-delay’
18232          This function behaves like ‘custom-initialize-set’, but it
18233          delays the actual initialization to the next Emacs start.
18234          This should be used in files that are preloaded (or for
18235          autoloaded variables), so that the initialization is done in
18236          the run-time context rather than the build-time context.  This
18237          also has the side-effect that the (delayed) initialization is
18238          performed with the ‘:set’ function.  *Note Building Emacs::.
18239
18240‘:local VALUE’
18241     If the VALUE is ‘t’, mark OPTION as automatically buffer-local; if
18242     the value is ‘permanent’, also set OPTIONs ‘permanent-local’
18243     property to ‘t’.  *Note Creating Buffer-Local::.
18244
18245‘:risky VALUE’
18246     Set the variable’s ‘risky-local-variable’ property to VALUE (*note
18247     File Local Variables::).
18248
18249‘:safe FUNCTION’
18250     Set the variable’s ‘safe-local-variable’ property to FUNCTION
18251     (*note File Local Variables::).
18252
18253‘:set-after VARIABLES’
18254     When setting variables according to saved customizations, make sure
18255     to set the variables VARIABLES before this one; i.e., delay setting
18256     this variable until after those others have been handled.  Use
18257     ‘:set-after’ if setting this variable won’t work properly unless
18258     those other variables already have their intended values.
18259
18260   It is useful to specify the ‘:require’ keyword for an option that
18261turns on a certain feature.  This causes Emacs to load the feature, if
18262it is not already loaded, whenever the option is set.  *Note Common
18263Keywords::.  Here is an example:
18264
18265     (defcustom frobnicate-automatically nil
18266       "Non-nil means automatically frobnicate all buffers."
18267       :type 'boolean
18268       :require 'frobnicate-mode
18269       :group 'frobnicate)
18270
18271   If a customization item has a type such as ‘hook’ or ‘alist’, which
18272supports ‘:options’, you can add additional values to the list from
18273outside the ‘defcustom’ declaration by calling
18274‘custom-add-frequent-value’.  For example, if you define a function
18275‘my-lisp-mode-initialization’ intended to be called from
18276‘emacs-lisp-mode-hook’, you might want to add that to the list of
18277reasonable values for ‘emacs-lisp-mode-hook’, but not by editing its
18278definition.  You can do it thus:
18279
18280     (custom-add-frequent-value 'emacs-lisp-mode-hook
18281        'my-lisp-mode-initialization)
18282
18283 -- Function: custom-add-frequent-value symbol value
18284     For the customization option SYMBOL, add VALUE to the list of
18285     reasonable values.
18286
18287     The precise effect of adding a value depends on the customization
18288     type of SYMBOL.
18289
18290   Internally, ‘defcustom’ uses the symbol property ‘standard-value’ to
18291record the expression for the standard value, ‘saved-value’ to record
18292the value saved by the user with the customization buffer, and
18293‘customized-value’ to record the value set by the user with the
18294customization buffer, but not saved.  *Note Symbol Properties::.  In
18295addition, there’s ‘themed-value’, which is used to record the value set
18296by a theme (*note Custom Themes::).  These properties are lists, the car
18297of which is an expression that evaluates to the value.
18298
18299 -- Function: custom-reevaluate-setting symbol
18300     This function re-evaluates the standard value of SYMBOL, which
18301     should be a user option declared via ‘defcustom’.  If the variable
18302     was customized, this function re-evaluates the saved value instead.
18303     Then it sets the user option to that value (using the option’s
18304     ‘:set’ property if that is defined).
18305
18306     This is useful for customizable options that are defined before
18307     their value could be computed correctly.  For example, during
18308     startup Emacs calls this function for some user options that were
18309     defined in pre-loaded Emacs Lisp files, but whose initial values
18310     depend on information available only at run-time.
18311
18312 -- Function: custom-variable-p arg
18313     This function returns non-‘nil’ if ARG is a customizable variable.
18314     A customizable variable is either a variable that has a
18315     ‘standard-value’ or ‘custom-autoload’ property (usually meaning it
18316     was declared with ‘defcustom’), or an alias for another
18317     customizable variable.
18318
18319
18320File: elisp.info,  Node: Customization Types,  Next: Applying Customizations,  Prev: Variable Definitions,  Up: Customization
18321
1832215.4 Customization Types
18323========================
18324
18325When you define a user option with ‘defcustom’, you must specify its
18326“customization type”.  That is a Lisp object which describes (1) which
18327values are legitimate and (2) how to display the value in the
18328customization buffer for editing.
18329
18330   You specify the customization type in ‘defcustom’ with the ‘:type’
18331keyword.  The argument of ‘:type’ is evaluated, but only once when the
18332‘defcustom’ is executed, so it isn’t useful for the value to vary.
18333Normally we use a quoted constant.  For example:
18334
18335     (defcustom diff-command "diff"
18336       "The command to use to run diff."
18337       :type '(string)
18338       :group 'diff)
18339
18340   In general, a customization type is a list whose first element is a
18341symbol, one of the customization type names defined in the following
18342sections.  After this symbol come a number of arguments, depending on
18343the symbol.  Between the type symbol and its arguments, you can
18344optionally write keyword-value pairs (*note Type Keywords::).
18345
18346   Some type symbols do not use any arguments; those are called “simple
18347types”.  For a simple type, if you do not use any keyword-value pairs,
18348you can omit the parentheses around the type symbol.  For example just
18349‘string’ as a customization type is equivalent to ‘(string)’.
18350
18351   All customization types are implemented as widgets; see *note
18352Introduction: (widget)Top, for details.
18353
18354* Menu:
18355
18356* Simple Types::            Simple customization types: sexp, integer, etc.
18357* Composite Types::         Build new types from other types or data.
18358* Splicing into Lists::     Splice elements into list with ‘:inline’.
18359* Type Keywords::           Keyword-argument pairs in a customization type.
18360* Defining New Types::      Give your type a name.
18361
18362
18363File: elisp.info,  Node: Simple Types,  Next: Composite Types,  Up: Customization Types
18364
1836515.4.1 Simple Types
18366-------------------
18367
18368This section describes all the simple customization types.  For several
18369of these customization types, the customization widget provides inline
18370completion with ‘C-M-i’ or ‘M-<TAB>’.
18371
18372‘sexp’
18373     The value may be any Lisp object that can be printed and read back.
18374     You can use ‘sexp’ as a fall-back for any option, if you don’t want
18375     to take the time to work out a more specific type to use.
18376
18377‘integer’
18378     The value must be an integer.
18379
18380‘number’
18381     The value must be a number (floating point or integer).
18382
18383‘float’
18384     The value must be floating point.
18385
18386‘string’
18387     The value must be a string.  The customization buffer shows the
18388     string without delimiting ‘"’ characters or ‘\’ quotes.
18389
18390‘regexp’
18391     Like ‘string’ except that the string must be a valid regular
18392     expression.
18393
18394‘character’
18395     The value must be a character code.  A character code is actually
18396     an integer, but this type shows the value by inserting the
18397     character in the buffer, rather than by showing the number.
18398
18399‘file’
18400     The value must be a file name.  The widget provides completion.
18401
18402‘(file :must-match t)’
18403     The value must be a file name for an existing file.  The widget
18404     provides completion.
18405
18406‘directory’
18407     The value must be a directory.  The widget provides completion.
18408
18409‘hook’
18410     The value must be a list of functions.  This customization type is
18411     used for hook variables.  You can use the ‘:options’ keyword in a
18412     hook variable’s ‘defcustom’ to specify a list of functions
18413     recommended for use in the hook; *Note Variable Definitions::.
18414
18415‘symbol’
18416     The value must be a symbol.  It appears in the customization buffer
18417     as the symbol name.  The widget provides completion.
18418
18419‘function’
18420     The value must be either a lambda expression or a function name.
18421     The widget provides completion for function names.
18422
18423‘variable’
18424     The value must be a variable name.  The widget provides completion.
18425
18426‘face’
18427     The value must be a symbol which is a face name.  The widget
18428     provides completion.
18429
18430‘boolean’
18431     The value is boolean—either ‘nil’ or ‘t’.  Note that by using
18432     ‘choice’ and ‘const’ together (see the next section), you can
18433     specify that the value must be ‘nil’ or ‘t’, but also specify the
18434     text to describe each value in a way that fits the specific meaning
18435     of the alternative.
18436
18437‘key-sequence’
18438     The value is a key sequence.  The customization buffer shows the
18439     key sequence using the same syntax as the ‘kbd’ function.  *Note
18440     Key Sequences::.
18441
18442‘coding-system’
18443     The value must be a coding-system name, and you can do completion
18444     with ‘M-<TAB>’.
18445
18446‘color’
18447     The value must be a valid color name.  The widget provides
18448     completion for color names, as well as a sample and a button for
18449     selecting a color name from a list of color names shown in a
18450     ‘*Colors*’ buffer.
18451
18452
18453File: elisp.info,  Node: Composite Types,  Next: Splicing into Lists,  Prev: Simple Types,  Up: Customization Types
18454
1845515.4.2 Composite Types
18456----------------------
18457
18458When none of the simple types is appropriate, you can use composite
18459types, which build new types from other types or from specified data.
18460The specified types or data are called the “arguments” of the composite
18461type.  The composite type normally looks like this:
18462
18463     (CONSTRUCTOR ARGUMENTS...)
18464
18465but you can also add keyword-value pairs before the arguments, like
18466this:
18467
18468     (CONSTRUCTOR {KEYWORD VALUE}... ARGUMENTS...)
18469
18470   Here is a table of constructors and how to use them to write
18471composite types:
18472
18473‘(cons CAR-TYPE CDR-TYPE)’
18474     The value must be a cons cell, its CAR must fit CAR-TYPE, and its
18475     CDR must fit CDR-TYPE.  For example, ‘(cons string symbol)’ is a
18476     customization type which matches values such as ‘("foo" . foo)’.
18477
18478     In the customization buffer, the CAR and CDR are displayed and
18479     edited separately, each according to their specified type.
18480
18481‘(list ELEMENT-TYPES...)’
18482     The value must be a list with exactly as many elements as the
18483     ELEMENT-TYPES given; and each element must fit the corresponding
18484     ELEMENT-TYPE.
18485
18486     For example, ‘(list integer string function)’ describes a list of
18487     three elements; the first element must be an integer, the second a
18488     string, and the third a function.
18489
18490     In the customization buffer, each element is displayed and edited
18491     separately, according to the type specified for it.
18492
18493‘(group ELEMENT-TYPES...)’
18494     This works like ‘list’ except for the formatting of text in the
18495     Custom buffer.  ‘list’ labels each element value with its tag;
18496     ‘group’ does not.
18497
18498‘(vector ELEMENT-TYPES...)’
18499     Like ‘list’ except that the value must be a vector instead of a
18500     list.  The elements work the same as in ‘list’.
18501
18502‘(alist :key-type KEY-TYPE :value-type VALUE-TYPE)’
18503     The value must be a list of cons-cells, the CAR of each cell
18504     representing a key of customization type KEY-TYPE, and the CDR of
18505     the same cell representing a value of customization type
18506     VALUE-TYPE.  The user can add and delete key/value pairs, and edit
18507     both the key and the value of each pair.
18508
18509     If omitted, KEY-TYPE and VALUE-TYPE default to ‘sexp’.
18510
18511     The user can add any key matching the specified key type, but you
18512     can give some keys a preferential treatment by specifying them with
18513     the ‘:options’ (see *note Variable Definitions::).  The specified
18514     keys will always be shown in the customize buffer (together with a
18515     suitable value), with a checkbox to include or exclude or disable
18516     the key/value pair from the alist.  The user will not be able to
18517     edit the keys specified by the ‘:options’ keyword argument.
18518
18519     The argument to the ‘:options’ keywords should be a list of
18520     specifications for reasonable keys in the alist.  Ordinarily, they
18521     are simply atoms, which stand for themselves.  For example:
18522
18523          :options '("foo" "bar" "baz")
18524
18525     specifies that there are three known keys, namely ‘"foo"’, ‘"bar"’
18526     and ‘"baz"’, which will always be shown first.
18527
18528     You may want to restrict the value type for specific keys, for
18529     example, the value associated with the ‘"bar"’ key can only be an
18530     integer.  You can specify this by using a list instead of an atom
18531     in the list.  The first element will specify the key, like before,
18532     while the second element will specify the value type.  For example:
18533
18534          :options '("foo" ("bar" integer) "baz")
18535
18536     Finally, you may want to change how the key is presented.  By
18537     default, the key is simply shown as a ‘const’, since the user
18538     cannot change the special keys specified with the ‘:options’
18539     keyword.  However, you may want to use a more specialized type for
18540     presenting the key, like ‘function-item’ if you know it is a symbol
18541     with a function binding.  This is done by using a customization
18542     type specification instead of a symbol for the key.
18543
18544          :options '("foo"
18545                     ((function-item some-function) integer)
18546                     "baz")
18547
18548     Many alists use lists with two elements, instead of cons cells.
18549     For example,
18550
18551          (defcustom list-alist
18552            '(("foo" 1) ("bar" 2) ("baz" 3))
18553            "Each element is a list of the form (KEY VALUE).")
18554
18555     instead of
18556
18557          (defcustom cons-alist
18558            '(("foo" . 1) ("bar" . 2) ("baz" . 3))
18559            "Each element is a cons-cell (KEY . VALUE).")
18560
18561     Because of the way lists are implemented on top of cons cells, you
18562     can treat ‘list-alist’ in the example above as a cons cell alist,
18563     where the value type is a list with a single element containing the
18564     real value.
18565
18566          (defcustom list-alist '(("foo" 1) ("bar" 2) ("baz" 3))
18567            "Each element is a list of the form (KEY VALUE)."
18568            :type '(alist :value-type (group integer)))
18569
18570     The ‘group’ widget is used here instead of ‘list’ only because the
18571     formatting is better suited for the purpose.
18572
18573     Similarly, you can have alists with more values associated with
18574     each key, using variations of this trick:
18575
18576          (defcustom person-data '(("brian"  50 t)
18577                                   ("dorith" 55 nil)
18578                                   ("ken"    52 t))
18579            "Alist of basic info about people.
18580          Each element has the form (NAME AGE MALE-FLAG)."
18581            :type '(alist :value-type (group integer boolean)))
18582
18583‘(plist :key-type KEY-TYPE :value-type VALUE-TYPE)’
18584     This customization type is similar to ‘alist’ (see above), except
18585     that (i) the information is stored as a property list, (*note
18586     Property Lists::), and (ii) KEY-TYPE, if omitted, defaults to
18587     ‘symbol’ rather than ‘sexp’.
18588
18589‘(choice ALTERNATIVE-TYPES...)’
18590     The value must fit one of ALTERNATIVE-TYPES.  For example, ‘(choice
18591     integer string)’ allows either an integer or a string.
18592
18593     In the customization buffer, the user selects an alternative using
18594     a menu, and can then edit the value in the usual way for that
18595     alternative.
18596
18597     Normally the strings in this menu are determined automatically from
18598     the choices; however, you can specify different strings for the
18599     menu by including the ‘:tag’ keyword in the alternatives.  For
18600     example, if an integer stands for a number of spaces, while a
18601     string is text to use verbatim, you might write the customization
18602     type this way,
18603
18604          (choice (integer :tag "Number of spaces")
18605                  (string :tag "Literal text"))
18606
18607     so that the menu offers ‘Number of spaces’ and ‘Literal text’.
18608
18609     In any alternative for which ‘nil’ is not a valid value, other than
18610     a ‘const’, you should specify a valid default for that alternative
18611     using the ‘:value’ keyword.  *Note Type Keywords::.
18612
18613     If some values are covered by more than one of the alternatives,
18614     customize will choose the first alternative that the value fits.
18615     This means you should always list the most specific types first,
18616     and the most general last.  Here’s an example of proper usage:
18617
18618          (choice (const :tag "Off" nil)
18619                  symbol (sexp :tag "Other"))
18620
18621     This way, the special value ‘nil’ is not treated like other
18622     symbols, and symbols are not treated like other Lisp expressions.
18623
18624‘(radio ELEMENT-TYPES...)’
18625     This is similar to ‘choice’, except that the choices are displayed
18626     using radio buttons rather than a menu.  This has the advantage of
18627     displaying documentation for the choices when applicable and so is
18628     often a good choice for a choice between constant functions
18629     (‘function-item’ customization types).
18630
18631‘(const VALUE)’
18632     The value must be VALUE—nothing else is allowed.
18633
18634     The main use of ‘const’ is inside of ‘choice’.  For example,
18635     ‘(choice integer (const nil))’ allows either an integer or ‘nil’.
18636
18637     ‘:tag’ is often used with ‘const’, inside of ‘choice’.  For
18638     example,
18639
18640          (choice (const :tag "Yes" t)
18641                  (const :tag "No" nil)
18642                  (const :tag "Ask" foo))
18643
18644     describes a variable for which ‘t’ means yes, ‘nil’ means no, and
18645     ‘foo’ means “ask”.
18646
18647‘(other VALUE)’
18648     This alternative can match any Lisp value, but if the user chooses
18649     this alternative, that selects the value VALUE.
18650
18651     The main use of ‘other’ is as the last element of ‘choice’.  For
18652     example,
18653
18654          (choice (const :tag "Yes" t)
18655                  (const :tag "No" nil)
18656                  (other :tag "Ask" foo))
18657
18658     describes a variable for which ‘t’ means yes, ‘nil’ means no, and
18659     anything else means “ask”.  If the user chooses ‘Ask’ from the menu
18660     of alternatives, that specifies the value ‘foo’; but any other
18661     value (not ‘t’, ‘nil’ or ‘foo’) displays as ‘Ask’, just like ‘foo’.
18662
18663‘(function-item FUNCTION)’
18664     Like ‘const’, but used for values which are functions.  This
18665     displays the documentation string as well as the function name.
18666     The documentation string is either the one you specify with ‘:doc’,
18667     or FUNCTION’s own documentation string.
18668
18669‘(variable-item VARIABLE)’
18670     Like ‘const’, but used for values which are variable names.  This
18671     displays the documentation string as well as the variable name.
18672     The documentation string is either the one you specify with ‘:doc’,
18673     or VARIABLE’s own documentation string.
18674
18675‘(set TYPES...)’
18676     The value must be a list, and each element of the list must match
18677     one of the TYPES specified.
18678
18679     This appears in the customization buffer as a checklist, so that
18680     each of TYPES may have either one corresponding element or none.
18681     It is not possible to specify two different elements that match the
18682     same one of TYPES.  For example, ‘(set integer symbol)’ allows one
18683     integer and/or one symbol in the list; it does not allow multiple
18684     integers or multiple symbols.  As a result, it is rare to use
18685     nonspecific types such as ‘integer’ in a ‘set’.
18686
18687     Most often, the TYPES in a ‘set’ are ‘const’ types, as shown here:
18688
18689          (set (const :bold) (const :italic))
18690
18691     Sometimes they describe possible elements in an alist:
18692
18693          (set (cons :tag "Height" (const height) integer)
18694               (cons :tag "Width" (const width) integer))
18695
18696     That lets the user specify a height value optionally and a width
18697     value optionally.
18698
18699‘(repeat ELEMENT-TYPE)’
18700     The value must be a list and each element of the list must fit the
18701     type ELEMENT-TYPE.  This appears in the customization buffer as a
18702     list of elements, with ‘[INS]’ and ‘[DEL]’ buttons for adding more
18703     elements or removing elements.
18704
18705‘(restricted-sexp :match-alternatives CRITERIA)’
18706     This is the most general composite type construct.  The value may
18707     be any Lisp object that satisfies one of CRITERIA.  CRITERIA should
18708     be a list, and each element should be one of these possibilities:
18709
18710        • A predicate—that is, a function of one argument that returns
18711          either ‘nil’ or non-‘nil’ according to the argument.  Using a
18712          predicate in the list says that objects for which the
18713          predicate returns non-‘nil’ are acceptable.
18714
18715        • A quoted constant—that is, ‘'OBJECT’.  This sort of element in
18716          the list says that OBJECT itself is an acceptable value.
18717
18718     For example,
18719
18720          (restricted-sexp :match-alternatives
18721                           (integerp 't 'nil))
18722
18723     allows integers, ‘t’ and ‘nil’ as legitimate values.
18724
18725     The customization buffer shows all legitimate values using their
18726     read syntax, and the user edits them textually.
18727
18728   Here is a table of the keywords you can use in keyword-value pairs in
18729a composite type:
18730
18731‘:tag TAG’
18732     Use TAG as the name of this alternative, for user communication
18733     purposes.  This is useful for a type that appears inside of a
18734     ‘choice’.
18735
18736‘:match-alternatives CRITERIA’
18737     Use CRITERIA to match possible values.  This is used only in
18738     ‘restricted-sexp’.
18739
18740‘:args ARGUMENT-LIST’
18741     Use the elements of ARGUMENT-LIST as the arguments of the type
18742     construct.  For instance, ‘(const :args (foo))’ is equivalent to
18743     ‘(const foo)’.  You rarely need to write ‘:args’ explicitly,
18744     because normally the arguments are recognized automatically as
18745     whatever follows the last keyword-value pair.
18746
18747
18748File: elisp.info,  Node: Splicing into Lists,  Next: Type Keywords,  Prev: Composite Types,  Up: Customization Types
18749
1875015.4.3 Splicing into Lists
18751--------------------------
18752
18753The ‘:inline’ feature lets you splice a variable number of elements into
18754the middle of a ‘list’ or ‘vector’ customization type.  You use it by
18755adding ‘:inline t’ to a type specification which is contained in a
18756‘list’ or ‘vector’ specification.
18757
18758   Normally, each entry in a ‘list’ or ‘vector’ type specification
18759describes a single element type.  But when an entry contains ‘:inline
18760t’, the value it matches is merged directly into the containing
18761sequence.  For example, if the entry matches a list with three elements,
18762those become three elements of the overall sequence.  This is analogous
18763to ‘,@’ in a backquote construct (*note Backquote::).
18764
18765   For example, to specify a list whose first element must be ‘baz’ and
18766whose remaining arguments should be zero or more of ‘foo’ and ‘bar’, use
18767this customization type:
18768
18769     (list (const baz) (set :inline t (const foo) (const bar)))
18770
18771This matches values such as ‘(baz)’, ‘(baz foo)’, ‘(baz bar)’ and ‘(baz
18772foo bar)’.
18773
18774   When the element-type is a ‘choice’, you use ‘:inline’ not in the
18775‘choice’ itself, but in (some of) the alternatives of the ‘choice’.  For
18776example, to match a list which must start with a file name, followed
18777either by the symbol ‘t’ or two strings, use this customization type:
18778
18779     (list file
18780           (choice (const t)
18781                   (list :inline t string string)))
18782
18783If the user chooses the first alternative in the choice, then the
18784overall list has two elements and the second element is ‘t’.  If the
18785user chooses the second alternative, then the overall list has three
18786elements and the second and third must be strings.
18787
18788   The widgets can specify predicates to say whether an inline value
18789matches the widget with the ‘:match-inline’ element.
18790
18791
18792File: elisp.info,  Node: Type Keywords,  Next: Defining New Types,  Prev: Splicing into Lists,  Up: Customization Types
18793
1879415.4.4 Type Keywords
18795--------------------
18796
18797You can specify keyword-argument pairs in a customization type after the
18798type name symbol.  Here are the keywords you can use, and their
18799meanings:
18800
18801‘:value DEFAULT’
18802     Provide a default value.
18803
18804     If ‘nil’ is not a valid value for the alternative, then it is
18805     essential to specify a valid default with ‘:value’.
18806
18807     If you use this for a type that appears as an alternative inside of
18808     ‘choice’; it specifies the default value to use, at first, if and
18809     when the user selects this alternative with the menu in the
18810     customization buffer.
18811
18812     Of course, if the actual value of the option fits this alternative,
18813     it will appear showing the actual value, not DEFAULT.
18814
18815‘:format FORMAT-STRING’
18816     This string will be inserted in the buffer to represent the value
18817     corresponding to the type.  The following ‘%’ escapes are available
18818     for use in FORMAT-STRING:
18819
18820     ‘%[BUTTON%]’
18821          Display the text BUTTON marked as a button.  The ‘:action’
18822          attribute specifies what the button will do if the user
18823          invokes it; its value is a function which takes two
18824          arguments—the widget which the button appears in, and the
18825          event.
18826
18827          There is no way to specify two different buttons with
18828          different actions.
18829
18830     ‘%{SAMPLE%}’
18831          Show SAMPLE in a special face specified by ‘:sample-face’.
18832
18833     ‘%v’
18834          Substitute the item’s value.  How the value is represented
18835          depends on the kind of item, and (for variables) on the
18836          customization type.
18837
18838     ‘%d’
18839          Substitute the item’s documentation string.
18840
18841     ‘%h’
18842          Like ‘%d’, but if the documentation string is more than one
18843          line, add a button to control whether to show all of it or
18844          just the first line.
18845
18846     ‘%t’
18847          Substitute the tag here.  You specify the tag with the ‘:tag’
18848          keyword.
18849
18850     ‘%%’
18851          Display a literal ‘%’.
18852
18853‘:action ACTION’
18854     Perform ACTION if the user clicks on a button.
18855
18856‘:button-face FACE’
18857     Use the face FACE (a face name or a list of face names) for button
18858     text displayed with ‘%[...%]’.
18859
18860‘:button-prefix PREFIX’
18861‘:button-suffix SUFFIX’
18862     These specify the text to display before and after a button.  Each
18863     can be:
18864
18865     ‘nil’
18866          No text is inserted.
18867
18868     a string
18869          The string is inserted literally.
18870
18871     a symbol
18872          The symbol’s value is used.
18873
18874‘:tag TAG’
18875     Use TAG (a string) as the tag for the value (or part of the value)
18876     that corresponds to this type.
18877
18878‘:doc DOC’
18879     Use DOC as the documentation string for this value (or part of the
18880     value) that corresponds to this type.  In order for this to work,
18881     you must specify a value for ‘:format’, and use ‘%d’ or ‘%h’ in
18882     that value.
18883
18884     The usual reason to specify a documentation string for a type is to
18885     provide more information about the meanings of alternatives inside
18886     a ‘choice’ type or the parts of some other composite type.
18887
18888‘:help-echo MOTION-DOC’
18889     When you move to this item with ‘widget-forward’ or
18890     ‘widget-backward’, it will display the string MOTION-DOC in the
18891     echo area.  In addition, MOTION-DOC is used as the mouse
18892     ‘help-echo’ string and may actually be a function or form evaluated
18893     to yield a help string.  If it is a function, it is called with one
18894     argument, the widget.
18895
18896‘:match FUNCTION’
18897     Specify how to decide whether a value matches the type.  The
18898     corresponding value, FUNCTION, should be a function that accepts
18899     two arguments, a widget and a value; it should return non-‘nil’ if
18900     the value is acceptable.
18901
18902‘:match-inline FUNCTION’
18903     Specify how to decide whether an inline value matches the type.
18904     The corresponding value, FUNCTION, should be a function that
18905     accepts two arguments, a widget and an inline value; it should
18906     return non-‘nil’ if the value is acceptable.  See *note Splicing
18907     into Lists:: for more information about inline values.
18908
18909‘:validate FUNCTION’
18910     Specify a validation function for input.  FUNCTION takes a widget
18911     as an argument, and should return ‘nil’ if the widget’s current
18912     value is valid for the widget.  Otherwise, it should return the
18913     widget containing the invalid data, and set that widget’s ‘:error’
18914     property to a string explaining the error.
18915
18916
18917File: elisp.info,  Node: Defining New Types,  Prev: Type Keywords,  Up: Customization Types
18918
1891915.4.5 Defining New Types
18920-------------------------
18921
18922In the previous sections we have described how to construct elaborate
18923type specifications for ‘defcustom’.  In some cases you may want to give
18924such a type specification a name.  The obvious case is when you are
18925using the same type for many user options: rather than repeat the
18926specification for each option, you can give the type specification a
18927name, and use that name each ‘defcustom’.  The other case is when a user
18928option’s value is a recursive data structure.  To make it possible for a
18929datatype to refer to itself, it needs to have a name.
18930
18931   Since custom types are implemented as widgets, the way to define a
18932new customize type is to define a new widget.  We are not going to
18933describe the widget interface here in details, see *note Introduction:
18934(widget)Top, for that.  Instead we are going to demonstrate the minimal
18935functionality needed for defining new customize types by a simple
18936example.
18937
18938     (define-widget 'binary-tree-of-string 'lazy
18939       "A binary tree made of cons-cells and strings."
18940       :offset 4
18941       :tag "Node"
18942       :type '(choice (string :tag "Leaf" :value "")
18943                      (cons :tag "Interior"
18944                            :value ("" . "")
18945                            binary-tree-of-string
18946                            binary-tree-of-string)))
18947
18948     (defcustom foo-bar ""
18949       "Sample variable holding a binary tree of strings."
18950       :type 'binary-tree-of-string)
18951
18952   The function to define a new widget is called ‘define-widget’.  The
18953first argument is the symbol we want to make a new widget type.  The
18954second argument is a symbol representing an existing widget, the new
18955widget is going to be defined in terms of difference from the existing
18956widget.  For the purpose of defining new customization types, the ‘lazy’
18957widget is perfect, because it accepts a ‘:type’ keyword argument with
18958the same syntax as the keyword argument to ‘defcustom’ with the same
18959name.  The third argument is a documentation string for the new widget.
18960You will be able to see that string with the ‘M-x widget-browse <RET>
18961binary-tree-of-string <RET>’ command.
18962
18963   After these mandatory arguments follow the keyword arguments.  The
18964most important is ‘:type’, which describes the data type we want to
18965match with this widget.  Here a ‘binary-tree-of-string’ is described as
18966being either a string, or a cons-cell whose car and cdr are themselves
18967both ‘binary-tree-of-string’.  Note the reference to the widget type we
18968are currently in the process of defining.  The ‘:tag’ attribute is a
18969string to name the widget in the user interface, and the ‘:offset’
18970argument is there to ensure that child nodes are indented four spaces
18971relative to the parent node, making the tree structure apparent in the
18972customization buffer.
18973
18974   The ‘defcustom’ shows how the new widget can be used as an ordinary
18975customization type.
18976
18977   The reason for the name ‘lazy’ is that the other composite widgets
18978convert their inferior widgets to internal form when the widget is
18979instantiated in a buffer.  This conversion is recursive, so the inferior
18980widgets will convert _their_ inferior widgets.  If the data structure is
18981itself recursive, this conversion is an infinite recursion.  The ‘lazy’
18982widget prevents the recursion: it convert its ‘:type’ argument only when
18983needed.
18984
18985
18986File: elisp.info,  Node: Applying Customizations,  Next: Custom Themes,  Prev: Customization Types,  Up: Customization
18987
1898815.5 Applying Customizations
18989============================
18990
18991The following functions are responsible for installing the user’s
18992customization settings for variables and faces, respectively.  When the
18993user invokes ‘Save for future sessions’ in the Customize interface, that
18994takes effect by writing a ‘custom-set-variables’ and/or a
18995‘custom-set-faces’ form into the custom file, to be evaluated the next
18996time Emacs starts.
18997
18998 -- Function: custom-set-variables &rest args
18999     This function installs the variable customizations specified by
19000     ARGS.  Each argument in ARGS should have the form
19001
19002          (VAR EXPRESSION [NOW [REQUEST [COMMENT]]])
19003
19004     VAR is a variable name (a symbol), and EXPRESSION is an expression
19005     which evaluates to the desired customized value.
19006
19007     If the ‘defcustom’ form for VAR has been evaluated prior to this
19008     ‘custom-set-variables’ call, EXPRESSION is immediately evaluated,
19009     and the variable’s value is set to the result.  Otherwise,
19010     EXPRESSION is stored into the variable’s ‘saved-value’ property, to
19011     be evaluated when the relevant ‘defcustom’ is called (usually when
19012     the library defining that variable is loaded into Emacs).
19013
19014     The NOW, REQUEST, and COMMENT entries are for internal use only,
19015     and may be omitted.  NOW, if non-‘nil’, means to set the variable’s
19016     value now, even if the variable’s ‘defcustom’ form has not been
19017     evaluated.  REQUEST is a list of features to be loaded immediately
19018     (*note Named Features::).  COMMENT is a string describing the
19019     customization.
19020
19021 -- Function: custom-set-faces &rest args
19022     This function installs the face customizations specified by ARGS.
19023     Each argument in ARGS should have the form
19024
19025          (FACE SPEC [NOW [COMMENT]])
19026
19027     FACE is a face name (a symbol), and SPEC is the customized face
19028     specification for that face (*note Defining Faces::).
19029
19030     The NOW and COMMENT entries are for internal use only, and may be
19031     omitted.  NOW, if non-‘nil’, means to install the face
19032     specification now, even if the ‘defface’ form has not been
19033     evaluated.  COMMENT is a string describing the customization.
19034
19035
19036File: elisp.info,  Node: Custom Themes,  Prev: Applying Customizations,  Up: Customization
19037
1903815.6 Custom Themes
19039==================
19040
19041“Custom themes” are collections of settings that can be enabled or
19042disabled as a unit.  *Note (emacs)Custom Themes::.  Each Custom theme is
19043defined by an Emacs Lisp source file, which should follow the
19044conventions described in this section.  (Instead of writing a Custom
19045theme by hand, you can also create one using a Customize-like interface;
19046*note (emacs)Creating Custom Themes::.)
19047
19048   A Custom theme file should be named ‘FOO-theme.el’, where FOO is the
19049theme name.  The first Lisp form in the file should be a call to
19050‘deftheme’, and the last form should be a call to ‘provide-theme’.
19051
19052 -- Macro: deftheme theme &optional doc
19053     This macro declares THEME (a symbol) as the name of a Custom theme.
19054     The optional argument DOC should be a string describing the theme;
19055     this is the description shown when the user invokes the
19056     ‘describe-theme’ command or types ‘?’ in the ‘*Custom Themes*’
19057     buffer.
19058
19059     Two special theme names are disallowed (using them causes an
19060     error): ‘user’ is a dummy theme that stores the user’s direct
19061     customization settings, and ‘changed’ is a dummy theme that stores
19062     changes made outside of the Customize system.
19063
19064 -- Macro: provide-theme theme
19065     This macro declares that the theme named THEME has been fully
19066     specified.
19067
19068   In between ‘deftheme’ and ‘provide-theme’ are Lisp forms specifying
19069the theme settings: usually a call to ‘custom-theme-set-variables’
19070and/or a call to ‘custom-theme-set-faces’.
19071
19072 -- Function: custom-theme-set-variables theme &rest args
19073     This function specifies the Custom theme THEME’s variable settings.
19074     THEME should be a symbol.  Each argument in ARGS should be a list
19075     of the form
19076
19077          (VAR EXPRESSION [NOW [REQUEST [COMMENT]]])
19078
19079     where the list entries have the same meanings as in
19080     ‘custom-set-variables’.  *Note Applying Customizations::.
19081
19082 -- Function: custom-theme-set-faces theme &rest args
19083     This function specifies the Custom theme THEME’s face settings.
19084     THEME should be a symbol.  Each argument in ARGS should be a list
19085     of the form
19086
19087          (FACE SPEC [NOW [COMMENT]])
19088
19089     where the list entries have the same meanings as in
19090     ‘custom-set-faces’.  *Note Applying Customizations::.
19091
19092   In theory, a theme file can also contain other Lisp forms, which
19093would be evaluated when loading the theme, but that is bad form.  To
19094protect against loading themes containing malicious code, Emacs displays
19095the source file and asks for confirmation from the user before loading
19096any non-built-in theme for the first time.  As such, themes are not
19097ordinarily byte-compiled, and source files always take precedence when
19098Emacs is looking for a theme to load.
19099
19100   The following functions are useful for programmatically enabling and
19101disabling themes:
19102
19103 -- Function: custom-theme-p theme
19104     This function return a non-‘nil’ value if THEME (a symbol) is the
19105     name of a Custom theme (i.e., a Custom theme which has been loaded
19106     into Emacs, whether or not the theme is enabled).  Otherwise, it
19107     returns ‘nil’.
19108
19109 -- Variable: custom-known-themes
19110     The value of this variable is a list of themes loaded into Emacs.
19111     Each theme is represented by a Lisp symbol (the theme name).  The
19112     default value of this variable is a list containing two dummy
19113     themes: ‘(user changed)’.  The ‘changed’ theme stores settings made
19114     before any Custom themes are applied (e.g., variables set outside
19115     of Customize).  The ‘user’ theme stores settings the user has
19116     customized and saved.  Any additional themes declared with the
19117     ‘deftheme’ macro are added to the front of this list.
19118
19119 -- Command: load-theme theme &optional no-confirm no-enable
19120     This function loads the Custom theme named THEME from its source
19121     file, looking for the source file in the directories specified by
19122     the variable ‘custom-theme-load-path’.  *Note (emacs)Custom
19123     Themes::.  It also “enables” the theme (unless the optional
19124     argument NO-ENABLE is non-‘nil’), causing its variable and face
19125     settings to take effect.  It prompts the user for confirmation
19126     before loading the theme, unless the optional argument NO-CONFIRM
19127     is non-‘nil’.
19128
19129 -- Command: enable-theme theme
19130     This function enables the Custom theme named THEME.  It signals an
19131     error if no such theme has been loaded.
19132
19133 -- Command: disable-theme theme
19134     This function disables the Custom theme named THEME.  The theme
19135     remains loaded, so that a subsequent call to ‘enable-theme’ will
19136     re-enable it.
19137
19138
19139File: elisp.info,  Node: Loading,  Next: Byte Compilation,  Prev: Customization,  Up: Top
19140
1914116 Loading
19142**********
19143
19144Loading a file of Lisp code means bringing its contents into the Lisp
19145environment in the form of Lisp objects.  Emacs finds and opens the
19146file, reads the text, evaluates each form, and then closes the file.
19147Such a file is also called a “Lisp library”.
19148
19149   The load functions evaluate all the expressions in a file just as the
19150‘eval-buffer’ function evaluates all the expressions in a buffer.  The
19151difference is that the load functions read and evaluate the text in the
19152file as found on disk, not the text in an Emacs buffer.
19153
19154   The loaded file must contain Lisp expressions, either as source code
19155or as byte-compiled code.  Each form in the file is called a “top-level
19156form”.  There is no special format for the forms in a loadable file; any
19157form in a file may equally well be typed directly into a buffer and
19158evaluated there.  (Indeed, most code is tested this way.)  Most often,
19159the forms are function definitions and variable definitions.
19160
19161   Emacs can also load compiled dynamic modules: shared libraries that
19162provide additional functionality for use in Emacs Lisp programs, just
19163like a package written in Emacs Lisp would.  When a dynamic module is
19164loaded, Emacs calls a specially-named initialization function which the
19165module needs to implement, and which exposes the additional functions
19166and variables to Emacs Lisp programs.
19167
19168   For on-demand loading of external libraries which are known in
19169advance to be required by certain Emacs primitives, *note Dynamic
19170Libraries::.
19171
19172* Menu:
19173
19174* How Programs Do Loading:: The ‘load’ function and others.
19175* Load Suffixes::           Details about the suffixes that ‘load’ tries.
19176* Library Search::          Finding a library to load.
19177* Loading Non-ASCII::       Non-ASCII characters in Emacs Lisp files.
19178* Autoload::                Setting up a function to autoload.
19179* Repeated Loading::        Precautions about loading a file twice.
19180* Named Features::          Loading a library if it isn’t already loaded.
19181* Where Defined::           Finding which file defined a certain symbol.
19182* Unloading::               How to unload a library that was loaded.
19183* Hooks for Loading::       Providing code to be run when
19184                              particular libraries are loaded.
19185* Dynamic Modules::         Modules provide additional Lisp primitives.
19186
19187
19188File: elisp.info,  Node: How Programs Do Loading,  Next: Load Suffixes,  Up: Loading
19189
1919016.1 How Programs Do Loading
19191============================
19192
19193Emacs Lisp has several interfaces for loading.  For example, ‘autoload’
19194creates a placeholder object for a function defined in a file; trying to
19195call the autoloading function loads the file to get the function’s real
19196definition (*note Autoload::).  ‘require’ loads a file if it isn’t
19197already loaded (*note Named Features::).  Ultimately, all these
19198facilities call the ‘load’ function to do the work.
19199
19200 -- Function: load filename &optional missing-ok nomessage nosuffix
19201          must-suffix
19202     This function finds and opens a file of Lisp code, evaluates all
19203     the forms in it, and closes the file.
19204
19205     To find the file, ‘load’ first looks for a file named
19206FILENAME.elc’, that is, for a file whose name is FILENAME with the
19207     extension ‘.elc’ appended.  If such a file exists, it is loaded.
19208     If there is no file by that name, then ‘load’ looks for a file
19209     named ‘FILENAME.el’.  If that file exists, it is loaded.  If Emacs
19210     was compiled with support for dynamic modules (*note Dynamic
19211     Modules::), ‘load’ next looks for a file named ‘FILENAME.EXT’,
19212     where EXT is a system-dependent file-name extension of shared
19213     libraries.  Finally, if neither of those names is found, ‘load’
19214     looks for a file named FILENAME with nothing appended, and loads it
19215     if it exists.  (The ‘load’ function is not clever about looking at
19216     FILENAME.  In the perverse case of a file named ‘foo.el.el’,
19217     evaluation of ‘(load "foo.el")’ will indeed find it.)
19218
19219     If Auto Compression mode is enabled, as it is by default, then if
19220     ‘load’ can not find a file, it searches for a compressed version of
19221     the file before trying other file names.  It decompresses and loads
19222     it if it exists.  It looks for compressed versions by appending
19223     each of the suffixes in ‘jka-compr-load-suffixes’ to the file name.
19224     The value of this variable must be a list of strings.  Its standard
19225     value is ‘(".gz")’.
19226
19227     If the optional argument NOSUFFIX is non-‘nil’, then ‘load’ does
19228     not try the suffixes ‘.elc’ and ‘.el’.  In this case, you must
19229     specify the precise file name you want, except that, if Auto
19230     Compression mode is enabled, ‘load’ will still use
19231     ‘jka-compr-load-suffixes’ to find compressed versions.  By
19232     specifying the precise file name and using ‘t’ for NOSUFFIX, you
19233     can prevent file names like ‘foo.el.el’ from being tried.
19234
19235     If the optional argument MUST-SUFFIX is non-‘nil’, then ‘load’
19236     insists that the file name used must end in either ‘.el’ or ‘.elc’
19237     (possibly extended with a compression suffix) or the shared-library
19238     extension, unless it contains an explicit directory name.
19239
19240     If the option ‘load-prefer-newer’ is non-‘nil’, then when searching
19241     suffixes, ‘load’ selects whichever version of a file (‘.elc’,
19242     ‘.el’, etc.) has been modified most recently.
19243
19244     If FILENAME is a relative file name, such as ‘foo’ or
19245baz/foo.bar’, ‘load’ searches for the file using the variable
19246     ‘load-path’.  It appends FILENAME to each of the directories listed
19247     in ‘load-path’, and loads the first file it finds whose name
19248     matches.  The current default directory is tried only if it is
19249     specified in ‘load-path’, where ‘nil’ stands for the default
19250     directory.  ‘load’ tries all three possible suffixes in the first
19251     directory in ‘load-path’, then all three suffixes in the second
19252     directory, and so on.  *Note Library Search::.
19253
19254     Whatever the name under which the file is eventually found, and the
19255     directory where Emacs found it, Emacs sets the value of the
19256     variable ‘load-file-name’ to that file’s name.
19257
19258     If you get a warning that ‘foo.elc’ is older than ‘foo.el’, it
19259     means you should consider recompiling ‘foo.el’.  *Note Byte
19260     Compilation::.
19261
19262     When loading a source file (not compiled), ‘load’ performs
19263     character set translation just as Emacs would do when visiting the
19264     file.  *Note Coding Systems::.
19265
19266     When loading an uncompiled file, Emacs tries to expand any macros
19267     that the file contains (*note Macros::).  We refer to this as
19268     “eager macro expansion”.  Doing this (rather than deferring the
19269     expansion until the relevant code runs) can significantly speed up
19270     the execution of uncompiled code.  Sometimes, this macro expansion
19271     cannot be done, owing to a cyclic dependency.  In the simplest
19272     example of this, the file you are loading refers to a macro defined
19273     in another file, and that file in turn requires the file you are
19274     loading.  This is generally harmless.  Emacs prints a warning
19275     (‘Eager macro-expansion skipped due to cycle...’) giving details of
19276     the problem, but it still loads the file, just leaving the macro
19277     unexpanded for now.  You may wish to restructure your code so that
19278     this does not happen.  Loading a compiled file does not cause
19279     macroexpansion, because this should already have happened during
19280     compilation.  *Note Compiling Macros::.
19281
19282     Messages like ‘Loading foo...’ and ‘Loading foo...done’ appear in
19283     the echo area during loading unless NOMESSAGE is non-‘nil’.
19284
19285     Any unhandled errors while loading a file terminate loading.  If
19286     the load was done for the sake of ‘autoload’, any function
19287     definitions made during the loading are undone.
19288
19289     If ‘load’ can’t find the file to load, then normally it signals a
19290     ‘file-error’ (with ‘Cannot open load file FILENAME’).  But if
19291     MISSING-OK is non-‘nil’, then ‘load’ just returns ‘nil’.
19292
19293     You can use the variable ‘load-read-function’ to specify a function
19294     for ‘load’ to use instead of ‘read’ for reading expressions.  See
19295     below.
19296
19297     ‘load’ returns ‘t’ if the file loads successfully.
19298
19299 -- Command: load-file filename
19300     This command loads the file FILENAME.  If FILENAME is a relative
19301     file name, then the current default directory is assumed.  This
19302     command does not use ‘load-path’, and does not append suffixes.
19303     However, it does look for compressed versions (if Auto Compression
19304     Mode is enabled).  Use this command if you wish to specify
19305     precisely the file name to load.
19306
19307 -- Command: load-library library
19308     This command loads the library named LIBRARY.  It is equivalent to
19309     ‘load’, except for the way it reads its argument interactively.
19310     *Note (emacs)Lisp Libraries::.
19311
19312 -- Variable: load-in-progress
19313     This variable is non-‘nil’ if Emacs is in the process of loading a
19314     file, and it is ‘nil’ otherwise.
19315
19316 -- Variable: load-file-name
19317     When Emacs is in the process of loading a file, this variable’s
19318     value is the name of that file, as Emacs found it during the search
19319     described earlier in this section.
19320
19321 -- Variable: load-read-function
19322     This variable specifies an alternate expression-reading function
19323     for ‘load’ and ‘eval-region’ to use instead of ‘read’.  The
19324     function should accept one argument, just as ‘read’ does.
19325
19326     By default, this variable’s value is ‘read’.  *Note Input
19327     Functions::.
19328
19329     Instead of using this variable, it is cleaner to use another, newer
19330     feature: to pass the function as the READ-FUNCTION argument to
19331     ‘eval-region’.  *Note Eval: Definition of eval-region.
19332
19333   For information about how ‘load’ is used in building Emacs, see *note
19334Building Emacs::.
19335
19336
19337File: elisp.info,  Node: Load Suffixes,  Next: Library Search,  Prev: How Programs Do Loading,  Up: Loading
19338
1933916.2 Load Suffixes
19340==================
19341
19342We now describe some technical details about the exact suffixes that
19343‘load’ tries.
19344
19345 -- Variable: load-suffixes
19346     This is a list of suffixes indicating (compiled or source) Emacs
19347     Lisp files.  It should not include the empty string.  ‘load’ uses
19348     these suffixes in order when it appends Lisp suffixes to the
19349     specified file name.  The standard value is ‘(".elc" ".el")’ which
19350     produces the behavior described in the previous section.
19351
19352 -- Variable: load-file-rep-suffixes
19353     This is a list of suffixes that indicate representations of the
19354     same file.  This list should normally start with the empty string.
19355     When ‘load’ searches for a file it appends the suffixes in this
19356     list, in order, to the file name, before searching for another
19357     file.
19358
19359     Enabling Auto Compression mode appends the suffixes in
19360     ‘jka-compr-load-suffixes’ to this list and disabling Auto
19361     Compression mode removes them again.  The standard value of
19362     ‘load-file-rep-suffixes’ if Auto Compression mode is disabled is
19363     ‘("")’.  Given that the standard value of ‘jka-compr-load-suffixes’
19364     is ‘(".gz")’, the standard value of ‘load-file-rep-suffixes’ if
19365     Auto Compression mode is enabled is ‘("" ".gz")’.
19366
19367 -- Function: get-load-suffixes
19368     This function returns the list of all suffixes that ‘load’ should
19369     try, in order, when its MUST-SUFFIX argument is non-‘nil’.  This
19370     takes both ‘load-suffixes’ and ‘load-file-rep-suffixes’ into
19371     account.  If ‘load-suffixes’, ‘jka-compr-load-suffixes’ and
19372     ‘load-file-rep-suffixes’ all have their standard values, this
19373     function returns ‘(".elc" ".elc.gz" ".el" ".el.gz")’ if Auto
19374     Compression mode is enabled and ‘(".elc" ".el")’ if Auto
19375     Compression mode is disabled.
19376
19377   To summarize, ‘load’ normally first tries the suffixes in the value
19378of ‘(get-load-suffixes)’ and then those in ‘load-file-rep-suffixes’.  If
19379NOSUFFIX is non-‘nil’, it skips the former group, and if MUST-SUFFIX is
19380non-‘nil’, it skips the latter group.
19381
19382 -- User Option: load-prefer-newer
19383     If this option is non-‘nil’, then rather than stopping at the first
19384     suffix that exists, ‘load’ tests them all, and uses whichever file
19385     is the newest.
19386
19387
19388File: elisp.info,  Node: Library Search,  Next: Loading Non-ASCII,  Prev: Load Suffixes,  Up: Loading
19389
1939016.3 Library Search
19391===================
19392
19393When Emacs loads a Lisp library, it searches for the library in a list
19394of directories specified by the variable ‘load-path’.
19395
19396 -- Variable: load-path
19397     The value of this variable is a list of directories to search when
19398     loading files with ‘load’.  Each element is a string (which must be
19399     a directory) or ‘nil’ (which stands for the current working
19400     directory).
19401
19402   When Emacs starts up, it sets up the value of ‘load-path’ in several
19403steps.  First, it initializes ‘load-path’ using default locations set
19404when Emacs was compiled.  Normally, this is a directory something like
19405
19406     "/usr/local/share/emacs/VERSION/lisp"
19407
19408   (In this and the following examples, replace ‘/usr/local’ with the
19409installation prefix appropriate for your Emacs.)  These directories
19410contain the standard Lisp files that come with Emacs.  If Emacs cannot
19411find them, it will not start correctly.
19412
19413   If you run Emacs from the directory where it was built—that is, an
19414executable that has not been formally installed—Emacs instead
19415initializes ‘load-path’ using the ‘lisp’ directory in the directory
19416containing the sources from which it was built.  If you built Emacs in a
19417separate directory from the sources, it also adds the lisp directories
19418from the build directory.  (In all cases, elements are represented as
19419absolute file names.)
19420
19421   Unless you start Emacs with the ‘--no-site-lisp’ option, it then adds
19422two more ‘site-lisp’ directories to the front of ‘load-path’.  These are
19423intended for locally installed Lisp files, and are normally of the form:
19424
19425     "/usr/local/share/emacs/VERSION/site-lisp"
19426
19427and
19428
19429     "/usr/local/share/emacs/site-lisp"
19430
19431The first one is for locally installed files for a specific Emacs
19432version; the second is for locally installed files meant for use with
19433all installed Emacs versions.  (If Emacs is running uninstalled, it also
19434adds ‘site-lisp’ directories from the source and build directories, if
19435they exist.  Normally these directories do not contain ‘site-lisp’
19436directories.)
19437
19438   If the environment variable ‘EMACSLOADPATH’ is set, it modifies the
19439above initialization procedure.  Emacs initializes ‘load-path’ based on
19440the value of the environment variable.
19441
19442   The syntax of ‘EMACSLOADPATH’ is the same as used for ‘PATH’;
19443directories are separated by ‘:’ (or ‘;’, on some operating systems).
19444Here is an example of how to set ‘EMACSLOADPATH’ variable (from a
19445‘sh’-style shell):
19446
19447     export EMACSLOADPATH=/home/foo/.emacs.d/lisp:
19448
19449   An empty element in the value of the environment variable, whether
19450trailing (as in the above example), leading, or embedded, is replaced by
19451the default value of ‘load-path’ as determined by the standard
19452initialization procedure.  If there are no such empty elements, then
19453‘EMACSLOADPATH’ specifies the entire ‘load-path’.  You must include
19454either an empty element, or the explicit path to the directory
19455containing the standard Lisp files, else Emacs will not function.
19456(Another way to modify ‘load-path’ is to use the ‘-L’ command-line
19457option when starting Emacs; see below.)
19458
19459   For each directory in ‘load-path’, Emacs then checks to see if it
19460contains a file ‘subdirs.el’, and if so, loads it.  The ‘subdirs.el19461file is created when Emacs is built/installed, and contains code that
19462causes Emacs to add any subdirectories of those directories to
19463‘load-path’.  Both immediate subdirectories and subdirectories multiple
19464levels down are added.  But it excludes subdirectories whose names do
19465not start with a letter or digit, and subdirectories named ‘RCS’ or
19466‘CVS’, and subdirectories containing a file named ‘.nosearch’.
19467
19468   Next, Emacs adds any extra load directories that you specify using
19469the ‘-L’ command-line option (*note (emacs)Action Arguments::).  It also
19470adds the directories where optional packages are installed, if any
19471(*note Packaging Basics::).
19472
19473   It is common to add code to one’s init file (*note Init File::) to
19474add one or more directories to ‘load-path’.  For example:
19475
19476     (push "~/.emacs.d/lisp" load-path)
19477
19478   Dumping Emacs uses a special value of ‘load-path’.  If you use a
19479site-load.el’ or ‘site-init.el’ file to customize the dumped Emacs
19480(*note Building Emacs::), any changes to ‘load-path’ that these files
19481make will be lost after dumping.
19482
19483 -- Command: locate-library library &optional nosuffix path
19484          interactive-call
19485     This command finds the precise file name for library LIBRARY.  It
19486     searches for the library in the same way ‘load’ does, and the
19487     argument NOSUFFIX has the same meaning as in ‘load’: don’t add
19488     suffixes ‘.elc’ or ‘.el’ to the specified name LIBRARY.
19489
19490     If the PATH is non-‘nil’, that list of directories is used instead
19491     of ‘load-path’.
19492
19493     When ‘locate-library’ is called from a program, it returns the file
19494     name as a string.  When the user runs ‘locate-library’
19495     interactively, the argument INTERACTIVE-CALL is ‘t’, and this tells
19496     ‘locate-library’ to display the file name in the echo area.
19497
19498 -- Command: list-load-path-shadows &optional stringp
19499     This command shows a list of “shadowed” Emacs Lisp files.  A
19500     shadowed file is one that will not normally be loaded, despite
19501     being in a directory on ‘load-path’, due to the existence of
19502     another similarly-named file in a directory earlier on ‘load-path’.
19503
19504     For instance, suppose ‘load-path’ is set to
19505
19506            ("/opt/emacs/site-lisp" "/usr/share/emacs/23.3/lisp")
19507
19508     and that both these directories contain a file named ‘foo.el’.
19509     Then ‘(require 'foo)’ never loads the file in the second directory.
19510     Such a situation might indicate a problem in the way Emacs was
19511     installed.
19512
19513     When called from Lisp, this function prints a message listing the
19514     shadowed files, instead of displaying them in a buffer.  If the
19515     optional argument ‘stringp’ is non-‘nil’, it instead returns the
19516     shadowed files as a string.
19517
19518
19519File: elisp.info,  Node: Loading Non-ASCII,  Next: Autoload,  Prev: Library Search,  Up: Loading
19520
1952116.4 Loading Non-ASCII Characters
19522=================================
19523
19524When Emacs Lisp programs contain string constants with non-ASCII
19525characters, these can be represented within Emacs either as unibyte
19526strings or as multibyte strings (*note Text Representations::).  Which
19527representation is used depends on how the file is read into Emacs.  If
19528it is read with decoding into multibyte representation, the text of the
19529Lisp program will be multibyte text, and its string constants will be
19530multibyte strings.  If a file containing Latin-1 characters (for
19531example) is read without decoding, the text of the program will be
19532unibyte text, and its string constants will be unibyte strings.  *Note
19533Coding Systems::.
19534
19535   In most Emacs Lisp programs, the fact that non-ASCII strings are
19536multibyte strings should not be noticeable, since inserting them in
19537unibyte buffers converts them to unibyte automatically.  However, if
19538this does make a difference, you can force a particular Lisp file to be
19539interpreted as unibyte by writing ‘coding: raw-text’ in a local
19540variables section.  With that designator, the file will unconditionally
19541be interpreted as unibyte.  This can matter when making keybindings to
19542non-ASCII characters written as ‘?vLITERAL’.
19543
19544
19545File: elisp.info,  Node: Autoload,  Next: Repeated Loading,  Prev: Loading Non-ASCII,  Up: Loading
19546
1954716.5 Autoload
19548=============
19549
19550The “autoload” facility lets you register the existence of a function or
19551macro, but put off loading the file that defines it.  The first call to
19552the function automatically loads the proper library, in order to install
19553the real definition and other associated code, then runs the real
19554definition as if it had been loaded all along.  Autoloading can also be
19555triggered by looking up the documentation of the function or macro
19556(*note Documentation Basics::), and completion of variable and function
19557names (*note Autoload by Prefix:: below).
19558
19559* Menu:
19560
19561* Autoload by Prefix:: Autoload by Prefix.
19562* When to Autoload::   When to Use Autoload.
19563
19564   There are two ways to set up an autoloaded function: by calling
19565‘autoload’, and by writing a “magic” comment in the source before the
19566real definition.  ‘autoload’ is the low-level primitive for autoloading;
19567any Lisp program can call ‘autoload’ at any time.  Magic comments are
19568the most convenient way to make a function autoload, for packages
19569installed along with Emacs.  These comments do nothing on their own, but
19570they serve as a guide for the command ‘update-file-autoloads’, which
19571constructs calls to ‘autoload’ and arranges to execute them when Emacs
19572is built.
19573
19574 -- Function: autoload function filename &optional docstring interactive
19575          type
19576     This function defines the function (or macro) named FUNCTION so as
19577     to load automatically from FILENAME.  The string FILENAME specifies
19578     the file to load to get the real definition of FUNCTION.
19579
19580     If FILENAME does not contain either a directory name, or the suffix
19581     ‘.el’ or ‘.elc’, this function insists on adding one of these
19582     suffixes, and it will not load from a file whose name is just
19583     FILENAME with no added suffix.  (The variable ‘load-suffixes’
19584     specifies the exact required suffixes.)
19585
19586     The argument DOCSTRING is the documentation string for the
19587     function.  Specifying the documentation string in the call to
19588     ‘autoload’ makes it possible to look at the documentation without
19589     loading the function’s real definition.  Normally, this should be
19590     identical to the documentation string in the function definition
19591     itself.  If it isn’t, the function definition’s documentation
19592     string takes effect when it is loaded.
19593
19594     If INTERACTIVE is non-‘nil’, that says FUNCTION can be called
19595     interactively.  This lets completion in ‘M-x’ work without loading
19596     FUNCTION’s real definition.  The complete interactive specification
19597     is not given here; it’s not needed unless the user actually calls
19598     FUNCTION, and when that happens, it’s time to load the real
19599     definition.
19600
19601     You can autoload macros and keymaps as well as ordinary functions.
19602     Specify TYPE as ‘macro’ if FUNCTION is really a macro.  Specify
19603     TYPE as ‘keymap’ if FUNCTION is really a keymap.  Various parts of
19604     Emacs need to know this information without loading the real
19605     definition.
19606
19607     An autoloaded keymap loads automatically during key lookup when a
19608     prefix key’s binding is the symbol FUNCTION.  Autoloading does not
19609     occur for other kinds of access to the keymap.  In particular, it
19610     does not happen when a Lisp program gets the keymap from the value
19611     of a variable and calls ‘define-key’; not even if the variable name
19612     is the same symbol FUNCTION.
19613
19614     If FUNCTION already has a non-void function definition that is not
19615     an autoload object, this function does nothing and returns ‘nil’.
19616     Otherwise, it constructs an autoload object (*note Autoload
19617     Type::), and stores it as the function definition for FUNCTION.
19618     The autoload object has this form:
19619
19620          (autoload FILENAME DOCSTRING INTERACTIVE TYPE)
19621
19622     For example,
19623
19624          (symbol-function 'run-prolog)
19625               ⇒ (autoload "prolog" 169681 t nil)
19626
19627     In this case, ‘"prolog"’ is the name of the file to load, 169681
19628     refers to the documentation string in the ‘emacs/etc/DOC’ file
19629     (*note Documentation Basics::), ‘t’ means the function is
19630     interactive, and ‘nil’ that it is not a macro or a keymap.
19631
19632 -- Function: autoloadp object
19633     This function returns non-‘nil’ if OBJECT is an autoload object.
19634     For example, to check if ‘run-prolog’ is defined as an autoloaded
19635     function, evaluate
19636
19637          (autoloadp (symbol-function 'run-prolog))
19638
19639   The autoloaded file usually contains other definitions and may
19640require or provide one or more features.  If the file is not completely
19641loaded (due to an error in the evaluation of its contents), any function
19642definitions or ‘provide’ calls that occurred during the load are undone.
19643This is to ensure that the next attempt to call any function autoloading
19644from this file will try again to load the file.  If not for this, then
19645some of the functions in the file might be defined by the aborted load,
19646but fail to work properly for the lack of certain subroutines not loaded
19647successfully because they come later in the file.
19648
19649   If the autoloaded file fails to define the desired Lisp function or
19650macro, then an error is signaled with data ‘"Autoloading failed to
19651define function FUNCTION-NAME"’.
19652
19653   A magic autoload comment (often called an “autoload cookie”) consists
19654of ‘;;;###autoload’, on a line by itself, just before the real
19655definition of the function in its autoloadable source file.  The command
19656‘M-x update-file-autoloads’ writes a corresponding ‘autoload’ call into
19657loaddefs.el’.  (The string that serves as the autoload cookie and the
19658name of the file generated by ‘update-file-autoloads’ can be changed
19659from the above defaults, see below.)  Building Emacs loads ‘loaddefs.el19660and thus calls ‘autoload’.  ‘M-x update-directory-autoloads’ is even
19661more powerful; it updates autoloads for all files in the current
19662directory.
19663
19664   The same magic comment can copy any kind of form into ‘loaddefs.el’.
19665The form following the magic comment is copied verbatim, _except_ if it
19666is one of the forms which the autoload facility handles specially (e.g.,
19667by conversion into an ‘autoload’ call).  The forms which are not copied
19668verbatim are the following:
19669
19670Definitions for function or function-like objects:
19671     ‘defun’ and ‘defmacro’; also ‘cl-defun’ and ‘cl-defmacro’ (*note
19672     (cl)Argument Lists::), and ‘define-overloadable-function’ (see the
19673     commentary in ‘mode-local.el’).
19674
19675Definitions for major or minor modes:
19676     ‘define-minor-mode’, ‘define-globalized-minor-mode’,
19677     ‘define-generic-mode’, ‘define-derived-mode’,
19678     ‘easy-mmode-define-minor-mode’, ‘easy-mmode-define-global-mode’,
19679     ‘define-compilation-mode’, and ‘define-global-minor-mode’.
19680
19681Other definition types:
19682     ‘defcustom’, ‘defgroup’, ‘defclass’ (*note EIEIO: (eieio)Top.), and
19683     ‘define-skeleton’ (*note Autotyping: (autotype)Top.).
19684
19685   You can also use a magic comment to execute a form at build time
19686_without_ executing it when the file itself is loaded.  To do this,
19687write the form _on the same line_ as the magic comment.  Since it is in
19688a comment, it does nothing when you load the source file; but ‘M-x
19689update-file-autoloads’ copies it to ‘loaddefs.el’, where it is executed
19690while building Emacs.
19691
19692   The following example shows how ‘doctor’ is prepared for autoloading
19693with a magic comment:
19694
19695     ;;;###autoload
19696     (defun doctor ()
19697       "Switch to *doctor* buffer and start giving psychotherapy."
19698       (interactive)
19699       (switch-to-buffer "*doctor*")
19700       (doctor-mode))
19701
19702Here’s what that produces in ‘loaddefs.el’:
19703
19704     (autoload 'doctor "doctor" "\
19705     Switch to *doctor* buffer and start giving psychotherapy.
19706
19707     \(fn)" t nil)
19708
19709The backslash and newline immediately following the double-quote are a
19710convention used only in the preloaded uncompiled Lisp files such as
19711loaddefs.el’; they tell ‘make-docfile’ to put the documentation string
19712in the ‘etc/DOC’ file.  *Note Building Emacs::.  See also the commentary
19713in ‘lib-src/make-docfile.c’.  ‘(fn)’ in the usage part of the
19714documentation string is replaced with the function’s name when the
19715various help functions (*note Help Functions::) display it.
19716
19717   If you write a function definition with an unusual macro that is not
19718one of the known and recognized function definition methods, use of an
19719ordinary magic autoload comment would copy the whole definition into
19720loaddefs.el’.  That is not desirable.  You can put the desired
19721‘autoload’ call into ‘loaddefs.el’ instead by writing this:
19722
19723     ;;;###autoload (autoload 'foo "myfile")
19724     (mydefunmacro foo
19725       ...)
19726
19727   You can use a non-default string as the autoload cookie and have the
19728corresponding autoload calls written into a file whose name is different
19729from the default ‘loaddefs.el’.  Emacs provides two variables to control
19730this:
19731
19732 -- Variable: generate-autoload-cookie
19733     The value of this variable should be a string whose syntax is a
19734     Lisp comment.  ‘M-x update-file-autoloads’ copies the Lisp form
19735     that follows the cookie into the autoload file it generates.  The
19736     default value of this variable is ‘";;;###autoload"’.
19737
19738 -- Variable: generated-autoload-file
19739     The value of this variable names an Emacs Lisp file where the
19740     autoload calls should go.  The default value is ‘loaddefs.el’, but
19741     you can override that, e.g., in the local variables section of a
19742     ‘.el’ file (*note File Local Variables::).  The autoload file is
19743     assumed to contain a trailer starting with a formfeed character.
19744
19745   The following function may be used to explicitly load the library
19746specified by an autoload object:
19747
19748 -- Function: autoload-do-load autoload &optional name macro-only
19749     This function performs the loading specified by AUTOLOAD, which
19750     should be an autoload object.  The optional argument NAME, if
19751     non-‘nil’, should be a symbol whose function value is AUTOLOAD; in
19752     that case, the return value of this function is the symbol’s new
19753     function value.  If the value of the optional argument MACRO-ONLY
19754     is ‘macro’, this function avoids loading a function, only a macro.
19755
19756
19757File: elisp.info,  Node: Autoload by Prefix,  Next: When to Autoload,  Up: Autoload
19758
1975916.5.1 Autoload by Prefix
19760-------------------------
19761
19762During completion for the commands ‘describe-variable’ and
19763‘describe-function’, Emacs will try to load files which may contain
19764definitions matching the prefix being completed.  The variable
19765‘definition-prefixes’ holds a hashtable which maps a prefix to the
19766corresponding list of files to load for it.  Entries to this mapping are
19767added by calls to ‘register-definition-prefixes’ which are generated by
19768‘update-file-autoloads’ (*note Autoload::).  Files which don’t contain
19769any definitions worth loading (test files, for examples), should set
19770‘autoload-compute-prefixes’ to ‘nil’ as a file-local variable.
19771
19772
19773File: elisp.info,  Node: When to Autoload,  Prev: Autoload by Prefix,  Up: Autoload
19774
1977516.5.2 When to Use Autoload
19776---------------------------
19777
19778Do not add an autoload comment unless it is really necessary.
19779Autoloading code means it is always globally visible.  Once an item is
19780autoloaded, there is no compatible way to transition back to it not
19781being autoloaded (after people become accustomed to being able to use it
19782without an explicit load).
19783
19784   • The most common items to autoload are the interactive entry points
19785     to a library.  For example, if ‘python.el’ is a library defining a
19786     major-mode for editing Python code, autoload the definition of the
19787     ‘python-mode’ function, so that people can simply use ‘M-x
19788     python-mode’ to load the library.
19789
19790   • Variables usually don’t need to be autoloaded.  An exception is if
19791     the variable on its own is generally useful without the whole
19792     defining library being loaded.  (An example of this might be
19793     something like ‘find-exec-terminator’.)
19794
19795   • Don’t autoload a user option just so that a user can set it.
19796
19797   • Never add an autoload _comment_ to silence a compiler warning in
19798     another file.  In the file that produces the warning, use ‘(defvar
19799     foo)’ to silence an undefined variable warning, and
19800     ‘declare-function’ (*note Declaring Functions::) to silence an
19801     undefined function warning; or require the relevant library; or use
19802     an explicit autoload _statement_.
19803
19804
19805File: elisp.info,  Node: Repeated Loading,  Next: Named Features,  Prev: Autoload,  Up: Loading
19806
1980716.6 Repeated Loading
19808=====================
19809
19810You can load a given file more than once in an Emacs session.  For
19811example, after you have rewritten and reinstalled a function definition
19812by editing it in a buffer, you may wish to return to the original
19813version; you can do this by reloading the file it came from.
19814
19815   When you load or reload files, bear in mind that the ‘load’ and
19816‘load-library’ functions automatically load a byte-compiled file rather
19817than a non-compiled file of similar name.  If you rewrite a file that
19818you intend to save and reinstall, you need to byte-compile the new
19819version; otherwise Emacs will load the older, byte-compiled file instead
19820of your newer, non-compiled file!  If that happens, the message
19821displayed when loading the file includes, ‘(compiled; note, source is
19822newer)’, to remind you to recompile it.
19823
19824   When writing the forms in a Lisp library file, keep in mind that the
19825file might be loaded more than once.  For example, think about whether
19826each variable should be reinitialized when you reload the library;
19827‘defvar’ does not change the value if the variable is already
19828initialized.  (*Note Defining Variables::.)
19829
19830   The simplest way to add an element to an alist is like this:
19831
19832     (push '(leif-mode " Leif") minor-mode-alist)
19833
19834But this would add multiple elements if the library is reloaded.  To
19835avoid the problem, use ‘add-to-list’ (*note List Variables::):
19836
19837     (add-to-list 'minor-mode-alist '(leif-mode " Leif"))
19838
19839   Occasionally you will want to test explicitly whether a library has
19840already been loaded.  If the library uses ‘provide’ to provide a named
19841feature, you can use ‘featurep’ earlier in the file to test whether the
19842‘provide’ call has been executed before (*note Named Features::).
19843Alternatively, you could use something like this:
19844
19845     (defvar foo-was-loaded nil)
19846
19847     (unless foo-was-loaded
19848       EXECUTE-FIRST-TIME-ONLY
19849       (setq foo-was-loaded t))
19850
19851
19852
19853File: elisp.info,  Node: Named Features,  Next: Where Defined,  Prev: Repeated Loading,  Up: Loading
19854
1985516.7 Features
19856=============
19857
19858‘provide’ and ‘require’ are an alternative to ‘autoload’ for loading
19859files automatically.  They work in terms of named “features”.
19860Autoloading is triggered by calling a specific function, but a feature
19861is loaded the first time another program asks for it by name.
19862
19863   A feature name is a symbol that stands for a collection of functions,
19864variables, etc.  The file that defines them should “provide” the
19865feature.  Another program that uses them may ensure they are defined by
19866“requiring” the feature.  This loads the file of definitions if it
19867hasn’t been loaded already.
19868
19869   To require the presence of a feature, call ‘require’ with the feature
19870name as argument.  ‘require’ looks in the global variable ‘features’ to
19871see whether the desired feature has been provided already.  If not, it
19872loads the feature from the appropriate file.  This file should call
19873‘provide’ at the top level to add the feature to ‘features’; if it fails
19874to do so, ‘require’ signals an error.
19875
19876   For example, in ‘idlwave.el’, the definition for
19877‘idlwave-complete-filename’ includes the following code:
19878
19879     (defun idlwave-complete-filename ()
19880       "Use the comint stuff to complete a file name."
19881        (require 'comint)
19882        (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
19883               (comint-completion-addsuffix nil)
19884               ...)
19885            (comint-dynamic-complete-filename)))
19886
19887The expression ‘(require 'comint)’ loads the file ‘comint.el’ if it has
19888not yet been loaded, ensuring that ‘comint-dynamic-complete-filename’ is
19889defined.  Features are normally named after the files that provide them,
19890so that ‘require’ need not be given the file name.  (Note that it is
19891important that the ‘require’ statement be outside the body of the ‘let’.
19892Loading a library while its variables are let-bound can have unintended
19893consequences, namely the variables becoming unbound after the let
19894exits.)
19895
19896   The ‘comint.el’ file contains the following top-level expression:
19897
19898     (provide 'comint)
19899
19900This adds ‘comint’ to the global ‘features’ list, so that ‘(require
19901'comint)’ will henceforth know that nothing needs to be done.
19902
19903   When ‘require’ is used at top level in a file, it takes effect when
19904you byte-compile that file (*note Byte Compilation::) as well as when
19905you load it.  This is in case the required package contains macros that
19906the byte compiler must know about.  It also avoids byte compiler
19907warnings for functions and variables defined in the file loaded with
19908‘require’.
19909
19910   Although top-level calls to ‘require’ are evaluated during byte
19911compilation, ‘provide’ calls are not.  Therefore, you can ensure that a
19912file of definitions is loaded before it is byte-compiled by including a
19913‘provide’ followed by a ‘require’ for the same feature, as in the
19914following example.
19915
19916     (provide 'my-feature)  ; Ignored by byte compiler,
19917                            ;   evaluated by ‘load’.
19918     (require 'my-feature)  ; Evaluated by byte compiler.
19919
19920The compiler ignores the ‘provide’, then processes the ‘require’ by
19921loading the file in question.  Loading the file does execute the
19922‘provide’ call, so the subsequent ‘require’ call does nothing when the
19923file is loaded.
19924
19925 -- Function: provide feature &optional subfeatures
19926     This function announces that FEATURE is now loaded, or being
19927     loaded, into the current Emacs session.  This means that the
19928     facilities associated with FEATURE are or will be available for
19929     other Lisp programs.
19930
19931     The direct effect of calling ‘provide’ is to add FEATURE to the
19932     front of ‘features’ if it is not already in that list and call any
19933     ‘eval-after-load’ code waiting for it (*note Hooks for Loading::).
19934     The argument FEATURE must be a symbol.  ‘provide’ returns FEATURE.
19935
19936     If provided, SUBFEATURES should be a list of symbols indicating a
19937     set of specific subfeatures provided by this version of FEATURE.
19938     You can test the presence of a subfeature using ‘featurep’.  The
19939     idea of subfeatures is that you use them when a package (which is
19940     one FEATURE) is complex enough to make it useful to give names to
19941     various parts or functionalities of the package, which might or
19942     might not be loaded, or might or might not be present in a given
19943     version.  *Note Network Feature Testing::, for an example.
19944
19945          features
19946               ⇒ (bar bish)
19947
19948          (provide 'foo)
19949               ⇒ foo
19950          features
19951               ⇒ (foo bar bish)
19952
19953     When a file is loaded to satisfy an autoload, and it stops due to
19954     an error in the evaluation of its contents, any function
19955     definitions or ‘provide’ calls that occurred during the load are
19956     undone.  *Note Autoload::.
19957
19958 -- Function: require feature &optional filename noerror
19959     This function checks whether FEATURE is present in the current
19960     Emacs session (using ‘(featurep FEATURE)’; see below).  The
19961     argument FEATURE must be a symbol.
19962
19963     If the feature is not present, then ‘require’ loads FILENAME with
19964     ‘load’.  If FILENAME is not supplied, then the name of the symbol
19965     FEATURE is used as the base file name to load.  However, in this
19966     case, ‘require’ insists on finding FEATURE with an added ‘.el’ or
19967     ‘.elc’ suffix (possibly extended with a compression suffix); a file
19968     whose name is just FEATURE won’t be used.  (The variable
19969     ‘load-suffixes’ specifies the exact required Lisp suffixes.)
19970
19971     If NOERROR is non-‘nil’, that suppresses errors from actual loading
19972     of the file.  In that case, ‘require’ returns ‘nil’ if loading the
19973     file fails.  Normally, ‘require’ returns FEATURE.
19974
19975     If loading the file succeeds but does not provide FEATURE,
19976     ‘require’ signals an error about the missing feature.
19977
19978 -- Function: featurep feature &optional subfeature
19979     This function returns ‘t’ if FEATURE has been provided in the
19980     current Emacs session (i.e., if FEATURE is a member of ‘features’.)
19981     If SUBFEATURE is non-‘nil’, then the function returns ‘t’ only if
19982     that subfeature is provided as well (i.e., if SUBFEATURE is a
19983     member of the ‘subfeature’ property of the FEATURE symbol.)
19984
19985 -- Variable: features
19986     The value of this variable is a list of symbols that are the
19987     features loaded in the current Emacs session.  Each symbol was put
19988     in this list with a call to ‘provide’.  The order of the elements
19989     in the ‘features’ list is not significant.
19990
19991
19992File: elisp.info,  Node: Where Defined,  Next: Unloading,  Prev: Named Features,  Up: Loading
19993
1999416.8 Which File Defined a Certain Symbol
19995========================================
19996
19997 -- Function: symbol-file symbol &optional type
19998     This function returns the name of the file that defined SYMBOL.  If
19999     TYPE is ‘nil’, then any kind of definition is acceptable.  If TYPE
20000     is ‘defun’, ‘defvar’, or ‘defface’, that specifies function
20001     definition, variable definition, or face definition only.
20002
20003     The value is normally an absolute file name.  It can also be ‘nil’,
20004     if the definition is not associated with any file.  If SYMBOL
20005     specifies an autoloaded function, the value can be a relative file
20006     name without extension.
20007
20008   The basis for ‘symbol-file’ is the data in the variable
20009‘load-history’.
20010
20011 -- Variable: load-history
20012     The value of this variable is an alist that associates the names of
20013     loaded library files with the names of the functions and variables
20014     they defined, as well as the features they provided or required.
20015
20016     Each element in this alist describes one loaded library (including
20017     libraries that are preloaded at startup).  It is a list whose CAR
20018     is the absolute file name of the library (a string).  The rest of
20019     the list elements have these forms:
20020
20021     ‘VAR’
20022          The symbol VAR was defined as a variable.
20023     ‘(defun . FUN)’
20024          The function FUN was defined.
20025     ‘(t . FUN)’
20026          The function FUN was previously an autoload before this
20027          library redefined it as a function.  The following element is
20028          always ‘(defun . FUN)’, which represents defining FUN as a
20029          function.
20030     ‘(autoload . FUN)’
20031          The function FUN was defined as an autoload.
20032     ‘(defface . FACE)’
20033          The face FACE was defined.
20034     ‘(require . FEATURE)’
20035          The feature FEATURE was required.
20036     ‘(provide . FEATURE)’
20037          The feature FEATURE was provided.
20038     ‘(cl-defmethod METHOD SPECIALIZERS)’
20039          The named METHOD was defined by using ‘cl-defmethod’, with
20040          SPECIALIZERS as its specializers.
20041     ‘(define-type . TYPE)’
20042          The type TYPE was defined.
20043
20044     The value of ‘load-history’ may have one element whose CAR is
20045     ‘nil’.  This element describes definitions made with ‘eval-buffer’
20046     on a buffer that is not visiting a file.
20047
20048   The command ‘eval-region’ updates ‘load-history’, but does so by
20049adding the symbols defined to the element for the file being visited,
20050rather than replacing that element.  *Note Eval::.
20051
20052
20053File: elisp.info,  Node: Unloading,  Next: Hooks for Loading,  Prev: Where Defined,  Up: Loading
20054
2005516.9 Unloading
20056==============
20057
20058You can discard the functions and variables loaded by a library to
20059reclaim memory for other Lisp objects.  To do this, use the function
20060‘unload-feature’:
20061
20062 -- Command: unload-feature feature &optional force
20063     This command unloads the library that provided feature FEATURE.  It
20064     undefines all functions, macros, and variables defined in that
20065     library with ‘defun’, ‘defalias’, ‘defsubst’, ‘defmacro’,
20066     ‘defconst’, ‘defvar’, and ‘defcustom’.  It then restores any
20067     autoloads formerly associated with those symbols.  (Loading saves
20068     these in the ‘autoload’ property of the symbol.)
20069
20070     Before restoring the previous definitions, ‘unload-feature’ runs
20071     ‘remove-hook’ to remove functions in the library from certain
20072     hooks.  These hooks include variables whose names end in ‘-hook’
20073     (or the deprecated suffix ‘-hooks’), plus those listed in
20074     ‘unload-feature-special-hooks’, as well as ‘auto-mode-alist’.  This
20075     is to prevent Emacs from ceasing to function because important
20076     hooks refer to functions that are no longer defined.
20077
20078     Standard unloading activities also undoes ELP profiling of
20079     functions in that library, unprovides any features provided by the
20080     library, and cancels timers held in variables defined by the
20081     library.
20082
20083     If these measures are not sufficient to prevent malfunction, a
20084     library can define an explicit unloader named
20085     ‘FEATURE-unload-function’.  If that symbol is defined as a
20086     function, ‘unload-feature’ calls it with no arguments before doing
20087     anything else.  It can do whatever is appropriate to unload the
20088     library.  If it returns ‘nil’, ‘unload-feature’ proceeds to take
20089     the normal unload actions.  Otherwise it considers the job to be
20090     done.
20091
20092     Ordinarily, ‘unload-feature’ refuses to unload a library on which
20093     other loaded libraries depend.  (A library A depends on library B
20094     if A contains a ‘require’ for B.)  If the optional argument FORCE
20095     is non-‘nil’, dependencies are ignored and you can unload any
20096     library.
20097
20098   The ‘unload-feature’ function is written in Lisp; its actions are
20099based on the variable ‘load-history’.
20100
20101 -- Variable: unload-feature-special-hooks
20102     This variable holds a list of hooks to be scanned before unloading
20103     a library, to remove functions defined in the library.
20104
20105
20106File: elisp.info,  Node: Hooks for Loading,  Next: Dynamic Modules,  Prev: Unloading,  Up: Loading
20107
2010816.10 Hooks for Loading
20109=======================
20110
20111You can ask for code to be executed each time Emacs loads a library, by
20112using the variable ‘after-load-functions’:
20113
20114 -- Variable: after-load-functions
20115     This abnormal hook is run after loading a file.  Each function in
20116     the hook is called with a single argument, the absolute filename of
20117     the file that was just loaded.
20118
20119   If you want code to be executed when a _particular_ library is
20120loaded, use the macro ‘with-eval-after-load’:
20121
20122 -- Macro: with-eval-after-load library body...
20123     This macro arranges to evaluate BODY at the end of loading the file
20124     LIBRARY, each time LIBRARY is loaded.  If LIBRARY is already
20125     loaded, it evaluates BODY right away.
20126
20127     You don’t need to give a directory or extension in the file name
20128     LIBRARY.  Normally, you just give a bare file name, like this:
20129
20130          (with-eval-after-load "edebug" (def-edebug-spec c-point t))
20131
20132     To restrict which files can trigger the evaluation, include a
20133     directory or an extension or both in LIBRARY.  Only a file whose
20134     absolute true name (i.e., the name with all symbolic links chased
20135     out) matches all the given name components will match.  In the
20136     following example, ‘my_inst.elc’ or ‘my_inst.elc.gz’ in some
20137     directory ‘..../foo/bar’ will trigger the evaluation, but not
20138my_inst.el’:
20139
20140          (with-eval-after-load "foo/bar/my_inst.elc" ...)
20141
20142     LIBRARY can also be a feature (i.e., a symbol), in which case BODY
20143     is evaluated at the end of any file where ‘(provide LIBRARY)’ is
20144     called.
20145
20146     An error in BODY does not undo the load, but does prevent execution
20147     of the rest of BODY.
20148
20149   Normally, well-designed Lisp programs should not use
20150‘with-eval-after-load’.  If you need to examine and set the variables
20151defined in another library (those meant for outside use), you can do it
20152immediately—there is no need to wait until the library is loaded.  If
20153you need to call functions defined by that library, you should load the
20154library, preferably with ‘require’ (*note Named Features::).
20155
20156
20157File: elisp.info,  Node: Dynamic Modules,  Prev: Hooks for Loading,  Up: Loading
20158
2015916.11 Emacs Dynamic Modules
20160===========================
20161
20162A “dynamic Emacs module” is a shared library that provides additional
20163functionality for use in Emacs Lisp programs, just like a package
20164written in Emacs Lisp would.
20165
20166   Functions that load Emacs Lisp packages can also load dynamic
20167modules.  They recognize dynamic modules by looking at their file-name
20168extension, a.k.a. “suffix”.  This suffix is platform-dependent.
20169
20170 -- Variable: module-file-suffix
20171     This variable holds the system-dependent value of the file-name
20172     extension of the module files.  Its value is ‘.so’ on POSIX hosts
20173     and ‘.dll’ on MS-Windows.
20174
20175   Every dynamic module should export a C-callable function named
20176‘emacs_module_init’, which Emacs will call as part of the call to ‘load’
20177or ‘require’ which loads the module.  It should also export a symbol
20178named ‘plugin_is_GPL_compatible’ to indicate that its code is released
20179under the GPL or compatible license; Emacs will signal an error if your
20180program tries to load modules that don’t export such a symbol.
20181
20182   If a module needs to call Emacs functions, it should do so through
20183the API (Application Programming Interface) defined and documented in
20184the header file ‘emacs-module.h’ that is part of the Emacs distribution.
20185*Note Writing Dynamic Modules::, for details of using that API when
20186writing your own modules.
20187
20188   Modules can create ‘user-ptr’ Lisp objects that embed pointers to C
20189struct’s defined by the module.  This is useful for keeping around
20190complex data structures created by a module, to be passed back to the
20191module’s functions.  User-ptr objects can also have associated
20192“finalizers” – functions to be run when the object is GC’ed; this is
20193useful for freeing any resources allocated for the underlying data
20194structure, such as memory, open file descriptors, etc.  *Note Module
20195Values::.
20196
20197 -- Function: user-ptrp object
20198     This function returns ‘t’ if its argument is a ‘user-ptr’ object.
20199
20200 -- Function: module-load file
20201     Emacs calls this low-level primitive to load a module from the
20202     specified FILE and perform the necessary initialization of the
20203     module.  This is the primitive which makes sure the module exports
20204     the ‘plugin_is_GPL_compatible’ symbol, calls the module’s
20205     ‘emacs_module_init’ function, and signals an error if that function
20206     returns an error indication, or if the use typed ‘C-g’ during the
20207     initialization.  If the initialization succeeds, ‘module-load’
20208     returns ‘t’.  Note that FILE must already have the proper file-name
20209     extension, as this function doesn’t try looking for files with
20210     known extensions, unlike ‘load’.
20211
20212     Unlike ‘load’, ‘module-load’ doesn’t record the module in
20213     ‘load-history’, doesn’t print any messages, and doesn’t protect
20214     against recursive loads.  Most users should therefore use ‘load’,
20215     ‘load-file’, ‘load-library’, or ‘require’ instead of ‘module-load’.
20216
20217   Loadable modules in Emacs are enabled by using the ‘--with-modules’
20218option at configure time.
20219
20220
20221File: elisp.info,  Node: Byte Compilation,  Next: Debugging,  Prev: Loading,  Up: Top
20222
2022317 Byte Compilation
20224*******************
20225
20226Emacs Lisp has a “compiler” that translates functions written in Lisp
20227into a special representation called “byte-code” that can be executed
20228more efficiently.  The compiler replaces Lisp function definitions with
20229byte-code.  When a byte-code function is called, its definition is
20230evaluated by the “byte-code interpreter”.
20231
20232   Because the byte-compiled code is evaluated by the byte-code
20233interpreter, instead of being executed directly by the machine’s
20234hardware (as true compiled code is), byte-code is completely
20235transportable from machine to machine without recompilation.  It is not,
20236however, as fast as true compiled code.
20237
20238   In general, any version of Emacs can run byte-compiled code produced
20239by recent earlier versions of Emacs, but the reverse is not true.
20240
20241   If you do not want a Lisp file to be compiled, ever, put a file-local
20242variable binding for ‘no-byte-compile’ into it, like this:
20243
20244     ;; -*-no-byte-compile: t; -*-
20245
20246* Menu:
20247
20248* Speed of Byte-Code::          An example of speedup from byte compilation.
20249* Compilation Functions::       Byte compilation functions.
20250* Docs and Compilation::        Dynamic loading of documentation strings.
20251* Dynamic Loading::             Dynamic loading of individual functions.
20252* Eval During Compile::         Code to be evaluated when you compile.
20253* Compiler Errors::             Handling compiler error messages.
20254* Byte-Code Objects::           The data type used for byte-compiled functions.
20255* Disassembly::                 Disassembling byte-code; how to read byte-code.
20256
20257
20258File: elisp.info,  Node: Speed of Byte-Code,  Next: Compilation Functions,  Up: Byte Compilation
20259
2026017.1 Performance of Byte-Compiled Code
20261======================================
20262
20263A byte-compiled function is not as efficient as a primitive function
20264written in C, but runs much faster than the version written in Lisp.
20265Here is an example:
20266
20267     (defun silly-loop (n)
20268       "Return the time, in seconds, to run N iterations of a loop."
20269       (let ((t1 (float-time)))
20270         (while (> (setq n (1- n)) 0))
20271         (- (float-time) t1)))
20272     ⇒ silly-loop
20273
20274     (silly-loop 50000000)
20275     ⇒ 10.235304117202759
20276
20277     (byte-compile 'silly-loop)
20278     ⇒ [Compiled code not shown]
20279
20280     (silly-loop 50000000)
20281     ⇒ 3.705854892730713
20282
20283   In this example, the interpreted code required 10 seconds to run,
20284whereas the byte-compiled code required less than 4 seconds.  These
20285results are representative, but actual results may vary.
20286
20287
20288File: elisp.info,  Node: Compilation Functions,  Next: Docs and Compilation,  Prev: Speed of Byte-Code,  Up: Byte Compilation
20289
2029017.2 Byte-Compilation Functions
20291===============================
20292
20293You can byte-compile an individual function or macro definition with the
20294‘byte-compile’ function.  You can compile a whole file with
20295‘byte-compile-file’, or several files with ‘byte-recompile-directory’ or
20296‘batch-byte-compile’.
20297
20298   Sometimes, the byte compiler produces warning and/or error messages
20299(*note Compiler Errors::, for details).  These messages are normally
20300recorded in a buffer called ‘*Compile-Log*’, which uses Compilation
20301mode.  *Note (emacs)Compilation Mode::.  However, if the variable
20302‘byte-compile-debug’ is non-‘nil’, error messages will be signaled as
20303Lisp errors instead (*note Errors::).
20304
20305   Be careful when writing macro calls in files that you intend to
20306byte-compile.  Since macro calls are expanded when they are compiled,
20307the macros need to be loaded into Emacs or the byte compiler will not do
20308the right thing.  The usual way to handle this is with ‘require’ forms
20309which specify the files containing the needed macro definitions (*note
20310Named Features::).  Normally, the byte compiler does not evaluate the
20311code that it is compiling, but it handles ‘require’ forms specially, by
20312loading the specified libraries.  To avoid loading the macro definition
20313files when someone _runs_ the compiled program, write
20314‘eval-when-compile’ around the ‘require’ calls (*note Eval During
20315Compile::).  For more details, *Note Compiling Macros::.
20316
20317   Inline (‘defsubst’) functions are less troublesome; if you compile a
20318call to such a function before its definition is known, the call will
20319still work right, it will just run slower.
20320
20321 -- Function: byte-compile symbol
20322     This function byte-compiles the function definition of SYMBOL,
20323     replacing the previous definition with the compiled one.  The
20324     function definition of SYMBOL must be the actual code for the
20325     function; ‘byte-compile’ does not handle function indirection.  The
20326     return value is the byte-code function object which is the compiled
20327     definition of SYMBOL (*note Byte-Code Objects::).
20328
20329          (defun factorial (integer)
20330            "Compute factorial of INTEGER."
20331            (if (= 1 integer) 1
20332              (* integer (factorial (1- integer)))))
20333          ⇒ factorial
20334
20335          (byte-compile 'factorial)
2033620337          #[(integer)
20338            "^H\301U\203^H^@\301\207\302^H\303^HS!\"\207"
20339            [integer 1 * factorial]
20340            4 "Compute factorial of INTEGER."]
20341
20342     If SYMBOL’s definition is a byte-code function object,
20343     ‘byte-compile’ does nothing and returns ‘nil’.  It does not compile
20344     the symbol’s definition again, since the original (non-compiled)
20345     code has already been replaced in the symbol’s function cell by the
20346     byte-compiled code.
20347
20348     The argument to ‘byte-compile’ can also be a ‘lambda’ expression.
20349     In that case, the function returns the corresponding compiled code
20350     but does not store it anywhere.
20351
20352 -- Command: compile-defun &optional arg
20353     This command reads the defun containing point, compiles it, and
20354     evaluates the result.  If you use this on a defun that is actually
20355     a function definition, the effect is to install a compiled version
20356     of that function.
20357
20358     ‘compile-defun’ normally displays the result of evaluation in the
20359     echo area, but if ARG is non-‘nil’, it inserts the result in the
20360     current buffer after the form it has compiled.
20361
20362 -- Command: byte-compile-file filename &optional load
20363     This function compiles a file of Lisp code named FILENAME into a
20364     file of byte-code.  The output file’s name is made by changing the
20365     ‘.el’ suffix into ‘.elc’; if FILENAME does not end in ‘.el’, it
20366     adds ‘.elc’ to the end of FILENAME.
20367
20368     Compilation works by reading the input file one form at a time.  If
20369     it is a definition of a function or macro, the compiled function or
20370     macro definition is written out.  Other forms are batched together,
20371     then each batch is compiled, and written so that its compiled code
20372     will be executed when the file is read.  All comments are discarded
20373     when the input file is read.
20374
20375     This command returns ‘t’ if there were no errors and ‘nil’
20376     otherwise.  When called interactively, it prompts for the file
20377     name.
20378
20379     If LOAD is non-‘nil’, this command loads the compiled file after
20380     compiling it.  Interactively, LOAD is the prefix argument.
20381
20382          $ ls -l push*
20383          -rw-r--r-- 1 lewis lewis 791 Oct  5 20:31 push.el
20384
20385          (byte-compile-file "~/emacs/push.el")
20386               ⇒ t
20387
20388          $ ls -l push*
20389          -rw-r--r-- 1 lewis lewis 791 Oct  5 20:31 push.el
20390          -rw-rw-rw- 1 lewis lewis 638 Oct  8 20:25 push.elc
20391
20392 -- Command: byte-recompile-directory directory &optional flag force
20393     This command recompiles every ‘.el’ file in DIRECTORY (or its
20394     subdirectories) that needs recompilation.  A file needs
20395     recompilation if a ‘.elc’ file exists but is older than the ‘.el’
20396     file.
20397
20398     When a ‘.el’ file has no corresponding ‘.elc’ file, FLAG says what
20399     to do.  If it is ‘nil’, this command ignores these files.  If FLAG
20400     is 0, it compiles them.  If it is neither ‘nil’ nor 0, it asks the
20401     user whether to compile each such file, and asks about each
20402     subdirectory as well.
20403
20404     Interactively, ‘byte-recompile-directory’ prompts for DIRECTORY and
20405     FLAG is the prefix argument.
20406
20407     If FORCE is non-‘nil’, this command recompiles every ‘.el’ file
20408     that has a ‘.elc’ file.
20409
20410     The returned value is unpredictable.
20411
20412 -- Function: batch-byte-compile &optional noforce
20413     This function runs ‘byte-compile-file’ on files specified on the
20414     command line.  This function must be used only in a batch execution
20415     of Emacs, as it kills Emacs on completion.  An error in one file
20416     does not prevent processing of subsequent files, but no output file
20417     will be generated for it, and the Emacs process will terminate with
20418     a nonzero status code.
20419
20420     If NOFORCE is non-‘nil’, this function does not recompile files
20421     that have an up-to-date ‘.elc’ file.
20422
20423          $ emacs -batch -f batch-byte-compile *.el
20424
20425
20426File: elisp.info,  Node: Docs and Compilation,  Next: Dynamic Loading,  Prev: Compilation Functions,  Up: Byte Compilation
20427
2042817.3 Documentation Strings and Compilation
20429==========================================
20430
20431When Emacs loads functions and variables from a byte-compiled file, it
20432normally does not load their documentation strings into memory.  Each
20433documentation string is dynamically loaded from the byte-compiled file
20434only when needed.  This saves memory, and speeds up loading by skipping
20435the processing of the documentation strings.
20436
20437   This feature has a drawback: if you delete, move, or alter the
20438compiled file (such as by compiling a new version), Emacs may no longer
20439be able to access the documentation string of previously-loaded
20440functions or variables.  Such a problem normally only occurs if you
20441build Emacs yourself, and happen to edit and/or recompile the Lisp
20442source files.  To solve it, just reload each file after recompilation.
20443
20444   Dynamic loading of documentation strings from byte-compiled files is
20445determined, at compile time, for each byte-compiled file.  It can be
20446disabled via the option ‘byte-compile-dynamic-docstrings’.
20447
20448 -- User Option: byte-compile-dynamic-docstrings
20449     If this is non-‘nil’, the byte compiler generates compiled files
20450     that are set up for dynamic loading of documentation strings.
20451
20452     To disable the dynamic loading feature for a specific file, set
20453     this option to ‘nil’ in its header line (*note Local Variables in
20454     Files: (emacs)File Variables.), like this:
20455
20456          -*-byte-compile-dynamic-docstrings: nil;-*-
20457
20458     This is useful mainly if you expect to change the file, and you
20459     want Emacs sessions that have already loaded it to keep working
20460     when the file changes.
20461
20462   Internally, the dynamic loading of documentation strings is
20463accomplished by writing compiled files with a special Lisp reader
20464construct, ‘#@COUNT’.  This construct skips the next COUNT characters.
20465It also uses the ‘#$’ construct, which stands for the name of this file,
20466as a string.  Do not use these constructs in Lisp source files; they are
20467not designed to be clear to humans reading the file.
20468
20469
20470File: elisp.info,  Node: Dynamic Loading,  Next: Eval During Compile,  Prev: Docs and Compilation,  Up: Byte Compilation
20471
2047217.4 Dynamic Loading of Individual Functions
20473============================================
20474
20475When you compile a file, you can optionally enable the “dynamic function
20476loading” feature (also known as “lazy loading”).  With dynamic function
20477loading, loading the file doesn’t fully read the function definitions in
20478the file.  Instead, each function definition contains a place-holder
20479which refers to the file.  The first time each function is called, it
20480reads the full definition from the file, to replace the place-holder.
20481
20482   The advantage of dynamic function loading is that loading the file
20483should become faster.  This is a good thing for a file which contains
20484many separate user-callable functions, if using one of them does not
20485imply you will probably also use the rest.  A specialized mode which
20486provides many keyboard commands often has that usage pattern: a user may
20487invoke the mode, but use only a few of the commands it provides.
20488
20489   The dynamic loading feature has certain disadvantages:
20490
20491   • If you delete or move the compiled file after loading it, Emacs can
20492     no longer load the remaining function definitions not already
20493     loaded.
20494
20495   • If you alter the compiled file (such as by compiling a new
20496     version), then trying to load any function not already loaded will
20497     usually yield nonsense results.
20498
20499   These problems will never happen in normal circumstances with
20500installed Emacs files.  But they are quite likely to happen with Lisp
20501files that you are changing.  The easiest way to prevent these problems
20502is to reload the new compiled file immediately after each recompilation.
20503
20504   _Experience shows that using dynamic function loading provides
20505benefits that are hardly measurable, so this feature is deprecated since
20506Emacs 27.1._
20507
20508   The byte compiler uses the dynamic function loading feature if the
20509variable ‘byte-compile-dynamic’ is non-‘nil’ at compilation time.  Do
20510not set this variable globally, since dynamic loading is desirable only
20511for certain files.  Instead, enable the feature for specific source
20512files with file-local variable bindings.  For example, you could do it
20513by writing this text in the source file’s first line:
20514
20515     -*-byte-compile-dynamic: t;-*-
20516
20517 -- Variable: byte-compile-dynamic
20518     If this is non-‘nil’, the byte compiler generates compiled files
20519     that are set up for dynamic function loading.
20520
20521 -- Function: fetch-bytecode function
20522     If FUNCTION is a byte-code function object, this immediately
20523     finishes loading the byte code of FUNCTION from its byte-compiled
20524     file, if it is not fully loaded already.  Otherwise, it does
20525     nothing.  It always returns FUNCTION.
20526
20527
20528File: elisp.info,  Node: Eval During Compile,  Next: Compiler Errors,  Prev: Dynamic Loading,  Up: Byte Compilation
20529
2053017.5 Evaluation During Compilation
20531==================================
20532
20533These features permit you to write code to be evaluated during
20534compilation of a program.
20535
20536 -- Special Form: eval-and-compile body...
20537     This form marks BODY to be evaluated both when you compile the
20538     containing code and when you run it (whether compiled or not).
20539
20540     You can get a similar result by putting BODY in a separate file and
20541     referring to that file with ‘require’.  That method is preferable
20542     when BODY is large.  Effectively ‘require’ is automatically
20543     ‘eval-and-compile’, the package is loaded both when compiling and
20544     executing.
20545
20546     ‘autoload’ is also effectively ‘eval-and-compile’ too.  It’s
20547     recognized when compiling, so uses of such a function don’t produce
20548     “not known to be defined” warnings.
20549
20550     Most uses of ‘eval-and-compile’ are fairly sophisticated.
20551
20552     If a macro has a helper function to build its result, and that
20553     macro is used both locally and outside the package, then
20554     ‘eval-and-compile’ should be used to get the helper both when
20555     compiling and then later when running.
20556
20557     If functions are defined programmatically (with ‘fset’ say), then
20558     ‘eval-and-compile’ can be used to have that done at compile-time as
20559     well as run-time, so calls to those functions are checked (and
20560     warnings about “not known to be defined” suppressed).
20561
20562 -- Special Form: eval-when-compile body...
20563     This form marks BODY to be evaluated at compile time but not when
20564     the compiled program is loaded.  The result of evaluation by the
20565     compiler becomes a constant which appears in the compiled program.
20566     If you load the source file, rather than compiling it, BODY is
20567     evaluated normally.
20568
20569     If you have a constant that needs some calculation to produce,
20570     ‘eval-when-compile’ can do that at compile-time.  For example,
20571
20572          (defvar my-regexp
20573            (eval-when-compile (regexp-opt '("aaa" "aba" "abb"))))
20574
20575     If you’re using another package, but only need macros from it (the
20576     byte compiler will expand those), then ‘eval-when-compile’ can be
20577     used to load it for compiling, but not executing.  For example,
20578
20579          (eval-when-compile
20580            (require 'my-macro-package))
20581
20582     The same sort of thing goes for macros and ‘defsubst’ functions
20583     defined locally and only for use within the file.  They are needed
20584     for compiling the file, but in most cases they are not needed for
20585     execution of the compiled file.  For example,
20586
20587          (eval-when-compile
20588            (unless (fboundp 'some-new-thing)
20589              (defmacro 'some-new-thing ()
20590                (compatibility code))))
20591
20592     This is often good for code that’s only a fallback for
20593     compatibility with other versions of Emacs.
20594
20595     *Common Lisp Note:* At top level, ‘eval-when-compile’ is analogous
20596     to the Common Lisp idiom ‘(eval-when (compile eval) ...)’.
20597     Elsewhere, the Common Lisp ‘#.’ reader macro (but not when
20598     interpreting) is closer to what ‘eval-when-compile’ does.
20599
20600
20601File: elisp.info,  Node: Compiler Errors,  Next: Byte-Code Objects,  Prev: Eval During Compile,  Up: Byte Compilation
20602
2060317.6 Compiler Errors
20604====================
20605
20606Error and warning messages from byte compilation are printed in a buffer
20607named ‘*Compile-Log*’.  These messages include file names and line
20608numbers identifying the location of the problem.  The usual Emacs
20609commands for operating on compiler output can be used on these messages.
20610
20611   When an error is due to invalid syntax in the program, the byte
20612compiler might get confused about the error’s exact location.  One way
20613to investigate is to switch to the buffer ‘ *Compiler Input*’.  (This
20614buffer name starts with a space, so it does not show up in the Buffer
20615Menu.)  This buffer contains the program being compiled, and point shows
20616how far the byte compiler was able to read; the cause of the error might
20617be nearby.  *Note Syntax Errors::, for some tips for locating syntax
20618errors.
20619
20620   A common type of warning issued by the byte compiler is for functions
20621and variables that were used but not defined.  Such warnings report the
20622line number for the end of the file, not the locations where the missing
20623functions or variables were used; to find these, you must search the
20624file manually.
20625
20626   If you are sure that a warning message about a missing function or
20627variable is unjustified, there are several ways to suppress it:
20628
20629   • You can suppress the warning for a specific call to a function FUNC
20630     by conditionalizing it on an ‘fboundp’ test, like this:
20631
20632          (if (fboundp 'FUNC) ...(FUNC ...)...)
20633
20634     The call to FUNC must be in the THEN-FORM of the ‘if’, and FUNC
20635     must appear quoted in the call to ‘fboundp’.  (This feature
20636     operates for ‘cond’ as well.)
20637
20638   • Likewise, you can suppress the warning for a specific use of a
20639     variable VARIABLE by conditionalizing it on a ‘boundp’ test:
20640
20641          (if (boundp 'VARIABLE) ...VARIABLE...)
20642
20643     The reference to VARIABLE must be in the THEN-FORM of the ‘if’, and
20644     VARIABLE must appear quoted in the call to ‘boundp’.
20645
20646   • You can tell the compiler that a function is defined using
20647     ‘declare-function’.  *Note Declaring Functions::.
20648
20649   • Likewise, you can tell the compiler that a variable is defined
20650     using ‘defvar’ with no initial value.  (Note that this marks the
20651     variable as special, i.e. dynamically bound, but only within the
20652     current lexical scope, or file if at top-level.)  *Note Defining
20653     Variables::.
20654
20655   You can also suppress compiler warnings within a certain expression
20656using the ‘with-suppressed-warnings’ macro:
20657
20658 -- Special Form: with-suppressed-warnings warnings body...
20659     In execution, this is equivalent to ‘(progn BODY...)’, but the
20660     compiler does not issue warnings for the specified conditions in
20661     BODY.  WARNINGS is an associative list of warning symbols and
20662     function/variable symbols they apply to.  For instance, if you wish
20663     to call an obsolete function called ‘foo’, but want to suppress the
20664     compilation warning, say:
20665
20666          (with-suppressed-warnings ((obsolete foo))
20667            (foo ...))
20668
20669   For more coarse-grained suppression of compiler warnings, you can use
20670the ‘with-no-warnings’ construct:
20671
20672 -- Special Form: with-no-warnings body...
20673     In execution, this is equivalent to ‘(progn BODY...)’, but the
20674     compiler does not issue warnings for anything that occurs inside
20675     BODY.
20676
20677     We recommend that you use ‘with-suppressed-warnings’ instead, but
20678     if you do use this construct, that you use it around the smallest
20679     possible piece of code to avoid missing possible warnings other
20680     than one you intend to suppress.
20681
20682   Byte compiler warnings can be controlled more precisely by setting
20683the variable ‘byte-compile-warnings’.  See its documentation string for
20684details.
20685
20686   Sometimes you may wish the byte-compiler warnings to be reported
20687using ‘error’.  If so, set ‘byte-compile-error-on-warn’ to a non-‘nil’
20688value.
20689
20690
20691File: elisp.info,  Node: Byte-Code Objects,  Next: Disassembly,  Prev: Compiler Errors,  Up: Byte Compilation
20692
2069317.7 Byte-Code Function Objects
20694===============================
20695
20696Byte-compiled functions have a special data type: they are “byte-code
20697function objects”.  Whenever such an object appears as a function to be
20698called, Emacs uses the byte-code interpreter to execute the byte-code.
20699
20700   Internally, a byte-code function object is much like a vector; its
20701elements can be accessed using ‘aref’.  Its printed representation is
20702like that for a vector, with an additional ‘#’ before the opening ‘[’.
20703It must have at least four elements; there is no maximum number, but
20704only the first six elements have any normal use.  They are:
20705
20706ARGDESC
20707     The descriptor of the arguments.  This can either be a list of
20708     arguments, as described in *note Argument List::, or an integer
20709     encoding the required number of arguments.  In the latter case, the
20710     value of the descriptor specifies the minimum number of arguments
20711     in the bits zero to 6, and the maximum number of arguments in bits
20712     8 to 14.  If the argument list uses ‘&rest’, then bit 7 is set;
20713     otherwise it’s cleared.
20714
20715     If ARGDESC is a list, the arguments will be dynamically bound
20716     before executing the byte code.  If ARGDESC is an integer, the
20717     arguments will be instead pushed onto the stack of the byte-code
20718     interpreter, before executing the code.
20719
20720BYTE-CODE
20721     The string containing the byte-code instructions.
20722
20723CONSTANTS
20724     The vector of Lisp objects referenced by the byte code.  These
20725     include symbols used as function names and variable names.
20726
20727STACKSIZE
20728     The maximum stack size this function needs.
20729
20730DOCSTRING
20731     The documentation string (if any); otherwise, ‘nil’.  The value may
20732     be a number or a list, in case the documentation string is stored
20733     in a file.  Use the function ‘documentation’ to get the real
20734     documentation string (*note Accessing Documentation::).
20735
20736INTERACTIVE
20737     The interactive spec (if any).  This can be a string or a Lisp
20738     expression.  It is ‘nil’ for a function that isn’t interactive.
20739
20740   Here’s an example of a byte-code function object, in printed
20741representation.  It is the definition of the command ‘backward-sexp’.
20742
20743     #[256
20744       "\211\204^G^@\300\262^A\301^A[!\207"
20745       [1 forward-sexp]
20746       3
20747       1793299
20748       "^p"]
20749
20750   The primitive way to create a byte-code object is with
20751‘make-byte-code’:
20752
20753 -- Function: make-byte-code &rest elements
20754     This function constructs and returns a byte-code function object
20755     with ELEMENTS as its elements.
20756
20757   You should not try to come up with the elements for a byte-code
20758function yourself, because if they are inconsistent, Emacs may crash
20759when you call the function.  Always leave it to the byte compiler to
20760create these objects; it makes the elements consistent (we hope).
20761
20762
20763File: elisp.info,  Node: Disassembly,  Prev: Byte-Code Objects,  Up: Byte Compilation
20764
2076517.8 Disassembled Byte-Code
20766===========================
20767
20768People do not write byte-code; that job is left to the byte compiler.
20769But we provide a disassembler to satisfy a cat-like curiosity.  The
20770disassembler converts the byte-compiled code into human-readable form.
20771
20772   The byte-code interpreter is implemented as a simple stack machine.
20773It pushes values onto a stack of its own, then pops them off to use them
20774in calculations whose results are themselves pushed back on the stack.
20775When a byte-code function returns, it pops a value off the stack and
20776returns it as the value of the function.
20777
20778   In addition to the stack, byte-code functions can use, bind, and set
20779ordinary Lisp variables, by transferring values between variables and
20780the stack.
20781
20782 -- Command: disassemble object &optional buffer-or-name
20783     This command displays the disassembled code for OBJECT.  In
20784     interactive use, or if BUFFER-OR-NAME is ‘nil’ or omitted, the
20785     output goes in a buffer named ‘*Disassemble*’.  If BUFFER-OR-NAME
20786     is non-‘nil’, it must be a buffer or the name of an existing
20787     buffer.  Then the output goes there, at point, and point is left
20788     before the output.
20789
20790     The argument OBJECT can be a function name, a lambda expression
20791     (*note Lambda Expressions::), or a byte-code object (*note
20792     Byte-Code Objects::).  If it is a lambda expression, ‘disassemble’
20793     compiles it and disassembles the resulting compiled code.
20794
20795   Here are two examples of using the ‘disassemble’ function.  We have
20796added explanatory comments to help you relate the byte-code to the Lisp
20797source; these do not appear in the output of ‘disassemble’.
20798
20799     (defun factorial (integer)
20800       "Compute factorial of an integer."
20801       (if (= 1 integer) 1
20802         (* integer (factorial (1- integer)))))
20803          ⇒ factorial
20804
20805     (factorial 4)
20806          ⇒ 24
20807
20808     (disassemble 'factorial)
20809          ⊣ byte-code for factorial:
20810      doc: Compute factorial of an integer.
20811      args: (integer)
20812
20813     0   varref   integer      ; Get the value of ‘integer’ and
20814                               ;   push it onto the stack.
20815     1   constant 1            ; Push 1 onto stack.
20816     2   eqlsign               ; Pop top two values off stack, compare
20817                               ;   them, and push result onto stack.
20818     3   goto-if-nil 1         ; Pop and test top of stack;
20819                               ;   if ‘nil’, go to 1, else continue.
20820     6   constant 1            ; Push 1 onto top of stack.
20821     7   return                ; Return the top element of the stack.
20822     8:1 varref   integer      ; Push value of ‘integer’ onto stack.
20823     9   constant factorial    ; Push ‘factorial’ onto stack.
20824     10  varref   integer      ; Push value of ‘integer’ onto stack.
20825     11  sub1                  ; Pop ‘integer’, decrement value,
20826                               ;   push new value onto stack.
20827     12  call     1            ; Call function ‘factorial’ using first
20828                               ;   (i.e., top) stack element as argument;
20829                               ;   push returned value onto stack.
20830     13 mult                   ; Pop top two values off stack, multiply
20831                               ;   them, and push result onto stack.
20832     14 return                 ; Return the top element of the stack.
20833
20834   The ‘silly-loop’ function is somewhat more complex:
20835
20836     (defun silly-loop (n)
20837       "Return time before and after N iterations of a loop."
20838       (let ((t1 (current-time-string)))
20839         (while (> (setq n (1- n))
20840                   0))
20841         (list t1 (current-time-string))))
20842          ⇒ silly-loop
20843
20844     (disassemble 'silly-loop)
20845          ⊣ byte-code for silly-loop:
20846      doc: Return time before and after N iterations of a loop.
20847      args: (n)
20848
20849     0   constant current-time-string  ; Push ‘current-time-string’
20850                                       ;   onto top of stack.
20851     1   call     0            ; Call ‘current-time-string’ with no
20852                               ;   argument, push result onto stack.
20853     2   varbind  t1           ; Pop stack and bind ‘t1’ to popped value.
20854     3:1 varref   n            ; Get value of ‘n’ from the environment
20855                               ;   and push the value on the stack.
20856     4   sub1                  ; Subtract 1 from top of stack.
20857     5   dup                   ; Duplicate top of stack; i.e., copy the top
20858                               ;   of the stack and push copy onto stack.
20859     6   varset   n            ; Pop the top of the stack,
20860                               ;   and bind ‘n’ to the value.
20861
20862     ;; (In effect, the sequence ‘dup varset’ copies the top of the stack
20863     ;; into the value of ‘n’ without popping it.)
20864
20865     7   constant 0            ; Push 0 onto stack.
20866     8   gtr                   ; Pop top two values off stack,
20867                               ;   test if N is greater than 0
20868                               ;   and push result onto stack.
20869     9   goto-if-not-nil 1     ; Goto 1 if ‘n’ > 0
20870                               ;   (this continues the while loop)
20871                               ;   else continue.
20872     12  varref   t1           ; Push value of ‘t1’ onto stack.
20873     13  constant current-time-string  ; Push ‘current-time-string’
20874                                       ;   onto the top of the stack.
20875     14  call     0            ; Call ‘current-time-string’ again.
20876     15  unbind   1            ; Unbind ‘t1’ in local environment.
20877     16  list2                 ; Pop top two elements off stack, create a
20878                               ;   list of them, and push it onto stack.
20879     17  return                ; Return value of the top of stack.
20880
20881
20882File: elisp.info,  Node: Debugging,  Next: Read and Print,  Prev: Byte Compilation,  Up: Top
20883
2088418 Debugging Lisp Programs
20885**************************
20886
20887There are several ways to find and investigate problems in an Emacs Lisp
20888program.
20889
20890   • If a problem occurs when you run the program, you can use the
20891     built-in Emacs Lisp debugger to suspend the Lisp evaluator, and
20892     examine and/or alter its internal state.
20893
20894   • You can use Edebug, a source-level debugger for Emacs Lisp.
20895
20896   • You can trace the execution of functions involved in the problem
20897     using the tracing facilities provided by the ‘trace.el’ package.
20898     This package provides the functions ‘trace-function-foreground’ and
20899     ‘trace-function-background’ for tracing function calls, and
20900     ‘trace-values’ for adding values of select variables to the trace.
20901     For the details, see the documentation of these facilities in
20902trace.el’.
20903
20904   • If a syntactic problem is preventing Lisp from even reading the
20905     program, you can locate it using Lisp editing commands.
20906
20907   • You can look at the error and warning messages produced by the byte
20908     compiler when it compiles the program.  *Note Compiler Errors::.
20909
20910   • You can use the Testcover package to perform coverage testing on
20911     the program.
20912
20913   • You can use the ERT package to write regression tests for the
20914     program.  *Note the ERT manual: (ert)Top.
20915
20916   • You can profile the program to get hints about how to make it more
20917     efficient.
20918
20919   Other useful tools for debugging input and output problems are the
20920dribble file (*note Terminal Input::) and the ‘open-termscript’ function
20921(*note Terminal Output::).
20922
20923* Menu:
20924
20925* Debugger::            A debugger for the Emacs Lisp evaluator.
20926* Edebug::              A source-level Emacs Lisp debugger.
20927* Syntax Errors::       How to find syntax errors.
20928* Test Coverage::       Ensuring you have tested all branches in your code.
20929* Profiling::           Measuring the resources that your code uses.
20930
20931
20932File: elisp.info,  Node: Debugger,  Next: Edebug,  Up: Debugging
20933
2093418.1 The Lisp Debugger
20935======================
20936
20937The ordinary “Lisp debugger” provides the ability to suspend evaluation
20938of a form.  While evaluation is suspended (a state that is commonly
20939known as a “break”), you may examine the run time stack, examine the
20940values of local or global variables, or change those values.  Since a
20941break is a recursive edit, all the usual editing facilities of Emacs are
20942available; you can even run programs that will enter the debugger
20943recursively.  *Note Recursive Editing::.
20944
20945* Menu:
20946
20947* Error Debugging::       Entering the debugger when an error happens.
20948* Infinite Loops::        Stopping and debugging a program that doesn’t exit.
20949* Function Debugging::    Entering it when a certain function is called.
20950* Variable Debugging::    Entering it when a variable is modified.
20951* Explicit Debug::        Entering it at a certain point in the program.
20952* Using Debugger::        What the debugger does.
20953* Backtraces::            What you see while in the debugger.
20954* Debugger Commands::     Commands used while in the debugger.
20955* Invoking the Debugger:: How to call the function ‘debug’.
20956* Internals of Debugger:: Subroutines of the debugger, and global variables.
20957
20958
20959File: elisp.info,  Node: Error Debugging,  Next: Infinite Loops,  Up: Debugger
20960
2096118.1.1 Entering the Debugger on an Error
20962----------------------------------------
20963
20964The most important time to enter the debugger is when a Lisp error
20965happens.  This allows you to investigate the immediate causes of the
20966error.
20967
20968   However, entry to the debugger is not a normal consequence of an
20969error.  Many commands signal Lisp errors when invoked inappropriately,
20970and during ordinary editing it would be very inconvenient to enter the
20971debugger each time this happens.  So if you want errors to enter the
20972debugger, set the variable ‘debug-on-error’ to non-‘nil’.  (The command
20973‘toggle-debug-on-error’ provides an easy way to do this.)
20974
20975 -- User Option: debug-on-error
20976     This variable determines whether the debugger is called when an
20977     error is signaled and not handled.  If ‘debug-on-error’ is ‘t’, all
20978     kinds of errors call the debugger, except those listed in
20979     ‘debug-ignored-errors’ (see below).  If it is ‘nil’, none call the
20980     debugger.
20981
20982     The value can also be a list of error conditions (*note Signaling
20983     Errors::).  Then the debugger is called only for error conditions
20984     in this list (except those also listed in ‘debug-ignored-errors’).
20985     For example, if you set ‘debug-on-error’ to the list
20986     ‘(void-variable)’, the debugger is only called for errors about a
20987     variable that has no value.
20988
20989     Note that ‘eval-expression-debug-on-error’ overrides this variable
20990     in some cases; see below.
20991
20992     When this variable is non-‘nil’, Emacs does not create an error
20993     handler around process filter functions and sentinels.  Therefore,
20994     errors in these functions also invoke the debugger.  *Note
20995     Processes::.
20996
20997 -- User Option: debug-ignored-errors
20998     This variable specifies errors which should not enter the debugger,
20999     regardless of the value of ‘debug-on-error’.  Its value is a list
21000     of error condition symbols and/or regular expressions.  If the
21001     error has any of those condition symbols, or if the error message
21002     matches any of the regular expressions, then that error does not
21003     enter the debugger.
21004
21005     The normal value of this variable includes ‘user-error’, as well as
21006     several errors that happen often during editing but rarely result
21007     from bugs in Lisp programs.  However, “rarely” is not “never”; if
21008     your program fails with an error that matches this list, you may
21009     try changing this list to debug the error.  The easiest way is
21010     usually to set ‘debug-ignored-errors’ to ‘nil’.
21011
21012 -- User Option: eval-expression-debug-on-error
21013     If this variable has a non-‘nil’ value (the default), running the
21014     command ‘eval-expression’ causes ‘debug-on-error’ to be temporarily
21015     bound to ‘t’.  *Note Evaluating Emacs Lisp Expressions: (emacs)Lisp
21016     Eval.
21017
21018     If ‘eval-expression-debug-on-error’ is ‘nil’, then the value of
21019     ‘debug-on-error’ is not changed during ‘eval-expression’.
21020
21021 -- User Option: debug-on-signal
21022     Normally, errors caught by ‘condition-case’ never invoke the
21023     debugger.  The ‘condition-case’ gets a chance to handle the error
21024     before the debugger gets a chance.
21025
21026     If you change ‘debug-on-signal’ to a non-‘nil’ value, the debugger
21027     gets the first chance at every error, regardless of the presence of
21028     ‘condition-case’.  (To invoke the debugger, the error must still
21029     fulfill the criteria specified by ‘debug-on-error’ and
21030     ‘debug-ignored-errors’.)
21031
21032     For example, setting this variable is useful to get a backtrace
21033     from code evaluated by emacsclient’s ‘--eval’ option.  If Lisp code
21034     evaluated by emacsclient signals an error while this variable is
21035     non-‘nil’, the backtrace will popup in the running Emacs.
21036
21037     *Warning:* Setting this variable to non-‘nil’ may have annoying
21038     effects.  Various parts of Emacs catch errors in the normal course
21039     of affairs, and you may not even realize that errors happen there.
21040     If you need to debug code wrapped in ‘condition-case’, consider
21041     using ‘condition-case-unless-debug’ (*note Handling Errors::).
21042
21043 -- User Option: debug-on-event
21044     If you set ‘debug-on-event’ to a special event (*note Special
21045     Events::), Emacs will try to enter the debugger as soon as it
21046     receives this event, bypassing ‘special-event-map’.  At present,
21047     the only supported values correspond to the signals ‘SIGUSR1’ and
21048     ‘SIGUSR2’ (this is the default).  This can be helpful when
21049     ‘inhibit-quit’ is set and Emacs is not otherwise responding.
21050
21051 -- Variable: debug-on-message
21052     If you set ‘debug-on-message’ to a regular expression, Emacs will
21053     enter the debugger if it displays a matching message in the echo
21054     area.  For example, this can be useful when trying to find the
21055     cause of a particular message.
21056
21057   To debug an error that happens during loading of the init file, use
21058the option ‘--debug-init’.  This binds ‘debug-on-error’ to ‘t’ while
21059loading the init file, and bypasses the ‘condition-case’ which normally
21060catches errors in the init file.
21061
21062
21063File: elisp.info,  Node: Infinite Loops,  Next: Function Debugging,  Prev: Error Debugging,  Up: Debugger
21064
2106518.1.2 Debugging Infinite Loops
21066-------------------------------
21067
21068When a program loops infinitely and fails to return, your first problem
21069is to stop the loop.  On most operating systems, you can do this with
21070‘C-g’, which causes a “quit”.  *Note Quitting::.
21071
21072   Ordinary quitting gives no information about why the program was
21073looping.  To get more information, you can set the variable
21074‘debug-on-quit’ to non-‘nil’.  Once you have the debugger running in the
21075middle of the infinite loop, you can proceed from the debugger using the
21076stepping commands.  If you step through the entire loop, you may get
21077enough information to solve the problem.
21078
21079   Quitting with ‘C-g’ is not considered an error, and ‘debug-on-error’
21080has no effect on the handling of ‘C-g’.  Likewise, ‘debug-on-quit’ has
21081no effect on errors.
21082
21083 -- User Option: debug-on-quit
21084     This variable determines whether the debugger is called when ‘quit’
21085     is signaled and not handled.  If ‘debug-on-quit’ is non-‘nil’, then
21086     the debugger is called whenever you quit (that is, type ‘C-g’).  If
21087     ‘debug-on-quit’ is ‘nil’ (the default), then the debugger is not
21088     called when you quit.
21089
21090
21091File: elisp.info,  Node: Function Debugging,  Next: Variable Debugging,  Prev: Infinite Loops,  Up: Debugger
21092
2109318.1.3 Entering the Debugger on a Function Call
21094-----------------------------------------------
21095
21096To investigate a problem that happens in the middle of a program, one
21097useful technique is to enter the debugger whenever a certain function is
21098called.  You can do this to the function in which the problem occurs,
21099and then step through the function, or you can do this to a function
21100called shortly before the problem, step quickly over the call to that
21101function, and then step through its caller.
21102
21103 -- Command: debug-on-entry function-name
21104     This function requests FUNCTION-NAME to invoke the debugger each
21105     time it is called.
21106
21107     Any function or macro defined as Lisp code may be set to break on
21108     entry, regardless of whether it is interpreted code or compiled
21109     code.  If the function is a command, it will enter the debugger
21110     when called from Lisp and when called interactively (after the
21111     reading of the arguments).  You can also set debug-on-entry for
21112     primitive functions (i.e., those written in C) this way, but it
21113     only takes effect when the primitive is called from Lisp code.
21114     Debug-on-entry is not allowed for special forms.
21115
21116     When ‘debug-on-entry’ is called interactively, it prompts for
21117     FUNCTION-NAME in the minibuffer.  If the function is already set up
21118     to invoke the debugger on entry, ‘debug-on-entry’ does nothing.
21119     ‘debug-on-entry’ always returns FUNCTION-NAME.
21120
21121     Here’s an example to illustrate use of this function:
21122
21123          (defun fact (n)
21124            (if (zerop n) 1
21125                (* n (fact (1- n)))))
21126               ⇒ fact
21127          (debug-on-entry 'fact)
21128               ⇒ fact
21129          (fact 3)
21130
21131          ------ Buffer: *Backtrace* ------
21132          Debugger entered--entering a function:
21133          * fact(3)
21134            eval((fact 3))
21135            eval-last-sexp-1(nil)
21136            eval-last-sexp(nil)
21137            call-interactively(eval-last-sexp)
21138          ------ Buffer: *Backtrace* ------
21139
21140
21141 -- Command: cancel-debug-on-entry &optional function-name
21142     This function undoes the effect of ‘debug-on-entry’ on
21143     FUNCTION-NAME.  When called interactively, it prompts for
21144     FUNCTION-NAME in the minibuffer.  If FUNCTION-NAME is omitted or
21145     ‘nil’, it cancels break-on-entry for all functions.  Calling
21146     ‘cancel-debug-on-entry’ does nothing to a function which is not
21147     currently set up to break on entry.
21148
21149
21150File: elisp.info,  Node: Variable Debugging,  Next: Explicit Debug,  Prev: Function Debugging,  Up: Debugger
21151
2115218.1.4 Entering the debugger when a variable is modified
21153--------------------------------------------------------
21154
21155Sometimes a problem with a function is due to a wrong setting of a
21156variable.  Setting up the debugger to trigger whenever the variable is
21157changed is a quick way to find the origin of the setting.
21158
21159 -- Command: debug-on-variable-change variable
21160     This function arranges for the debugger to be called whenever
21161     VARIABLE is modified.
21162
21163     It is implemented using the watchpoint mechanism, so it inherits
21164     the same characteristics and limitations: all aliases of VARIABLE
21165     will be watched together, only dynamic variables can be watched,
21166     and changes to the objects referenced by variables are not
21167     detected.  For details, see *note Watching Variables::.
21168
21169 -- Command: cancel-debug-on-variable-change &optional variable
21170     This function undoes the effect of ‘debug-on-variable-change’ on
21171     VARIABLE.  When called interactively, it prompts for VARIABLE in
21172     the minibuffer.  If VARIABLE is omitted or ‘nil’, it cancels
21173     break-on-change for all variables.  Calling
21174     ‘cancel-debug-on-variable-change’ does nothing to a variable which
21175     is not currently set up to break on change.
21176
21177
21178File: elisp.info,  Node: Explicit Debug,  Next: Using Debugger,  Prev: Variable Debugging,  Up: Debugger
21179
2118018.1.5 Explicit Entry to the Debugger
21181-------------------------------------
21182
21183You can cause the debugger to be called at a certain point in your
21184program by writing the expression ‘(debug)’ at that point.  To do this,
21185visit the source file, insert the text ‘(debug)’ at the proper place,
21186and type ‘C-M-x’ (‘eval-defun’, a Lisp mode key binding).  *Warning:* if
21187you do this for temporary debugging purposes, be sure to undo this
21188insertion before you save the file!
21189
21190   The place where you insert ‘(debug)’ must be a place where an
21191additional form can be evaluated and its value ignored.  (If the value
21192of ‘(debug)’ isn’t ignored, it will alter the execution of the program!)
21193The most common suitable places are inside a ‘progn’ or an implicit
21194‘progn’ (*note Sequencing::).
21195
21196   If you don’t know exactly where in the source code you want to put
21197the debug statement, but you want to display a backtrace when a certain
21198message is displayed, you can set ‘debug-on-message’ to a regular
21199expression matching the desired message.
21200
21201
21202File: elisp.info,  Node: Using Debugger,  Next: Backtraces,  Prev: Explicit Debug,  Up: Debugger
21203
2120418.1.6 Using the Debugger
21205-------------------------
21206
21207When the debugger is entered, it displays the previously selected buffer
21208in one window and a buffer named ‘*Backtrace*’ in another window.  The
21209backtrace buffer contains one line for each level of Lisp function
21210execution currently going on.  At the beginning of this buffer is a
21211message describing the reason that the debugger was invoked (such as the
21212error message and associated data, if it was invoked due to an error).
21213
21214   The backtrace buffer is read-only and uses a special major mode,
21215Debugger mode, in which letters are defined as debugger commands.  The
21216usual Emacs editing commands are available; thus, you can switch windows
21217to examine the buffer that was being edited at the time of the error,
21218switch buffers, visit files, or do any other sort of editing.  However,
21219the debugger is a recursive editing level (*note Recursive Editing::)
21220and it is wise to go back to the backtrace buffer and exit the debugger
21221(with the ‘q’ command) when you are finished with it.  Exiting the
21222debugger gets out of the recursive edit and buries the backtrace buffer.
21223(You can customize what the ‘q’ command does with the backtrace buffer
21224by setting the variable ‘debugger-bury-or-kill’.  For example, set it to
21225‘kill’ if you prefer to kill the buffer rather than bury it.  Consult
21226the variable’s documentation for more possibilities.)
21227
21228   When the debugger has been entered, the ‘debug-on-error’ variable is
21229temporarily set according to ‘eval-expression-debug-on-error’.  If the
21230latter variable is non-‘nil’, ‘debug-on-error’ will temporarily be set
21231to ‘t’.  This means that any further errors that occur while doing a
21232debugging session will (by default) trigger another backtrace.  If this
21233is not what you want, you can either set
21234‘eval-expression-debug-on-error’ to ‘nil’, or set ‘debug-on-error’ to
21235‘nil’ in ‘debugger-mode-hook’.
21236
21237   The debugger itself must be run byte-compiled, since it makes
21238assumptions about the state of the Lisp interpreter.  These assumptions
21239are false if the debugger is running interpreted.
21240
21241
21242File: elisp.info,  Node: Backtraces,  Next: Debugger Commands,  Prev: Using Debugger,  Up: Debugger
21243
2124418.1.7 Backtraces
21245-----------------
21246
21247Debugger mode is derived from Backtrace mode, which is also used to show
21248backtraces by Edebug and ERT.  (*note Edebug::, and *note the ERT
21249manual: (ert)Top.)
21250
21251   The backtrace buffer shows you the functions that are executing and
21252their argument values.  When a backtrace buffer is created, it shows
21253each stack frame on one, possibly very long, line.  (A stack frame is
21254the place where the Lisp interpreter records information about a
21255particular invocation of a function.)  The most recently called function
21256will be at the top.
21257
21258   In a backtrace you can specify a stack frame by moving point to a
21259line describing that frame.  The frame whose line point is on is
21260considered the “current frame”.
21261
21262   If a function name is underlined, that means Emacs knows where its
21263source code is located.  You can click with the mouse on that name, or
21264move to it and type <RET>, to visit the source code.  You can also type
21265<RET> while point is on any name of a function or variable which is not
21266underlined, to see help information for that symbol in a help buffer, if
21267any exists.  The ‘xref-find-definitions’ command, bound to <M-.>, can
21268also be used on any identifier in a backtrace (*note (emacs)Looking Up
21269Identifiers::).
21270
21271   In backtraces, the tails of long lists and the ends of long strings,
21272vectors or structures, as well as objects which are deeply nested, will
21273be printed as underlined “...”.  You can click with the mouse on a
21274“...”, or type <RET> while point is on it, to show the part of the
21275object that was hidden.  To control how much abbreviation is done,
21276customize ‘backtrace-line-length’.
21277
21278   Here is a list of commands for navigating and viewing backtraces:
21279
21280‘v’
21281     Toggle the display of local variables of the current stack frame.
21282
21283‘p’
21284     Move to the beginning of the frame, or to the beginning of the
21285     previous frame.
21286
21287‘n’
21288     Move to the beginning of the next frame.
21289
21290‘+’
21291     Add line breaks and indentation to the top-level Lisp form at point
21292     to make it more readable.
21293
21294‘-’
21295     Collapse the top-level Lisp form at point back to a single line.
21296
21297‘#’
21298     Toggle ‘print-circle’ for the frame at point.
21299
21300‘:’
21301     Toggle ‘print-gensym’ for the frame at point.
21302
21303‘.’
21304     Expand all the forms abbreviated with “...” in the frame at point.
21305
21306
21307File: elisp.info,  Node: Debugger Commands,  Next: Invoking the Debugger,  Prev: Backtraces,  Up: Debugger
21308
2130918.1.8 Debugger Commands
21310------------------------
21311
21312The debugger buffer (in Debugger mode) provides special commands in
21313addition to the usual Emacs commands and to the Backtrace mode commands
21314described in the previous section.  The most important use of debugger
21315commands is for stepping through code, so that you can see how control
21316flows.  The debugger can step through the control structures of an
21317interpreted function, but cannot do so in a byte-compiled function.  If
21318you would like to step through a byte-compiled function, replace it with
21319an interpreted definition of the same function.  (To do this, visit the
21320source for the function and type ‘C-M-x’ on its definition.)  You cannot
21321use the Lisp debugger to step through a primitive function.
21322
21323   Some of the debugger commands operate on the current frame.  If a
21324frame starts with a star, that means that exiting that frame will call
21325the debugger again.  This is useful for examining the return value of a
21326function.
21327
21328   Here is a list of Debugger mode commands:
21329
21330‘c’
21331     Exit the debugger and continue execution.  This resumes execution
21332     of the program as if the debugger had never been entered (aside
21333     from any side-effects that you caused by changing variable values
21334     or data structures while inside the debugger).
21335
21336‘d’
21337     Continue execution, but enter the debugger the next time any Lisp
21338     function is called.  This allows you to step through the
21339     subexpressions of an expression, seeing what values the
21340     subexpressions compute, and what else they do.
21341
21342     The stack frame made for the function call which enters the
21343     debugger in this way will be flagged automatically so that the
21344     debugger will be called again when the frame is exited.  You can
21345     use the ‘u’ command to cancel this flag.
21346
21347‘b’
21348     Flag the current frame so that the debugger will be entered when
21349     the frame is exited.  Frames flagged in this way are marked with
21350     stars in the backtrace buffer.
21351
21352‘u’
21353     Don’t enter the debugger when the current frame is exited.  This
21354     cancels a ‘b’ command on that frame.  The visible effect is to
21355     remove the star from the line in the backtrace buffer.
21356
21357‘j’
21358     Flag the current frame like ‘b’.  Then continue execution like ‘c’,
21359     but temporarily disable break-on-entry for all functions that are
21360     set up to do so by ‘debug-on-entry’.
21361
21362‘e’
21363     Read a Lisp expression in the minibuffer, evaluate it (with the
21364     relevant lexical environment, if applicable), and print the value
21365     in the echo area.  The debugger alters certain important variables,
21366     and the current buffer, as part of its operation; ‘e’ temporarily
21367     restores their values from outside the debugger, so you can examine
21368     and change them.  This makes the debugger more transparent.  By
21369     contrast, ‘M-:’ does nothing special in the debugger; it shows you
21370     the variable values within the debugger.
21371
21372‘R’
21373     Like ‘e’, but also save the result of evaluation in the buffer
21374     ‘*Debugger-record*’.
21375
21376‘q’
21377     Terminate the program being debugged; return to top-level Emacs
21378     command execution.
21379
21380     If the debugger was entered due to a ‘C-g’ but you really want to
21381     quit, and not debug, use the ‘q’ command.
21382
21383‘r’
21384     Return a value from the debugger.  The value is computed by reading
21385     an expression with the minibuffer and evaluating it.
21386
21387     The ‘r’ command is useful when the debugger was invoked due to exit
21388     from a Lisp call frame (as requested with ‘b’ or by entering the
21389     frame with ‘d’); then the value specified in the ‘r’ command is
21390     used as the value of that frame.  It is also useful if you call
21391     ‘debug’ and use its return value.  Otherwise, ‘r’ has the same
21392     effect as ‘c’, and the specified return value does not matter.
21393
21394     You can’t use ‘r’ when the debugger was entered due to an error.
21395
21396‘l’
21397     Display a list of functions that will invoke the debugger when
21398     called.  This is a list of functions that are set to break on entry
21399     by means of ‘debug-on-entry’.
21400
21401
21402File: elisp.info,  Node: Invoking the Debugger,  Next: Internals of Debugger,  Prev: Debugger Commands,  Up: Debugger
21403
2140418.1.9 Invoking the Debugger
21405----------------------------
21406
21407Here we describe in full detail the function ‘debug’ that is used to
21408invoke the debugger.
21409
21410 -- Command: debug &rest debugger-args
21411     This function enters the debugger.  It switches buffers to a buffer
21412     named ‘*Backtrace*’ (or ‘*Backtrace*<2>’ if it is the second
21413     recursive entry to the debugger, etc.), and fills it with
21414     information about the stack of Lisp function calls.  It then enters
21415     a recursive edit, showing the backtrace buffer in Debugger mode.
21416
21417     The Debugger mode ‘c’, ‘d’, ‘j’, and ‘r’ commands exit the
21418     recursive edit; then ‘debug’ switches back to the previous buffer
21419     and returns to whatever called ‘debug’.  This is the only way the
21420     function ‘debug’ can return to its caller.
21421
21422     The use of the DEBUGGER-ARGS is that ‘debug’ displays the rest of
21423     its arguments at the top of the ‘*Backtrace*’ buffer, so that the
21424     user can see them.  Except as described below, this is the _only_
21425     way these arguments are used.
21426
21427     However, certain values for first argument to ‘debug’ have a
21428     special significance.  (Normally, these values are used only by the
21429     internals of Emacs, and not by programmers calling ‘debug’.)  Here
21430     is a table of these special values:
21431
21432     ‘lambda’
21433          A first argument of ‘lambda’ means ‘debug’ was called because
21434          of entry to a function when ‘debug-on-next-call’ was
21435          non-‘nil’.  The debugger displays ‘Debugger entered--entering
21436          a function:’ as a line of text at the top of the buffer.
21437
21438     ‘debug’
21439          ‘debug’ as first argument means ‘debug’ was called because of
21440          entry to a function that was set to debug on entry.  The
21441          debugger displays the string ‘Debugger entered--entering a
21442          function:’, just as in the ‘lambda’ case.  It also marks the
21443          stack frame for that function so that it will invoke the
21444          debugger when exited.
21445
21446     ‘t’
21447          When the first argument is ‘t’, this indicates a call to
21448          ‘debug’ due to evaluation of a function call form when
21449          ‘debug-on-next-call’ is non-‘nil’.  The debugger displays
21450          ‘Debugger entered--beginning evaluation of function call
21451          form:’ as the top line in the buffer.
21452
21453     ‘exit’
21454          When the first argument is ‘exit’, it indicates the exit of a
21455          stack frame previously marked to invoke the debugger on exit.
21456          The second argument given to ‘debug’ in this case is the value
21457          being returned from the frame.  The debugger displays
21458          ‘Debugger entered--returning value:’ in the top line of the
21459          buffer, followed by the value being returned.
21460
21461     ‘error’
21462          When the first argument is ‘error’, the debugger indicates
21463          that it is being entered because an error or ‘quit’ was
21464          signaled and not handled, by displaying ‘Debugger
21465          entered--Lisp error:’ followed by the error signaled and any
21466          arguments to ‘signal’.  For example,
21467
21468               (let ((debug-on-error t))
21469                 (/ 1 0))
21470
21471               ------ Buffer: *Backtrace* ------
21472               Debugger entered--Lisp error: (arith-error)
21473                 /(1 0)
21474               ...
21475               ------ Buffer: *Backtrace* ------
21476
21477          If an error was signaled, presumably the variable
21478          ‘debug-on-error’ is non-‘nil’.  If ‘quit’ was signaled, then
21479          presumably the variable ‘debug-on-quit’ is non-‘nil’.
21480
21481     ‘nil’
21482          Use ‘nil’ as the first of the DEBUGGER-ARGS when you want to
21483          enter the debugger explicitly.  The rest of the DEBUGGER-ARGS
21484          are printed on the top line of the buffer.  You can use this
21485          feature to display messages—for example, to remind yourself of
21486          the conditions under which ‘debug’ is called.
21487
21488
21489File: elisp.info,  Node: Internals of Debugger,  Prev: Invoking the Debugger,  Up: Debugger
21490
2149118.1.10 Internals of the Debugger
21492---------------------------------
21493
21494This section describes functions and variables used internally by the
21495debugger.
21496
21497 -- Variable: debugger
21498     The value of this variable is the function to call to invoke the
21499     debugger.  Its value must be a function of any number of arguments,
21500     or, more typically, the name of a function.  This function should
21501     invoke some kind of debugger.  The default value of the variable is
21502     ‘debug’.
21503
21504     The first argument that Lisp hands to the function indicates why it
21505     was called.  The convention for arguments is detailed in the
21506     description of ‘debug’ (*note Invoking the Debugger::).
21507
21508 -- Function: backtrace
21509     This function prints a trace of Lisp function calls currently
21510     active.  The trace is identical to the one that ‘debug’ would show
21511     in the ‘*Backtrace*’ buffer.  The return value is always nil.
21512
21513     In the following example, a Lisp expression calls ‘backtrace’
21514     explicitly.  This prints the backtrace to the stream
21515     ‘standard-output’, which, in this case, is the buffer
21516     ‘backtrace-output’.
21517
21518     Each line of the backtrace represents one function call.  The line
21519     shows the function followed by a list of the values of the
21520     function’s arguments if they are all known; if they are still being
21521     computed, the line consists of a list containing the function and
21522     its unevaluated arguments.  Long lists or deeply nested structures
21523     may be elided.
21524
21525          (with-output-to-temp-buffer "backtrace-output"
21526            (let ((var 1))
21527              (save-excursion
21528                (setq var (eval '(progn
21529                                   (1+ var)
21530                                   (list 'testing (backtrace))))))))
21531
21532               ⇒ (testing nil)
21533
21534          ----------- Buffer: backtrace-output ------------
21535            backtrace()
21536            (list 'testing (backtrace))
21537            (progn ...)
21538            eval((progn (1+ var) (list 'testing (backtrace))))
21539            (setq ...)
21540            (save-excursion ...)
21541            (let ...)
21542            (with-output-to-temp-buffer ...)
21543            eval((with-output-to-temp-buffer ...))
21544            eval-last-sexp-1(nil)
21545            eval-last-sexp(nil)
21546            call-interactively(eval-last-sexp)
21547          ----------- Buffer: backtrace-output ------------
21548
21549 -- User Option: debugger-stack-frame-as-list
21550     If this variable is non-‘nil’, every stack frame of the backtrace
21551     is displayed as a list.  This aims at improving the backtrace
21552     readability at the cost of special forms no longer being visually
21553     different from regular function calls.
21554
21555     With ‘debugger-stack-frame-as-list’ non-‘nil’, the above example
21556     would look as follows:
21557
21558          ----------- Buffer: backtrace-output ------------
21559            (backtrace)
21560            (list 'testing (backtrace))
21561            (progn ...)
21562            (eval (progn (1+ var) (list 'testing (backtrace))))
21563            (setq ...)
21564            (save-excursion ...)
21565            (let ...)
21566            (with-output-to-temp-buffer ...)
21567            (eval (with-output-to-temp-buffer ...))
21568            (eval-last-sexp-1 nil)
21569            (eval-last-sexp nil)
21570            (call-interactively eval-last-sexp)
21571          ----------- Buffer: backtrace-output ------------
21572
21573 -- Variable: debug-on-next-call
21574     If this variable is non-‘nil’, it says to call the debugger before
21575     the next ‘eval’, ‘apply’ or ‘funcall’.  Entering the debugger sets
21576     ‘debug-on-next-call’ to ‘nil’.
21577
21578     The ‘d’ command in the debugger works by setting this variable.
21579
21580 -- Function: backtrace-debug level flag
21581     This function sets the debug-on-exit flag of the stack frame LEVEL
21582     levels down the stack, giving it the value FLAG.  If FLAG is
21583     non-‘nil’, this will cause the debugger to be entered when that
21584     frame later exits.  Even a nonlocal exit through that frame will
21585     enter the debugger.
21586
21587     This function is used only by the debugger.
21588
21589 -- Variable: command-debug-status
21590     This variable records the debugging status of the current
21591     interactive command.  Each time a command is called interactively,
21592     this variable is bound to ‘nil’.  The debugger can set this
21593     variable to leave information for future debugger invocations
21594     during the same command invocation.
21595
21596     The advantage of using this variable rather than an ordinary global
21597     variable is that the data will never carry over to a subsequent
21598     command invocation.
21599
21600     This variable is obsolete and will be removed in future versions.
21601
21602 -- Function: backtrace-frame frame-number &optional base
21603     The function ‘backtrace-frame’ is intended for use in Lisp
21604     debuggers.  It returns information about what computation is
21605     happening in the stack frame FRAME-NUMBER levels down.
21606
21607     If that frame has not evaluated the arguments yet, or is a special
21608     form, the value is ‘(nil FUNCTION ARG-FORMS...)’.
21609
21610     If that frame has evaluated its arguments and called its function
21611     already, the return value is ‘(t FUNCTION ARG-VALUES...)’.
21612
21613     In the return value, FUNCTION is whatever was supplied as the CAR
21614     of the evaluated list, or a ‘lambda’ expression in the case of a
21615     macro call.  If the function has a ‘&rest’ argument, that is
21616     represented as the tail of the list ARG-VALUES.
21617
21618     If BASE is specified, FRAME-NUMBER counts relative to the topmost
21619     frame whose FUNCTION is BASE.
21620
21621     If FRAME-NUMBER is out of range, ‘backtrace-frame’ returns ‘nil’.
21622
21623 -- Function: mapbacktrace function &optional base
21624     The function ‘mapbacktrace’ calls FUNCTION once for each frame in
21625     the backtrace, starting at the first frame whose function is BASE
21626     (or from the top if BASE is omitted or ‘nil’).
21627
21628     FUNCTION is called with four arguments: EVALD, FUNC, ARGS, and
21629     FLAGS.
21630
21631     If a frame has not evaluated its arguments yet or is a special
21632     form, EVALD is ‘nil’ and ARGS is a list of forms.
21633
21634     If a frame has evaluated its arguments and called its function
21635     already, EVALD is ‘t’ and ARGS is a list of values.  FLAGS is a
21636     plist of properties of the current frame: currently, the only
21637     supported property is ‘:debug-on-exit’, which is ‘t’ if the stack
21638     frame’s ‘debug-on-exit’ flag is set.
21639
21640
21641File: elisp.info,  Node: Edebug,  Next: Syntax Errors,  Prev: Debugger,  Up: Debugging
21642
2164318.2 Edebug
21644===========
21645
21646Edebug is a source-level debugger for Emacs Lisp programs, with which
21647you can:
21648
21649   • Step through evaluation, stopping before and after each expression.
21650
21651   • Set conditional or unconditional breakpoints.
21652
21653   • Stop when a specified condition is true (the global break event).
21654
21655   • Trace slow or fast, stopping briefly at each stop point, or at each
21656     breakpoint.
21657
21658   • Display expression results and evaluate expressions as if outside
21659     of Edebug.
21660
21661   • Automatically re-evaluate a list of expressions and display their
21662     results each time Edebug updates the display.
21663
21664   • Output trace information on function calls and returns.
21665
21666   • Stop when an error occurs.
21667
21668   • Display a backtrace, omitting Edebug’s own frames.
21669
21670   • Specify argument evaluation for macros and defining forms.
21671
21672   • Obtain rudimentary coverage testing and frequency counts.
21673
21674   The first three sections below should tell you enough about Edebug to
21675start using it.
21676
21677* Menu:
21678
21679* Using Edebug::                Introduction to use of Edebug.
21680* Instrumenting::               You must instrument your code
21681                                  in order to debug it with Edebug.
21682* Modes: Edebug Execution Modes. Execution modes, stopping more or less often.
21683* Jumping::                     Commands to jump to a specified place.
21684* Misc: Edebug Misc.            Miscellaneous commands.
21685* Breaks::                      Setting breakpoints to make the program stop.
21686* Trapping Errors::             Trapping errors with Edebug.
21687* Views: Edebug Views.          Views inside and outside of Edebug.
21688* Eval: Edebug Eval.            Evaluating expressions within Edebug.
21689* Eval List::                   Expressions whose values are displayed
21690                                  each time you enter Edebug.
21691* Printing in Edebug::          Customization of printing.
21692* Trace Buffer::                How to produce trace output in a buffer.
21693* Coverage Testing::            How to test evaluation coverage.
21694* The Outside Context::         Data that Edebug saves and restores.
21695* Edebug and Macros::           Specifying how to handle macro calls.
21696* Options: Edebug Options.      Option variables for customizing Edebug.
21697
21698
21699File: elisp.info,  Node: Using Edebug,  Next: Instrumenting,  Up: Edebug
21700
2170118.2.1 Using Edebug
21702-------------------
21703
21704To debug a Lisp program with Edebug, you must first “instrument” the
21705Lisp code that you want to debug.  A simple way to do this is to first
21706move point into the definition of a function or macro and then do ‘C-u
21707C-M-x’ (‘eval-defun’ with a prefix argument).  See *note
21708Instrumenting::, for alternative ways to instrument code.
21709
21710   Once a function is instrumented, any call to the function activates
21711Edebug.  Depending on which Edebug execution mode you have selected,
21712activating Edebug may stop execution and let you step through the
21713function, or it may update the display and continue execution while
21714checking for debugging commands.  The default execution mode is step,
21715which stops execution.  *Note Edebug Execution Modes::.
21716
21717   Within Edebug, you normally view an Emacs buffer showing the source
21718of the Lisp code you are debugging.  This is referred to as the “source
21719code buffer”, and it is temporarily read-only.
21720
21721   An arrow in the left fringe indicates the line where the function is
21722executing.  Point initially shows where within the line the function is
21723executing, but this ceases to be true if you move point yourself.
21724
21725   If you instrument the definition of ‘fac’ (shown below) and then
21726execute ‘(fac 3)’, here is what you would normally see.  Point is at the
21727open-parenthesis before ‘if’.
21728
21729     (defun fac (n)
21730     =>★(if (< 0 n)
21731           (* n (fac (1- n)))
21732         1))
21733
21734   The places within a function where Edebug can stop execution are
21735called “stop points”.  These occur both before and after each
21736subexpression that is a list, and also after each variable reference.
21737Here we use periods to show the stop points in the function ‘fac’:
21738
21739     (defun fac (n)
21740       .(if .(< 0 n.).
21741           .(* n. .(fac .(1- n.).).).
21742         1).)
21743
21744   The special commands of Edebug are available in the source code
21745buffer in addition to the commands of Emacs Lisp mode.  For example, you
21746can type the Edebug command <SPC> to execute until the next stop point.
21747If you type <SPC> once after entry to ‘fac’, here is the display you
21748will see:
21749
21750     (defun fac (n)
21751     =>(if ★(< 0 n)
21752           (* n (fac (1- n)))
21753         1))
21754
21755   When Edebug stops execution after an expression, it displays the
21756expression’s value in the echo area.
21757
21758   Other frequently used commands are ‘b’ to set a breakpoint at a stop
21759point, ‘g’ to execute until a breakpoint is reached, and ‘q’ to exit
21760Edebug and return to the top-level command loop.  Type ‘?’ to display a
21761list of all Edebug commands.
21762
21763
21764File: elisp.info,  Node: Instrumenting,  Next: Edebug Execution Modes,  Prev: Using Edebug,  Up: Edebug
21765
2176618.2.2 Instrumenting for Edebug
21767-------------------------------
21768
21769In order to use Edebug to debug Lisp code, you must first “instrument”
21770the code.  Instrumenting code inserts additional code into it, to invoke
21771Edebug at the proper places.
21772
21773   When you invoke command ‘C-M-x’ (‘eval-defun’) with a prefix argument
21774on a function definition, it instruments the definition before
21775evaluating it.  (This does not modify the source code itself.)  If the
21776variable ‘edebug-all-defs’ is non-‘nil’, that inverts the meaning of the
21777prefix argument: in this case, ‘C-M-x’ instruments the definition
21778_unless_ it has a prefix argument.  The default value of
21779‘edebug-all-defs’ is ‘nil’.  The command ‘M-x edebug-all-defs’ toggles
21780the value of the variable ‘edebug-all-defs’.
21781
21782   If ‘edebug-all-defs’ is non-‘nil’, then the commands ‘eval-region’,
21783‘eval-current-buffer’, and ‘eval-buffer’ also instrument any definitions
21784they evaluate.  Similarly, ‘edebug-all-forms’ controls whether
21785‘eval-region’ should instrument _any_ form, even non-defining forms.
21786This doesn’t apply to loading or evaluations in the minibuffer.  The
21787command ‘M-x edebug-all-forms’ toggles this option.
21788
21789   Another command, ‘M-x edebug-eval-top-level-form’, is available to
21790instrument any top-level form regardless of the values of
21791‘edebug-all-defs’ and ‘edebug-all-forms’.  ‘edebug-defun’ is an alias
21792for ‘edebug-eval-top-level-form’.
21793
21794   While Edebug is active, the command ‘I’ (‘edebug-instrument-callee’)
21795instruments the definition of the function or macro called by the list
21796form after point, if it is not already instrumented.  This is possible
21797only if Edebug knows where to find the source for that function; for
21798this reason, after loading Edebug, ‘eval-region’ records the position of
21799every definition it evaluates, even if not instrumenting it.  See also
21800the ‘i’ command (*note Jumping::), which steps into the call after
21801instrumenting the function.
21802
21803   Edebug knows how to instrument all the standard special forms,
21804‘interactive’ forms with an expression argument, anonymous lambda
21805expressions, and other defining forms.  However, Edebug cannot determine
21806on its own what a user-defined macro will do with the arguments of a
21807macro call, so you must provide that information using Edebug
21808specifications; for details, *note Edebug and Macros::.
21809
21810   When Edebug is about to instrument code for the first time in a
21811session, it runs the hook ‘edebug-setup-hook’, then sets it to ‘nil’.
21812You can use this to load Edebug specifications associated with a package
21813you are using, but only when you use Edebug.
21814
21815   If Edebug detects a syntax error while instrumenting, it leaves point
21816at the erroneous code and signals an ‘invalid-read-syntax’ error.
21817Example:
21818
21819     error→ Invalid read syntax: "Expected lambda expression"
21820
21821   One potential reason for such a failure to instrument is that some
21822macro definitions are not yet known to Emacs.  To work around this, load
21823the file which defines the function you are about to instrument.
21824
21825   To remove instrumentation from a definition, simply re-evaluate its
21826definition in a way that does not instrument.  There are two ways of
21827evaluating forms that never instrument them: from a file with ‘load’,
21828and from the minibuffer with ‘eval-expression’ (‘M-:’).
21829
21830   A different way to remove the instrumentation from a definition is to
21831use the ‘edebug-remove-instrumentation’ command.  It also allows
21832removing the instrumentation from everything that has been instrumented.
21833
21834   *Note Edebug Eval::, for other evaluation functions available inside
21835of Edebug.
21836
21837
21838File: elisp.info,  Node: Edebug Execution Modes,  Next: Jumping,  Prev: Instrumenting,  Up: Edebug
21839
2184018.2.3 Edebug Execution Modes
21841-----------------------------
21842
21843Edebug supports several execution modes for running the program you are
21844debugging.  We call these alternatives “Edebug execution modes”; do not
21845confuse them with major or minor modes.  The current Edebug execution
21846mode determines how far Edebug continues execution before
21847stopping—whether it stops at each stop point, or continues to the next
21848breakpoint, for example—and how much Edebug displays the progress of the
21849evaluation before it stops.
21850
21851   Normally, you specify the Edebug execution mode by typing a command
21852to continue the program in a certain mode.  Here is a table of these
21853commands; all except for ‘S’ resume execution of the program, at least
21854for a certain distance.
21855
21856‘S’
21857     Stop: don’t execute any more of the program, but wait for more
21858     Edebug commands (‘edebug-stop’).
21859
21860‘<SPC>’
21861     Step: stop at the next stop point encountered (‘edebug-step-mode’).
21862
21863‘n’
21864     Next: stop at the next stop point encountered after an expression
21865     (‘edebug-next-mode’).  Also see ‘edebug-forward-sexp’ in *note
21866     Jumping::.
21867
21868‘t’
21869     Trace: pause (normally one second) at each Edebug stop point
21870     (‘edebug-trace-mode’).
21871
21872‘T’
21873     Rapid trace: update the display at each stop point, but don’t
21874     actually pause (‘edebug-Trace-fast-mode’).
21875
21876‘g’
21877     Go: run until the next breakpoint (‘edebug-go-mode’).  *Note
21878     Breakpoints::.
21879
21880‘c’
21881     Continue: pause one second at each breakpoint, and then continue
21882     (‘edebug-continue-mode’).
21883
21884‘C’
21885     Rapid continue: move point to each breakpoint, but don’t pause
21886     (‘edebug-Continue-fast-mode’).
21887
21888‘G’
21889     Go non-stop: ignore breakpoints (‘edebug-Go-nonstop-mode’).  You
21890     can still stop the program by typing ‘S’, or any editing command.
21891
21892   In general, the execution modes earlier in the above list run the
21893program more slowly or stop sooner than the modes later in the list.
21894
21895   When you enter a new Edebug level, Edebug will normally stop at the
21896first instrumented function it encounters.  If you prefer to stop only
21897at a break point, or not at all (for example, when gathering coverage
21898data), change the value of ‘edebug-initial-mode’ from its default ‘step’
21899to ‘go’, or ‘Go-nonstop’, or one of its other values (*note Edebug
21900Options::).  You can do this readily with ‘C-x C-a C-m’
21901(‘edebug-set-initial-mode’):
21902
21903 -- Command: edebug-set-initial-mode
21904     This command, bound to ‘C-x C-a C-m’, sets ‘edebug-initial-mode’.
21905     It prompts you for a key to indicate the mode.  You should enter
21906     one of the eight keys listed above, which sets the corresponding
21907     mode.
21908
21909   Note that you may reenter the same Edebug level several times if, for
21910example, an instrumented function is called several times from one
21911command.
21912
21913   While executing or tracing, you can interrupt the execution by typing
21914any Edebug command.  Edebug stops the program at the next stop point and
21915then executes the command you typed.  For example, typing ‘t’ during
21916execution switches to trace mode at the next stop point.  You can use
21917‘S’ to stop execution without doing anything else.
21918
21919   If your function happens to read input, a character you type
21920intending to interrupt execution may be read by the function instead.
21921You can avoid such unintended results by paying attention to when your
21922program wants input.
21923
21924   Keyboard macros containing the commands in this section do not
21925completely work: exiting from Edebug, to resume the program, loses track
21926of the keyboard macro.  This is not easy to fix.  Also, defining or
21927executing a keyboard macro outside of Edebug does not affect commands
21928inside Edebug.  This is usually an advantage.  See also the
21929‘edebug-continue-kbd-macro’ option in *note Edebug Options::.
21930
21931 -- User Option: edebug-sit-for-seconds
21932     This option specifies how many seconds to wait between execution
21933     steps in trace mode or continue mode.  The default is 1 second.
21934
21935
21936File: elisp.info,  Node: Jumping,  Next: Edebug Misc,  Prev: Edebug Execution Modes,  Up: Edebug
21937
2193818.2.4 Jumping
21939--------------
21940
21941The commands described in this section execute until they reach a
21942specified location.  All except ‘i’ make a temporary breakpoint to
21943establish the place to stop, then switch to go mode.  Any other
21944breakpoint reached before the intended stop point will also stop
21945execution.  *Note Breakpoints::, for the details on breakpoints.
21946
21947   These commands may fail to work as expected in case of nonlocal exit,
21948as that can bypass the temporary breakpoint where you expected the
21949program to stop.
21950
21951‘h’
21952     Proceed to the stop point near where point is (‘edebug-goto-here’).
21953
21954‘f’
21955     Run the program for one expression (‘edebug-forward-sexp’).
21956
21957‘o’
21958     Run the program until the end of the containing sexp
21959     (‘edebug-step-out’).
21960
21961‘i’
21962     Step into the function or macro called by the form after point
21963     (‘edebug-step-in’).
21964
21965   The ‘h’ command proceeds to the stop point at or after the current
21966location of point, using a temporary breakpoint.
21967
21968   The ‘f’ command runs the program forward over one expression.  More
21969precisely, it sets a temporary breakpoint at the position that
21970‘forward-sexp’ would reach, then executes in go mode so that the program
21971will stop at breakpoints.
21972
21973   With a prefix argument N, the temporary breakpoint is placed N sexps
21974beyond point.  If the containing list ends before N more elements, then
21975the place to stop is after the containing expression.
21976
21977   You must check that the position ‘forward-sexp’ finds is a place that
21978the program will really get to.  In ‘cond’, for example, this may not be
21979true.
21980
21981   For flexibility, the ‘f’ command does ‘forward-sexp’ starting at
21982point, rather than at the stop point.  If you want to execute one
21983expression _from the current stop point_, first type ‘w’
21984(‘edebug-where’) to move point there, and then type ‘f’.
21985
21986   The ‘o’ command continues out of an expression.  It places a
21987temporary breakpoint at the end of the sexp containing point.  If the
21988containing sexp is a function definition itself, ‘o’ continues until
21989just before the last sexp in the definition.  If that is where you are
21990now, it returns from the function and then stops.  In other words, this
21991command does not exit the currently executing function unless you are
21992positioned after the last sexp.
21993
21994   Normally, the ‘h’, ‘f’, and ‘o’ commands display “Break” and pause
21995for ‘edebug-sit-for-seconds’ before showing the result of the form just
21996evaluated.  You can avoid this pause by setting ‘edebug-sit-on-break’ to
21997‘nil’.  *Note Edebug Options::.
21998
21999   The ‘i’ command steps into the function or macro called by the list
22000form after point, and stops at its first stop point.  Note that the form
22001need not be the one about to be evaluated.  But if the form is a
22002function call about to be evaluated, remember to use this command before
22003any of the arguments are evaluated, since otherwise it will be too late.
22004
22005   The ‘i’ command instruments the function or macro it’s supposed to
22006step into, if it isn’t instrumented already.  This is convenient, but
22007keep in mind that the function or macro remains instrumented unless you
22008explicitly arrange to deinstrument it.
22009
22010
22011File: elisp.info,  Node: Edebug Misc,  Next: Breaks,  Prev: Jumping,  Up: Edebug
22012
2201318.2.5 Miscellaneous Edebug Commands
22014------------------------------------
22015
22016Some miscellaneous Edebug commands are described here.
22017
22018‘?’
22019     Display the help message for Edebug (‘edebug-help’).
22020
22021‘a’
22022‘C-]’
22023     Abort one level back to the previous command level
22024     (‘abort-recursive-edit’).
22025
22026‘q’
22027     Return to the top level editor command loop (‘top-level’).  This
22028     exits all recursive editing levels, including all levels of Edebug
22029     activity.  However, instrumented code protected with
22030     ‘unwind-protect’ or ‘condition-case’ forms may resume debugging.
22031
22032‘Q’
22033     Like ‘q’, but don’t stop even for protected code
22034     (‘edebug-top-level-nonstop’).
22035
22036‘r’
22037     Redisplay the most recently known expression result in the echo
22038     area (‘edebug-previous-result’).
22039
22040‘d’
22041     Display a backtrace, excluding Edebug’s own functions for clarity
22042     (‘edebug-pop-to-backtrace’).
22043
22044     *Note Backtraces::, for a description of backtraces and the
22045     commands which work on them.
22046
22047     If you would like to see Edebug’s functions in the backtrace, use
22048     ‘M-x edebug-backtrace-show-instrumentation’.  To hide them again
22049     use ‘M-x edebug-backtrace-hide-instrumentation’.
22050
22051     If a backtrace frame starts with ‘>’ that means that Edebug knows
22052     where the source code for the frame is located.  Use ‘s’ to jump to
22053     the source code for the current frame.
22054
22055     The backtrace buffer is killed automatically when you continue
22056     execution.
22057
22058   You can invoke commands from Edebug that activate Edebug again
22059recursively.  Whenever Edebug is active, you can quit to the top level
22060with ‘q’ or abort one recursive edit level with ‘C-]’.  You can display
22061a backtrace of all the pending evaluations with ‘d’.
22062
22063
22064File: elisp.info,  Node: Breaks,  Next: Trapping Errors,  Prev: Edebug Misc,  Up: Edebug
22065
2206618.2.6 Breaks
22067-------------
22068
22069Edebug’s step mode stops execution when the next stop point is reached.
22070There are three other ways to stop Edebug execution once it has started:
22071breakpoints, the global break condition, and source breakpoints.
22072
22073* Menu:
22074
22075* Breakpoints::                 Breakpoints at stop points.
22076* Global Break Condition::      Breaking on an event.
22077* Source Breakpoints::          Embedding breakpoints in source code.
22078
22079
22080File: elisp.info,  Node: Breakpoints,  Next: Global Break Condition,  Up: Breaks
22081
2208218.2.6.1 Edebug Breakpoints
22083...........................
22084
22085While using Edebug, you can specify “breakpoints” in the program you are
22086testing: these are places where execution should stop.  You can set a
22087breakpoint at any stop point, as defined in *note Using Edebug::.  For
22088setting and unsetting breakpoints, the stop point that is affected is
22089the first one at or after point in the source code buffer.  Here are the
22090Edebug commands for breakpoints:
22091
22092‘b’
22093     Set a breakpoint at the stop point at or after point
22094     (‘edebug-set-breakpoint’).  If you use a prefix argument, the
22095     breakpoint is temporary—it turns off the first time it stops the
22096     program.  An overlay with the ‘edebug-enabled-breakpoint’ or
22097     ‘edebug-disabled-breakpoint’ faces is put at the breakpoint.
22098
22099‘u’
22100     Unset the breakpoint (if any) at the stop point at or after point
22101     (‘edebug-unset-breakpoint’).
22102
22103‘U’
22104     Unset any breakpoints in the current form
22105     (‘edebug-unset-breakpoints’).
22106
22107‘D’
22108     Toggle whether to disable the breakpoint near point
22109     (‘edebug-toggle-disable-breakpoint’).  This command is mostly
22110     useful if the breakpoint is conditional and it would take some work
22111     to recreate the condition.
22112
22113‘x CONDITION <RET>’
22114     Set a conditional breakpoint which stops the program only if
22115     evaluating CONDITION produces a non-‘nil’ value
22116     (‘edebug-set-conditional-breakpoint’).  With a prefix argument, the
22117     breakpoint is temporary.
22118
22119‘B’
22120     Move point to the next breakpoint in the current definition
22121     (‘edebug-next-breakpoint’).
22122
22123   While in Edebug, you can set a breakpoint with ‘b’ and unset one with
22124‘u’.  First move point to the Edebug stop point of your choice, then
22125type ‘b’ or ‘u’ to set or unset a breakpoint there.  Unsetting a
22126breakpoint where none has been set has no effect.
22127
22128   Re-evaluating or reinstrumenting a definition removes all of its
22129previous breakpoints.
22130
22131   A “conditional breakpoint” tests a condition each time the program
22132gets there.  Any errors that occur as a result of evaluating the
22133condition are ignored, as if the result were ‘nil’.  To set a
22134conditional breakpoint, use ‘x’, and specify the condition expression in
22135the minibuffer.  Setting a conditional breakpoint at a stop point that
22136has a previously established conditional breakpoint puts the previous
22137condition expression in the minibuffer so you can edit it.
22138
22139   You can make a conditional or unconditional breakpoint “temporary” by
22140using a prefix argument with the command to set the breakpoint.  When a
22141temporary breakpoint stops the program, it is automatically unset.
22142
22143   Edebug always stops or pauses at a breakpoint, except when the Edebug
22144mode is Go-nonstop.  In that mode, it ignores breakpoints entirely.
22145
22146   To find out where your breakpoints are, use the ‘B’ command, which
22147moves point to the next breakpoint following point, within the same
22148function, or to the first breakpoint if there are no following
22149breakpoints.  This command does not continue execution—it just moves
22150point in the buffer.
22151
22152
22153File: elisp.info,  Node: Global Break Condition,  Next: Source Breakpoints,  Prev: Breakpoints,  Up: Breaks
22154
2215518.2.6.2 Global Break Condition
22156...............................
22157
22158A “global break condition” stops execution when a specified condition is
22159satisfied, no matter where that may occur.  Edebug evaluates the global
22160break condition at every stop point; if it evaluates to a non-‘nil’
22161value, then execution stops or pauses depending on the execution mode,
22162as if a breakpoint had been hit.  If evaluating the condition gets an
22163error, execution does not stop.
22164
22165   The condition expression is stored in
22166‘edebug-global-break-condition’.  You can specify a new expression using
22167the ‘X’ command from the source code buffer while Edebug is active, or
22168using ‘C-x X X’ from any buffer at any time, as long as Edebug is loaded
22169(‘edebug-set-global-break-condition’).
22170
22171   The global break condition is the simplest way to find where in your
22172code some event occurs, but it makes code run much more slowly.  So you
22173should reset the condition to ‘nil’ when not using it.
22174
22175
22176File: elisp.info,  Node: Source Breakpoints,  Prev: Global Break Condition,  Up: Breaks
22177
2217818.2.6.3 Source Breakpoints
22179...........................
22180
22181All breakpoints in a definition are forgotten each time you reinstrument
22182it.  If you wish to make a breakpoint that won’t be forgotten, you can
22183write a “source breakpoint”, which is simply a call to the function
22184‘edebug’ in your source code.  You can, of course, make such a call
22185conditional.  For example, in the ‘fac’ function, you can insert the
22186first line as shown below, to stop when the argument reaches zero:
22187
22188     (defun fac (n)
22189       (if (= n 0) (edebug))
22190       (if (< 0 n)
22191           (* n (fac (1- n)))
22192         1))
22193
22194   When the ‘fac’ definition is instrumented and the function is called,
22195the call to ‘edebug’ acts as a breakpoint.  Depending on the execution
22196mode, Edebug stops or pauses there.
22197
22198   If no instrumented code is being executed when ‘edebug’ is called,
22199that function calls ‘debug’.
22200
22201
22202File: elisp.info,  Node: Trapping Errors,  Next: Edebug Views,  Prev: Breaks,  Up: Edebug
22203
2220418.2.7 Trapping Errors
22205----------------------
22206
22207Emacs normally displays an error message when an error is signaled and
22208not handled with ‘condition-case’.  While Edebug is active and executing
22209instrumented code, it normally responds to all unhandled errors.  You
22210can customize this with the options ‘edebug-on-error’ and
22211‘edebug-on-quit’; see *note Edebug Options::.
22212
22213   When Edebug responds to an error, it shows the last stop point
22214encountered before the error.  This may be the location of a call to a
22215function which was not instrumented, and within which the error actually
22216occurred.  For an unbound variable error, the last known stop point
22217might be quite distant from the offending variable reference.  In that
22218case, you might want to display a full backtrace (*note Edebug Misc::).
22219
22220   If you change ‘debug-on-error’ or ‘debug-on-quit’ while Edebug is
22221active, these changes will be forgotten when Edebug becomes inactive.
22222Furthermore, during Edebug’s recursive edit, these variables are bound
22223to the values they had outside of Edebug.
22224
22225
22226File: elisp.info,  Node: Edebug Views,  Next: Edebug Eval,  Prev: Trapping Errors,  Up: Edebug
22227
2222818.2.8 Edebug Views
22229-------------------
22230
22231These Edebug commands let you view aspects of the buffer and window
22232status as they were before entry to Edebug.  The outside window
22233configuration is the collection of windows and contents that were in
22234effect outside of Edebug.
22235
22236‘P’
22237‘v’
22238     Switch to viewing the outside window configuration
22239     (‘edebug-view-outside’).  Type ‘C-x X w’ to return to Edebug.
22240
22241‘p’
22242     Temporarily display the outside current buffer with point at its
22243     outside position (‘edebug-bounce-point’), pausing for one second
22244     before returning to Edebug.  With a prefix argument N, pause for N
22245     seconds instead.
22246
22247‘w’
22248     Move point back to the current stop point in the source code buffer
22249     (‘edebug-where’).
22250
22251     If you use this command in a different window displaying the same
22252     buffer, that window will be used instead to display the current
22253     definition in the future.
22254
22255‘W’
22256     Toggle whether Edebug saves and restores the outside window
22257     configuration (‘edebug-toggle-save-windows’).
22258
22259     With a prefix argument, ‘W’ only toggles saving and restoring of
22260     the selected window.  To specify a window that is not displaying
22261     the source code buffer, you must use ‘C-x X W’ from the global
22262     keymap.
22263
22264   You can view the outside window configuration with ‘v’ or just bounce
22265to the point in the current buffer with ‘p’, even if it is not normally
22266displayed.
22267
22268   After moving point, you may wish to jump back to the stop point.  You
22269can do that with ‘w’ from a source code buffer.  You can jump back to
22270the stop point in the source code buffer from any buffer using ‘C-x X
22271w’.
22272
22273   Each time you use ‘W’ to turn saving _off_, Edebug forgets the saved
22274outside window configuration—so that even if you turn saving back _on_,
22275the current window configuration remains unchanged when you next exit
22276Edebug (by continuing the program).  However, the automatic redisplay of
22277‘*edebug*’ and ‘*edebug-trace*’ may conflict with the buffers you wish
22278to see unless you have enough windows open.
22279
22280
22281File: elisp.info,  Node: Edebug Eval,  Next: Eval List,  Prev: Edebug Views,  Up: Edebug
22282
2228318.2.9 Evaluation
22284-----------------
22285
22286While within Edebug, you can evaluate expressions as if Edebug were not
22287running.  Edebug tries to be invisible to the expression’s evaluation
22288and printing.  Evaluation of expressions that cause side effects will
22289work as expected, except for changes to data that Edebug explicitly
22290saves and restores.  *Note The Outside Context::, for details on this
22291process.
22292
22293‘e EXP <RET>’
22294     Evaluate expression EXP in the context outside of Edebug
22295     (‘edebug-eval-expression’).  That is, Edebug tries to minimize its
22296     interference with the evaluation.
22297
22298‘M-: EXP <RET>’
22299     Evaluate expression EXP in the context of Edebug itself
22300     (‘eval-expression’).
22301
22302‘C-x C-e’
22303     Evaluate the expression before point, in the context outside of
22304     Edebug (‘edebug-eval-last-sexp’).  With the prefix argument of zero
22305     (‘C-u 0 C-x C-e’), don’t shorten long items (like strings and
22306     lists).
22307
22308   Edebug supports evaluation of expressions containing references to
22309lexically bound symbols created by the following constructs in ‘cl.el’:
22310‘lexical-let’, ‘macrolet’, and ‘symbol-macrolet’.
22311
22312
22313File: elisp.info,  Node: Eval List,  Next: Printing in Edebug,  Prev: Edebug Eval,  Up: Edebug
22314
2231518.2.10 Evaluation List Buffer
22316------------------------------
22317
22318You can use the “evaluation list buffer”, called ‘*edebug*’, to evaluate
22319expressions interactively.  You can also set up the “evaluation list” of
22320expressions to be evaluated automatically each time Edebug updates the
22321display.
22322
22323‘E’
22324     Switch to the evaluation list buffer ‘*edebug*’
22325     (‘edebug-visit-eval-list’).
22326
22327   In the ‘*edebug*’ buffer you can use the commands of Lisp Interaction
22328mode (*note (emacs)Lisp Interaction::) as well as these special
22329commands:
22330
22331‘C-j’
22332     Evaluate the expression before point, in the outside context, and
22333     insert the value in the buffer (‘edebug-eval-print-last-sexp’).
22334     With prefix argument of zero (‘C-u 0 C-j’), don’t shorten long
22335     items (like strings and lists).
22336
22337‘C-x C-e’
22338     Evaluate the expression before point, in the context outside of
22339     Edebug (‘edebug-eval-last-sexp’).
22340
22341‘C-c C-u’
22342     Build a new evaluation list from the contents of the buffer
22343     (‘edebug-update-eval-list’).
22344
22345‘C-c C-d’
22346     Delete the evaluation list group that point is in
22347     (‘edebug-delete-eval-item’).
22348
22349‘C-c C-w’
22350     Switch back to the source code buffer at the current stop point
22351     (‘edebug-where’).
22352
22353   You can evaluate expressions in the evaluation list window with ‘C-j’
22354or ‘C-x C-e’, just as you would in ‘*scratch*’; but they are evaluated
22355in the context outside of Edebug.
22356
22357   The expressions you enter interactively (and their results) are lost
22358when you continue execution; but you can set up an “evaluation list”
22359consisting of expressions to be evaluated each time execution stops.
22360
22361   To do this, write one or more “evaluation list groups” in the
22362evaluation list buffer.  An evaluation list group consists of one or
22363more Lisp expressions.  Groups are separated by comment lines.
22364
22365   The command ‘C-c C-u’ (‘edebug-update-eval-list’) rebuilds the
22366evaluation list, scanning the buffer and using the first expression of
22367each group.  (The idea is that the second expression of the group is the
22368value previously computed and displayed.)
22369
22370   Each entry to Edebug redisplays the evaluation list by inserting each
22371expression in the buffer, followed by its current value.  It also
22372inserts comment lines so that each expression becomes its own group.
22373Thus, if you type ‘C-c C-u’ again without changing the buffer text, the
22374evaluation list is effectively unchanged.
22375
22376   If an error occurs during an evaluation from the evaluation list, the
22377error message is displayed in a string as if it were the result.
22378Therefore, expressions using variables that are not currently valid do
22379not interrupt your debugging.
22380
22381   Here is an example of what the evaluation list window looks like
22382after several expressions have been added to it:
22383
22384     (current-buffer)
22385     #<buffer *scratch*>
22386     ;---------------------------------------------------------------
22387     (selected-window)
22388     #<window 16 on *scratch*>
22389     ;---------------------------------------------------------------
22390     (point)
22391     196
22392     ;---------------------------------------------------------------
22393     bad-var
22394     "Symbol's value as variable is void: bad-var"
22395     ;---------------------------------------------------------------
22396     (recursion-depth)
22397     0
22398     ;---------------------------------------------------------------
22399     this-command
22400     eval-last-sexp
22401     ;---------------------------------------------------------------
22402
22403   To delete a group, move point into it and type ‘C-c C-d’, or simply
22404delete the text for the group and update the evaluation list with ‘C-c
22405C-u’.  To add a new expression to the evaluation list, insert the
22406expression at a suitable place, insert a new comment line, then type
22407‘C-c C-u’.  You need not insert dashes in the comment line—its contents
22408don’t matter.
22409
22410   After selecting ‘*edebug*’, you can return to the source code buffer
22411with ‘C-c C-w’.  The ‘*edebug*’ buffer is killed when you continue
22412execution, and recreated next time it is needed.
22413
22414
22415File: elisp.info,  Node: Printing in Edebug,  Next: Trace Buffer,  Prev: Eval List,  Up: Edebug
22416
2241718.2.11 Printing in Edebug
22418--------------------------
22419
22420If an expression in your program produces a value containing circular
22421list structure, you may get an error when Edebug attempts to print it.
22422
22423   One way to cope with circular structure is to set ‘print-length’ or
22424‘print-level’ to truncate the printing.  Edebug does this for you; it
22425binds ‘print-length’ and ‘print-level’ to the values of the variables
22426‘edebug-print-length’ and ‘edebug-print-level’ (so long as they have
22427non-‘nil’ values).  *Note Output Variables::.
22428
22429 -- User Option: edebug-print-length
22430     If non-‘nil’, Edebug binds ‘print-length’ to this value while
22431     printing results.  The default value is ‘50’.
22432
22433 -- User Option: edebug-print-level
22434     If non-‘nil’, Edebug binds ‘print-level’ to this value while
22435     printing results.  The default value is ‘50’.
22436
22437   You can also print circular structures and structures that share
22438elements more informatively by binding ‘print-circle’ to a non-‘nil’
22439value.
22440
22441   Here is an example of code that creates a circular structure:
22442
22443     (setq a (list 'x 'y))
22444     (setcar a a)
22445
22446Custom printing prints this as ‘Result: #1=(#1# y)’.  The ‘#1=’ notation
22447labels the structure that follows it with the label ‘1’, and the ‘#1#’
22448notation references the previously labeled structure.  This notation is
22449used for any shared elements of lists or vectors.
22450
22451 -- User Option: edebug-print-circle
22452     If non-‘nil’, Edebug binds ‘print-circle’ to this value while
22453     printing results.  The default value is ‘t’.
22454
22455   Other programs can also use custom printing; see ‘cust-print.el’ for
22456details.
22457
22458
22459File: elisp.info,  Node: Trace Buffer,  Next: Coverage Testing,  Prev: Printing in Edebug,  Up: Edebug
22460
2246118.2.12 Trace Buffer
22462--------------------
22463
22464Edebug can record an execution trace, storing it in a buffer named
22465‘*edebug-trace*’.  This is a log of function calls and returns, showing
22466the function names and their arguments and values.  To enable trace
22467recording, set ‘edebug-trace’ to a non-‘nil’ value.
22468
22469   Making a trace buffer is not the same thing as using trace execution
22470mode (*note Edebug Execution Modes::).
22471
22472   When trace recording is enabled, each function entry and exit adds
22473lines to the trace buffer.  A function entry record consists of ‘::::{’,
22474followed by the function name and argument values.  A function exit
22475record consists of ‘::::}’, followed by the function name and result of
22476the function.
22477
22478   The number of ‘:’s in an entry shows its recursion depth.  You can
22479use the braces in the trace buffer to find the matching beginning or end
22480of function calls.
22481
22482   You can customize trace recording for function entry and exit by
22483redefining the functions ‘edebug-print-trace-before’ and
22484‘edebug-print-trace-after’.
22485
22486 -- Macro: edebug-tracing string body...
22487     This macro requests additional trace information around the
22488     execution of the BODY forms.  The argument STRING specifies text to
22489     put in the trace buffer, after the ‘{’ or ‘}’.  All the arguments
22490     are evaluated, and ‘edebug-tracing’ returns the value of the last
22491     form in BODY.
22492
22493 -- Function: edebug-trace format-string &rest format-args
22494     This function inserts text in the trace buffer.  It computes the
22495     text with ‘(apply 'format FORMAT-STRING FORMAT-ARGS)’.  It also
22496     appends a newline to separate entries.
22497
22498   ‘edebug-tracing’ and ‘edebug-trace’ insert lines in the trace buffer
22499whenever they are called, even if Edebug is not active.  Adding text to
22500the trace buffer also scrolls its window to show the last lines
22501inserted.
22502
22503
22504File: elisp.info,  Node: Coverage Testing,  Next: The Outside Context,  Prev: Trace Buffer,  Up: Edebug
22505
2250618.2.13 Coverage Testing
22507------------------------
22508
22509Edebug provides rudimentary coverage testing and display of execution
22510frequency.
22511
22512   Coverage testing works by comparing the result of each expression
22513with the previous result; each form in the program is considered covered
22514if it has returned two different values since you began testing coverage
22515in the current Emacs session.  Thus, to do coverage testing on your
22516program, execute it under various conditions and note whether it behaves
22517correctly; Edebug will tell you when you have tried enough different
22518conditions that each form has returned two different values.
22519
22520   Coverage testing makes execution slower, so it is only done if
22521‘edebug-test-coverage’ is non-‘nil’.  Frequency counting is performed
22522for all executions of an instrumented function, even if the execution
22523mode is Go-nonstop, and regardless of whether coverage testing is
22524enabled.
22525
22526   Use ‘C-x X =’ (‘edebug-display-freq-count’) to display both the
22527coverage information and the frequency counts for a definition.  Just
22528‘=’ (‘edebug-temp-display-freq-count’) displays the same information
22529temporarily, only until you type another key.
22530
22531 -- Command: edebug-display-freq-count
22532     This command displays the frequency count data for each line of the
22533     current definition.
22534
22535     It inserts frequency counts as comment lines after each line of
22536     code.  You can undo all insertions with one ‘undo’ command.  The
22537     counts appear under the ‘(’ before an expression or the ‘)’ after
22538     an expression, or on the last character of a variable.  To simplify
22539     the display, a count is not shown if it is equal to the count of an
22540     earlier expression on the same line.
22541
22542     The character ‘=’ following the count for an expression says that
22543     the expression has returned the same value each time it was
22544     evaluated.  In other words, it is not yet covered for coverage
22545     testing purposes.
22546
22547     To clear the frequency count and coverage data for a definition,
22548     simply reinstrument it with ‘eval-defun’.
22549
22550   For example, after evaluating ‘(fac 5)’ with a source breakpoint, and
22551setting ‘edebug-test-coverage’ to ‘t’, when the breakpoint is reached,
22552the frequency data looks like this:
22553
22554     (defun fac (n)
22555       (if (= n 0) (edebug))
22556     ;#6           1      = =5
22557       (if (< 0 n)
22558     ;#5         =
22559           (* n (fac (1- n)))
22560     ;#    5               0
22561         1))
22562     ;#   0
22563
22564   The comment lines show that ‘fac’ was called 6 times.  The first ‘if’
22565statement returned 5 times with the same result each time; the same is
22566true of the condition on the second ‘if’.  The recursive call of ‘fac’
22567did not return at all.
22568
22569
22570File: elisp.info,  Node: The Outside Context,  Next: Edebug and Macros,  Prev: Coverage Testing,  Up: Edebug
22571
2257218.2.14 The Outside Context
22573---------------------------
22574
22575Edebug tries to be transparent to the program you are debugging, but it
22576does not succeed completely.  Edebug also tries to be transparent when
22577you evaluate expressions with ‘e’ or with the evaluation list buffer, by
22578temporarily restoring the outside context.  This section explains
22579precisely what context Edebug restores, and how Edebug fails to be
22580completely transparent.
22581
22582* Menu:
22583
22584* Checking Whether to Stop::    When Edebug decides what to do.
22585* Edebug Display Update::       When Edebug updates the display.
22586* Edebug Recursive Edit::       When Edebug stops execution.
22587
22588
22589File: elisp.info,  Node: Checking Whether to Stop,  Next: Edebug Display Update,  Up: The Outside Context
22590
2259118.2.14.1 Checking Whether to Stop
22592..................................
22593
22594Whenever Edebug is entered, it needs to save and restore certain data
22595before even deciding whether to make trace information or stop the
22596program.
22597
22598   • ‘max-lisp-eval-depth’ (*note Eval::) and ‘max-specpdl-size’ (*note
22599     Local Variables::) are both increased to reduce Edebug’s impact on
22600     the stack.  You could, however, still run out of stack space when
22601     using Edebug.  You can also enlarge the value of ‘edebug-max-depth’
22602     if Edebug reaches the limit of recursion depth instrumenting code
22603     that contains very large quoted lists.
22604
22605   • The state of keyboard macro execution is saved and restored.  While
22606     Edebug is active, ‘executing-kbd-macro’ is bound to ‘nil’ unless
22607     ‘edebug-continue-kbd-macro’ is non-‘nil’.
22608
22609
22610File: elisp.info,  Node: Edebug Display Update,  Next: Edebug Recursive Edit,  Prev: Checking Whether to Stop,  Up: The Outside Context
22611
2261218.2.14.2 Edebug Display Update
22613...............................
22614
22615When Edebug needs to display something (e.g., in trace mode), it saves
22616the current window configuration from outside Edebug (*note Window
22617Configurations::).  When you exit Edebug, it restores the previous
22618window configuration.
22619
22620   Emacs redisplays only when it pauses.  Usually, when you continue
22621execution, the program re-enters Edebug at a breakpoint or after
22622stepping, without pausing or reading input in between.  In such cases,
22623Emacs never gets a chance to redisplay the outside configuration.
22624Consequently, what you see is the same window configuration as the last
22625time Edebug was active, with no interruption.
22626
22627   Entry to Edebug for displaying something also saves and restores the
22628following data (though some of them are deliberately not restored if an
22629error or quit signal occurs).
22630
22631   • Which buffer is current, and the positions of point and the mark in
22632     the current buffer, are saved and restored.
22633
22634   • The outside window configuration is saved and restored if
22635     ‘edebug-save-windows’ is non-‘nil’ (*note Edebug Options::).
22636
22637     The window configuration is not restored on error or quit, but the
22638     outside selected window _is_ reselected even on error or quit in
22639     case a ‘save-excursion’ is active.  If the value of
22640     ‘edebug-save-windows’ is a list, only the listed windows are saved
22641     and restored.
22642
22643     The window start and horizontal scrolling of the source code buffer
22644     are not restored, however, so that the display remains coherent
22645     within Edebug.
22646
22647   • The value of point in each displayed buffer is saved and restored
22648     if ‘edebug-save-displayed-buffer-points’ is non-‘nil’.
22649
22650   • The variables ‘overlay-arrow-position’ and ‘overlay-arrow-string’
22651     are saved and restored, so you can safely invoke Edebug from the
22652     recursive edit elsewhere in the same buffer.
22653
22654   • ‘cursor-in-echo-area’ is locally bound to ‘nil’ so that the cursor
22655     shows up in the window.
22656
22657
22658File: elisp.info,  Node: Edebug Recursive Edit,  Prev: Edebug Display Update,  Up: The Outside Context
22659
2266018.2.14.3 Edebug Recursive Edit
22661...............................
22662
22663When Edebug is entered and actually reads commands from the user, it
22664saves (and later restores) these additional data:
22665
22666   • The current match data.  *Note Match Data::.
22667
22668   • The variables ‘last-command’, ‘this-command’, ‘last-command-event’,
22669     ‘last-input-event’, ‘last-event-frame’, ‘last-nonmenu-event’, and
22670     ‘track-mouse’.  Commands in Edebug do not affect these variables
22671     outside of Edebug.
22672
22673     Executing commands within Edebug can change the key sequence that
22674     would be returned by ‘this-command-keys’, and there is no way to
22675     reset the key sequence from Lisp.
22676
22677     Edebug cannot save and restore the value of
22678     ‘unread-command-events’.  Entering Edebug while this variable has a
22679     nontrivial value can interfere with execution of the program you
22680     are debugging.
22681
22682   • Complex commands executed while in Edebug are added to the variable
22683     ‘command-history’.  In rare cases this can alter execution.
22684
22685   • Within Edebug, the recursion depth appears one deeper than the
22686     recursion depth outside Edebug.  This is not true of the
22687     automatically updated evaluation list window.
22688
22689   • ‘standard-output’ and ‘standard-input’ are bound to ‘nil’ by the
22690     ‘recursive-edit’, but Edebug temporarily restores them during
22691     evaluations.
22692
22693   • The state of keyboard macro definition is saved and restored.
22694     While Edebug is active, ‘defining-kbd-macro’ is bound to
22695     ‘edebug-continue-kbd-macro’.
22696
22697
22698File: elisp.info,  Node: Edebug and Macros,  Next: Edebug Options,  Prev: The Outside Context,  Up: Edebug
22699
2270018.2.15 Edebug and Macros
22701-------------------------
22702
22703To make Edebug properly instrument expressions that call macros, some
22704extra care is needed.  This subsection explains the details.
22705
22706* Menu:
22707
22708* Instrumenting Macro Calls::   The basic problem.
22709* Specification List::          How to specify complex patterns of evaluation.
22710* Backtracking::                What Edebug does when matching fails.
22711* Specification Examples::      To help understand specifications.
22712
22713
22714File: elisp.info,  Node: Instrumenting Macro Calls,  Next: Specification List,  Up: Edebug and Macros
22715
2271618.2.15.1 Instrumenting Macro Calls
22717...................................
22718
22719When Edebug instruments an expression that calls a Lisp macro, it needs
22720additional information about the macro to do the job properly.  This is
22721because there is no a-priori way to tell which subexpressions of the
22722macro call are forms to be evaluated.  (Evaluation may occur explicitly
22723in the macro body, or when the resulting expansion is evaluated, or any
22724time later.)
22725
22726   Therefore, you must define an Edebug specification for each macro
22727that Edebug will encounter, to explain the format of calls to that
22728macro.  To do this, add a ‘debug’ declaration to the macro definition.
22729Here is a simple example that shows the specification for the ‘for’
22730example macro (*note Argument Evaluation::).
22731
22732     (defmacro for (var from init to final do &rest body)
22733       "Execute a simple \"for\" loop.
22734     For example, (for i from 1 to 10 do (print i))."
22735       (declare (debug (symbolp "from" form "to" form "do" &rest form)))
22736       ...)
22737
22738   The Edebug specification says which parts of a call to the macro are
22739forms to be evaluated.  For simple macros, the specification often looks
22740very similar to the formal argument list of the macro definition, but
22741specifications are much more general than macro arguments.  *Note
22742Defining Macros::, for more explanation of the ‘declare’ form.
22743
22744   Take care to ensure that the specifications are known to Edebug when
22745you instrument code.  If you are instrumenting a function which uses a
22746macro defined in another file, you may first need to either evaluate the
22747‘require’ forms in the file containing your function, or explicitly load
22748the file containing the macro.  If the definition of a macro is wrapped
22749by ‘eval-when-compile’, you may need to evaluate it.
22750
22751   You can also define an edebug specification for a macro separately
22752from the macro definition with ‘def-edebug-spec’.  Adding ‘debug’
22753declarations is preferred, and more convenient, for macro definitions in
22754Lisp, but ‘def-edebug-spec’ makes it possible to define Edebug
22755specifications for special forms implemented in C.
22756
22757 -- Macro: def-edebug-spec macro specification
22758     Specify which expressions of a call to macro MACRO are forms to be
22759     evaluated.  SPECIFICATION should be the edebug specification.
22760     Neither argument is evaluated.
22761
22762     The MACRO argument can actually be any symbol, not just a macro
22763     name.
22764
22765   Here is a table of the possibilities for SPECIFICATION and how each
22766directs processing of arguments.
22767
22768‘t’
22769     All arguments are instrumented for evaluation.
22770
22771‘0’
22772     None of the arguments is instrumented.
22773
22774a symbol
22775     The symbol must have an Edebug specification, which is used
22776     instead.  This indirection is repeated until another kind of
22777     specification is found.  This allows you to inherit the
22778     specification from another macro.
22779
22780a list
22781     The elements of the list describe the types of the arguments of a
22782     calling form.  The possible elements of a specification list are
22783     described in the following sections.
22784
22785   If a macro has no Edebug specification, neither through a ‘debug’
22786declaration nor through a ‘def-edebug-spec’ call, the variable
22787‘edebug-eval-macro-args’ comes into play.
22788
22789 -- User Option: edebug-eval-macro-args
22790     This controls the way Edebug treats macro arguments with no
22791     explicit Edebug specification.  If it is ‘nil’ (the default), none
22792     of the arguments is instrumented for evaluation.  Otherwise, all
22793     arguments are instrumented.
22794
22795
22796File: elisp.info,  Node: Specification List,  Next: Backtracking,  Prev: Instrumenting Macro Calls,  Up: Edebug and Macros
22797
2279818.2.15.2 Specification List
22799............................
22800
22801A “specification list” is required for an Edebug specification if some
22802arguments of a macro call are evaluated while others are not.  Some
22803elements in a specification list match one or more arguments, but others
22804modify the processing of all following elements.  The latter, called
22805“specification keywords”, are symbols beginning with ‘&’ (such as
22806‘&optional’).
22807
22808   A specification list may contain sublists, which match arguments that
22809are themselves lists, or it may contain vectors used for grouping.
22810Sublists and groups thus subdivide the specification list into a
22811hierarchy of levels.  Specification keywords apply only to the remainder
22812of the sublist or group they are contained in.
22813
22814   When a specification list involves alternatives or repetition,
22815matching it against an actual macro call may require backtracking.  For
22816more details, *note Backtracking::.
22817
22818   Edebug specifications provide the power of regular expression
22819matching, plus some context-free grammar constructs: the matching of
22820sublists with balanced parentheses, recursive processing of forms, and
22821recursion via indirect specifications.
22822
22823   Here’s a table of the possible elements of a specification list, with
22824their meanings (see *note Specification Examples::, for the referenced
22825examples):
22826
22827‘sexp’
22828     A single unevaluated Lisp object, which is not instrumented.
22829
22830‘form’
22831     A single evaluated expression, which is instrumented.  If your
22832     macro wraps the expression with ‘lambda’ before it is evaluated,
22833     use ‘def-form’ instead.  See ‘def-form’ below.
22834
22835‘place’
22836     A generalized variable.  *Note Generalized Variables::.
22837
22838‘body’
22839     Short for ‘&rest form’.  See ‘&rest’ below.  If your macro wraps
22840     its body of code with ‘lambda’ before it is evaluated, use
22841     ‘def-body’ instead.  See ‘def-body’ below.
22842
22843‘function-form’
22844     A function form: either a quoted function symbol, a quoted lambda
22845     expression, or a form (that should evaluate to a function symbol or
22846     lambda expression).  This is useful when an argument that’s a
22847     lambda expression might be quoted with ‘quote’ rather than
22848     ‘function’, since it instruments the body of the lambda expression
22849     either way.
22850
22851‘lambda-expr’
22852     A lambda expression with no quoting.
22853
22854‘&optional’
22855     All following elements in the specification list are optional; as
22856     soon as one does not match, Edebug stops matching at this level.
22857
22858     To make just a few elements optional, followed by non-optional
22859     elements, use ‘[&optional SPECS...]’.  To specify that several
22860     elements must all match or none, use ‘&optional [SPECS...]’.  See
22861     the ‘defun’ example.
22862
22863‘&rest’
22864     All following elements in the specification list are repeated zero
22865     or more times.  In the last repetition, however, it is not a
22866     problem if the expression runs out before matching all of the
22867     elements of the specification list.
22868
22869     To repeat only a few elements, use ‘[&rest SPECS...]’.  To specify
22870     several elements that must all match on every repetition, use
22871     ‘&rest [SPECS...]’.
22872
22873‘&or’
22874     Each of the following elements in the specification list is an
22875     alternative.  One of the alternatives must match, or the ‘&or’
22876     specification fails.
22877
22878     Each list element following ‘&or’ is a single alternative.  To
22879     group two or more list elements as a single alternative, enclose
22880     them in ‘[...]’.
22881
22882‘&not’
22883     Each of the following elements is matched as alternatives as if by
22884     using ‘&or’, but if any of them match, the specification fails.  If
22885     none of them match, nothing is matched, but the ‘&not’
22886     specification succeeds.
22887
22888‘&define’
22889     Indicates that the specification is for a defining form.  Edebug’s
22890     definition of a defining form is a form containing one or more code
22891     forms which are saved and executed later, after the execution of
22892     the defining form.
22893
22894     The defining form itself is not instrumented (that is, Edebug does
22895     not stop before and after the defining form), but forms inside it
22896     typically will be instrumented.  The ‘&define’ keyword should be
22897     the first element in a list specification.
22898
22899‘nil’
22900     This is successful when there are no more arguments to match at the
22901     current argument list level; otherwise it fails.  See sublist
22902     specifications and the backquote example.
22903
22904‘gate’
22905     No argument is matched but backtracking through the gate is
22906     disabled while matching the remainder of the specifications at this
22907     level.  This is primarily used to generate more specific syntax
22908     error messages.  See *note Backtracking::, for more details.  Also
22909     see the ‘let’ example.
22910
22911‘OTHER-SYMBOL’
22912     Any other symbol in a specification list may be a predicate or an
22913     indirect specification.
22914
22915     If the symbol has an Edebug specification, this “indirect
22916     specification” should be either a list specification that is used
22917     in place of the symbol, or a function that is called to process the
22918     arguments.  The specification may be defined with ‘def-edebug-spec’
22919     just as for macros.  See the ‘defun’ example.
22920
22921     Otherwise, the symbol should be a predicate.  The predicate is
22922     called with the argument, and if the predicate returns ‘nil’, the
22923     specification fails and the argument is not instrumented.
22924
22925     Some suitable predicates include ‘symbolp’, ‘integerp’, ‘stringp’,
22926     ‘vectorp’, and ‘atom’.
22927
22928‘[ELEMENTS...]’
22929     A vector of elements groups the elements into a single “group
22930     specification”.  Its meaning has nothing to do with vectors.
22931
22932‘"STRING"’
22933     The argument should be a symbol named STRING.  This specification
22934     is equivalent to the quoted symbol, ‘'SYMBOL’, where the name of
22935     SYMBOL is the STRING, but the string form is preferred.
22936
22937‘(vector ELEMENTS...)’
22938     The argument should be a vector whose elements must match the
22939     ELEMENTS in the specification.  See the backquote example.
22940
22941‘(ELEMENTS...)’
22942     Any other list is a “sublist specification” and the argument must
22943     be a list whose elements match the specification ELEMENTS.
22944
22945     A sublist specification may be a dotted list and the corresponding
22946     list argument may then be a dotted list.  Alternatively, the last
22947     CDR of a dotted list specification may be another sublist
22948     specification (via a grouping or an indirect specification, e.g.,
22949     ‘(spec . [(more specs...)])’) whose elements match the non-dotted
22950     list arguments.  This is useful in recursive specifications such as
22951     in the backquote example.  Also see the description of a ‘nil’
22952     specification above for terminating such recursion.
22953
22954     Note that a sublist specification written as ‘(specs . nil)’ is
22955     equivalent to ‘(specs)’, and ‘(specs . (sublist-elements...))’ is
22956     equivalent to ‘(specs sublist-elements...)’.
22957
22958   Here is a list of additional specifications that may appear only
22959after ‘&define’.  See the ‘defun’ example.
22960
22961‘name’
22962     The argument, a symbol, is the name of the defining form.
22963
22964     A defining form is not required to have a name field; and it may
22965     have multiple name fields.
22966
22967‘:name’
22968     This construct does not actually match an argument.  The element
22969     following ‘:name’ should be a symbol; it is used as an additional
22970     name component for the definition.  You can use this to add a
22971     unique, static component to the name of the definition.  It may be
22972     used more than once.
22973
22974‘arg’
22975     The argument, a symbol, is the name of an argument of the defining
22976     form.  However, lambda-list keywords (symbols starting with ‘&’)
22977     are not allowed.
22978
22979‘lambda-list’
22980     This matches a lambda list—the argument list of a lambda
22981     expression.
22982
22983‘def-body’
22984     The argument is the body of code in a definition.  This is like
22985     ‘body’, described above, but a definition body must be instrumented
22986     with a different Edebug call that looks up information associated
22987     with the definition.  Use ‘def-body’ for the highest level list of
22988     forms within the definition.
22989
22990‘def-form’
22991     The argument is a single, highest-level form in a definition.  This
22992     is like ‘def-body’, except it is used to match a single form rather
22993     than a list of forms.  As a special case, ‘def-form’ also means
22994     that tracing information is not output when the form is executed.
22995     See the ‘interactive’ example.
22996
22997
22998File: elisp.info,  Node: Backtracking,  Next: Specification Examples,  Prev: Specification List,  Up: Edebug and Macros
22999
2300018.2.15.3 Backtracking in Specifications
23001........................................
23002
23003If a specification fails to match at some point, this does not
23004necessarily mean a syntax error will be signaled; instead,
23005“backtracking” will take place until all alternatives have been
23006exhausted.  Eventually every element of the argument list must be
23007matched by some element in the specification, and every required element
23008in the specification must match some argument.
23009
23010   When a syntax error is detected, it might not be reported until much
23011later, after higher-level alternatives have been exhausted, and with the
23012point positioned further from the real error.  But if backtracking is
23013disabled when an error occurs, it can be reported immediately.  Note
23014that backtracking is also reenabled automatically in several situations;
23015when a new alternative is established by ‘&optional’, ‘&rest’, or ‘&or’,
23016or at the start of processing a sublist, group, or indirect
23017specification.  The effect of enabling or disabling backtracking is
23018limited to the remainder of the level currently being processed and
23019lower levels.
23020
23021   Backtracking is disabled while matching any of the form
23022specifications (that is, ‘form’, ‘body’, ‘def-form’, and ‘def-body’).
23023These specifications will match any form so any error must be in the
23024form itself rather than at a higher level.
23025
23026   Backtracking is also disabled after successfully matching a quoted
23027symbol or string specification, since this usually indicates a
23028recognized construct.  But if you have a set of alternative constructs
23029that all begin with the same symbol, you can usually work around this
23030constraint by factoring the symbol out of the alternatives, e.g.,
23031‘["foo" &or [first case] [second case] ...]’.
23032
23033   Most needs are satisfied by these two ways that backtracking is
23034automatically disabled, but occasionally it is useful to explicitly
23035disable backtracking by using the ‘gate’ specification.  This is useful
23036when you know that no higher alternatives could apply.  See the example
23037of the ‘let’ specification.
23038
23039
23040File: elisp.info,  Node: Specification Examples,  Prev: Backtracking,  Up: Edebug and Macros
23041
2304218.2.15.4 Specification Examples
23043................................
23044
23045It may be easier to understand Edebug specifications by studying the
23046examples provided here.
23047
23048   A ‘let’ special form has a sequence of bindings and a body.  Each of
23049the bindings is either a symbol or a sublist with a symbol and optional
23050expression.  In the specification below, notice the ‘gate’ inside of the
23051sublist to prevent backtracking once a sublist is found.
23052
23053     (def-edebug-spec let
23054       ((&rest
23055         &or symbolp (gate symbolp &optional form))
23056        body))
23057
23058   Edebug uses the following specifications for ‘defun’ and the
23059associated argument list and ‘interactive’ specifications.  It is
23060necessary to handle interactive forms specially since an expression
23061argument is actually evaluated outside of the function body.  (The
23062specification for ‘defmacro’ is very similar to that for ‘defun’, but
23063allows for the ‘declare’ statement.)
23064
23065     (def-edebug-spec defun
23066       (&define name lambda-list
23067                [&optional stringp]   ; Match the doc string, if present.
23068                [&optional ("interactive" interactive)]
23069                def-body))
23070
23071     (def-edebug-spec lambda-list
23072       (([&rest arg]
23073         [&optional ["&optional" arg &rest arg]]
23074         &optional ["&rest" arg]
23075         )))
23076
23077     (def-edebug-spec interactive
23078       (&optional &or stringp def-form))    ; Notice: ‘def-form’
23079
23080   The specification for backquote below illustrates how to match dotted
23081lists and use ‘nil’ to terminate recursion.  It also illustrates how
23082components of a vector may be matched.  (The actual specification
23083defined by Edebug is a little different, and does not support dotted
23084lists because doing so causes very deep recursion that could fail.)
23085
23086     (def-edebug-spec \` (backquote-form))   ; Alias just for clarity.
23087
23088     (def-edebug-spec backquote-form
23089       (&or ([&or "," ",@"] &or ("quote" backquote-form) form)
23090            (backquote-form . [&or nil backquote-form])
23091            (vector &rest backquote-form)
23092            sexp))
23093
23094
23095File: elisp.info,  Node: Edebug Options,  Prev: Edebug and Macros,  Up: Edebug
23096
2309718.2.16 Edebug Options
23098----------------------
23099
23100These options affect the behavior of Edebug:
23101
23102 -- User Option: edebug-setup-hook
23103     Functions to call before Edebug is used.  Each time it is set to a
23104     new value, Edebug will call those functions once and then reset
23105     ‘edebug-setup-hook’ to ‘nil’.  You could use this to load up Edebug
23106     specifications associated with a package you are using, but only
23107     when you also use Edebug.  *Note Instrumenting::.
23108
23109 -- User Option: edebug-all-defs
23110     If this is non-‘nil’, normal evaluation of defining forms such as
23111     ‘defun’ and ‘defmacro’ instruments them for Edebug.  This applies
23112     to ‘eval-defun’, ‘eval-region’, ‘eval-buffer’, and
23113     ‘eval-current-buffer’.
23114
23115     Use the command ‘M-x edebug-all-defs’ to toggle the value of this
23116     option.  *Note Instrumenting::.
23117
23118 -- User Option: edebug-all-forms
23119     If this is non-‘nil’, the commands ‘eval-defun’, ‘eval-region’,
23120     ‘eval-buffer’, and ‘eval-current-buffer’ instrument all forms, even
23121     those that don’t define anything.  This doesn’t apply to loading or
23122     evaluations in the minibuffer.
23123
23124     Use the command ‘M-x edebug-all-forms’ to toggle the value of this
23125     option.  *Note Instrumenting::.
23126
23127 -- User Option: edebug-eval-macro-args
23128     When this is non-‘nil’, all macro arguments will be instrumented in
23129     the generated code.  For any macro, an ‘edebug-form-spec’ overrides
23130     this option.  So to specify exceptions for macros that have some
23131     arguments evaluated and some not, use ‘def-edebug-spec’ to specify
23132     an ‘edebug-form-spec’.
23133
23134 -- User Option: edebug-save-windows
23135     If this is non-‘nil’, Edebug saves and restores the window
23136     configuration.  That takes some time, so if your program does not
23137     care what happens to the window configurations, it is better to set
23138     this variable to ‘nil’.
23139
23140     If the value is a list, only the listed windows are saved and
23141     restored.
23142
23143     You can use the ‘W’ command in Edebug to change this variable
23144     interactively.  *Note Edebug Display Update::.
23145
23146 -- User Option: edebug-save-displayed-buffer-points
23147     If this is non-‘nil’, Edebug saves and restores point in all
23148     displayed buffers.
23149
23150     Saving and restoring point in other buffers is necessary if you are
23151     debugging code that changes the point of a buffer that is displayed
23152     in a non-selected window.  If Edebug or the user then selects the
23153     window, point in that buffer will move to the window’s value of
23154     point.
23155
23156     Saving and restoring point in all buffers is expensive, since it
23157     requires selecting each window twice, so enable this only if you
23158     need it.  *Note Edebug Display Update::.
23159
23160 -- User Option: edebug-initial-mode
23161     If this variable is non-‘nil’, it specifies the initial execution
23162     mode for Edebug when it is first activated.  Possible values are
23163     ‘step’, ‘next’, ‘go’, ‘Go-nonstop’, ‘trace’, ‘Trace-fast’,
23164     ‘continue’, and ‘Continue-fast’.
23165
23166     The default value is ‘step’.  This variable can be set
23167     interactively with ‘C-x C-a C-m’ (‘edebug-set-initial-mode’).
23168     *Note Edebug Execution Modes::.
23169
23170 -- User Option: edebug-trace
23171     If this is non-‘nil’, trace each function entry and exit.  Tracing
23172     output is displayed in a buffer named ‘*edebug-trace*’, one
23173     function entry or exit per line, indented by the recursion level.
23174
23175     Also see ‘edebug-tracing’, in *note Trace Buffer::.
23176
23177 -- User Option: edebug-test-coverage
23178     If non-‘nil’, Edebug tests coverage of all expressions debugged.
23179     *Note Coverage Testing::.
23180
23181 -- User Option: edebug-continue-kbd-macro
23182     If non-‘nil’, continue defining or executing any keyboard macro
23183     that is executing outside of Edebug.  Use this with caution since
23184     it is not debugged.  *Note Edebug Execution Modes::.
23185
23186 -- User Option: edebug-print-length
23187     If non-‘nil’, the default value of ‘print-length’ for printing
23188     results in Edebug.  *Note Output Variables::.
23189
23190 -- User Option: edebug-print-level
23191     If non-‘nil’, the default value of ‘print-level’ for printing
23192     results in Edebug.  *Note Output Variables::.
23193
23194 -- User Option: edebug-print-circle
23195     If non-‘nil’, the default value of ‘print-circle’ for printing
23196     results in Edebug.  *Note Output Variables::.
23197
23198 -- User Option: edebug-unwrap-results
23199     If non-‘nil’, Edebug tries to remove any of its own instrumentation
23200     when showing the results of expressions.  This is relevant when
23201     debugging macros where the results of expressions are themselves
23202     instrumented expressions.  As a very artificial example, suppose
23203     that the example function ‘fac’ has been instrumented, and consider
23204     a macro of the form:
23205
23206          (defmacro test () "Edebug example."
23207            (if (symbol-function 'fac)
23208                ...))
23209
23210     If you instrument the ‘test’ macro and step through it, then by
23211     default the result of the ‘symbol-function’ call has numerous
23212     ‘edebug-after’ and ‘edebug-before’ forms, which can make it
23213     difficult to see the actual result.  If ‘edebug-unwrap-results’ is
23214     non-‘nil’, Edebug tries to remove these forms from the result.
23215
23216 -- User Option: edebug-on-error
23217     Edebug binds ‘debug-on-error’ to this value, if ‘debug-on-error’
23218     was previously ‘nil’.  *Note Trapping Errors::.
23219
23220 -- User Option: edebug-on-quit
23221     Edebug binds ‘debug-on-quit’ to this value, if ‘debug-on-quit’ was
23222     previously ‘nil’.  *Note Trapping Errors::.
23223
23224   If you change the values of ‘edebug-on-error’ or ‘edebug-on-quit’
23225while Edebug is active, their values won’t be used until the _next_ time
23226Edebug is invoked via a new command.
23227
23228 -- User Option: edebug-global-break-condition
23229     If non-‘nil’, an expression to test for at every stop point.  If
23230     the result is non-‘nil’, then break.  Errors are ignored.  *Note
23231     Global Break Condition::.
23232
23233 -- User Option: edebug-sit-for-seconds
23234     Number of seconds to pause when a breakpoint is reached and the
23235     execution mode is trace or continue.  *Note Edebug Execution
23236     Modes::.
23237
23238 -- User Option: edebug-sit-on-break
23239     Whether or not to pause for ‘edebug-sit-for-seconds’ on reaching a
23240     breakpoint.  Set to ‘nil’ to prevent the pause, non-‘nil’ to allow
23241     it.
23242
23243 -- User Option: edebug-behavior-alist
23244     By default, this alist contains one entry with the key ‘edebug’ and
23245     a list of three functions, which are the default implementations of
23246     the functions inserted in instrumented code: ‘edebug-enter’,
23247     ‘edebug-before’ and ‘edebug-after’.  To change Edebug’s behavior
23248     globally, modify the default entry.
23249
23250     Edebug’s behavior may also be changed on a per-definition basis by
23251     adding an entry to this alist, with a key of your choice and three
23252     functions.  Then set the ‘edebug-behavior’ symbol property of an
23253     instrumented definition to the key of the new entry, and Edebug
23254     will call the new functions in place of its own for that
23255     definition.
23256
23257 -- User Option: edebug-new-definition-function
23258     A function run by Edebug after it wraps the body of a definition or
23259     closure.  After Edebug has initialized its own data, this function
23260     is called with one argument, the symbol associated with the
23261     definition, which may be the actual symbol defined or one generated
23262     by Edebug.  This function may be used to set the ‘edebug-behavior’
23263     symbol property of each definition instrumented by Edebug.
23264
23265 -- User Option: edebug-after-instrumentation-function
23266     To inspect or modify Edebug’s instrumentation before it is used,
23267     set this variable to a function which takes one argument, an
23268     instrumented top-level form, and returns either the same or a
23269     replacement form, which Edebug will then use as the final result of
23270     instrumentation.
23271
23272
23273File: elisp.info,  Node: Syntax Errors,  Next: Test Coverage,  Prev: Edebug,  Up: Debugging
23274
2327518.3 Debugging Invalid Lisp Syntax
23276==================================
23277
23278The Lisp reader reports invalid syntax, but cannot say where the real
23279problem is.  For example, the error ‘End of file during parsing’ in
23280evaluating an expression indicates an excess of open parentheses (or
23281square brackets).  The reader detects this imbalance at the end of the
23282file, but it cannot figure out where the close parenthesis should have
23283been.  Likewise, ‘Invalid read syntax: ")"’ indicates an excess close
23284parenthesis or missing open parenthesis, but does not say where the
23285missing parenthesis belongs.  How, then, to find what to change?
23286
23287   If the problem is not simply an imbalance of parentheses, a useful
23288technique is to try ‘C-M-e’ (‘end-of-defun’, *note (emacs)Moving by
23289Defuns::) at the beginning of each defun, and see if it goes to the
23290place where that defun appears to end.  If it does not, there is a
23291problem in that defun.
23292
23293   However, unmatched parentheses are the most common syntax errors in
23294Lisp, and we can give further advice for those cases.  (In addition,
23295just moving point through the code with Show Paren mode enabled might
23296find the mismatch.)
23297
23298* Menu:
23299
23300* Excess Open::     How to find a spurious open paren or missing close.
23301* Excess Close::    How to find a spurious close paren or missing open.
23302
23303
23304File: elisp.info,  Node: Excess Open,  Next: Excess Close,  Up: Syntax Errors
23305
2330618.3.1 Excess Open Parentheses
23307------------------------------
23308
23309The first step is to find the defun that is unbalanced.  If there is an
23310excess open parenthesis, the way to do this is to go to the end of the
23311file and type ‘C-u C-M-u’ (‘backward-up-list’, *note (emacs)Moving by
23312Parens::).  This will move you to the beginning of the first defun that
23313is unbalanced.
23314
23315   The next step is to determine precisely what is wrong.  There is no
23316way to be sure of this except by studying the program, but often the
23317existing indentation is a clue to where the parentheses should have
23318been.  The easiest way to use this clue is to reindent with ‘C-M-q’
23319(‘indent-pp-sexp’, *note (emacs)Multi-line Indent::) and see what moves.
23320*But don’t do this yet!*  Keep reading, first.
23321
23322   Before you do this, make sure the defun has enough close parentheses.
23323Otherwise, ‘C-M-q’ will get an error, or will reindent all the rest of
23324the file until the end.  So move to the end of the defun and insert a
23325close parenthesis there.  Don’t use ‘C-M-e’ (‘end-of-defun’) to move
23326there, since that too will fail to work until the defun is balanced.
23327
23328   Now you can go to the beginning of the defun and type ‘C-M-q’.
23329Usually all the lines from a certain point to the end of the function
23330will shift to the right.  There is probably a missing close parenthesis,
23331or a superfluous open parenthesis, near that point.  (However, don’t
23332assume this is true; study the code to make sure.)  Once you have found
23333the discrepancy, undo the ‘C-M-q’ with ‘C-_’ (‘undo’), since the old
23334indentation is probably appropriate to the intended parentheses.
23335
23336   After you think you have fixed the problem, use ‘C-M-q’ again.  If
23337the old indentation actually fit the intended nesting of parentheses,
23338and you have put back those parentheses, ‘C-M-q’ should not change
23339anything.
23340
23341
23342File: elisp.info,  Node: Excess Close,  Prev: Excess Open,  Up: Syntax Errors
23343
2334418.3.2 Excess Close Parentheses
23345-------------------------------
23346
23347To deal with an excess close parenthesis, first go to the beginning of
23348the file, then type ‘C-u -1 C-M-u’ (‘backward-up-list’ with an argument
23349of −1) to find the end of the first unbalanced defun.
23350
23351   Then find the actual matching close parenthesis by typing ‘C-M-f’
23352(‘forward-sexp’, *note (emacs)Expressions::) at the beginning of that
23353defun.  This will leave you somewhere short of the place where the defun
23354ought to end.  It is possible that you will find a spurious close
23355parenthesis in that vicinity.
23356
23357   If you don’t see a problem at that point, the next thing to do is to
23358type ‘C-M-q’ (‘indent-pp-sexp’) at the beginning of the defun.  A range
23359of lines will probably shift left; if so, the missing open parenthesis
23360or spurious close parenthesis is probably near the first of those lines.
23361(However, don’t assume this is true; study the code to make sure.)  Once
23362you have found the discrepancy, undo the ‘C-M-q’ with ‘C-_’ (‘undo’),
23363since the old indentation is probably appropriate to the intended
23364parentheses.
23365
23366   After you think you have fixed the problem, use ‘C-M-q’ again.  If
23367the old indentation actually fits the intended nesting of parentheses,
23368and you have put back those parentheses, ‘C-M-q’ should not change
23369anything.
23370
23371
23372File: elisp.info,  Node: Test Coverage,  Next: Profiling,  Prev: Syntax Errors,  Up: Debugging
23373
2337418.4 Test Coverage
23375==================
23376
23377You can do coverage testing for a file of Lisp code by loading the
23378‘testcover’ library and using the command ‘M-x testcover-start <RET>
23379FILE <RET>’ to instrument the code.  Then test your code by calling it
23380one or more times.  Then use the command ‘M-x testcover-mark-all’ to
23381display colored highlights on the code to show where coverage is
23382insufficient.  The command ‘M-x testcover-next-mark’ will move point
23383forward to the next highlighted spot.
23384
23385   Normally, a red highlight indicates the form was never completely
23386evaluated; a brown highlight means it always evaluated to the same value
23387(meaning there has been little testing of what is done with the result).
23388However, the red highlight is skipped for forms that can’t possibly
23389complete their evaluation, such as ‘error’.  The brown highlight is
23390skipped for forms that are expected to always evaluate to the same
23391value, such as ‘(setq x 14)’.
23392
23393   For difficult cases, you can add do-nothing macros to your code to
23394give advice to the test coverage tool.
23395
23396 -- Macro: 1value form
23397     Evaluate FORM and return its value, but inform coverage testing
23398     that FORM’s value should always be the same.
23399
23400 -- Macro: noreturn form
23401     Evaluate FORM, informing coverage testing that FORM should never
23402     return.  If it ever does return, you get a run-time error.
23403
23404   Edebug also has a coverage testing feature (*note Coverage
23405Testing::).  These features partly duplicate each other, and it would be
23406cleaner to combine them.
23407
23408
23409File: elisp.info,  Node: Profiling,  Prev: Test Coverage,  Up: Debugging
23410
2341118.5 Profiling
23412==============
23413
23414If your program is working correctly, but not fast enough, and you want
23415to make it run more quickly or efficiently, the first thing to do is
23416“profile” your code so that you know where it spends most of the
23417execution time.  If you find that one particular function is responsible
23418for a significant portion of the execution time, you can start looking
23419for ways to optimize that piece.
23420
23421   Emacs has built-in support for this.  To begin profiling, type ‘M-x
23422profiler-start’.  You can choose to profile by processor usage, memory
23423usage, or both.  Then run the code you’d like to speed up.  After that,
23424type ‘M-x profiler-report’ to display a summary buffer for each resource
23425(cpu and memory) that you chose to profile.  The names of the report
23426buffers include the times at which the reports were generated, so you
23427can generate another report later on without erasing previous results.
23428When you have finished profiling, type ‘M-x profiler-stop’ (there is a
23429small overhead associated with profiling, so we don’t recommend leaving
23430it active except when you are actually running the code you want to
23431examine).
23432
23433   The profiler report buffer shows, on each line, a function that was
23434called, followed by how much resources (cpu or memory) it used in
23435absolute and percentage terms since profiling started.  If a given line
23436has a ‘+’ symbol at the left-hand side, you can expand that line by
23437typing ‘<RET>’, in order to see the function(s) called by the
23438higher-level function.  Use a prefix argument (‘C-u <RET>’) to see the
23439whole call tree below a function.  Pressing ‘<RET>’ again will collapse
23440back to the original state.
23441
23442   Press ‘j’ or ‘mouse-2’ to jump to the definition of a function at
23443point.  Press ‘d’ to view a function’s documentation.  You can save a
23444profile to a file using ‘C-x C-w’.  You can compare two profiles using
23445‘=’.
23446
23447   The ‘elp’ library offers an alternative approach, which is useful
23448when you know in advance which Lisp function(s) you want to profile.
23449Using that library, you begin by setting ‘elp-function-list’ to the list
23450of function symbols—those are the functions you want to profile.  Then
23451type ‘M-x elp-instrument-list <RET> nil <RET>’ to arrange for profiling
23452those functions.  After running the code you want to profile, invoke
23453‘M-x elp-results’ to display the current results.  See the file ‘elp.el23454for more detailed instructions.  This approach is limited to profiling
23455functions written in Lisp, it cannot profile Emacs primitives.
23456
23457   You can measure the time it takes to evaluate individual Emacs Lisp
23458forms using the ‘benchmark’ library.  See the macros ‘benchmark-run’,
23459‘benchmark-run-compiled’ and ‘benchmark-progn’ in ‘benchmark.el’.  You
23460can also use the ‘benchmark’ command for timing forms interactively.
23461
23462   To profile Emacs at the level of its C code, you can build it using
23463the ‘--enable-profiling’ option of ‘configure’.  When Emacs exits, it
23464generates a file ‘gmon.out’ that you can examine using the ‘gprof’
23465utility.  This feature is mainly useful for debugging Emacs.  It
23466actually stops the Lisp-level ‘M-x profiler-...’ commands described
23467above from working.
23468
23469
23470File: elisp.info,  Node: Read and Print,  Next: Minibuffers,  Prev: Debugging,  Up: Top
23471
2347219 Reading and Printing Lisp Objects
23473************************************
23474
23475“Printing” and “reading” are the operations of converting Lisp objects
23476to textual form and vice versa.  They use the printed representations
23477and read syntax described in *note Lisp Data Types::.
23478
23479   This chapter describes the Lisp functions for reading and printing.
23480It also describes “streams”, which specify where to get the text (if
23481reading) or where to put it (if printing).
23482
23483* Menu:
23484
23485* Streams Intro::     Overview of streams, reading and printing.
23486* Input Streams::     Various data types that can be used as input streams.
23487* Input Functions::   Functions to read Lisp objects from text.
23488* Output Streams::    Various data types that can be used as output streams.
23489* Output Functions::  Functions to print Lisp objects as text.
23490* Output Variables::  Variables that control what the printing functions do.
23491
23492
23493File: elisp.info,  Node: Streams Intro,  Next: Input Streams,  Up: Read and Print
23494
2349519.1 Introduction to Reading and Printing
23496=========================================
23497
23498“Reading” a Lisp object means parsing a Lisp expression in textual form
23499and producing a corresponding Lisp object.  This is how Lisp programs
23500get into Lisp from files of Lisp code.  We call the text the “read
23501syntax” of the object.  For example, the text ‘(a . 5)’ is the read
23502syntax for a cons cell whose CAR is ‘a’ and whose CDR is the number 5.
23503
23504   “Printing” a Lisp object means producing text that represents that
23505object—converting the object to its “printed representation” (*note
23506Printed Representation::).  Printing the cons cell described above
23507produces the text ‘(a . 5)’.
23508
23509   Reading and printing are more or less inverse operations: printing
23510the object that results from reading a given piece of text often
23511produces the same text, and reading the text that results from printing
23512an object usually produces a similar-looking object.  For example,
23513printing the symbol ‘foo’ produces the text ‘foo’, and reading that text
23514returns the symbol ‘foo’.  Printing a list whose elements are ‘a’ and
23515‘b’ produces the text ‘(a b)’, and reading that text produces a list
23516(but not the same list) with elements ‘a’ and ‘b’.
23517
23518   However, these two operations are not precisely inverse to each
23519other.  There are three kinds of exceptions:
23520
23521   • Printing can produce text that cannot be read.  For example,
23522     buffers, windows, frames, subprocesses and markers print as text
23523     that starts with ‘#’; if you try to read this text, you get an
23524     error.  There is no way to read those data types.
23525
23526   • One object can have multiple textual representations.  For example,
23527     ‘1’ and ‘01’ represent the same integer, and ‘(a b)’ and ‘(a .
23528     (b))’ represent the same list.  Reading will accept any of the
23529     alternatives, but printing must choose one of them.
23530
23531   • Comments can appear at certain points in the middle of an object’s
23532     read sequence without affecting the result of reading it.
23533
23534
23535File: elisp.info,  Node: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Read and Print
23536
2353719.2 Input Streams
23538==================
23539
23540Most of the Lisp functions for reading text take an “input stream” as an
23541argument.  The input stream specifies where or how to get the characters
23542of the text to be read.  Here are the possible types of input stream:
23543
23544BUFFER
23545     The input characters are read from BUFFER, starting with the
23546     character directly after point.  Point advances as characters are
23547     read.
23548
23549MARKER
23550     The input characters are read from the buffer that MARKER is in,
23551     starting with the character directly after the marker.  The marker
23552     position advances as characters are read.  The value of point in
23553     the buffer has no effect when the stream is a marker.
23554
23555STRING
23556     The input characters are taken from STRING, starting at the first
23557     character in the string and using as many characters as required.
23558
23559FUNCTION
23560     The input characters are generated by FUNCTION, which must support
23561     two kinds of calls:
23562
23563        • When it is called with no arguments, it should return the next
23564          character.
23565
23566        • When it is called with one argument (always a character),
23567          FUNCTION should save the argument and arrange to return it on
23568          the next call.  This is called “unreading” the character; it
23569          happens when the Lisp reader reads one character too many and
23570          wants to put it back where it came from.  In this case, it
23571          makes no difference what value FUNCTION returns.
23572
23573‘t’
23574     ‘t’ used as a stream means that the input is read from the
23575     minibuffer.  In fact, the minibuffer is invoked once and the text
23576     given by the user is made into a string that is then used as the
23577     input stream.  If Emacs is running in batch mode (*note Batch
23578     Mode::), standard input is used instead of the minibuffer.  For
23579     example,
23580          (message "%s" (read t))
23581     will in batch mode read a Lisp expression from standard input and
23582     print the result to standard output.
23583
23584‘nil’
23585     ‘nil’ supplied as an input stream means to use the value of
23586     ‘standard-input’ instead; that value is the “default input stream”,
23587     and must be a non-‘nil’ input stream.
23588
23589SYMBOL
23590     A symbol as input stream is equivalent to the symbol’s function
23591     definition (if any).
23592
23593   Here is an example of reading from a stream that is a buffer, showing
23594where point is located before and after:
23595
23596     ---------- Buffer: foo ----------
23597     This★ is the contents of foo.
23598     ---------- Buffer: foo ----------
23599
23600     (read (get-buffer "foo"))
23601          ⇒ is
23602     (read (get-buffer "foo"))
23603          ⇒ the
23604
23605     ---------- Buffer: foo ----------
23606     This is the★ contents of foo.
23607     ---------- Buffer: foo ----------
23608
23609Note that the first read skips a space.  Reading skips any amount of
23610whitespace preceding the significant text.
23611
23612   Here is an example of reading from a stream that is a marker,
23613initially positioned at the beginning of the buffer shown.  The value
23614read is the symbol ‘This’.
23615
23616
23617     ---------- Buffer: foo ----------
23618     This is the contents of foo.
23619     ---------- Buffer: foo ----------
23620
23621     (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
23622          ⇒ #<marker at 1 in foo>
23623     (read m)
23624          ⇒ This
23625     m
23626          ⇒ #<marker at 5 in foo>   ;; Before the first space.
23627
23628   Here we read from the contents of a string:
23629
23630     (read "(When in) the course")
23631          ⇒ (When in)
23632
23633   The following example reads from the minibuffer.  The prompt is:
23634‘Lisp expression: ’.  (That is always the prompt used when you read from
23635the stream ‘t’.)  The user’s input is shown following the prompt.
23636
23637     (read t)
23638          ⇒ 23
23639     ---------- Buffer: Minibuffer ----------
23640     Lisp expression: 23 <RET>
23641     ---------- Buffer: Minibuffer ----------
23642
23643   Finally, here is an example of a stream that is a function, named
23644‘useless-stream’.  Before we use the stream, we initialize the variable
23645‘useless-list’ to a list of characters.  Then each call to the function
23646‘useless-stream’ obtains the next character in the list or unreads a
23647character by adding it to the front of the list.
23648
23649     (setq useless-list (append "XY()" nil))
23650          ⇒ (88 89 40 41)
23651
23652     (defun useless-stream (&optional unread)
23653       (if unread
23654           (setq useless-list (cons unread useless-list))
23655         (prog1 (car useless-list)
23656                (setq useless-list (cdr useless-list)))))
23657          ⇒ useless-stream
23658
23659Now we read using the stream thus constructed:
23660
23661     (read 'useless-stream)
23662          ⇒ XY
23663
23664     useless-list
23665          ⇒ (40 41)
23666
23667Note that the open and close parentheses remain in the list.  The Lisp
23668reader encountered the open parenthesis, decided that it ended the
23669input, and unread it.  Another attempt to read from the stream at this
23670point would read ‘()’ and return ‘nil’.
23671
23672
23673File: elisp.info,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Read and Print
23674
2367519.3 Input Functions
23676====================
23677
23678This section describes the Lisp functions and variables that pertain to
23679reading.
23680
23681   In the functions below, STREAM stands for an input stream (see the
23682previous section).  If STREAM is ‘nil’ or omitted, it defaults to the
23683value of ‘standard-input’.
23684
23685   An ‘end-of-file’ error is signaled if reading encounters an
23686unterminated list, vector, or string.
23687
23688 -- Function: read &optional stream
23689     This function reads one textual Lisp expression from STREAM,
23690     returning it as a Lisp object.  This is the basic Lisp input
23691     function.
23692
23693 -- Function: read-from-string string &optional start end
23694     This function reads the first textual Lisp expression from the text
23695     in STRING.  It returns a cons cell whose CAR is that expression,
23696     and whose CDR is an integer giving the position of the next
23697     remaining character in the string (i.e., the first one not read).
23698
23699     If START is supplied, then reading begins at index START in the
23700     string (where the first character is at index 0).  If you specify
23701     END, then reading is forced to stop just before that index, as if
23702     the rest of the string were not there.
23703
23704     For example:
23705
23706          (read-from-string "(setq x 55) (setq y 5)")
23707               ⇒ ((setq x 55) . 11)
23708          (read-from-string "\"A short string\"")
23709               ⇒ ("A short string" . 16)
23710
23711          ;; Read starting at the first character.
23712          (read-from-string "(list 112)" 0)
23713               ⇒ ((list 112) . 10)
23714          ;; Read starting at the second character.
23715          (read-from-string "(list 112)" 1)
23716               ⇒ (list . 5)
23717          ;; Read starting at the seventh character,
23718          ;;   and stopping at the ninth.
23719          (read-from-string "(list 112)" 6 8)
23720               ⇒ (11 . 8)
23721
23722 -- Variable: standard-input
23723     This variable holds the default input stream—the stream that ‘read’
23724     uses when the STREAM argument is ‘nil’.  The default is ‘t’,
23725     meaning use the minibuffer.
23726
23727 -- Variable: read-circle
23728     If non-‘nil’, this variable enables the reading of circular and
23729     shared structures.  *Note Circular Objects::.  Its default value is
23730     ‘t’.
23731
23732   When reading or writing from the standard input/output streams of the
23733Emacs process in batch mode, it is sometimes required to make sure any
23734arbitrary binary data will be read/written verbatim, and/or that no
23735translation of newlines to or from CR-LF pairs is performed.  This issue
23736does not exist on POSIX hosts, only on MS-Windows and MS-DOS.  The
23737following function allows you to control the I/O mode of any standard
23738stream of the Emacs process.
23739
23740 -- Function: set-binary-mode stream mode
23741     Switch STREAM into binary or text I/O mode.  If MODE is non-‘nil’,
23742     switch to binary mode, otherwise switch to text mode.  The value of
23743     STREAM can be one of ‘stdin’, ‘stdout’, or ‘stderr’.  This function
23744     flushes any pending output data of STREAM as a side effect, and
23745     returns the previous value of I/O mode for STREAM.  On POSIX hosts,
23746     it always returns a non-‘nil’ value and does nothing except
23747     flushing pending output.
23748
23749
23750File: elisp.info,  Node: Output Streams,  Next: Output Functions,  Prev: Input Functions,  Up: Read and Print
23751
2375219.4 Output Streams
23753===================
23754
23755An output stream specifies what to do with the characters produced by
23756printing.  Most print functions accept an output stream as an optional
23757argument.  Here are the possible types of output stream:
23758
23759BUFFER
23760     The output characters are inserted into BUFFER at point.  Point
23761     advances as characters are inserted.
23762
23763MARKER
23764     The output characters are inserted into the buffer that MARKER
23765     points into, at the marker position.  The marker position advances
23766     as characters are inserted.  The value of point in the buffer has
23767     no effect on printing when the stream is a marker, and this kind of
23768     printing does not move point (except that if the marker points at
23769     or before the position of point, point advances with the
23770     surrounding text, as usual).
23771
23772FUNCTION
23773     The output characters are passed to FUNCTION, which is responsible
23774     for storing them away.  It is called with a single character as
23775     argument, as many times as there are characters to be output, and
23776     is responsible for storing the characters wherever you want to put
23777     them.
23778
23779‘t’
23780     The output characters are displayed in the echo area.  If Emacs is
23781     running in batch mode (*note Batch Mode::), the output is written
23782     to the standard output descriptor instead.
23783
23784‘nil’
23785     ‘nil’ specified as an output stream means to use the value of the
23786     ‘standard-output’ variable instead; that value is the “default
23787     output stream”, and must not be ‘nil’.
23788
23789SYMBOL
23790     A symbol as output stream is equivalent to the symbol’s function
23791     definition (if any).
23792
23793   Many of the valid output streams are also valid as input streams.
23794The difference between input and output streams is therefore more a
23795matter of how you use a Lisp object, than of different types of object.
23796
23797   Here is an example of a buffer used as an output stream.  Point is
23798initially located as shown immediately before the ‘h’ in ‘the’.  At the
23799end, point is located directly before that same ‘h’.
23800
23801     ---------- Buffer: foo ----------
23802     This is t★he contents of foo.
23803     ---------- Buffer: foo ----------
23804
23805     (print "This is the output" (get-buffer "foo"))
23806          ⇒ "This is the output"
23807
23808     ---------- Buffer: foo ----------
23809     This is t
23810     "This is the output"
23811     ★he contents of foo.
23812     ---------- Buffer: foo ----------
23813
23814   Now we show a use of a marker as an output stream.  Initially, the
23815marker is in buffer ‘foo’, between the ‘t’ and the ‘h’ in the word
23816‘the’.  At the end, the marker has advanced over the inserted text so
23817that it remains positioned before the same ‘h’.  Note that the location
23818of point, shown in the usual fashion, has no effect.
23819
23820     ---------- Buffer: foo ----------
23821     This is the ★output
23822     ---------- Buffer: foo ----------
23823
23824     (setq m (copy-marker 10))
23825          ⇒ #<marker at 10 in foo>
23826
23827     (print "More output for foo." m)
23828          ⇒ "More output for foo."
23829
23830     ---------- Buffer: foo ----------
23831     This is t
23832     "More output for foo."
23833     he ★output
23834     ---------- Buffer: foo ----------
23835
23836     m
23837          ⇒ #<marker at 34 in foo>
23838
23839   The following example shows output to the echo area:
23840
23841     (print "Echo Area output" t)
23842          ⇒ "Echo Area output"
23843     ---------- Echo Area ----------
23844     "Echo Area output"
23845     ---------- Echo Area ----------
23846
23847   Finally, we show the use of a function as an output stream.  The
23848function ‘eat-output’ takes each character that it is given and conses
23849it onto the front of the list ‘last-output’ (*note Building Lists::).
23850At the end, the list contains all the characters output, but in reverse
23851order.
23852
23853     (setq last-output nil)
23854          ⇒ nil
23855
23856     (defun eat-output (c)
23857       (setq last-output (cons c last-output)))
23858          ⇒ eat-output
23859
23860     (print "This is the output" #'eat-output)
23861          ⇒ "This is the output"
23862
23863     last-output
23864          ⇒ (10 34 116 117 112 116 117 111 32 101 104
23865         116 32 115 105 32 115 105 104 84 34 10)
23866
23867Now we can put the output in the proper order by reversing the list:
23868
23869     (concat (nreverse last-output))
23870          ⇒ "
23871     \"This is the output\"
23872     "
23873
23874Calling ‘concat’ converts the list to a string so you can see its
23875contents more clearly.
23876
23877 -- Function: external-debugging-output character
23878     This function can be useful as an output stream when debugging.  It
23879     writes CHARACTER to the standard error stream.
23880
23881     For example
23882          (print "This is the output" #'external-debugging-output)
23883          ⊣ This is the output
23884          ⇒ "This is the output"
23885
23886
23887File: elisp.info,  Node: Output Functions,  Next: Output Variables,  Prev: Output Streams,  Up: Read and Print
23888
2388919.5 Output Functions
23890=====================
23891
23892This section describes the Lisp functions for printing Lisp
23893objects—converting objects into their printed representation.
23894
23895   Some of the Emacs printing functions add quoting characters to the
23896output when necessary so that it can be read properly.  The quoting
23897characters used are ‘"’ and ‘\’; they distinguish strings from symbols,
23898and prevent punctuation characters in strings and symbols from being
23899taken as delimiters when reading.  *Note Printed Representation::, for
23900full details.  You specify quoting or no quoting by the choice of
23901printing function.
23902
23903   If the text is to be read back into Lisp, then you should print with
23904quoting characters to avoid ambiguity.  Likewise, if the purpose is to
23905describe a Lisp object clearly for a Lisp programmer.  However, if the
23906purpose of the output is to look nice for humans, then it is usually
23907better to print without quoting.
23908
23909   Lisp objects can refer to themselves.  Printing a self-referential
23910object in the normal way would require an infinite amount of text, and
23911the attempt could cause infinite recursion.  Emacs detects such
23912recursion and prints ‘#LEVEL’ instead of recursively printing an object
23913already being printed.  For example, here ‘#0’ indicates a recursive
23914reference to the object at level 0 of the current print operation:
23915
23916     (setq foo (list nil))
23917          ⇒ (nil)
23918     (setcar foo foo)
23919          ⇒ (#0)
23920
23921   In the functions below, STREAM stands for an output stream.  (See the
23922previous section for a description of output streams.  Also *Note
23923external-debugging-output::, a useful stream value for debugging.)  If
23924STREAM is ‘nil’ or omitted, it defaults to the value of
23925‘standard-output’.
23926
23927 -- Function: print object &optional stream
23928     The ‘print’ function is a convenient way of printing.  It outputs
23929     the printed representation of OBJECT to STREAM, printing in
23930     addition one newline before OBJECT and another after it.  Quoting
23931     characters are used.  ‘print’ returns OBJECT.  For example:
23932
23933          (progn (print 'The\ cat\ in)
23934                 (print "the hat")
23935                 (print " came back"))
2393623937               ⊣ The\ cat\ in
2393823939               ⊣ "the hat"
2394023941               ⊣ " came back"
23942               ⇒ " came back"
23943
23944 -- Function: prin1 object &optional stream
23945     This function outputs the printed representation of OBJECT to
23946     STREAM.  It does not print newlines to separate output as ‘print’
23947     does, but it does use quoting characters just like ‘print’.  It
23948     returns OBJECT.
23949
23950          (progn (prin1 'The\ cat\ in)
23951                 (prin1 "the hat")
23952                 (prin1 " came back"))
23953               ⊣ The\ cat\ in"the hat"" came back"
23954               ⇒ " came back"
23955
23956 -- Function: princ object &optional stream
23957     This function outputs the printed representation of OBJECT to
23958     STREAM.  It returns OBJECT.
23959
23960     This function is intended to produce output that is readable by
23961     people, not by ‘read’, so it doesn’t insert quoting characters and
23962     doesn’t put double-quotes around the contents of strings.  It does
23963     not add any spacing between calls.
23964
23965          (progn
23966            (princ 'The\ cat)
23967            (princ " in the \"hat\""))
23968               ⊣ The cat in the "hat"
23969               ⇒ " in the \"hat\""
23970
23971 -- Function: terpri &optional stream ensure
23972     This function outputs a newline to STREAM.  The name stands for
23973     “terminate print”.  If ENSURE is non-‘nil’ no newline is printed if
23974     STREAM is already at the beginning of a line.  Note in this case
23975     STREAM can not be a function and an error is signaled if it is.
23976     This function returns ‘t’ if a newline is printed.
23977
23978 -- Function: write-char character &optional stream
23979     This function outputs CHARACTER to STREAM.  It returns CHARACTER.
23980
23981 -- Function: prin1-to-string object &optional noescape
23982     This function returns a string containing the text that ‘prin1’
23983     would have printed for the same argument.
23984
23985          (prin1-to-string 'foo)
23986               ⇒ "foo"
23987          (prin1-to-string (mark-marker))
23988               ⇒ "#<marker at 2773 in strings.texi>"
23989
23990     If NOESCAPE is non-‘nil’, that inhibits use of quoting characters
23991     in the output.  (This argument is supported in Emacs versions 19
23992     and later.)
23993
23994          (prin1-to-string "foo")
23995               ⇒ "\"foo\""
23996          (prin1-to-string "foo" t)
23997               ⇒ "foo"
23998
23999     See ‘format’, in *note Formatting Strings::, for other ways to
24000     obtain the printed representation of a Lisp object as a string.
24001
24002 -- Macro: with-output-to-string body...
24003     This macro executes the BODY forms with ‘standard-output’ set up to
24004     feed output into a string.  Then it returns that string.
24005
24006     For example, if the current buffer name is ‘foo’,
24007
24008          (with-output-to-string
24009            (princ "The buffer is ")
24010            (princ (buffer-name)))
24011
24012     returns ‘"The buffer is foo"’.
24013
24014 -- Function: pp object &optional stream
24015     This function outputs OBJECT to STREAM, just like ‘prin1’, but does
24016     it in a prettier way.  That is, it’ll indent and fill the object to
24017     make it more readable for humans.
24018
24019   If you need to use binary I/O in batch mode, e.g., use the functions
24020described in this section to write out arbitrary binary data or avoid
24021conversion of newlines on non-POSIX hosts, see *note set-binary-mode:
24022Input Functions.
24023
24024
24025File: elisp.info,  Node: Output Variables,  Prev: Output Functions,  Up: Read and Print
24026
2402719.6 Variables Affecting Output
24028===============================
24029
24030 -- Variable: standard-output
24031     The value of this variable is the default output stream—the stream
24032     that print functions use when the STREAM argument is ‘nil’.  The
24033     default is ‘t’, meaning display in the echo area.
24034
24035 -- Variable: print-quoted
24036     If this is non-‘nil’, that means to print quoted forms using
24037     abbreviated reader syntax, e.g., ‘(quote foo)’ prints as ‘'foo’,
24038     and ‘(function foo)’ as ‘#'foo’.  The default is ‘t’.
24039
24040 -- Variable: print-escape-newlines
24041     If this variable is non-‘nil’, then newline characters in strings
24042     are printed as ‘\n’ and formfeeds are printed as ‘\f’.  Normally
24043     these characters are printed as actual newlines and formfeeds.
24044
24045     This variable affects the print functions ‘prin1’ and ‘print’ that
24046     print with quoting.  It does not affect ‘princ’.  Here is an
24047     example using ‘prin1’:
24048
24049          (prin1 "a\nb")
24050               ⊣ "a
24051               ⊣ b"
24052               ⇒ "a
24053          b"
24054
24055          (let ((print-escape-newlines t))
24056            (prin1 "a\nb"))
24057               ⊣ "a\nb"
24058               ⇒ "a
24059          b"
24060
24061     In the second expression, the local binding of
24062     ‘print-escape-newlines’ is in effect during the call to ‘prin1’,
24063     but not during the printing of the result.
24064
24065 -- Variable: print-escape-control-characters
24066     If this variable is non-‘nil’, control characters in strings are
24067     printed as backslash sequences by the print functions ‘prin1’ and
24068     ‘print’ that print with quoting.  If this variable and
24069     ‘print-escape-newlines’ are both non-‘nil’, the latter takes
24070     precedences for newlines and formfeeds.
24071
24072 -- Variable: print-escape-nonascii
24073     If this variable is non-‘nil’, then unibyte non-ASCII characters in
24074     strings are unconditionally printed as backslash sequences by the
24075     print functions ‘prin1’ and ‘print’ that print with quoting.
24076
24077     Those functions also use backslash sequences for unibyte non-ASCII
24078     characters, regardless of the value of this variable, when the
24079     output stream is a multibyte buffer or a marker pointing into one.
24080
24081 -- Variable: print-escape-multibyte
24082     If this variable is non-‘nil’, then multibyte non-ASCII characters
24083     in strings are unconditionally printed as backslash sequences by
24084     the print functions ‘prin1’ and ‘print’ that print with quoting.
24085
24086     Those functions also use backslash sequences for multibyte
24087     non-ASCII characters, regardless of the value of this variable,
24088     when the output stream is a unibyte buffer or a marker pointing
24089     into one.
24090
24091 -- Variable: print-charset-text-property
24092     This variable controls printing of ‘charset’ text property on
24093     printing a string.  The value should be ‘nil’, ‘t’, or ‘default’.
24094
24095     If the value is ‘nil’, ‘charset’ text properties are never printed.
24096     If ‘t’, they are always printed.
24097
24098     If the value is ‘default’, only print ‘charset’ text properties if
24099     there is an “unexpected” ‘charset’ property.  For ascii characters,
24100     all charsets are considered “expected”.  Otherwise, the expected
24101     ‘charset’ property of a character is given by ‘char-charset’.
24102
24103 -- Variable: print-length
24104     The value of this variable is the maximum number of elements to
24105     print in any list, vector or bool-vector.  If an object being
24106     printed has more than this many elements, it is abbreviated with an
24107     ellipsis.
24108
24109     If the value is ‘nil’ (the default), then there is no limit.
24110
24111          (setq print-length 2)
24112               ⇒ 2
24113          (print '(1 2 3 4 5))
24114               ⊣ (1 2 ...)
24115               ⇒ (1 2 ...)
24116
24117 -- Variable: print-level
24118     The value of this variable is the maximum depth of nesting of
24119     parentheses and brackets when printed.  Any list or vector at a
24120     depth exceeding this limit is abbreviated with an ellipsis.  A
24121     value of ‘nil’ (which is the default) means no limit.
24122
24123 -- User Option: eval-expression-print-length
24124 -- User Option: eval-expression-print-level
24125     These are the values for ‘print-length’ and ‘print-level’ used by
24126     ‘eval-expression’, and thus, indirectly, by many interactive
24127     evaluation commands (*note Evaluating Emacs Lisp Expressions:
24128     (emacs)Lisp Eval.).
24129
24130   These variables are used for detecting and reporting circular and
24131shared structure:
24132
24133 -- Variable: print-circle
24134     If non-‘nil’, this variable enables detection of circular and
24135     shared structure in printing.  *Note Circular Objects::.
24136
24137 -- Variable: print-gensym
24138     If non-‘nil’, this variable enables detection of uninterned symbols
24139     (*note Creating Symbols::) in printing.  When this is enabled,
24140     uninterned symbols print with the prefix ‘#:’, which tells the Lisp
24141     reader to produce an uninterned symbol.
24142
24143 -- Variable: print-continuous-numbering
24144     If non-‘nil’, that means number continuously across print calls.
24145     This affects the numbers printed for ‘#N=’ labels and ‘#M#’
24146     references.  Don’t set this variable with ‘setq’; you should only
24147     bind it temporarily to ‘t’ with ‘let’.  When you do that, you
24148     should also bind ‘print-number-table’ to ‘nil’.
24149
24150 -- Variable: print-number-table
24151     This variable holds a vector used internally by printing to
24152     implement the ‘print-circle’ feature.  You should not use it except
24153     to bind it to ‘nil’ when you bind ‘print-continuous-numbering’.
24154
24155 -- Variable: float-output-format
24156     This variable specifies how to print floating-point numbers.  The
24157     default is ‘nil’, meaning use the shortest output that represents
24158     the number without losing information.
24159
24160     To control output format more precisely, you can put a string in
24161     this variable.  The string should hold a ‘%’-specification to be
24162     used in the C function ‘sprintf’.  For further restrictions on what
24163     you can use, see the variable’s documentation string.
24164
24165
24166File: elisp.info,  Node: Minibuffers,  Next: Command Loop,  Prev: Read and Print,  Up: Top
24167
2416820 Minibuffers
24169**************
24170
24171A “minibuffer” is a special buffer that Emacs commands use to read
24172arguments more complicated than the single numeric prefix argument.
24173These arguments include file names, buffer names, and command names (as
24174in ‘M-x’).  The minibuffer is displayed on the bottom line of the frame,
24175in the same place as the echo area (*note The Echo Area::), but only
24176while it is in use for reading an argument.
24177
24178* Menu:
24179
24180* Intro to Minibuffers::      Basic information about minibuffers.
24181* Text from Minibuffer::      How to read a straight text string.
24182* Object from Minibuffer::    How to read a Lisp object or expression.
24183* Minibuffer History::        Recording previous minibuffer inputs
24184                                so the user can reuse them.
24185* Initial Input::             Specifying initial contents for the minibuffer.
24186* Completion::                How to invoke and customize completion.
24187* Yes-or-No Queries::         Asking a question with a simple answer.
24188* Multiple Queries::          Asking complex questions.
24189* Reading a Password::        Reading a password from the terminal.
24190* Minibuffer Commands::       Commands used as key bindings in minibuffers.
24191* Minibuffer Windows::        Operating on the special minibuffer windows.
24192* Minibuffer Contents::       How such commands access the minibuffer text.
24193* Recursive Mini::            Whether recursive entry to minibuffer is allowed.
24194* Minibuffer Misc::           Various customization hooks and variables.
24195
24196
24197File: elisp.info,  Node: Intro to Minibuffers,  Next: Text from Minibuffer,  Up: Minibuffers
24198
2419920.1 Introduction to Minibuffers
24200================================
24201
24202In most ways, a minibuffer is a normal Emacs buffer.  Most operations
24203_within_ a buffer, such as editing commands, work normally in a
24204minibuffer.  However, many operations for managing buffers do not apply
24205to minibuffers.  The name of a minibuffer always has the form
24206‘ *Minibuf-NUMBER*’, and it cannot be changed.  Minibuffers are
24207displayed only in special windows used only for minibuffers; these
24208windows always appear at the bottom of a frame.  (Sometimes frames have
24209no minibuffer window, and sometimes a special kind of frame contains
24210nothing but a minibuffer window; see *note Minibuffers and Frames::.)
24211
24212   The text in the minibuffer always starts with the “prompt string”,
24213the text that was specified by the program that is using the minibuffer
24214to tell the user what sort of input to type.  This text is marked
24215read-only so you won’t accidentally delete or change it.  It is also
24216marked as a field (*note Fields::), so that certain motion functions,
24217including ‘beginning-of-line’, ‘forward-word’, ‘forward-sentence’, and
24218‘forward-paragraph’, stop at the boundary between the prompt and the
24219actual text.
24220
24221   The minibuffer’s window is normally a single line; it grows
24222automatically if the contents require more space.  Whilst the minibuffer
24223is active, you can explicitly resize its window temporarily with the
24224window sizing commands; the window reverts to its normal size when the
24225minibuffer is exited.  When the minibuffer is not active, you can resize
24226its window permanently by using the window sizing commands in the
24227frame’s other window, or dragging the mode line with the mouse.  (Due to
24228details of the current implementation, for this to work
24229‘resize-mini-windows’ must be ‘nil’.)  If the frame contains just a
24230minibuffer window, you can change its size by changing the frame’s size.
24231
24232   Use of the minibuffer reads input events, and that alters the values
24233of variables such as ‘this-command’ and ‘last-command’ (*note Command
24234Loop Info::).  Your program should bind them around the code that uses
24235the minibuffer, if you do not want that to change them.
24236
24237   Under some circumstances, a command can use a minibuffer even if
24238there is an active minibuffer; such a minibuffer is called a “recursive
24239minibuffer”.  The first minibuffer is named ‘ *Minibuf-1*’.  Recursive
24240minibuffers are named by incrementing the number at the end of the name.
24241(The names begin with a space so that they won’t show up in normal
24242buffer lists.)  Of several recursive minibuffers, the innermost (or most
24243recently entered) is the active minibuffer.  We usually call this _the_
24244minibuffer.  You can permit or forbid recursive minibuffers by setting
24245the variable ‘enable-recursive-minibuffers’, or by putting properties of
24246that name on command symbols (*Note Recursive Mini::.)
24247
24248   Like other buffers, a minibuffer uses a local keymap (*note
24249Keymaps::) to specify special key bindings.  The function that invokes
24250the minibuffer also sets up its local map according to the job to be
24251done.  *Note Text from Minibuffer::, for the non-completion minibuffer
24252local maps.  *Note Completion Commands::, for the minibuffer local maps
24253for completion.
24254
24255   When a minibuffer is inactive, its major mode is
24256‘minibuffer-inactive-mode’, with keymap ‘minibuffer-inactive-mode-map’.
24257This is only really useful if the minibuffer is in a separate frame.
24258*Note Minibuffers and Frames::.
24259
24260   When Emacs is running in batch mode, any request to read from the
24261minibuffer actually reads a line from the standard input descriptor that
24262was supplied when Emacs was started.  This supports only basic input:
24263none of the special minibuffer features (history, completion, etc.) are
24264available in batch mode.
24265
24266
24267File: elisp.info,  Node: Text from Minibuffer,  Next: Object from Minibuffer,  Prev: Intro to Minibuffers,  Up: Minibuffers
24268
2426920.2 Reading Text Strings with the Minibuffer
24270=============================================
24271
24272The most basic primitive for minibuffer input is ‘read-from-minibuffer’,
24273which can be used to read either a string or a Lisp object in textual
24274form.  The function ‘read-regexp’ is used for reading regular
24275expressions (*note Regular Expressions::), which are a special kind of
24276string.  There are also specialized functions for reading commands,
24277variables, file names, etc. (*note Completion::).
24278
24279   In most cases, you should not call minibuffer input functions in the
24280middle of a Lisp function.  Instead, do all minibuffer input as part of
24281reading the arguments for a command, in the ‘interactive’ specification.
24282*Note Defining Commands::.
24283
24284 -- Function: read-from-minibuffer prompt &optional initial keymap read
24285          history default inherit-input-method
24286     This function is the most general way to get input from the
24287     minibuffer.  By default, it accepts arbitrary text and returns it
24288     as a string; however, if READ is non-‘nil’, then it uses ‘read’ to
24289     convert the text into a Lisp object (*note Input Functions::).
24290
24291     The first thing this function does is to activate a minibuffer and
24292     display it with PROMPT (which must be a string) as the prompt.
24293     Then the user can edit text in the minibuffer.
24294
24295     When the user types a command to exit the minibuffer,
24296     ‘read-from-minibuffer’ constructs the return value from the text in
24297     the minibuffer.  Normally it returns a string containing that text.
24298     However, if READ is non-‘nil’, ‘read-from-minibuffer’ reads the
24299     text and returns the resulting Lisp object, unevaluated.  (*Note
24300     Input Functions::, for information about reading.)
24301
24302     The argument DEFAULT specifies default values to make available
24303     through the history commands.  It should be a string, a list of
24304     strings, or ‘nil’.  The string or strings become the minibuffer’s
24305     “future history”, available to the user with ‘M-n’.
24306
24307     If READ is non-‘nil’, then DEFAULT is also used as the input to
24308     ‘read’, if the user enters empty input.  If DEFAULT is a list of
24309     strings, the first string is used as the input.  If DEFAULT is
24310     ‘nil’, empty input results in an ‘end-of-file’ error.  However, in
24311     the usual case (where READ is ‘nil’), ‘read-from-minibuffer’
24312     ignores DEFAULT when the user enters empty input and returns an
24313     empty string, ‘""’.  In this respect, it differs from all the other
24314     minibuffer input functions in this chapter.
24315
24316     If KEYMAP is non-‘nil’, that keymap is the local keymap to use in
24317     the minibuffer.  If KEYMAP is omitted or ‘nil’, the value of
24318     ‘minibuffer-local-map’ is used as the keymap.  Specifying a keymap
24319     is the most important way to customize the minibuffer for various
24320     applications such as completion.
24321
24322     The argument HISTORY specifies a history list variable to use for
24323     saving the input and for history commands used in the minibuffer.
24324     It defaults to ‘minibuffer-history’.  You can optionally specify a
24325     starting position in the history list as well.  *Note Minibuffer
24326     History::.
24327
24328     If the variable ‘minibuffer-allow-text-properties’ is non-‘nil’,
24329     then the string that is returned includes whatever text properties
24330     were present in the minibuffer.  Otherwise all the text properties
24331     are stripped when the value is returned.
24332
24333     The text properties in ‘minibuffer-prompt-properties’ are applied
24334     to the prompt.  By default, this property list defines a face to
24335     use for the prompt.  This face, if present, is applied to the end
24336     of the face list and merged before display.
24337
24338     If the user wants to completely control the look of the prompt, the
24339     most convenient way to do that is to specify the ‘default’ face at
24340     the end of all face lists.  For instance:
24341
24342          (read-from-minibuffer
24343           (concat
24344            (propertize "Bold" 'face '(bold default))
24345            (propertize " and normal: " 'face '(default))))
24346
24347     If the argument INHERIT-INPUT-METHOD is non-‘nil’, then the
24348     minibuffer inherits the current input method (*note Input
24349     Methods::) and the setting of ‘enable-multibyte-characters’ (*note
24350     Text Representations::) from whichever buffer was current before
24351     entering the minibuffer.
24352
24353     Use of INITIAL is mostly deprecated; we recommend using a non-‘nil’
24354     value only in conjunction with specifying a cons cell for HISTORY.
24355     *Note Initial Input::.
24356
24357 -- Function: read-string prompt &optional initial history default
24358          inherit-input-method
24359     This function reads a string from the minibuffer and returns it.
24360     The arguments PROMPT, INITIAL, HISTORY and INHERIT-INPUT-METHOD are
24361     used as in ‘read-from-minibuffer’.  The keymap used is
24362     ‘minibuffer-local-map’.
24363
24364     The optional argument DEFAULT is used as in ‘read-from-minibuffer’,
24365     except that, if non-‘nil’, it also specifies a default value to
24366     return if the user enters null input.  As in ‘read-from-minibuffer’
24367     it should be a string, a list of strings, or ‘nil’, which is
24368     equivalent to an empty string.  When DEFAULT is a string, that
24369     string is the default value.  When it is a list of strings, the
24370     first string is the default value.  (All these strings are
24371     available to the user in the “future minibuffer history”.)
24372
24373     This function works by calling the ‘read-from-minibuffer’ function:
24374
24375          (read-string PROMPT INITIAL HISTORY DEFAULT INHERIT)
2437624377          (let ((value
24378                 (read-from-minibuffer PROMPT INITIAL nil nil
24379                                       HISTORY DEFAULT INHERIT)))
24380            (if (and (equal value "") DEFAULT)
24381                (if (consp DEFAULT) (car DEFAULT) DEFAULT)
24382              value))
24383
24384 -- Function: read-regexp prompt &optional defaults history
24385     This function reads a regular expression as a string from the
24386     minibuffer and returns it.  If the minibuffer prompt string PROMPT
24387     does not end in ‘:’ (followed by optional whitespace), the function
24388     adds ‘: ’ to the end, preceded by the default return value (see
24389     below), if that is non-empty.
24390
24391     The optional argument DEFAULTS controls the default value to return
24392     if the user enters null input, and should be one of: a string;
24393     ‘nil’, which is equivalent to an empty string; a list of strings;
24394     or a symbol.
24395
24396     If DEFAULTS is a symbol, ‘read-regexp’ consults the value of the
24397     variable ‘read-regexp-defaults-function’ (see below), and if that
24398     is non-‘nil’ uses it in preference to DEFAULTS.  The value in this
24399     case should be either:
24400
24401        − ‘regexp-history-last’, which means to use the first element of
24402          the appropriate minibuffer history list (see below).
24403
24404        − A function of no arguments, whose return value (which should
24405          be ‘nil’, a string, or a list of strings) becomes the value of
24406          DEFAULTS.
24407
24408     ‘read-regexp’ now ensures that the result of processing DEFAULTS is
24409     a list (i.e., if the value is ‘nil’ or a string, it converts it to
24410     a list of one element).  To this list, ‘read-regexp’ then appends a
24411     few potentially useful candidates for input.  These are:
24412
24413        − The word or symbol at point.
24414        − The last regexp used in an incremental search.
24415        − The last string used in an incremental search.
24416        − The last string or pattern used in query-replace commands.
24417
24418     The function now has a list of regular expressions that it passes
24419     to ‘read-from-minibuffer’ to obtain the user’s input.  The first
24420     element of the list is the default result in case of empty input.
24421     All elements of the list are available to the user as the “future
24422     minibuffer history” list (*note future list: (emacs)Minibuffer
24423     History.).
24424
24425     The optional argument HISTORY, if non-‘nil’, is a symbol specifying
24426     a minibuffer history list to use (*note Minibuffer History::).  If
24427     it is omitted or ‘nil’, the history list defaults to
24428     ‘regexp-history’.
24429
24430 -- User Option: read-regexp-defaults-function
24431     The function ‘read-regexp’ may use the value of this variable to
24432     determine its list of default regular expressions.  If non-‘nil’,
24433     the value of this variable should be either:
24434
24435        − The symbol ‘regexp-history-last’.
24436
24437        − A function of no arguments that returns either ‘nil’, a
24438          string, or a list of strings.
24439
24440     See ‘read-regexp’ above for details of how these values are used.
24441
24442 -- Variable: minibuffer-allow-text-properties
24443     If this variable is ‘nil’, then ‘read-from-minibuffer’ and
24444     ‘read-string’ strip all text properties from the minibuffer input
24445     before returning it.  However, ‘read-no-blanks-input’ (see below),
24446     as well as ‘read-minibuffer’ and related functions (*note Reading
24447     Lisp Objects With the Minibuffer: Object from Minibuffer.), and all
24448     functions that do minibuffer input with completion, discard text
24449     properties unconditionally, regardless of the value of this
24450     variable.
24451
24452 -- Variable: minibuffer-local-map
24453     This is the default local keymap for reading from the minibuffer.
24454     By default, it makes the following bindings:
24455
24456     ‘C-j’
24457          ‘exit-minibuffer’
24458
24459     <RET>
24460          ‘exit-minibuffer’
24461
24462     <M-<>
24463          ‘minibuffer-beginning-of-buffer’
24464
24465     ‘C-g’
24466          ‘abort-recursive-edit’
24467
24468     ‘M-n’
24469     <DOWN>
24470          ‘next-history-element’
24471
24472     ‘M-p’
24473     <UP>
24474          ‘previous-history-element’
24475
24476     ‘M-s’
24477          ‘next-matching-history-element’
24478
24479     ‘M-r’
24480          ‘previous-matching-history-element’
24481
24482 -- Function: read-no-blanks-input prompt &optional initial
24483          inherit-input-method
24484     This function reads a string from the minibuffer, but does not
24485     allow whitespace characters as part of the input: instead, those
24486     characters terminate the input.  The arguments PROMPT, INITIAL, and
24487     INHERIT-INPUT-METHOD are used as in ‘read-from-minibuffer’.
24488
24489     This is a simplified interface to the ‘read-from-minibuffer’
24490     function, and passes the value of the ‘minibuffer-local-ns-map’
24491     keymap as the KEYMAP argument for that function.  Since the keymap
24492     ‘minibuffer-local-ns-map’ does not rebind ‘C-q’, it _is_ possible
24493     to put a space into the string, by quoting it.
24494
24495     This function discards text properties, regardless of the value of
24496     ‘minibuffer-allow-text-properties’.
24497
24498          (read-no-blanks-input PROMPT INITIAL)
2449924500          (let (minibuffer-allow-text-properties)
24501            (read-from-minibuffer PROMPT INITIAL minibuffer-local-ns-map))
24502
24503 -- Variable: minibuffer-local-ns-map
24504     This built-in variable is the keymap used as the minibuffer local
24505     keymap in the function ‘read-no-blanks-input’.  By default, it
24506     makes the following bindings, in addition to those of
24507     ‘minibuffer-local-map’:
24508
24509     <SPC>
24510          ‘exit-minibuffer’
24511
24512     <TAB>
24513          ‘exit-minibuffer’
24514
24515     ‘?’
24516          ‘self-insert-and-exit’
24517
24518
24519File: elisp.info,  Node: Object from Minibuffer,  Next: Minibuffer History,  Prev: Text from Minibuffer,  Up: Minibuffers
24520
2452120.3 Reading Lisp Objects with the Minibuffer
24522=============================================
24523
24524This section describes functions for reading Lisp objects with the
24525minibuffer.
24526
24527 -- Function: read-minibuffer prompt &optional initial
24528     This function reads a Lisp object using the minibuffer, and returns
24529     it without evaluating it.  The arguments PROMPT and INITIAL are
24530     used as in ‘read-from-minibuffer’.
24531
24532     This is a simplified interface to the ‘read-from-minibuffer’
24533     function:
24534
24535          (read-minibuffer PROMPT INITIAL)
2453624537          (let (minibuffer-allow-text-properties)
24538            (read-from-minibuffer PROMPT INITIAL nil t))
24539
24540     Here is an example in which we supply the string ‘"(testing)"’ as
24541     initial input:
24542
24543          (read-minibuffer
24544           "Enter an expression: " (format "%s" '(testing)))
24545
24546          ;; Here is how the minibuffer is displayed:
24547
24548          ---------- Buffer: Minibuffer ----------
24549          Enter an expression: (testing)★
24550          ---------- Buffer: Minibuffer ----------
24551
24552     The user can type <RET> immediately to use the initial input as a
24553     default, or can edit the input.
24554
24555 -- Function: eval-minibuffer prompt &optional initial
24556     This function reads a Lisp expression using the minibuffer,
24557     evaluates it, then returns the result.  The arguments PROMPT and
24558     INITIAL are used as in ‘read-from-minibuffer’.
24559
24560     This function simply evaluates the result of a call to
24561     ‘read-minibuffer’:
24562
24563          (eval-minibuffer PROMPT INITIAL)
2456424565          (eval (read-minibuffer PROMPT INITIAL))
24566
24567 -- Function: edit-and-eval-command prompt form
24568     This function reads a Lisp expression in the minibuffer, evaluates
24569     it, then returns the result.  The difference between this command
24570     and ‘eval-minibuffer’ is that here the initial FORM is not optional
24571     and it is treated as a Lisp object to be converted to printed
24572     representation rather than as a string of text.  It is printed with
24573     ‘prin1’, so if it is a string, double-quote characters (‘"’) appear
24574     in the initial text.  *Note Output Functions::.
24575
24576     In the following example, we offer the user an expression with
24577     initial text that is already a valid form:
24578
24579          (edit-and-eval-command "Please edit: " '(forward-word 1))
24580
24581          ;; After evaluation of the preceding expression,
24582          ;;   the following appears in the minibuffer:
24583
24584          ---------- Buffer: Minibuffer ----------
24585          Please edit: (forward-word 1)★
24586          ---------- Buffer: Minibuffer ----------
24587
24588     Typing <RET> right away would exit the minibuffer and evaluate the
24589     expression, thus moving point forward one word.
24590
24591
24592File: elisp.info,  Node: Minibuffer History,  Next: Initial Input,  Prev: Object from Minibuffer,  Up: Minibuffers
24593
2459420.4 Minibuffer History
24595=======================
24596
24597A “minibuffer history list” records previous minibuffer inputs so the
24598user can reuse them conveniently.  It is a variable whose value is a
24599list of strings (previous inputs), most recent first.
24600
24601   There are many separate minibuffer history lists, used for different
24602kinds of inputs.  It’s the Lisp programmer’s job to specify the right
24603history list for each use of the minibuffer.
24604
24605   You specify a minibuffer history list with the optional HISTORY
24606argument to ‘read-from-minibuffer’ or ‘completing-read’.  Here are the
24607possible values for it:
24608
24609VARIABLE
24610     Use VARIABLE (a symbol) as the history list.
24611
24612(VARIABLE . STARTPOS)
24613     Use VARIABLE (a symbol) as the history list, and assume that the
24614     initial history position is STARTPOS (a nonnegative integer).
24615
24616     Specifying 0 for STARTPOS is equivalent to just specifying the
24617     symbol VARIABLE.  ‘previous-history-element’ will display the most
24618     recent element of the history list in the minibuffer.  If you
24619     specify a positive STARTPOS, the minibuffer history functions
24620     behave as if ‘(elt VARIABLE (1- STARTPOS))’ were the history
24621     element currently shown in the minibuffer.
24622
24623     For consistency, you should also specify that element of the
24624     history as the initial minibuffer contents, using the INITIAL
24625     argument to the minibuffer input function (*note Initial Input::).
24626
24627   If you don’t specify HISTORY, then the default history list
24628‘minibuffer-history’ is used.  For other standard history lists, see
24629below.  You can also create your own history list variable; just
24630initialize it to ‘nil’ before the first use.  If the variable is buffer
24631local, then each buffer will have its own input history list.
24632
24633   Both ‘read-from-minibuffer’ and ‘completing-read’ add new elements to
24634the history list automatically, and provide commands to allow the user
24635to reuse items on the list.  The only thing your program needs to do to
24636use a history list is to initialize it and to pass its name to the input
24637functions when you wish.  But it is safe to modify the list by hand when
24638the minibuffer input functions are not using it.
24639
24640   Emacs functions that add a new element to a history list can also
24641delete old elements if the list gets too long.  The variable
24642‘history-length’ specifies the maximum length for most history lists.
24643To specify a different maximum length for a particular history list, put
24644the length in the ‘history-length’ property of the history list symbol.
24645The variable ‘history-delete-duplicates’ specifies whether to delete
24646duplicates in history.
24647
24648 -- Function: add-to-history history-var newelt &optional maxelt
24649          keep-all
24650     This function adds a new element NEWELT, if it isn’t the empty
24651     string, to the history list stored in the variable HISTORY-VAR, and
24652     returns the updated history list.  It limits the list length to the
24653     value of MAXELT (if non-‘nil’) or ‘history-length’ (described
24654     below).  The possible values of MAXELT have the same meaning as the
24655     values of ‘history-length’.  HISTORY-VAR cannot refer to a lexical
24656     variable.
24657
24658     Normally, ‘add-to-history’ removes duplicate members from the
24659     history list if ‘history-delete-duplicates’ is non-‘nil’.  However,
24660     if KEEP-ALL is non-‘nil’, that says not to remove duplicates, and
24661     to add NEWELT to the list even if it is empty.
24662
24663 -- Variable: history-add-new-input
24664     If the value of this variable is ‘nil’, standard functions that
24665     read from the minibuffer don’t add new elements to the history
24666     list.  This lets Lisp programs explicitly manage input history by
24667     using ‘add-to-history’.  The default value is ‘t’.
24668
24669 -- User Option: history-length
24670     The value of this variable specifies the maximum length for all
24671     history lists that don’t specify their own maximum lengths.  If the
24672     value is ‘t’, that means there is no maximum (don’t delete old
24673     elements).  If a history list variable’s symbol has a non-‘nil’
24674     ‘history-length’ property, it overrides this variable for that
24675     particular history list.
24676
24677 -- User Option: history-delete-duplicates
24678     If the value of this variable is ‘t’, that means when adding a new
24679     history element, all previous identical elements are deleted.
24680
24681   Here are some of the standard minibuffer history list variables:
24682
24683 -- Variable: minibuffer-history
24684     The default history list for minibuffer history input.
24685
24686 -- Variable: query-replace-history
24687     A history list for arguments to ‘query-replace’ (and similar
24688     arguments to other commands).
24689
24690 -- Variable: file-name-history
24691     A history list for file-name arguments.
24692
24693 -- Variable: buffer-name-history
24694     A history list for buffer-name arguments.
24695
24696 -- Variable: regexp-history
24697     A history list for regular expression arguments.
24698
24699 -- Variable: extended-command-history
24700     A history list for arguments that are names of extended commands.
24701
24702 -- Variable: shell-command-history
24703     A history list for arguments that are shell commands.
24704
24705 -- Variable: read-expression-history
24706     A history list for arguments that are Lisp expressions to evaluate.
24707
24708 -- Variable: face-name-history
24709     A history list for arguments that are faces.
24710
24711 -- Variable: custom-variable-history
24712     A history list for variable-name arguments read by ‘read-variable’.
24713
24714
24715File: elisp.info,  Node: Initial Input,  Next: Completion,  Prev: Minibuffer History,  Up: Minibuffers
24716
2471720.5 Initial Input
24718==================
24719
24720Several of the functions for minibuffer input have an argument called
24721INITIAL.  This is a mostly-deprecated feature for specifying that the
24722minibuffer should start out with certain text, instead of empty as
24723usual.
24724
24725   If INITIAL is a string, the minibuffer starts out containing the text
24726of the string, with point at the end, when the user starts to edit the
24727text.  If the user simply types <RET> to exit the minibuffer, it will
24728use the initial input string to determine the value to return.
24729
24730   *We discourage use of a non-‘nil’ value for INITIAL*, because initial
24731input is an intrusive interface.  History lists and default values
24732provide a much more convenient method to offer useful default inputs to
24733the user.
24734
24735   There is just one situation where you should specify a string for an
24736INITIAL argument.  This is when you specify a cons cell for the HISTORY
24737argument.  *Note Minibuffer History::.
24738
24739   INITIAL can also be a cons cell of the form ‘(STRING . POSITION)’.
24740This means to insert STRING in the minibuffer but put point at POSITION
24741within the string’s text.
24742
24743   As a historical accident, POSITION was implemented inconsistently in
24744different functions.  In ‘completing-read’, POSITION’s value is
24745interpreted as origin-zero; that is, a value of 0 means the beginning of
24746the string, 1 means after the first character, etc.  In
24747‘read-minibuffer’, and the other non-completion minibuffer input
24748functions that support this argument, 1 means the beginning of the
24749string, 2 means after the first character, etc.
24750
24751   Use of a cons cell as the value for INITIAL arguments is deprecated.
24752
24753
24754File: elisp.info,  Node: Completion,  Next: Yes-or-No Queries,  Prev: Initial Input,  Up: Minibuffers
24755
2475620.6 Completion
24757===============
24758
24759“Completion” is a feature that fills in the rest of a name starting from
24760an abbreviation for it.  Completion works by comparing the user’s input
24761against a list of valid names and determining how much of the name is
24762determined uniquely by what the user has typed.  For example, when you
24763type ‘C-x b’ (‘switch-to-buffer’) and then type the first few letters of
24764the name of the buffer to which you wish to switch, and then type <TAB>
24765(‘minibuffer-complete’), Emacs extends the name as far as it can.
24766
24767   Standard Emacs commands offer completion for names of symbols, files,
24768buffers, and processes; with the functions in this section, you can
24769implement completion for other kinds of names.
24770
24771   The ‘try-completion’ function is the basic primitive for completion:
24772it returns the longest determined completion of a given initial string,
24773with a given set of strings to match against.
24774
24775   The function ‘completing-read’ provides a higher-level interface for
24776completion.  A call to ‘completing-read’ specifies how to determine the
24777list of valid names.  The function then activates the minibuffer with a
24778local keymap that binds a few keys to commands useful for completion.
24779Other functions provide convenient simple interfaces for reading certain
24780kinds of names with completion.
24781
24782* Menu:
24783
24784* Basic Completion::       Low-level functions for completing strings.
24785* Minibuffer Completion::  Invoking the minibuffer with completion.
24786* Completion Commands::    Minibuffer commands that do completion.
24787* High-Level Completion::  Convenient special cases of completion
24788                             (reading buffer names, variable names, etc.).
24789* Reading File Names::     Using completion to read file names and
24790                             shell commands.
24791* Completion Variables::   Variables controlling completion behavior.
24792* Programmed Completion::  Writing your own completion function.
24793* Completion in Buffers::  Completing text in ordinary buffers.
24794
24795
24796File: elisp.info,  Node: Basic Completion,  Next: Minibuffer Completion,  Up: Completion
24797
2479820.6.1 Basic Completion Functions
24799---------------------------------
24800
24801The following completion functions have nothing in themselves to do with
24802minibuffers.  We describe them here to keep them near the higher-level
24803completion features that do use the minibuffer.
24804
24805 -- Function: try-completion string collection &optional predicate
24806     This function returns the longest common substring of all possible
24807     completions of STRING in COLLECTION.
24808
24809     COLLECTION is called the “completion table”.  Its value must be a
24810     list of strings or cons cells, an obarray, a hash table, or a
24811     completion function.
24812
24813     ‘try-completion’ compares STRING against each of the permissible
24814     completions specified by the completion table.  If no permissible
24815     completions match, it returns ‘nil’.  If there is just one matching
24816     completion, and the match is exact, it returns ‘t’.  Otherwise, it
24817     returns the longest initial sequence common to all possible
24818     matching completions.
24819
24820     If COLLECTION is a list, the permissible completions are specified
24821     by the elements of the list, each of which should be either a
24822     string, or a cons cell whose CAR is either a string or a symbol (a
24823     symbol is converted to a string using ‘symbol-name’).  If the list
24824     contains elements of any other type, those are ignored.
24825
24826     If COLLECTION is an obarray (*note Creating Symbols::), the names
24827     of all symbols in the obarray form the set of permissible
24828     completions.
24829
24830     If COLLECTION is a hash table, then the keys that are strings or
24831     symbols are the possible completions.  Other keys are ignored.
24832
24833     You can also use a function as COLLECTION.  Then the function is
24834     solely responsible for performing completion; ‘try-completion’
24835     returns whatever this function returns.  The function is called
24836     with three arguments: STRING, PREDICATE and ‘nil’ (the third
24837     argument is so that the same function can be used in
24838     ‘all-completions’ and do the appropriate thing in either case).
24839     *Note Programmed Completion::.
24840
24841     If the argument PREDICATE is non-‘nil’, then it must be a function
24842     of one argument, unless COLLECTION is a hash table, in which case
24843     it should be a function of two arguments.  It is used to test each
24844     possible match, and the match is accepted only if PREDICATE returns
24845     non-‘nil’.  The argument given to PREDICATE is either a string or a
24846     cons cell (the CAR of which is a string) from the alist, or a
24847     symbol (_not_ a symbol name) from the obarray.  If COLLECTION is a
24848     hash table, PREDICATE is called with two arguments, the string key
24849     and the associated value.
24850
24851     In addition, to be acceptable, a completion must also match all the
24852     regular expressions in ‘completion-regexp-list’.  (Unless
24853     COLLECTION is a function, in which case that function has to handle
24854     ‘completion-regexp-list’ itself.)
24855
24856     In the first of the following examples, the string ‘foo’ is matched
24857     by three of the alist CARs.  All of the matches begin with the
24858     characters ‘fooba’, so that is the result.  In the second example,
24859     there is only one possible match, and it is exact, so the return
24860     value is ‘t’.
24861
24862          (try-completion
24863           "foo"
24864           '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
24865               ⇒ "fooba"
24866
24867          (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
24868               ⇒ t
24869
24870     In the following example, numerous symbols begin with the
24871     characters ‘forw’, and all of them begin with the word ‘forward’.
24872     In most of the symbols, this is followed with a ‘-’, but not in
24873     all, so no more than ‘forward’ can be completed.
24874
24875          (try-completion "forw" obarray)
24876               ⇒ "forward"
24877
24878     Finally, in the following example, only two of the three possible
24879     matches pass the predicate ‘test’ (the string ‘foobaz’ is too
24880     short).  Both of those begin with the string ‘foobar’.
24881
24882          (defun test (s)
24883            (> (length (car s)) 6))
24884               ⇒ test
24885          (try-completion
24886           "foo"
24887           '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
24888           'test)
24889               ⇒ "foobar"
24890
24891 -- Function: all-completions string collection &optional predicate
24892     This function returns a list of all possible completions of STRING.
24893     The arguments to this function are the same as those of
24894     ‘try-completion’, and it uses ‘completion-regexp-list’ in the same
24895     way that ‘try-completion’ does.
24896
24897     If COLLECTION is a function, it is called with three arguments:
24898     STRING, PREDICATE and ‘t’; then ‘all-completions’ returns whatever
24899     the function returns.  *Note Programmed Completion::.
24900
24901     Here is an example, using the function ‘test’ shown in the example
24902     for ‘try-completion’:
24903
24904          (defun test (s)
24905            (> (length (car s)) 6))
24906               ⇒ test
24907
24908          (all-completions
24909           "foo"
24910           '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
24911           'test)
24912               ⇒ ("foobar1" "foobar2")
24913
24914 -- Function: test-completion string collection &optional predicate
24915     This function returns non-‘nil’ if STRING is a valid completion
24916     alternative specified by COLLECTION and PREDICATE.  The arguments
24917     are the same as in ‘try-completion’.  For instance, if COLLECTION
24918     is a list of strings, this is true if STRING appears in the list
24919     and PREDICATE is satisfied.
24920
24921     This function uses ‘completion-regexp-list’ in the same way that
24922     ‘try-completion’ does.
24923
24924     If PREDICATE is non-‘nil’ and if COLLECTION contains several
24925     strings that are equal to each other, as determined by
24926     ‘compare-strings’ according to ‘completion-ignore-case’, then
24927     PREDICATE should accept either all or none of them.  Otherwise, the
24928     return value of ‘test-completion’ is essentially unpredictable.
24929
24930     If COLLECTION is a function, it is called with three arguments, the
24931     values STRING, PREDICATE and ‘lambda’; whatever it returns,
24932     ‘test-completion’ returns in turn.
24933
24934 -- Function: completion-boundaries string collection predicate suffix
24935     This function returns the boundaries of the field on which
24936     COLLECTION will operate, assuming that STRING holds the text before
24937     point and SUFFIX holds the text after point.
24938
24939     Normally completion operates on the whole string, so for all normal
24940     collections, this will always return ‘(0 . (length SUFFIX))’.  But
24941     more complex completion such as completion on files is done one
24942     field at a time.  For example, completion of ‘"/usr/sh"’ will
24943     include ‘"/usr/share/"’ but not ‘"/usr/share/doc"’ even if
24944     ‘"/usr/share/doc"’ exists.  Also ‘all-completions’ on ‘"/usr/sh"’
24945     will not include ‘"/usr/share/"’ but only ‘"share/"’.  So if STRING
24946     is ‘"/usr/sh"’ and SUFFIX is ‘"e/doc"’, ‘completion-boundaries’
24947     will return ‘(5 . 1)’ which tells us that the COLLECTION will only
24948     return completion information that pertains to the area after
24949     ‘"/usr/"’ and before ‘"/doc"’.
24950
24951   If you store a completion alist in a variable, you should mark the
24952variable as risky by giving it a non-‘nil’ ‘risky-local-variable’
24953property.  *Note File Local Variables::.
24954
24955 -- Variable: completion-ignore-case
24956     If the value of this variable is non-‘nil’, case is not considered
24957     significant in completion.  Within ‘read-file-name’, this variable
24958     is overridden by ‘read-file-name-completion-ignore-case’ (*note
24959     Reading File Names::); within ‘read-buffer’, it is overridden by
24960     ‘read-buffer-completion-ignore-case’ (*note High-Level
24961     Completion::).
24962
24963 -- Variable: completion-regexp-list
24964     This is a list of regular expressions.  The completion functions
24965     only consider a completion acceptable if it matches all regular
24966     expressions in this list, with ‘case-fold-search’ (*note Searching
24967     and Case::) bound to the value of ‘completion-ignore-case’.
24968
24969 -- Macro: lazy-completion-table var fun
24970     This macro provides a way to initialize the variable VAR as a
24971     collection for completion in a lazy way, not computing its actual
24972     contents until they are first needed.  You use this macro to
24973     produce a value that you store in VAR.  The actual computation of
24974     the proper value is done the first time you do completion using
24975     VAR.  It is done by calling FUN with no arguments.  The value FUN
24976     returns becomes the permanent value of VAR.
24977
24978     Here is an example:
24979
24980          (defvar foo (lazy-completion-table foo make-my-alist))
24981
24982   There are several functions that take an existing completion table
24983and return a modified version.  ‘completion-table-case-fold’ returns a
24984case-insensitive table.  ‘completion-table-in-turn’ and
24985‘completion-table-merge’ combine multiple input tables in different
24986ways.  ‘completion-table-subvert’ alters a table to use a different
24987initial prefix.  ‘completion-table-with-quoting’ returns a table
24988suitable for operating on quoted text.
24989‘completion-table-with-predicate’ filters a table with a predicate
24990function.  ‘completion-table-with-terminator’ adds a terminating string.
24991
24992
24993File: elisp.info,  Node: Minibuffer Completion,  Next: Completion Commands,  Prev: Basic Completion,  Up: Completion
24994
2499520.6.2 Completion and the Minibuffer
24996------------------------------------
24997
24998This section describes the basic interface for reading from the
24999minibuffer with completion.
25000
25001 -- Function: completing-read prompt collection &optional predicate
25002          require-match initial history default inherit-input-method
25003     This function reads a string in the minibuffer, assisting the user
25004     by providing completion.  It activates the minibuffer with prompt
25005     PROMPT, which must be a string.
25006
25007     The actual completion is done by passing the completion table
25008     COLLECTION and the completion predicate PREDICATE to the function
25009     ‘try-completion’ (*note Basic Completion::).  This happens in
25010     certain commands bound in the local keymaps used for completion.
25011     Some of these commands also call ‘test-completion’.  Thus, if
25012     PREDICATE is non-‘nil’, it should be compatible with COLLECTION and
25013     ‘completion-ignore-case’.  *Note Definition of test-completion::.
25014
25015     *Note Programmed Completion::, for detailed requirements when
25016     COLLECTION is a function.
25017
25018     The value of the optional argument REQUIRE-MATCH determines how the
25019     user may exit the minibuffer:
25020
25021        • If ‘nil’, the usual minibuffer exit commands work regardless
25022          of the input in the minibuffer.
25023
25024        • If ‘t’, the usual minibuffer exit commands won’t exit unless
25025          the input completes to an element of COLLECTION.
25026
25027        • If ‘confirm’, the user can exit with any input, but is asked
25028          for confirmation if the input is not an element of COLLECTION.
25029
25030        • If ‘confirm-after-completion’, the user can exit with any
25031          input, but is asked for confirmation if the preceding command
25032          was a completion command (i.e., one of the commands in
25033          ‘minibuffer-confirm-exit-commands’) and the resulting input is
25034          not an element of COLLECTION.  *Note Completion Commands::.
25035
25036        • Any other value of REQUIRE-MATCH behaves like ‘t’, except that
25037          the exit commands won’t exit if it performs completion.
25038
25039     However, empty input is always permitted, regardless of the value
25040     of REQUIRE-MATCH; in that case, ‘completing-read’ returns the first
25041     element of DEFAULT, if it is a list; ‘""’, if DEFAULT is ‘nil’; or
25042     DEFAULT.  The string or strings in DEFAULT are also available to
25043     the user through the history commands.
25044
25045     The function ‘completing-read’ uses
25046     ‘minibuffer-local-completion-map’ as the keymap if REQUIRE-MATCH is
25047     ‘nil’, and uses ‘minibuffer-local-must-match-map’ if REQUIRE-MATCH
25048     is non-‘nil’.  *Note Completion Commands::.
25049
25050     The argument HISTORY specifies which history list variable to use
25051     for saving the input and for minibuffer history commands.  It
25052     defaults to ‘minibuffer-history’.  *Note Minibuffer History::.
25053
25054     The argument INITIAL is mostly deprecated; we recommend using a
25055     non-‘nil’ value only in conjunction with specifying a cons cell for
25056     HISTORY.  *Note Initial Input::.  For default input, use DEFAULT
25057     instead.
25058
25059     If the argument INHERIT-INPUT-METHOD is non-‘nil’, then the
25060     minibuffer inherits the current input method (*note Input
25061     Methods::) and the setting of ‘enable-multibyte-characters’ (*note
25062     Text Representations::) from whichever buffer was current before
25063     entering the minibuffer.
25064
25065     If the variable ‘completion-ignore-case’ is non-‘nil’, completion
25066     ignores case when comparing the input against the possible matches.
25067     *Note Basic Completion::.  In this mode of operation, PREDICATE
25068     must also ignore case, or you will get surprising results.
25069
25070     Here’s an example of using ‘completing-read’:
25071
25072          (completing-read
25073           "Complete a foo: "
25074           '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
25075           nil t "fo")
25076
25077          ;; After evaluation of the preceding expression,
25078          ;;   the following appears in the minibuffer:
25079
25080          ---------- Buffer: Minibuffer ----------
25081          Complete a foo: fo★
25082          ---------- Buffer: Minibuffer ----------
25083
25084     If the user then types ‘<DEL> <DEL> b <RET>’, ‘completing-read’
25085     returns ‘barfoo’.
25086
25087     The ‘completing-read’ function binds variables to pass information
25088     to the commands that actually do completion.  They are described in
25089     the following section.
25090
25091 -- Variable: completing-read-function
25092     The value of this variable must be a function, which is called by
25093     ‘completing-read’ to actually do its work.  It should accept the
25094     same arguments as ‘completing-read’.  This can be bound to a
25095     different function to completely override the normal behavior of
25096     ‘completing-read’.
25097
25098
25099File: elisp.info,  Node: Completion Commands,  Next: High-Level Completion,  Prev: Minibuffer Completion,  Up: Completion
25100
2510120.6.3 Minibuffer Commands that Do Completion
25102---------------------------------------------
25103
25104This section describes the keymaps, commands and user options used in
25105the minibuffer to do completion.
25106
25107 -- Variable: minibuffer-completion-table
25108     The value of this variable is the completion table (*note Basic
25109     Completion::) used for completion in the minibuffer.  This is the
25110     global variable that contains what ‘completing-read’ passes to
25111     ‘try-completion’.  It is used by minibuffer completion commands
25112     such as ‘minibuffer-complete-word’.
25113
25114 -- Variable: minibuffer-completion-predicate
25115     This variable’s value is the predicate that ‘completing-read’
25116     passes to ‘try-completion’.  The variable is also used by the other
25117     minibuffer completion functions.
25118
25119 -- Variable: minibuffer-completion-confirm
25120     This variable determines whether Emacs asks for confirmation before
25121     exiting the minibuffer; ‘completing-read’ binds this variable, and
25122     the function ‘minibuffer-complete-and-exit’ checks the value before
25123     exiting.  If the value is ‘nil’, confirmation is not required.  If
25124     the value is ‘confirm’, the user may exit with an input that is not
25125     a valid completion alternative, but Emacs asks for confirmation.
25126     If the value is ‘confirm-after-completion’, the user may exit with
25127     an input that is not a valid completion alternative, but Emacs asks
25128     for confirmation if the user submitted the input right after any of
25129     the completion commands in ‘minibuffer-confirm-exit-commands’.
25130
25131 -- Variable: minibuffer-confirm-exit-commands
25132     This variable holds a list of commands that cause Emacs to ask for
25133     confirmation before exiting the minibuffer, if the REQUIRE-MATCH
25134     argument to ‘completing-read’ is ‘confirm-after-completion’.  The
25135     confirmation is requested if the user attempts to exit the
25136     minibuffer immediately after calling any command in this list.
25137
25138 -- Command: minibuffer-complete-word
25139     This function completes the minibuffer contents by at most a single
25140     word.  Even if the minibuffer contents have only one completion,
25141     ‘minibuffer-complete-word’ does not add any characters beyond the
25142     first character that is not a word constituent.  *Note Syntax
25143     Tables::.
25144
25145 -- Command: minibuffer-complete
25146     This function completes the minibuffer contents as far as possible.
25147
25148 -- Command: minibuffer-complete-and-exit
25149     This function completes the minibuffer contents, and exits if
25150     confirmation is not required, i.e., if
25151     ‘minibuffer-completion-confirm’ is ‘nil’.  If confirmation _is_
25152     required, it is given by repeating this command immediately—the
25153     command is programmed to work without confirmation when run twice
25154     in succession.
25155
25156 -- Command: minibuffer-completion-help
25157     This function creates a list of the possible completions of the
25158     current minibuffer contents.  It works by calling ‘all-completions’
25159     using the value of the variable ‘minibuffer-completion-table’ as
25160     the COLLECTION argument, and the value of
25161     ‘minibuffer-completion-predicate’ as the PREDICATE argument.  The
25162     list of completions is displayed as text in a buffer named
25163     ‘*Completions*’.
25164
25165 -- Function: display-completion-list completions
25166     This function displays COMPLETIONS to the stream in
25167     ‘standard-output’, usually a buffer.  (*Note Read and Print::, for
25168     more information about streams.)  The argument COMPLETIONS is
25169     normally a list of completions just returned by ‘all-completions’,
25170     but it does not have to be.  Each element may be a symbol or a
25171     string, either of which is simply printed.  It can also be a list
25172     of two strings, which is printed as if the strings were
25173     concatenated.  The first of the two strings is the actual
25174     completion, the second string serves as annotation.
25175
25176     This function is called by ‘minibuffer-completion-help’.  A common
25177     way to use it is together with ‘with-output-to-temp-buffer’, like
25178     this:
25179
25180          (with-output-to-temp-buffer "*Completions*"
25181            (display-completion-list
25182              (all-completions (buffer-string) my-alist)))
25183
25184 -- User Option: completion-auto-help
25185     If this variable is non-‘nil’, the completion commands
25186     automatically display a list of possible completions whenever
25187     nothing can be completed because the next character is not uniquely
25188     determined.
25189
25190 -- Variable: minibuffer-local-completion-map
25191     ‘completing-read’ uses this value as the local keymap when an exact
25192     match of one of the completions is not required.  By default, this
25193     keymap makes the following bindings:
25194
25195     ‘?’
25196          ‘minibuffer-completion-help’
25197
25198     <SPC>
25199          ‘minibuffer-complete-word’
25200
25201     <TAB>
25202          ‘minibuffer-complete’
25203
25204     and uses ‘minibuffer-local-map’ as its parent keymap (*note
25205     Definition of minibuffer-local-map::).
25206
25207 -- Variable: minibuffer-local-must-match-map
25208     ‘completing-read’ uses this value as the local keymap when an exact
25209     match of one of the completions is required.  Therefore, no keys
25210     are bound to ‘exit-minibuffer’, the command that exits the
25211     minibuffer unconditionally.  By default, this keymap makes the
25212     following bindings:
25213
25214     ‘C-j’
25215          ‘minibuffer-complete-and-exit’
25216
25217     <RET>
25218          ‘minibuffer-complete-and-exit’
25219
25220     and uses ‘minibuffer-local-completion-map’ as its parent keymap.
25221
25222 -- Variable: minibuffer-local-filename-completion-map
25223     This is a sparse keymap that simply unbinds <SPC>; because
25224     filenames can contain spaces.  The function ‘read-file-name’
25225     combines this keymap with either ‘minibuffer-local-completion-map’
25226     or ‘minibuffer-local-must-match-map’.
25227
25228 -- Variable: minibuffer-beginning-of-buffer-movement
25229     If non-‘nil’, the ‘M-<’ command will move to the end of the prompt
25230     if point is after the end of the prompt.  If point is at or before
25231     the end of the prompt, move to the start of the buffer.  If this
25232     variable is ‘nil’, the command behaves like ‘beginning-of-buffer’.
25233
25234
25235File: elisp.info,  Node: High-Level Completion,  Next: Reading File Names,  Prev: Completion Commands,  Up: Completion
25236
2523720.6.4 High-Level Completion Functions
25238--------------------------------------
25239
25240This section describes the higher-level convenience functions for
25241reading certain sorts of names with completion.
25242
25243   In most cases, you should not call these functions in the middle of a
25244Lisp function.  When possible, do all minibuffer input as part of
25245reading the arguments for a command, in the ‘interactive’ specification.
25246*Note Defining Commands::.
25247
25248 -- Function: read-buffer prompt &optional default require-match
25249          predicate
25250     This function reads the name of a buffer and returns it as a
25251     string.  It prompts with PROMPT.  The argument DEFAULT is the
25252     default name to use, the value to return if the user exits with an
25253     empty minibuffer.  If non-‘nil’, it should be a string, a list of
25254     strings, or a buffer.  If it is a list, the default value is the
25255     first element of this list.  It is mentioned in the prompt, but is
25256     not inserted in the minibuffer as initial input.
25257
25258     The argument PROMPT should be a string ending with a colon and a
25259     space.  If DEFAULT is non-‘nil’, the function inserts it in PROMPT
25260     before the colon to follow the convention for reading from the
25261     minibuffer with a default value (*note Programming Tips::).
25262
25263     The optional argument REQUIRE-MATCH has the same meaning as in
25264     ‘completing-read’.  *Note Minibuffer Completion::.
25265
25266     The optional argument PREDICATE, if non-‘nil’, specifies a function
25267     to filter the buffers that should be considered: the function will
25268     be called with every potential candidate as its argument, and
25269     should return ‘nil’ to reject the candidate, non-‘nil’ to accept
25270     it.
25271
25272     In the following example, the user enters ‘minibuffer.t’, and then
25273     types <RET>.  The argument REQUIRE-MATCH is ‘t’, and the only
25274     buffer name starting with the given input is ‘minibuffer.texi’, so
25275     that name is the value.
25276
25277          (read-buffer "Buffer name: " "foo" t)
25278          ;; After evaluation of the preceding expression,
25279          ;;   the following prompt appears,
25280          ;;   with an empty minibuffer:
25281
25282          ---------- Buffer: Minibuffer ----------
25283          Buffer name (default foo): ★
25284          ---------- Buffer: Minibuffer ----------
25285
25286          ;; The user types ‘minibuffer.t <RET>’.
25287               ⇒ "minibuffer.texi"
25288
25289 -- User Option: read-buffer-function
25290     This variable, if non-‘nil’, specifies a function for reading
25291     buffer names.  ‘read-buffer’ calls this function instead of doing
25292     its usual work, with the same arguments passed to ‘read-buffer’.
25293
25294 -- User Option: read-buffer-completion-ignore-case
25295     If this variable is non-‘nil’, ‘read-buffer’ ignores case when
25296     performing completion while reading the buffer name.
25297
25298 -- Function: read-command prompt &optional default
25299     This function reads the name of a command and returns it as a Lisp
25300     symbol.  The argument PROMPT is used as in ‘read-from-minibuffer’.
25301     Recall that a command is anything for which ‘commandp’ returns ‘t’,
25302     and a command name is a symbol for which ‘commandp’ returns ‘t’.
25303     *Note Interactive Call::.
25304
25305     The argument DEFAULT specifies what to return if the user enters
25306     null input.  It can be a symbol, a string or a list of strings.  If
25307     it is a string, ‘read-command’ interns it before returning it.  If
25308     it is a list, ‘read-command’ interns the first element of this
25309     list.  If DEFAULT is ‘nil’, that means no default has been
25310     specified; then if the user enters null input, the return value is
25311     ‘(intern "")’, that is, a symbol whose name is an empty string, and
25312     whose printed representation is ‘##’ (*note Symbol Type::).
25313
25314          (read-command "Command name? ")
25315
25316          ;; After evaluation of the preceding expression,
25317          ;;   the following prompt appears with an empty minibuffer:
25318
25319          ---------- Buffer: Minibuffer ----------
25320          Command name?
25321          ---------- Buffer: Minibuffer ----------
25322
25323     If the user types ‘forward-c <RET>’, then this function returns
25324     ‘forward-char’.
25325
25326     The ‘read-command’ function is a simplified interface to
25327     ‘completing-read’.  It uses the variable ‘obarray’ so as to
25328     complete in the set of extant Lisp symbols, and it uses the
25329     ‘commandp’ predicate so as to accept only command names:
25330
25331          (read-command PROMPT)
2533225333          (intern (completing-read PROMPT obarray
25334                                   'commandp t nil))
25335
25336 -- Function: read-variable prompt &optional default
25337     This function reads the name of a customizable variable and returns
25338     it as a symbol.  Its arguments have the same form as those of
25339     ‘read-command’.  It behaves just like ‘read-command’, except that
25340     it uses the predicate ‘custom-variable-p’ instead of ‘commandp’.
25341
25342 -- Command: read-color &optional prompt convert allow-empty display
25343     This function reads a string that is a color specification, either
25344     the color’s name or an RGB hex value such as ‘#RRRGGGBBB’.  It
25345     prompts with PROMPT (default: ‘"Color (name or #RGB triplet):"’)
25346     and provides completion for color names, but not for hex RGB
25347     values.  In addition to names of standard colors, completion
25348     candidates include the foreground and background colors at point.
25349
25350     Valid RGB values are described in *note Color Names::.
25351
25352     The function’s return value is the string typed by the user in the
25353     minibuffer.  However, when called interactively or if the optional
25354     argument CONVERT is non-‘nil’, it converts any input color name
25355     into the corresponding RGB value string and instead returns that.
25356     This function requires a valid color specification to be input.
25357     Empty color names are allowed when ALLOW-EMPTY is non-‘nil’ and the
25358     user enters null input.
25359
25360     Interactively, or when DISPLAY is non-‘nil’, the return value is
25361     also displayed in the echo area.
25362
25363   See also the functions ‘read-coding-system’ and
25364‘read-non-nil-coding-system’, in *note User-Chosen Coding Systems::, and
25365‘read-input-method-name’, in *note Input Methods::.
25366
25367
25368File: elisp.info,  Node: Reading File Names,  Next: Completion Variables,  Prev: High-Level Completion,  Up: Completion
25369
2537020.6.5 Reading File Names
25371-------------------------
25372
25373The high-level completion functions ‘read-file-name’,
25374‘read-directory-name’, and ‘read-shell-command’ are designed to read
25375file names, directory names, and shell commands, respectively.  They
25376provide special features, including automatic insertion of the default
25377directory.
25378
25379 -- Function: read-file-name prompt &optional directory default
25380          require-match initial predicate
25381     This function reads a file name, prompting with PROMPT and
25382     providing completion.
25383
25384     As an exception, this function reads a file name using a graphical
25385     file dialog instead of the minibuffer, if all of the following are
25386     true:
25387
25388       1. It is invoked via a mouse command.
25389
25390       2. The selected frame is on a graphical display supporting such
25391          dialogs.
25392
25393       3. The variable ‘use-dialog-box’ is non-‘nil’.  *Note Dialog
25394          Boxes: (emacs)Dialog Boxes.
25395
25396       4. The DIRECTORY argument, described below, does not specify a
25397          remote file.  *Note Remote Files: (emacs)Remote Files.
25398
25399     The exact behavior when using a graphical file dialog is
25400     platform-dependent.  Here, we simply document the behavior when
25401     using the minibuffer.
25402
25403     ‘read-file-name’ does not automatically expand the returned file
25404     name.  You can call ‘expand-file-name’ yourself if an absolute file
25405     name is required.
25406
25407     The optional argument REQUIRE-MATCH has the same meaning as in
25408     ‘completing-read’.  *Note Minibuffer Completion::.
25409
25410     The argument DIRECTORY specifies the directory to use for
25411     completing relative file names.  It should be an absolute directory
25412     name.  If the variable ‘insert-default-directory’ is non-‘nil’,
25413     DIRECTORY is also inserted in the minibuffer as initial input.  It
25414     defaults to the current buffer’s value of ‘default-directory’.
25415
25416     If you specify INITIAL, that is an initial file name to insert in
25417     the buffer (after DIRECTORY, if that is inserted).  In this case,
25418     point goes at the beginning of INITIAL.  The default for INITIAL is
25419     ‘nil’—don’t insert any file name.  To see what INITIAL does, try
25420     the command ‘C-x C-v’ in a buffer visiting a file.  *Please note:*
25421     we recommend using DEFAULT rather than INITIAL in most cases.
25422
25423     If DEFAULT is non-‘nil’, then the function returns DEFAULT if the
25424     user exits the minibuffer with the same non-empty contents that
25425     ‘read-file-name’ inserted initially.  The initial minibuffer
25426     contents are always non-empty if ‘insert-default-directory’ is
25427     non-‘nil’, as it is by default.  DEFAULT is not checked for
25428     validity, regardless of the value of REQUIRE-MATCH.  However, if
25429     REQUIRE-MATCH is non-‘nil’, the initial minibuffer contents should
25430     be a valid file (or directory) name.  Otherwise ‘read-file-name’
25431     attempts completion if the user exits without any editing, and does
25432     not return DEFAULT.  DEFAULT is also available through the history
25433     commands.
25434
25435     If DEFAULT is ‘nil’, ‘read-file-name’ tries to find a substitute
25436     default to use in its place, which it treats in exactly the same
25437     way as if it had been specified explicitly.  If DEFAULT is ‘nil’,
25438     but INITIAL is non-‘nil’, then the default is the absolute file
25439     name obtained from DIRECTORY and INITIAL.  If both DEFAULT and
25440     INITIAL are ‘nil’ and the buffer is visiting a file,
25441     ‘read-file-name’ uses the absolute file name of that file as
25442     default.  If the buffer is not visiting a file, then there is no
25443     default.  In that case, if the user types <RET> without any
25444     editing, ‘read-file-name’ simply returns the pre-inserted contents
25445     of the minibuffer.
25446
25447     If the user types <RET> in an empty minibuffer, this function
25448     returns an empty string, regardless of the value of REQUIRE-MATCH.
25449     This is, for instance, how the user can make the current buffer
25450     visit no file using ‘M-x set-visited-file-name’.
25451
25452     If PREDICATE is non-‘nil’, it specifies a function of one argument
25453     that decides which file names are acceptable completion
25454     alternatives.  A file name is an acceptable value if PREDICATE
25455     returns non-‘nil’ for it.
25456
25457     Here is an example of using ‘read-file-name’:
25458
25459          (read-file-name "The file is ")
25460
25461          ;; After evaluation of the preceding expression,
25462          ;;   the following appears in the minibuffer:
25463
25464          ---------- Buffer: Minibuffer ----------
25465          The file is /gp/gnu/elisp/★
25466          ---------- Buffer: Minibuffer ----------
25467
25468     Typing ‘manual <TAB>’ results in the following:
25469
25470          ---------- Buffer: Minibuffer ----------
25471          The file is /gp/gnu/elisp/manual.texi25472          ---------- Buffer: Minibuffer ----------
25473
25474     If the user types <RET>, ‘read-file-name’ returns the file name as
25475     the string ‘"/gp/gnu/elisp/manual.texi"’.
25476
25477 -- Variable: read-file-name-function
25478     If non-‘nil’, this should be a function that accepts the same
25479     arguments as ‘read-file-name’.  When ‘read-file-name’ is called, it
25480     calls this function with the supplied arguments instead of doing
25481     its usual work.
25482
25483 -- User Option: read-file-name-completion-ignore-case
25484     If this variable is non-‘nil’, ‘read-file-name’ ignores case when
25485     performing completion.
25486
25487 -- Function: read-directory-name prompt &optional directory default
25488          require-match initial
25489     This function is like ‘read-file-name’ but allows only directory
25490     names as completion alternatives.
25491
25492     If DEFAULT is ‘nil’ and INITIAL is non-‘nil’, ‘read-directory-name’
25493     constructs a substitute default by combining DIRECTORY (or the
25494     current buffer’s default directory if DIRECTORY is ‘nil’) and
25495     INITIAL.  If both DEFAULT and INITIAL are ‘nil’, this function uses
25496     DIRECTORY as substitute default, or the current buffer’s default
25497     directory if DIRECTORY is ‘nil’.
25498
25499 -- User Option: insert-default-directory
25500     This variable is used by ‘read-file-name’, and thus, indirectly, by
25501     most commands reading file names.  (This includes all commands that
25502     use the code letters ‘f’ or ‘F’ in their interactive form.  *Note
25503     Code Characters for interactive: Interactive Codes.)  Its value
25504     controls whether ‘read-file-name’ starts by placing the name of the
25505     default directory in the minibuffer, plus the initial file name, if
25506     any.  If the value of this variable is ‘nil’, then ‘read-file-name’
25507     does not place any initial input in the minibuffer (unless you
25508     specify initial input with the INITIAL argument).  In that case,
25509     the default directory is still used for completion of relative file
25510     names, but is not displayed.
25511
25512     If this variable is ‘nil’ and the initial minibuffer contents are
25513     empty, the user may have to explicitly fetch the next history
25514     element to access a default value.  If the variable is non-‘nil’,
25515     the initial minibuffer contents are always non-empty and the user
25516     can always request a default value by immediately typing <RET> in
25517     an unedited minibuffer.  (See above.)
25518
25519     For example:
25520
25521          ;; Here the minibuffer starts out with the default directory.
25522          (let ((insert-default-directory t))
25523            (read-file-name "The file is "))
25524
25525          ---------- Buffer: Minibuffer ----------
25526          The file is ~lewis/manual/★
25527          ---------- Buffer: Minibuffer ----------
25528
25529          ;; Here the minibuffer is empty and only the prompt
25530          ;;   appears on its line.
25531          (let ((insert-default-directory nil))
25532            (read-file-name "The file is "))
25533
25534          ---------- Buffer: Minibuffer ----------
25535          The file is ★
25536          ---------- Buffer: Minibuffer ----------
25537
25538 -- Function: read-shell-command prompt &optional initial history &rest
25539          args
25540     This function reads a shell command from the minibuffer, prompting
25541     with PROMPT and providing intelligent completion.  It completes the
25542     first word of the command using candidates that are appropriate for
25543     command names, and the rest of the command words as file names.
25544
25545     This function uses ‘minibuffer-local-shell-command-map’ as the
25546     keymap for minibuffer input.  The HISTORY argument specifies the
25547     history list to use; if is omitted or ‘nil’, it defaults to
25548     ‘shell-command-history’ (*note shell-command-history: Minibuffer
25549     History.).  The optional argument INITIAL specifies the initial
25550     content of the minibuffer (*note Initial Input::).  The rest of
25551     ARGS, if present, are used as the DEFAULT and INHERIT-INPUT-METHOD
25552     arguments in ‘read-from-minibuffer’ (*note Text from Minibuffer::).
25553
25554 -- Variable: minibuffer-local-shell-command-map
25555     This keymap is used by ‘read-shell-command’ for completing command
25556     and file names that are part of a shell command.  It uses
25557     ‘minibuffer-local-map’ as its parent keymap, and binds <TAB> to
25558     ‘completion-at-point’.
25559
25560
25561File: elisp.info,  Node: Completion Variables,  Next: Programmed Completion,  Prev: Reading File Names,  Up: Completion
25562
2556320.6.6 Completion Variables
25564---------------------------
25565
25566Here are some variables that can be used to alter the default completion
25567behavior.
25568
25569 -- User Option: completion-styles
25570     The value of this variable is a list of completion style (symbols)
25571     to use for performing completion.  A “completion style” is a set of
25572     rules for generating completions.  Each symbol occurring this list
25573     must have a corresponding entry in ‘completion-styles-alist’.
25574
25575 -- Variable: completion-styles-alist
25576     This variable stores a list of available completion styles.  Each
25577     element in the list has the form
25578
25579          (STYLE TRY-COMPLETION ALL-COMPLETIONS DOC)
25580
25581     Here, STYLE is the name of the completion style (a symbol), which
25582     may be used in the ‘completion-styles’ variable to refer to this
25583     style; TRY-COMPLETION is the function that does the completion;
25584     ALL-COMPLETIONS is the function that lists the completions; and DOC
25585     is a string describing the completion style.
25586
25587     The TRY-COMPLETION and ALL-COMPLETIONS functions should each accept
25588     four arguments: STRING, COLLECTION, PREDICATE, and POINT.  The
25589     STRING, COLLECTION, and PREDICATE arguments have the same meanings
25590     as in ‘try-completion’ (*note Basic Completion::), and the POINT
25591     argument is the position of point within STRING.  Each function
25592     should return a non-‘nil’ value if it performed its job, and ‘nil’
25593     if it did not (e.g., if there is no way to complete STRING
25594     according to the completion style).
25595
25596     When the user calls a completion command like ‘minibuffer-complete’
25597     (*note Completion Commands::), Emacs looks for the first style
25598     listed in ‘completion-styles’ and calls its TRY-COMPLETION
25599     function.  If this function returns ‘nil’, Emacs moves to the next
25600     listed completion style and calls its TRY-COMPLETION function, and
25601     so on until one of the TRY-COMPLETION functions successfully
25602     performs completion and returns a non-‘nil’ value.  A similar
25603     procedure is used for listing completions, via the ALL-COMPLETIONS
25604     functions.
25605
25606     *Note (emacs)Completion Styles::, for a description of the
25607     available completion styles.
25608
25609 -- User Option: completion-category-overrides
25610     This variable specifies special completion styles and other
25611     completion behaviors to use when completing certain types of text.
25612     Its value should be an alist with elements of the form ‘(CATEGORY .
25613     ALIST)’.  CATEGORY is a symbol describing what is being completed;
25614     currently, the ‘buffer’, ‘file’, and ‘unicode-name’ categories are
25615     defined, but others can be defined via specialized completion
25616     functions (*note Programmed Completion::).  ALIST is an association
25617     list describing how completion should behave for the corresponding
25618     category.  The following alist keys are supported:
25619
25620     ‘styles’
25621          The value should be a list of completion styles (symbols).
25622
25623     ‘cycle’
25624          The value should be a value for ‘completion-cycle-threshold’
25625          (*note (emacs)Completion Options::) for this category.
25626
25627     Additional alist entries may be defined in the future.
25628
25629 -- Variable: completion-extra-properties
25630     This variable is used to specify extra properties of the current
25631     completion command.  It is intended to be let-bound by specialized
25632     completion commands.  Its value should be a list of property and
25633     value pairs.  The following properties are supported:
25634
25635     ‘:annotation-function’
25636          The value should be a function to add annotations in the
25637          completions buffer.  This function must accept one argument, a
25638          completion, and should either return ‘nil’ or a string to be
25639          displayed next to the completion.
25640
25641     ‘:exit-function’
25642          The value should be a function to run after performing
25643          completion.  The function should accept two arguments, STRING
25644          and STATUS, where STRING is the text to which the field was
25645          completed, and STATUS indicates what kind of operation
25646          happened: ‘finished’ if text is now complete, ‘sole’ if the
25647          text cannot be further completed but completion is not
25648          finished, or ‘exact’ if the text is a valid completion but may
25649          be further completed.
25650
25651
25652File: elisp.info,  Node: Programmed Completion,  Next: Completion in Buffers,  Prev: Completion Variables,  Up: Completion
25653
2565420.6.7 Programmed Completion
25655----------------------------
25656
25657Sometimes it is not possible or convenient to create an alist or an
25658obarray containing all the intended possible completions ahead of time.
25659In such a case, you can supply your own function to compute the
25660completion of a given string.  This is called “programmed completion”.
25661Emacs uses programmed completion when completing file names (*note File
25662Name Completion::), among many other cases.
25663
25664   To use this feature, pass a function as the COLLECTION argument to
25665‘completing-read’.  The function ‘completing-read’ arranges to pass your
25666completion function along to ‘try-completion’, ‘all-completions’, and
25667other basic completion functions, which will then let your function do
25668all the work.
25669
25670   The completion function should accept three arguments:
25671
25672   • The string to be completed.
25673
25674   • A predicate function with which to filter possible matches, or
25675     ‘nil’ if none.  The function should call the predicate for each
25676     possible match, and ignore the match if the predicate returns
25677     ‘nil’.
25678
25679   • A flag specifying the type of completion operation to perform; see
25680     *note Basic Completion::, for the details of those operations.
25681     This flag may be one of the following values.
25682
25683     ‘nil’
25684          This specifies a ‘try-completion’ operation.  The function
25685          should return ‘nil’ if there are no matches; it should return
25686          ‘t’ if the specified string is a unique and exact match; and
25687          it should return the longest common prefix substring of all
25688          matches otherwise.
25689
25690     ‘t’
25691          This specifies an ‘all-completions’ operation.  The function
25692          should return a list of all possible completions of the
25693          specified string.
25694
25695     ‘lambda’
25696          This specifies a ‘test-completion’ operation.  The function
25697          should return ‘t’ if the specified string is an exact match
25698          for some completion alternative; ‘nil’ otherwise.
25699
25700     ‘(boundaries . SUFFIX)’
25701          This specifies a ‘completion-boundaries’ operation.  The
25702          function should return ‘(boundaries START . END)’, where START
25703          is the position of the beginning boundary in the specified
25704          string, and END is the position of the end boundary in SUFFIX.
25705
25706     ‘metadata’
25707          This specifies a request for information about the state of
25708          the current completion.  The return value should have the form
25709          ‘(metadata . ALIST)’, where ALIST is an alist whose elements
25710          are described below.
25711
25712     If the flag has any other value, the completion function should
25713     return ‘nil’.
25714
25715   The following is a list of metadata entries that a completion
25716function may return in response to a ‘metadata’ flag argument:
25717
25718‘category’
25719     The value should be a symbol describing what kind of text the
25720     completion function is trying to complete.  If the symbol matches
25721     one of the keys in ‘completion-category-overrides’, the usual
25722     completion behavior is overridden.  *Note Completion Variables::.
25723
25724‘annotation-function’
25725     The value should be a function for “annotating” completions.  The
25726     function should take one argument, STRING, which is a possible
25727     completion.  It should return a string, which is displayed after
25728     the completion STRING in the ‘*Completions*’ buffer.
25729
25730‘display-sort-function’
25731     The value should be a function for sorting completions.  The
25732     function should take one argument, a list of completion strings,
25733     and return a sorted list of completion strings.  It is allowed to
25734     alter the input list destructively.
25735
25736‘cycle-sort-function’
25737     The value should be a function for sorting completions, when
25738     ‘completion-cycle-threshold’ is non-‘nil’ and the user is cycling
25739     through completion alternatives.  *Note (emacs)Completion
25740     Options::.  Its argument list and return value are the same as for
25741     ‘display-sort-function’.
25742
25743 -- Function: completion-table-dynamic function &optional switch-buffer
25744     This function is a convenient way to write a function that can act
25745     as a programmed completion function.  The argument FUNCTION should
25746     be a function that takes one argument, a string, and returns a
25747     completion table (*note Basic Completion::) containing all the
25748     possible completions.  The table returned by FUNCTION can also
25749     include elements that don’t match the string argument; they are
25750     automatically filtered out by ‘completion-table-dynamic’.  In
25751     particular, FUNCTION can ignore its argument and return a full list
25752     of all possible completions.  You can think of
25753     ‘completion-table-dynamic’ as a transducer between FUNCTION and the
25754     interface for programmed completion functions.
25755
25756     If the optional argument SWITCH-BUFFER is non-‘nil’, and completion
25757     is performed in the minibuffer, FUNCTION will be called with
25758     current buffer set to the buffer from which the minibuffer was
25759     entered.
25760
25761     The return value of ‘completion-table-dynamic’ is a function that
25762     can be used as the 2nd argument to ‘try-completion’ and
25763     ‘all-completions’.  Note that this function will always return
25764     empty metadata and trivial boundaries (*note Programmed
25765     Completion::).
25766
25767 -- Function: completion-table-with-cache function &optional ignore-case
25768     This is a wrapper for ‘completion-table-dynamic’ that saves the
25769     last argument-result pair.  This means that multiple lookups with
25770     the same argument only need to call FUNCTION once.  This can be
25771     useful when a slow operation is involved, such as calling an
25772     external process.
25773
25774
25775File: elisp.info,  Node: Completion in Buffers,  Prev: Programmed Completion,  Up: Completion
25776
2577720.6.8 Completion in Ordinary Buffers
25778-------------------------------------
25779
25780Although completion is usually done in the minibuffer, the completion
25781facility can also be used on the text in ordinary Emacs buffers.  In
25782many major modes, in-buffer completion is performed by the ‘C-M-i’ or
25783‘M-<TAB>’ command, bound to ‘completion-at-point’.  *Note (emacs)Symbol
25784Completion::.  This command uses the abnormal hook variable
25785‘completion-at-point-functions’:
25786
25787 -- Variable: completion-at-point-functions
25788     The value of this abnormal hook should be a list of functions,
25789     which are used to compute a completion table (*note Basic
25790     Completion::) for completing the text at point.  It can be used by
25791     major modes to provide mode-specific completion tables (*note Major
25792     Mode Conventions::).
25793
25794     When the command ‘completion-at-point’ runs, it calls the functions
25795     in the list one by one, without any argument.  Each function should
25796     return ‘nil’ unless it can and wants to take responsibility for the
25797     completion data for the text at point.  Otherwise it should return
25798     a list of the following form:
25799
25800          (START END COLLECTION . PROPS)
25801
25802     START and END delimit the text to complete (which should enclose
25803     point).  COLLECTION is a completion table for completing that text,
25804     in a form suitable for passing as the second argument to
25805     ‘try-completion’ (*note Basic Completion::); completion
25806     alternatives will be generated from this completion table in the
25807     usual way, via the completion styles defined in ‘completion-styles’
25808     (*note Completion Variables::).  PROPS is a property list for
25809     additional information; any of the properties in
25810     ‘completion-extra-properties’ are recognized (*note Completion
25811     Variables::), as well as the following additional ones:
25812
25813     ‘:predicate’
25814          The value should be a predicate that completion candidates
25815          need to satisfy.
25816
25817     ‘:exclusive’
25818          If the value is ‘no’, then if the completion table fails to
25819          match the text at point, ‘completion-at-point’ moves on to the
25820          next function in ‘completion-at-point-functions’ instead of
25821          reporting a completion failure.
25822
25823     The functions on this hook should generally return quickly, since
25824     they may be called very often (e.g., from ‘post-command-hook’).
25825     Supplying a function for COLLECTION is strongly recommended if
25826     generating the list of completions is an expensive operation.
25827     Emacs may internally call functions in
25828     ‘completion-at-point-functions’ many times, but care about the
25829     value of COLLECTION for only some of these calls.  By supplying a
25830     function for COLLECTION, Emacs can defer generating completions
25831     until necessary.  You can use ‘completion-table-dynamic’ to create
25832     a wrapper function:
25833
25834          ;; Avoid this pattern.
25835          (let ((beg ...) (end ...) (my-completions (my-make-completions)))
25836            (list beg end my-completions))
25837
25838          ;; Use this instead.
25839          (let ((beg ...) (end ...))
25840            (list beg
25841                  end
25842                  (completion-table-dynamic
25843                    (lambda (_)
25844                      (my-make-completions)))))
25845
25846     Additionally, the COLLECTION should generally not be pre-filtered
25847     based on the current text between START and END, because that is
25848     the responsibility of the caller of ‘completion-at-point-functions’
25849     to do that according to the completion styles it decides to use.
25850
25851     A function in ‘completion-at-point-functions’ may also return a
25852     function instead of a list as described above.  In that case, that
25853     returned function is called, with no argument, and it is entirely
25854     responsible for performing the completion.  We discourage this
25855     usage; it is only intended to help convert old code to using
25856     ‘completion-at-point’.
25857
25858     The first function in ‘completion-at-point-functions’ to return a
25859     non-‘nil’ value is used by ‘completion-at-point’.  The remaining
25860     functions are not called.  The exception to this is when there is
25861     an ‘:exclusive’ specification, as described above.
25862
25863   The following function provides a convenient way to perform
25864completion on an arbitrary stretch of text in an Emacs buffer:
25865
25866 -- Function: completion-in-region start end collection &optional
25867          predicate
25868     This function completes the text in the current buffer between the
25869     positions START and END, using COLLECTION.  The argument COLLECTION
25870     has the same meaning as in ‘try-completion’ (*note Basic
25871     Completion::).
25872
25873     This function inserts the completion text directly into the current
25874     buffer.  Unlike ‘completing-read’ (*note Minibuffer Completion::),
25875     it does not activate the minibuffer.
25876
25877     For this function to work, point must be somewhere between START
25878     and END.
25879
25880
25881File: elisp.info,  Node: Yes-or-No Queries,  Next: Multiple Queries,  Prev: Completion,  Up: Minibuffers
25882
2588320.7 Yes-or-No Queries
25884======================
25885
25886This section describes functions used to ask the user a yes-or-no
25887question.  The function ‘y-or-n-p’ can be answered with a single
25888character; it is useful for questions where an inadvertent wrong answer
25889will not have serious consequences.  ‘yes-or-no-p’ is suitable for more
25890momentous questions, since it requires three or four characters to
25891answer.
25892
25893   If either of these functions is called in a command that was invoked
25894using the mouse—more precisely, if ‘last-nonmenu-event’ (*note Command
25895Loop Info::) is either ‘nil’ or a list—then it uses a dialog box or
25896pop-up menu to ask the question.  Otherwise, it uses keyboard input.
25897You can force use either of the mouse or of keyboard input by binding
25898‘last-nonmenu-event’ to a suitable value around the call.
25899
25900   Both ‘yes-or-no-p’ and ‘y-or-n-p’ use the minibuffer.
25901
25902 -- Function: y-or-n-p prompt
25903     This function asks the user a question, expecting input in the
25904     minibuffer.  It returns ‘t’ if the user types ‘y’, ‘nil’ if the
25905     user types ‘n’.  This function also accepts <SPC> to mean yes and
25906     <DEL> to mean no.  It accepts ‘C-]’ and ‘C-g’ to quit, because the
25907     question uses the minibuffer and for that reason the user might try
25908     to use ‘C-]’ to get out.  The answer is a single character, with no
25909     <RET> needed to terminate it.  Upper and lower case are equivalent.
25910
25911     “Asking the question” means printing PROMPT in the minibuffer,
25912     followed by the string ‘(y or n) ’.  If the input is not one of the
25913     expected answers (‘y’, ‘n’, ‘<SPC>’, ‘<DEL>’, or something that
25914     quits), the function responds ‘Please answer y or n.’, and repeats
25915     the request.
25916
25917     This function actually uses the minibuffer, but does not allow
25918     editing of the answer.  The cursor moves to the minibuffer while
25919     the question is being asked.
25920
25921     The answers and their meanings, even ‘y’ and ‘n’, are not
25922     hardwired, and are specified by the keymap ‘query-replace-map’
25923     (*note Search and Replace::).  In particular, if the user enters
25924     the special responses ‘recenter’, ‘scroll-up’, ‘scroll-down’,
25925     ‘scroll-other-window’, or ‘scroll-other-window-down’ (respectively
25926     bound to ‘C-l’, ‘C-v’, ‘M-v’, ‘C-M-v’ and ‘C-M-S-v’ in
25927     ‘query-replace-map’), this function performs the specified window
25928     recentering or scrolling operation, and poses the question again.
25929
25930 -- Function: y-or-n-p-with-timeout prompt seconds default
25931     Like ‘y-or-n-p’, except that if the user fails to answer within
25932     SECONDS seconds, this function stops waiting and returns DEFAULT.
25933     It works by setting up a timer; see *note Timers::.  The argument
25934     SECONDS should be a number.
25935
25936 -- Function: yes-or-no-p prompt
25937     This function asks the user a question, expecting input in the
25938     minibuffer.  It returns ‘t’ if the user enters ‘yes’, ‘nil’ if the
25939     user types ‘no’.  The user must type <RET> to finalize the
25940     response.  Upper and lower case are equivalent.
25941
25942     ‘yes-or-no-p’ starts by displaying PROMPT in the minibuffer,
25943     followed by ‘(yes or no) ’.  The user must type one of the expected
25944     responses; otherwise, the function responds ‘Please answer yes or
25945     no.’, waits about two seconds and repeats the request.
25946
25947     ‘yes-or-no-p’ requires more work from the user than ‘y-or-n-p’ and
25948     is appropriate for more crucial decisions.
25949
25950     Here is an example:
25951
25952          (yes-or-no-p "Do you really want to remove everything? ")
25953
25954          ;; After evaluation of the preceding expression,
25955          ;;   the following prompt appears,
25956          ;;   with an empty minibuffer:
25957
25958          ---------- Buffer: minibuffer ----------
25959          Do you really want to remove everything? (yes or no)
25960          ---------- Buffer: minibuffer ----------
25961
25962     If the user first types ‘y <RET>’, which is invalid because this
25963     function demands the entire word ‘yes’, it responds by displaying
25964     these prompts, with a brief pause between them:
25965
25966          ---------- Buffer: minibuffer ----------
25967          Please answer yes or no.
25968          Do you really want to remove everything? (yes or no)
25969          ---------- Buffer: minibuffer ----------
25970
25971
25972File: elisp.info,  Node: Multiple Queries,  Next: Reading a Password,  Prev: Yes-or-No Queries,  Up: Minibuffers
25973
2597420.8 Asking Multiple-Choice Questions
25975=====================================
25976
25977This section describes facilities for asking the user more complex
25978questions or several similar questions.
25979
25980   When you have a series of similar questions to ask, such as “Do you
25981want to save this buffer?” for each buffer in turn, you should use
25982‘map-y-or-n-p’ to ask the collection of questions, rather than asking
25983each question individually.  This gives the user certain convenient
25984facilities such as the ability to answer the whole series at once.
25985
25986 -- Function: map-y-or-n-p prompter actor list &optional help
25987          action-alist no-cursor-in-echo-area
25988     This function asks the user a series of questions, reading a
25989     single-character answer in the echo area for each one.
25990
25991     The value of LIST specifies the objects to ask questions about.  It
25992     should be either a list of objects or a generator function.  If it
25993     is a function, it should expect no arguments, and should return
25994     either the next object to ask about, or ‘nil’, meaning to stop
25995     asking questions.
25996
25997     The argument PROMPTER specifies how to ask each question.  If
25998     PROMPTER is a string, the question text is computed like this:
25999
26000          (format PROMPTER OBJECT)
26001
26002     where OBJECT is the next object to ask about (as obtained from
26003     LIST).
26004
26005     If not a string, PROMPTER should be a function of one argument (the
26006     next object to ask about) and should return the question text.  If
26007     the value is a string, that is the question to ask the user.  The
26008     function can also return ‘t’, meaning do act on this object (and
26009     don’t ask the user), or ‘nil’, meaning ignore this object (and
26010     don’t ask the user).
26011
26012     The argument ACTOR says how to act on the answers that the user
26013     gives.  It should be a function of one argument, and it is called
26014     with each object that the user says yes for.  Its argument is
26015     always an object obtained from LIST.
26016
26017     If the argument HELP is given, it should be a list of this form:
26018
26019          (SINGULAR PLURAL ACTION)
26020
26021     where SINGULAR is a string containing a singular noun that
26022     describes the objects conceptually being acted on, PLURAL is the
26023     corresponding plural noun, and ACTION is a transitive verb
26024     describing what ACTOR does.
26025
26026     If you don’t specify HELP, the default is ‘("object" "objects" "act
26027     on")’.
26028
26029     Each time a question is asked, the user may enter ‘y’, ‘Y’, or
26030     <SPC> to act on that object; ‘n’, ‘N’, or <DEL> to skip that
26031     object; ‘!’ to act on all following objects; <ESC> or ‘q’ to exit
26032     (skip all following objects); ‘.’ (period) to act on the current
26033     object and then exit; or ‘C-h’ to get help.  These are the same
26034     answers that ‘query-replace’ accepts.  The keymap
26035     ‘query-replace-map’ defines their meaning for ‘map-y-or-n-p’ as
26036     well as for ‘query-replace’; see *note Search and Replace::.
26037
26038     You can use ACTION-ALIST to specify additional possible answers and
26039     what they mean.  It is an alist of elements of the form ‘(CHAR
26040     FUNCTION HELP)’, each of which defines one additional answer.  In
26041     this element, CHAR is a character (the answer); FUNCTION is a
26042     function of one argument (an object from LIST); HELP is a string.
26043
26044     When the user responds with CHAR, ‘map-y-or-n-p’ calls FUNCTION.
26045     If it returns non-‘nil’, the object is considered acted upon, and
26046     ‘map-y-or-n-p’ advances to the next object in LIST.  If it returns
26047     ‘nil’, the prompt is repeated for the same object.
26048
26049     Normally, ‘map-y-or-n-p’ binds ‘cursor-in-echo-area’ while
26050     prompting.  But if NO-CURSOR-IN-ECHO-AREA is non-‘nil’, it does not
26051     do that.
26052
26053     If ‘map-y-or-n-p’ is called in a command that was invoked using the
26054     mouse—more precisely, if ‘last-nonmenu-event’ (*note Command Loop
26055     Info::) is either ‘nil’ or a list—then it uses a dialog box or
26056     pop-up menu to ask the question.  In this case, it does not use
26057     keyboard input or the echo area.  You can force use either of the
26058     mouse or of keyboard input by binding ‘last-nonmenu-event’ to a
26059     suitable value around the call.
26060
26061     The return value of ‘map-y-or-n-p’ is the number of objects acted
26062     on.
26063
26064   If you need to ask the user a question that might have more than just
260652 answers, use ‘read-answer’.
26066
26067 -- Function: read-answer question answers
26068     This function prompts the user with text in QUESTION, which should
26069     end in the ‘SPC’ character.  The function includes in the prompt
26070     the possible responses in ANSWERS by appending them to the end of
26071     QUESTION.  The possible responses are provided in ANSWERS as an
26072     alist whose elements are of the following form:
26073
26074          (LONG-ANSWER SHORT-ANSWER HELP-MESSAGE)
26075
26076     where LONG-ANSWER is the complete text of the user response, a
26077     string; SHORT-ANSWER is a short form of the same response, a single
26078     character or a function key; and HELP-MESSAGE is the text that
26079     describes the meaning of the answer.  If the variable
26080     ‘read-answer-short’ is non-‘nil’, the prompt will show the short
26081     variants of the possible answers and the user is expected to type
26082     the single characters/keys shown in the prompt; otherwise the
26083     prompt will show the long variants of the answers, and the user is
26084     expected to type the full text of one of the answers and end by
26085     pressing <RET>.  If ‘use-dialog-box’ is non-‘nil’, and this
26086     function was invoked by mouse events, the question and the answers
26087     will be displayed in a GUI dialog box.
26088
26089     The function returns the text of the LONG-ANSWER selected by the
26090     user, regardless of whether long or short answers were shown in the
26091     prompt and typed by the user.
26092
26093     Here is an example of using this function:
26094
26095          (let ((read-answer-short t))
26096            (read-answer "Foo "
26097               '(("yes"  ?y "perform the action")
26098                 ("no"   ?n "skip to the next")
26099                 ("all"  ?! "perform for the rest without more questions")
26100                 ("help" ?h "show help")
26101                 ("quit" ?q "exit"))))
26102
26103 -- Function: read-char-from-minibuffer prompt &optional chars history
26104     This function uses the minibuffer to read and return a single
26105     character.  Optionally, it ignores any input that is not a member
26106     of CHARS, a list of accepted characters.  The HISTORY argument
26107     specifies the history list symbol to use; if it is omitted or
26108     ‘nil’, this function doesn’t use the history.
26109
26110
26111File: elisp.info,  Node: Reading a Password,  Next: Minibuffer Commands,  Prev: Multiple Queries,  Up: Minibuffers
26112
2611320.9 Reading a Password
26114=======================
26115
26116To read a password to pass to another program, you can use the function
26117‘read-passwd’.
26118
26119 -- Function: read-passwd prompt &optional confirm default
26120     This function reads a password, prompting with PROMPT.  It does not
26121     echo the password as the user types it; instead, it echoes ‘*’ for
26122     each character in the password.  If you want to apply another
26123     character to hide the password, let-bind the variable
26124     ‘read-hide-char’ with that character.
26125
26126     The optional argument CONFIRM, if non-‘nil’, says to read the
26127     password twice and insist it must be the same both times.  If it
26128     isn’t the same, the user has to type it over and over until the
26129     last two times match.
26130
26131     The optional argument DEFAULT specifies the default password to
26132     return if the user enters empty input.  If DEFAULT is ‘nil’, then
26133     ‘read-passwd’ returns the null string in that case.
26134
26135
26136File: elisp.info,  Node: Minibuffer Commands,  Next: Minibuffer Windows,  Prev: Reading a Password,  Up: Minibuffers
26137
2613820.10 Minibuffer Commands
26139=========================
26140
26141This section describes some commands meant for use in the minibuffer.
26142
26143 -- Command: exit-minibuffer
26144     This command exits the active minibuffer.  It is normally bound to
26145     keys in minibuffer local keymaps.
26146
26147 -- Command: self-insert-and-exit
26148     This command exits the active minibuffer after inserting the last
26149     character typed on the keyboard (found in ‘last-command-event’;
26150     *note Command Loop Info::).
26151
26152 -- Command: previous-history-element n
26153     This command replaces the minibuffer contents with the value of the
26154     Nth previous (older) history element.
26155
26156 -- Command: next-history-element n
26157     This command replaces the minibuffer contents with the value of the
26158     Nth more recent history element.  The position in the history can
26159     go beyond the current position and invoke “future history” (*note
26160     Text from Minibuffer::).
26161
26162 -- Command: previous-matching-history-element pattern n
26163     This command replaces the minibuffer contents with the value of the
26164     Nth previous (older) history element that matches PATTERN (a
26165     regular expression).
26166
26167 -- Command: next-matching-history-element pattern n
26168     This command replaces the minibuffer contents with the value of the
26169     Nth next (newer) history element that matches PATTERN (a regular
26170     expression).
26171
26172 -- Command: previous-complete-history-element n
26173     This command replaces the minibuffer contents with the value of the
26174     Nth previous (older) history element that completes the current
26175     contents of the minibuffer before the point.
26176
26177 -- Command: next-complete-history-element n
26178     This command replaces the minibuffer contents with the value of the
26179     Nth next (newer) history element that completes the current
26180     contents of the minibuffer before the point.
26181
26182 -- Command: goto-history-element nabs
26183     This function puts element of the minibuffer history in the
26184     minibuffer.  The argument NABS specifies the absolute history
26185     position in descending order, where 0 means the current element and
26186     a positive number N means the Nth previous element.  NABS being a
26187     negative number -N means the Nth entry of “future history.”
26188
26189
26190File: elisp.info,  Node: Minibuffer Windows,  Next: Minibuffer Contents,  Prev: Minibuffer Commands,  Up: Minibuffers
26191
2619220.11 Minibuffer Windows
26193========================
26194
26195These functions access and select minibuffer windows, test whether they
26196are active and control how they get resized.
26197
26198 -- Function: minibuffer-window &optional frame
26199     This function returns the minibuffer window used for frame FRAME.
26200     If FRAME is ‘nil’, that stands for the selected frame.
26201
26202     Note that the minibuffer window used by a frame need not be part of
26203     that frame—a frame that has no minibuffer of its own necessarily
26204     uses some other frame’s minibuffer window.  The minibuffer window
26205     of a minibuffer-less frame can be changed by setting that frame’s
26206     ‘minibuffer’ frame parameter (*note Buffer Parameters::).
26207
26208 -- Function: set-minibuffer-window window
26209     This function specifies WINDOW as the minibuffer window to use.
26210     This affects where the minibuffer is displayed if you put text in
26211     it without invoking the usual minibuffer commands.  It has no
26212     effect on the usual minibuffer input functions because they all
26213     start by choosing the minibuffer window according to the selected
26214     frame.
26215
26216 -- Function: window-minibuffer-p &optional window
26217     This function returns ‘t’ if WINDOW is a minibuffer window.  WINDOW
26218     defaults to the selected window.
26219
26220   The following function returns the window showing the currently
26221active minibuffer.
26222
26223 -- Function: active-minibuffer-window
26224     This function returns the window of the currently active
26225     minibuffer, or ‘nil’ if there is no active minibuffer.
26226
26227   It is not sufficient to determine whether a given window shows the
26228currently active minibuffer by comparing it with the result of
26229‘(minibuffer-window)’, because there can be more than one minibuffer
26230window if there is more than one frame.
26231
26232 -- Function: minibuffer-window-active-p window
26233     This function returns non-‘nil’ if WINDOW shows the currently
26234     active minibuffer.
26235
26236   The following two options control whether minibuffer windows are
26237resized automatically and how large they can get in the process.
26238
26239 -- User Option: resize-mini-windows
26240     This option specifies whether minibuffer windows are resized
26241     automatically.  The default value is ‘grow-only’, which means that
26242     a minibuffer window by default expands automatically to accommodate
26243     the text it displays and shrinks back to one line as soon as the
26244     minibuffer gets empty.  If the value is ‘t’, Emacs will always try
26245     to fit the height of a minibuffer window to the text it displays
26246     (with a minimum of one line).  If the value is ‘nil’, a minibuffer
26247     window never changes size automatically.  In that case the window
26248     resizing commands (*note Resizing Windows::) can be used to adjust
26249     its height.
26250
26251 -- User Option: max-mini-window-height
26252     This option provides a maximum height for resizing minibuffer
26253     windows automatically.  A floating-point number specifies the
26254     maximum height as a fraction of the frame’s height; an integer
26255     specifies the maximum height in units of the frame’s canonical
26256     character height (*note Frame Font::).  The default value is 0.25.
26257
26258   Note that the values of the above two variables take effect at
26259display time, so let-binding them around code which produces echo-area
26260messages will not work.  If you want to prevent resizing of minibuffer
26261windows when displaying long messages, bind the ‘message-truncate-lines’
26262variable instead (*note Echo Area Customization::).
26263
26264   The option ‘resize-mini-windows’ does not affect the behavior of
26265minibuffer-only frames (*note Frame Layout::).  The following option
26266allows to automatically resize such frames as well.
26267
26268 -- User Option: resize-mini-frames
26269     If this is ‘nil’, minibuffer-only frames are never resized
26270     automatically.
26271
26272     If this is a function, that function is called with the
26273     minibuffer-only frame to be resized as sole argument.  At the time
26274     this function is called, the buffer of the minibuffer window of
26275     that frame is the buffer whose contents will be shown the next time
26276     that window is redisplayed.  The function is expected to fit the
26277     frame to the buffer in some appropriate way.
26278
26279     Any other non-‘nil’ value means to resize minibuffer-only frames by
26280     calling ‘fit-mini-frame-to-buffer’, a function that behaves like
26281     ‘fit-frame-to-buffer’ (*note Resizing Windows::) but does not strip
26282     leading or trailing empty lines from the buffer text.
26283
26284
26285File: elisp.info,  Node: Minibuffer Contents,  Next: Recursive Mini,  Prev: Minibuffer Windows,  Up: Minibuffers
26286
2628720.12 Minibuffer Contents
26288=========================
26289
26290These functions access the minibuffer prompt and contents.
26291
26292 -- Function: minibuffer-prompt
26293     This function returns the prompt string of the currently active
26294     minibuffer.  If no minibuffer is active, it returns ‘nil’.
26295
26296 -- Function: minibuffer-prompt-end
26297     This function returns the current position of the end of the
26298     minibuffer prompt, if a minibuffer is current.  Otherwise, it
26299     returns the minimum valid buffer position.
26300
26301 -- Function: minibuffer-prompt-width
26302     This function returns the current display-width of the minibuffer
26303     prompt, if a minibuffer is current.  Otherwise, it returns zero.
26304
26305 -- Function: minibuffer-contents
26306     This function returns the editable contents of the minibuffer (that
26307     is, everything except the prompt) as a string, if a minibuffer is
26308     current.  Otherwise, it returns the entire contents of the current
26309     buffer.
26310
26311 -- Function: minibuffer-contents-no-properties
26312     This is like ‘minibuffer-contents’, except that it does not copy
26313     text properties, just the characters themselves.  *Note Text
26314     Properties::.
26315
26316 -- Command: delete-minibuffer-contents
26317     This command erases the editable contents of the minibuffer (that
26318     is, everything except the prompt), if a minibuffer is current.
26319     Otherwise, it erases the entire current buffer.
26320
26321
26322File: elisp.info,  Node: Recursive Mini,  Next: Minibuffer Misc,  Prev: Minibuffer Contents,  Up: Minibuffers
26323
2632420.13 Recursive Minibuffers
26325===========================
26326
26327These functions and variables deal with recursive minibuffers (*note
26328Recursive Editing::):
26329
26330 -- Function: minibuffer-depth
26331     This function returns the current depth of activations of the
26332     minibuffer, a nonnegative integer.  If no minibuffers are active,
26333     it returns zero.
26334
26335 -- User Option: enable-recursive-minibuffers
26336     If this variable is non-‘nil’, you can invoke commands (such as
26337     ‘find-file’) that use minibuffers even while the minibuffer is
26338     active.  Such invocation produces a recursive editing level for a
26339     new minibuffer.  The outer-level minibuffer is invisible while you
26340     are editing the inner one.
26341
26342     If this variable is ‘nil’, you cannot invoke minibuffer commands
26343     when the minibuffer is active, not even if you switch to another
26344     window to do it.
26345
26346   If a command name has a property ‘enable-recursive-minibuffers’ that
26347is non-‘nil’, then the command can use the minibuffer to read arguments
26348even if it is invoked from the minibuffer.  A command can also achieve
26349this by binding ‘enable-recursive-minibuffers’ to ‘t’ in the interactive
26350declaration (*note Using Interactive::).  The minibuffer command
26351‘next-matching-history-element’ (normally ‘M-s’ in the minibuffer) does
26352the latter.
26353
26354
26355File: elisp.info,  Node: Minibuffer Misc,  Prev: Recursive Mini,  Up: Minibuffers
26356
2635720.14 Minibuffer Miscellany
26358===========================
26359
26360 -- Function: minibufferp &optional buffer-or-name
26361     This function returns non-‘nil’ if BUFFER-OR-NAME is a minibuffer.
26362     If BUFFER-OR-NAME is omitted, it tests the current buffer.
26363
26364 -- Variable: minibuffer-setup-hook
26365     This is a normal hook that is run whenever the minibuffer is
26366     entered.  *Note Hooks::.
26367
26368 -- Macro: minibuffer-with-setup-hook function &rest body
26369     This macro executes BODY after arranging for the specified FUNCTION
26370     to be called via ‘minibuffer-setup-hook’.  By default, FUNCTION is
26371     called before the other functions in the ‘minibuffer-setup-hook’
26372     list, but if FUNCTION is of the form ‘(:append FUNC)’, FUNC will be
26373     called _after_ the other hook functions.
26374
26375     The BODY forms should not use the minibuffer more than once.  If
26376     the minibuffer is re-entered recursively, FUNCTION will only be
26377     called once, for the outermost use of the minibuffer.
26378
26379 -- Variable: minibuffer-exit-hook
26380     This is a normal hook that is run whenever the minibuffer is
26381     exited.  *Note Hooks::.
26382
26383 -- Variable: minibuffer-help-form
26384     The current value of this variable is used to rebind ‘help-form’
26385     locally inside the minibuffer (*note Help Functions::).
26386
26387 -- Variable: minibuffer-scroll-window
26388     If the value of this variable is non-‘nil’, it should be a window
26389     object.  When the function ‘scroll-other-window’ is called in the
26390     minibuffer, it scrolls this window (*note Textual Scrolling::).
26391
26392 -- Function: minibuffer-selected-window
26393     This function returns the window that was selected just before the
26394     minibuffer window was selected.  If the selected window is not a
26395     minibuffer window, it returns ‘nil’.
26396
26397 -- Function: minibuffer-message string &rest args
26398     This function displays STRING temporarily at the end of the
26399     minibuffer text, for a few seconds, or until the next input event
26400     arrives, whichever comes first.  The variable
26401     ‘minibuffer-message-timeout’ specifies the number of seconds to
26402     wait in the absence of input.  It defaults to 2.  If ARGS is
26403     non-‘nil’, the actual message is obtained by passing STRING and
26404     ARGS through ‘format-message’.  *Note Formatting Strings::.
26405
26406 -- Command: minibuffer-inactive-mode
26407     This is the major mode used in inactive minibuffers.  It uses
26408     keymap ‘minibuffer-inactive-mode-map’.  This can be useful if the
26409     minibuffer is in a separate frame.  *Note Minibuffers and Frames::.
26410
26411
26412File: elisp.info,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
26413
2641421 Command Loop
26415***************
26416
26417When you run Emacs, it enters the “editor command loop” almost
26418immediately.  This loop reads key sequences, executes their definitions,
26419and displays the results.  In this chapter, we describe how these things
26420are done, and the subroutines that allow Lisp programs to do them.
26421
26422* Menu:
26423
26424* Command Overview::    How the command loop reads commands.
26425* Defining Commands::   Specifying how a function should read arguments.
26426* Interactive Call::    Calling a command, so that it will read arguments.
26427* Distinguish Interactive::     Making a command distinguish interactive calls.
26428* Command Loop Info::   Variables set by the command loop for you to examine.
26429* Adjusting Point::     Adjustment of point after a command.
26430* Input Events::        What input looks like when you read it.
26431* Reading Input::       How to read input events from the keyboard or mouse.
26432* Special Events::      Events processed immediately and individually.
26433* Waiting::             Waiting for user input or elapsed time.
26434* Quitting::            How ‘C-g’ works.  How to catch or defer quitting.
26435* Prefix Command Arguments::    How the commands to set prefix args work.
26436* Recursive Editing::   Entering a recursive edit,
26437                          and why you usually shouldn’t.
26438* Disabling Commands::  How the command loop handles disabled commands.
26439* Command History::     How the command history is set up, and how accessed.
26440* Keyboard Macros::     How keyboard macros are implemented.
26441
26442
26443File: elisp.info,  Node: Command Overview,  Next: Defining Commands,  Up: Command Loop
26444
2644521.1 Command Loop Overview
26446==========================
26447
26448The first thing the command loop must do is read a key sequence, which
26449is a sequence of input events that translates into a command.  It does
26450this by calling the function ‘read-key-sequence’.  Lisp programs can
26451also call this function (*note Key Sequence Input::).  They can also
26452read input at a lower level with ‘read-key’ or ‘read-event’ (*note
26453Reading One Event::), or discard pending input with ‘discard-input’
26454(*note Event Input Misc::).
26455
26456   The key sequence is translated into a command through the currently
26457active keymaps.  *Note Key Lookup::, for information on how this is
26458done.  The result should be a keyboard macro or an interactively
26459callable function.  If the key is ‘M-x’, then it reads the name of
26460another command, which it then calls.  This is done by the command
26461‘execute-extended-command’ (*note Interactive Call::).
26462
26463   Prior to executing the command, Emacs runs ‘undo-boundary’ to create
26464an undo boundary.  *Note Maintaining Undo::.
26465
26466   To execute a command, Emacs first reads its arguments by calling
26467‘command-execute’ (*note Interactive Call::).  For commands written in
26468Lisp, the ‘interactive’ specification says how to read the arguments.
26469This may use the prefix argument (*note Prefix Command Arguments::) or
26470may read with prompting in the minibuffer (*note Minibuffers::).  For
26471example, the command ‘find-file’ has an ‘interactive’ specification
26472which says to read a file name using the minibuffer.  The function body
26473of ‘find-file’ does not use the minibuffer, so if you call ‘find-file’
26474as a function from Lisp code, you must supply the file name string as an
26475ordinary Lisp function argument.
26476
26477   If the command is a keyboard macro (i.e., a string or vector), Emacs
26478executes it using ‘execute-kbd-macro’ (*note Keyboard Macros::).
26479
26480 -- Variable: pre-command-hook
26481     This normal hook is run by the editor command loop before it
26482     executes each command.  At that time, ‘this-command’ contains the
26483     command that is about to run, and ‘last-command’ describes the
26484     previous command.  *Note Command Loop Info::.
26485
26486 -- Variable: post-command-hook
26487     This normal hook is run by the editor command loop after it
26488     executes each command (including commands terminated prematurely by
26489     quitting or by errors).  At that time, ‘this-command’ refers to the
26490     command that just ran, and ‘last-command’ refers to the command
26491     before that.
26492
26493     This hook is also run when Emacs first enters the command loop (at
26494     which point ‘this-command’ and ‘last-command’ are both ‘nil’).
26495
26496   Quitting is suppressed while running ‘pre-command-hook’ and
26497‘post-command-hook’.  If an error happens while executing one of these
26498hooks, it does not terminate execution of the hook; instead the error is
26499silenced and the function in which the error occurred is removed from
26500the hook.
26501
26502   A request coming into the Emacs server (*note (emacs)Emacs Server::)
26503runs these two hooks just as a keyboard command does.
26504
26505
26506File: elisp.info,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
26507
2650821.2 Defining Commands
26509======================
26510
26511The special form ‘interactive’ turns a Lisp function into a command.
26512The ‘interactive’ form must be located at top-level in the function
26513body, usually as the first form in the body; this applies to both lambda
26514expressions (*note Lambda Expressions::) and ‘defun’ forms (*note
26515Defining Functions::).  This form does nothing during the actual
26516execution of the function; its presence serves as a flag, telling the
26517Emacs command loop that the function can be called interactively.  The
26518argument of the ‘interactive’ form specifies how the arguments for an
26519interactive call should be read.
26520
26521   Alternatively, an ‘interactive’ form may be specified in a function
26522symbol’s ‘interactive-form’ property.  A non-‘nil’ value for this
26523property takes precedence over any ‘interactive’ form in the function
26524body itself.  This feature is seldom used.
26525
26526   Sometimes, a function is only intended to be called interactively,
26527never directly from Lisp.  In that case, give the function a non-‘nil’
26528‘interactive-only’ property, either directly or via ‘declare’ (*note
26529Declare Form::).  This causes the byte compiler to warn if the command
26530is called from Lisp.  The output of ‘describe-function’ will include
26531similar information.  The value of the property can be: a string, which
26532the byte-compiler will use directly in its warning (it should end with a
26533period, and not start with a capital, e.g., ‘"use (system-name)
26534instead."’); ‘t’; any other symbol, which should be an alternative
26535function to use in Lisp code.
26536
26537   Generic functions (*note Generic Functions::) cannot be turned into
26538commands by adding the ‘interactive’ form to them.
26539
26540* Menu:
26541
26542* Using Interactive::     General rules for ‘interactive’.
26543* Interactive Codes::     The standard letter-codes for reading arguments
26544                             in various ways.
26545* Interactive Examples::  Examples of how to read interactive arguments.
26546* Generic Commands::      Select among command alternatives.
26547
26548
26549File: elisp.info,  Node: Using Interactive,  Next: Interactive Codes,  Up: Defining Commands
26550
2655121.2.1 Using ‘interactive’
26552--------------------------
26553
26554This section describes how to write the ‘interactive’ form that makes a
26555Lisp function an interactively-callable command, and how to examine a
26556command’s ‘interactive’ form.
26557
26558 -- Special Form: interactive arg-descriptor
26559     This special form declares that a function is a command, and that
26560     it may therefore be called interactively (via ‘M-x’ or by entering
26561     a key sequence bound to it).  The argument ARG-DESCRIPTOR declares
26562     how to compute the arguments to the command when the command is
26563     called interactively.
26564
26565     A command may be called from Lisp programs like any other function,
26566     but then the caller supplies the arguments and ARG-DESCRIPTOR has
26567     no effect.
26568
26569     The ‘interactive’ form must be located at top-level in the function
26570     body, or in the function symbol’s ‘interactive-form’ property
26571     (*note Symbol Properties::).  It has its effect because the command
26572     loop looks for it before calling the function (*note Interactive
26573     Call::).  Once the function is called, all its body forms are
26574     executed; at this time, if the ‘interactive’ form occurs within the
26575     body, the form simply returns ‘nil’ without even evaluating its
26576     argument.
26577
26578     By convention, you should put the ‘interactive’ form in the
26579     function body, as the first top-level form.  If there is an
26580     ‘interactive’ form in both the ‘interactive-form’ symbol property
26581     and the function body, the former takes precedence.  The
26582     ‘interactive-form’ symbol property can be used to add an
26583     interactive form to an existing function, or change how its
26584     arguments are processed interactively, without redefining the
26585     function.
26586
26587   There are three possibilities for the argument ARG-DESCRIPTOR:
26588
26589   • It may be omitted or ‘nil’; then the command is called with no
26590     arguments.  This leads quickly to an error if the command requires
26591     one or more arguments.
26592
26593   • It may be a string; its contents are a sequence of elements
26594     separated by newlines, one for each argument(1).  Each element
26595     consists of a code character (*note Interactive Codes::) optionally
26596     followed by a prompt (which some code characters use and some
26597     ignore).  Here is an example:
26598
26599          (interactive "P\nbFrobnicate buffer: ")
26600
26601     The code letter ‘P’ sets the command’s first argument to the raw
26602     command prefix (*note Prefix Command Arguments::).  ‘bFrobnicate
26603     buffer: ’ prompts the user with ‘Frobnicate buffer: ’ to enter the
26604     name of an existing buffer, which becomes the second and final
26605     argument.
26606
26607     The prompt string can use ‘%’ to include previous argument values
26608     (starting with the first argument) in the prompt.  This is done
26609     using ‘format-message’ (*note Formatting Strings::).  For example,
26610     here is how you could read the name of an existing buffer followed
26611     by a new name to give to that buffer:
26612
26613          (interactive "bBuffer to rename: \nsRename buffer %s to: ")
26614
26615     If ‘*’ appears at the beginning of the string, then an error is
26616     signaled if the buffer is read-only.
26617
26618     If ‘@’ appears at the beginning of the string, and if the key
26619     sequence used to invoke the command includes any mouse events, then
26620     the window associated with the first of those events is selected
26621     before the command is run.
26622
26623     If ‘^’ appears at the beginning of the string, and if the command
26624     was invoked through “shift-translation”, set the mark and activate
26625     the region temporarily, or extend an already active region, before
26626     the command is run.  If the command was invoked without
26627     shift-translation, and the region is temporarily active, deactivate
26628     the region before the command is run.  Shift-translation is
26629     controlled on the user level by ‘shift-select-mode’; see *note
26630     (emacs)Shift Selection::.
26631
26632     You can use ‘*’, ‘@’, and ‘^’ together; the order does not matter.
26633     Actual reading of arguments is controlled by the rest of the prompt
26634     string (starting with the first character that is not ‘*’, ‘@’, or
26635     ‘^’).
26636
26637   • It may be a Lisp expression that is not a string; then it should be
26638     a form that is evaluated to get a list of arguments to pass to the
26639     command.  Usually this form will call various functions to read
26640     input from the user, most often through the minibuffer (*note
26641     Minibuffers::) or directly from the keyboard (*note Reading
26642     Input::).
26643
26644     Providing point or the mark as an argument value is also common,
26645     but if you do this _and_ read input (whether using the minibuffer
26646     or not), be sure to get the integer values of point or the mark
26647     after reading.  The current buffer may be receiving subprocess
26648     output; if subprocess output arrives while the command is waiting
26649     for input, it could relocate point and the mark.
26650
26651     Here’s an example of what _not_ to do:
26652
26653          (interactive
26654           (list (region-beginning) (region-end)
26655                 (read-string "Foo: " nil 'my-history)))
26656
26657     Here’s how to avoid the problem, by examining point and the mark
26658     after reading the keyboard input:
26659
26660          (interactive
26661           (let ((string (read-string "Foo: " nil 'my-history)))
26662             (list (region-beginning) (region-end) string)))
26663
26664     *Warning:* the argument values should not include any data types
26665     that can’t be printed and then read.  Some facilities save
26666     ‘command-history’ in a file to be read in the subsequent sessions;
26667     if a command’s arguments contain a data type that prints using
26668     ‘#<...>’ syntax, those facilities won’t work.
26669
26670     There are, however, a few exceptions: it is ok to use a limited set
26671     of expressions such as ‘(point)’, ‘(mark)’, ‘(region-beginning)’,
26672     and ‘(region-end)’, because Emacs recognizes them specially and
26673     puts the expression (rather than its value) into the command
26674     history.  To see whether the expression you wrote is one of these
26675     exceptions, run the command, then examine ‘(car command-history)’.
26676
26677 -- Function: interactive-form function
26678     This function returns the ‘interactive’ form of FUNCTION.  If
26679     FUNCTION is an interactively callable function (*note Interactive
26680     Call::), the value is the command’s ‘interactive’ form
26681     ‘(interactive SPEC)’, which specifies how to compute its arguments.
26682     Otherwise, the value is ‘nil’.  If FUNCTION is a symbol, its
26683     function definition is used.
26684
26685   ---------- Footnotes ----------
26686
26687   (1) Some elements actually supply two arguments.
26688
26689
26690File: elisp.info,  Node: Interactive Codes,  Next: Interactive Examples,  Prev: Using Interactive,  Up: Defining Commands
26691
2669221.2.2 Code Characters for ‘interactive’
26693----------------------------------------
26694
26695The code character descriptions below contain a number of key words,
26696defined here as follows:
26697
26698Completion
26699     Provide completion.  <TAB>, <SPC>, and <RET> perform name
26700     completion because the argument is read using ‘completing-read’
26701     (*note Completion::).  ‘?’ displays a list of possible completions.
26702
26703Existing
26704     Require the name of an existing object.  An invalid name is not
26705     accepted; the commands to exit the minibuffer do not exit if the
26706     current input is not valid.
26707
26708Default
26709     A default value of some sort is used if the user enters no text in
26710     the minibuffer.  The default depends on the code character.
26711
26712No I/O
26713     This code letter computes an argument without reading any input.
26714     Therefore, it does not use a prompt string, and any prompt string
26715     you supply is ignored.
26716
26717     Even though the code letter doesn’t use a prompt string, you must
26718     follow it with a newline if it is not the last code character in
26719     the string.
26720
26721Prompt
26722     A prompt immediately follows the code character.  The prompt ends
26723     either with the end of the string or with a newline.
26724
26725Special
26726     This code character is meaningful only at the beginning of the
26727     interactive string, and it does not look for a prompt or a newline.
26728     It is a single, isolated character.
26729
26730   Here are the code character descriptions for use with ‘interactive’:
26731
26732‘*’
26733     Signal an error if the current buffer is read-only.  Special.
26734
26735‘@’
26736     Select the window mentioned in the first mouse event in the key
26737     sequence that invoked this command.  Special.
26738
26739‘^’
26740     If the command was invoked through shift-translation, set the mark
26741     and activate the region temporarily, or extend an already active
26742     region, before the command is run.  If the command was invoked
26743     without shift-translation, and the region is temporarily active,
26744     deactivate the region before the command is run.  Special.
26745
26746‘a’
26747     A function name (i.e., a symbol satisfying ‘fboundp’).  Existing,
26748     Completion, Prompt.
26749
26750‘b’
26751     The name of an existing buffer.  By default, uses the name of the
26752     current buffer (*note Buffers::).  Existing, Completion, Default,
26753     Prompt.
26754
26755‘B’
26756     A buffer name.  The buffer need not exist.  By default, uses the
26757     name of a recently used buffer other than the current buffer.
26758     Completion, Default, Prompt.
26759
26760‘c’
26761     A character.  The cursor does not move into the echo area.  Prompt.
26762
26763‘C’
26764     A command name (i.e., a symbol satisfying ‘commandp’).  Existing,
26765     Completion, Prompt.
26766
26767‘d’
26768     The position of point, as an integer (*note Point::).  No I/O.
26769
26770‘D’
26771     A directory.  The default is the current default directory of the
26772     current buffer, ‘default-directory’ (*note File Name Expansion::).
26773     Existing, Completion, Default, Prompt.
26774
26775‘e’
26776     The first or next non-keyboard event in the key sequence that
26777     invoked the command.  More precisely, ‘e’ gets events that are
26778     lists, so you can look at the data in the lists.  *Note Input
26779     Events::.  No I/O.
26780
26781     You use ‘e’ for mouse events and for special system events (*note
26782     Misc Events::).  The event list that the command receives depends
26783     on the event.  *Note Input Events::, which describes the forms of
26784     the list for each event in the corresponding subsections.
26785
26786     You can use ‘e’ more than once in a single command’s interactive
26787     specification.  If the key sequence that invoked the command has N
26788     events that are lists, the Nth ‘e’ provides the Nth such event.
26789     Events that are not lists, such as function keys and ASCII
26790     characters, do not count where ‘e’ is concerned.
26791
26792‘f’
26793     A file name of an existing file (*note File Names::).  The default
26794     directory is ‘default-directory’.  Existing, Completion, Default,
26795     Prompt.
26796
26797‘F’
26798     A file name.  The file need not exist.  Completion, Default,
26799     Prompt.
26800
26801‘G’
26802     A file name.  The file need not exist.  If the user enters just a
26803     directory name, then the value is just that directory name, with no
26804     file name within the directory added.  Completion, Default, Prompt.
26805
26806‘i’
26807     An irrelevant argument.  This code always supplies ‘nil’ as the
26808     argument’s value.  No I/O.
26809
26810‘k’
26811     A key sequence (*note Key Sequences::).  This keeps reading events
26812     until a command (or undefined command) is found in the current key
26813     maps.  The key sequence argument is represented as a string or
26814     vector.  The cursor does not move into the echo area.  Prompt.
26815
26816     If ‘k’ reads a key sequence that ends with a down-event, it also
26817     reads and discards the following up-event.  You can get access to
26818     that up-event with the ‘U’ code character.
26819
26820     This kind of input is used by commands such as ‘describe-key’ and
26821     ‘global-set-key’.
26822
26823‘K’
26824     A key sequence, whose definition you intend to change.  This works
26825     like ‘k’, except that it suppresses, for the last input event in
26826     the key sequence, the conversions that are normally used (when
26827     necessary) to convert an undefined key into a defined one.
26828
26829‘m’
26830     The position of the mark, as an integer.  No I/O.
26831
26832‘M’
26833     Arbitrary text, read in the minibuffer using the current buffer’s
26834     input method, and returned as a string (*note (emacs)Input
26835     Methods::).  Prompt.
26836
26837‘n’
26838     A number, read with the minibuffer.  If the input is not a number,
26839     the user has to try again.  ‘n’ never uses the prefix argument.
26840     Prompt.
26841
26842‘N’
26843     The numeric prefix argument; but if there is no prefix argument,
26844     read a number as with ‘n’.  The value is always a number.  *Note
26845     Prefix Command Arguments::.  Prompt.
26846
26847‘p’
26848     The numeric prefix argument.  (Note that this ‘p’ is lower case.)
26849     No I/O.
26850
26851‘P’
26852     The raw prefix argument.  (Note that this ‘P’ is upper case.)  No
26853     I/O.
26854
26855‘r’
26856     Point and the mark, as two numeric arguments, smallest first.  This
26857     is the only code letter that specifies two successive arguments
26858     rather than one.  This will signal an error if the mark is not set
26859     in the buffer which is current when the command is invoked.  If
26860     Transient Mark mode is turned on (*note The Mark::) — as it is by
26861     default — and user option ‘mark-even-if-inactive’ is ‘nil’, Emacs
26862     will signal an error even if the mark _is_ set, but is inactive.
26863     No I/O.
26864
26865‘s’
26866     Arbitrary text, read in the minibuffer and returned as a string
26867     (*note Text from Minibuffer::).  Terminate the input with either
26868     ‘C-j’ or <RET>.  (‘C-q’ may be used to include either of these
26869     characters in the input.)  Prompt.
26870
26871‘S’
26872     An interned symbol whose name is read in the minibuffer.  Terminate
26873     the input with either ‘C-j’ or <RET>.  Other characters that
26874     normally terminate a symbol (e.g., whitespace, parentheses and
26875     brackets) do not do so here.  Prompt.
26876
26877‘U’
26878     A key sequence or ‘nil’.  Can be used after a ‘k’ or ‘K’ argument
26879     to get the up-event that was discarded (if any) after ‘k’ or ‘K’
26880     read a down-event.  If no up-event has been discarded, ‘U’ provides
26881     ‘nil’ as the argument.  No I/O.
26882
26883‘v’
26884     A variable declared to be a user option (i.e., satisfying the
26885     predicate ‘custom-variable-p’).  This reads the variable using
26886     ‘read-variable’.  *Note Definition of read-variable::.  Existing,
26887     Completion, Prompt.
26888
26889‘x’
26890     A Lisp object, specified with its read syntax, terminated with a
26891     ‘C-j’ or <RET>.  The object is not evaluated.  *Note Object from
26892     Minibuffer::.  Prompt.
26893
26894‘X’
26895     A Lisp form’s value.  ‘X’ reads as ‘x’ does, then evaluates the
26896     form so that its value becomes the argument for the command.
26897     Prompt.
26898
26899‘z’
26900     A coding system name (a symbol).  If the user enters null input,
26901     the argument value is ‘nil’.  *Note Coding Systems::.  Completion,
26902     Existing, Prompt.
26903
26904‘Z’
26905     A coding system name (a symbol)—but only if this command has a
26906     prefix argument.  With no prefix argument, ‘Z’ provides ‘nil’ as
26907     the argument value.  Completion, Existing, Prompt.
26908
26909
26910File: elisp.info,  Node: Interactive Examples,  Next: Generic Commands,  Prev: Interactive Codes,  Up: Defining Commands
26911
2691221.2.3 Examples of Using ‘interactive’
26913--------------------------------------
26914
26915Here are some examples of ‘interactive’:
26916
26917     (defun foo1 ()              ; ‘foo1’ takes no arguments,
26918         (interactive)           ;   just moves forward two words.
26919         (forward-word 2))
26920          ⇒ foo1
26921
26922     (defun foo2 (n)             ; ‘foo2’ takes one argument,
26923         (interactive "^p")      ;   which is the numeric prefix.
26924                                 ; under ‘shift-select-mode’,
26925                                 ;   will activate or extend region.
26926         (forward-word (* 2 n)))
26927          ⇒ foo2
26928
26929     (defun foo3 (n)             ; ‘foo3’ takes one argument,
26930         (interactive "nCount:") ;   which is read with the Minibuffer.
26931         (forward-word (* 2 n)))
26932          ⇒ foo3
26933
26934     (defun three-b (b1 b2 b3)
26935       "Select three existing buffers.
26936     Put them into three windows, selecting the last one."
26937         (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
26938         (delete-other-windows)
26939         (split-window (selected-window) 8)
26940         (switch-to-buffer b1)
26941         (other-window 1)
26942         (split-window (selected-window) 8)
26943         (switch-to-buffer b2)
26944         (other-window 1)
26945         (switch-to-buffer b3))
26946          ⇒ three-b
26947     (three-b "*scratch*" "declarations.texi" "*mail*")
26948          ⇒ nil
26949
26950
26951File: elisp.info,  Node: Generic Commands,  Prev: Interactive Examples,  Up: Defining Commands
26952
2695321.2.4 Select among Command Alternatives
26954----------------------------------------
26955
26956The macro ‘define-alternatives’ can be used to define “generic
26957commands”.  These are interactive functions whose implementation can be
26958selected from several alternatives, as a matter of user preference.
26959
26960 -- Macro: define-alternatives command &rest customizations
26961     Define the new command COMMAND, a symbol.
26962
26963     When a user runs ‘M-x COMMAND <RET>’ for the first time, Emacs
26964     prompts for which real form of the command to use, and records the
26965     selection by way of a custom variable.  Using a prefix argument
26966     repeats this process of choosing an alternative.
26967
26968     The variable ‘COMMAND-alternatives’ should contain an alist with
26969     alternative implementations of COMMAND.  Until this variable is
26970     set, ‘define-alternatives’ has no effect.
26971
26972     If CUSTOMIZATIONS is non-‘nil’, it should consist of alternating
26973     ‘defcustom’ keywords (typically ‘:group’ and ‘:version’) and values
26974     to add to the declaration of ‘COMMAND-alternatives’.
26975
26976
26977File: elisp.info,  Node: Interactive Call,  Next: Distinguish Interactive,  Prev: Defining Commands,  Up: Command Loop
26978
2697921.3 Interactive Call
26980=====================
26981
26982After the command loop has translated a key sequence into a command, it
26983invokes that command using the function ‘command-execute’.  If the
26984command is a function, ‘command-execute’ calls ‘call-interactively’,
26985which reads the arguments and calls the command.  You can also call
26986these functions yourself.
26987
26988   Note that the term “command”, in this context, refers to an
26989interactively callable function (or function-like object), or a keyboard
26990macro.  It does not refer to the key sequence used to invoke a command
26991(*note Keymaps::).
26992
26993 -- Function: commandp object &optional for-call-interactively
26994     This function returns ‘t’ if OBJECT is a command.  Otherwise, it
26995     returns ‘nil’.
26996
26997     Commands include strings and vectors (which are treated as keyboard
26998     macros), lambda expressions that contain a top-level ‘interactive’
26999     form (*note Using Interactive::), byte-code function objects made
27000     from such lambda expressions, autoload objects that are declared as
27001     interactive (non-‘nil’ fourth argument to ‘autoload’), and some
27002     primitive functions.  Also, a symbol is considered a command if it
27003     has a non-‘nil’ ‘interactive-form’ property, or if its function
27004     definition satisfies ‘commandp’.
27005
27006     If FOR-CALL-INTERACTIVELY is non-‘nil’, then ‘commandp’ returns ‘t’
27007     only for objects that ‘call-interactively’ could call—thus, not for
27008     keyboard macros.
27009
27010     See ‘documentation’ in *note Accessing Documentation::, for a
27011     realistic example of using ‘commandp’.
27012
27013 -- Function: call-interactively command &optional record-flag keys
27014     This function calls the interactively callable function COMMAND,
27015     providing arguments according to its interactive calling
27016     specifications.  It returns whatever COMMAND returns.
27017
27018     If, for instance, you have a function with the following signature:
27019
27020          (defun foo (begin end)
27021            (interactive "r")
27022            ...)
27023
27024     then saying
27025
27026          (call-interactively 'foo)
27027
27028     will call ‘foo’ with the region (‘point’ and ‘mark’) as the
27029     arguments.
27030
27031     An error is signaled if COMMAND is not a function or if it cannot
27032     be called interactively (i.e., is not a command).  Note that
27033     keyboard macros (strings and vectors) are not accepted, even though
27034     they are considered commands, because they are not functions.  If
27035     COMMAND is a symbol, then ‘call-interactively’ uses its function
27036     definition.
27037
27038     If RECORD-FLAG is non-‘nil’, then this command and its arguments
27039     are unconditionally added to the list ‘command-history’.
27040     Otherwise, the command is added only if it uses the minibuffer to
27041     read an argument.  *Note Command History::.
27042
27043     The argument KEYS, if given, should be a vector which specifies the
27044     sequence of events to supply if the command inquires which events
27045     were used to invoke it.  If KEYS is omitted or ‘nil’, the default
27046     is the return value of ‘this-command-keys-vector’.  *Note
27047     Definition of this-command-keys-vector::.
27048
27049 -- Function: funcall-interactively function &rest arguments
27050     This function works like ‘funcall’ (*note Calling Functions::), but
27051     it makes the call look like an interactive invocation: a call to
27052     ‘called-interactively-p’ inside FUNCTION will return ‘t’.  If
27053     FUNCTION is not a command, it is called without signaling an error.
27054
27055 -- Function: command-execute command &optional record-flag keys special
27056     This function executes COMMAND.  The argument COMMAND must satisfy
27057     the ‘commandp’ predicate; i.e., it must be an interactively
27058     callable function or a keyboard macro.
27059
27060     A string or vector as COMMAND is executed with ‘execute-kbd-macro’.
27061     A function is passed to ‘call-interactively’ (see above), along
27062     with the RECORD-FLAG and KEYS arguments.
27063
27064     If COMMAND is a symbol, its function definition is used in its
27065     place.  A symbol with an ‘autoload’ definition counts as a command
27066     if it was declared to stand for an interactively callable function.
27067     Such a definition is handled by loading the specified library and
27068     then rechecking the definition of the symbol.
27069
27070     The argument SPECIAL, if given, means to ignore the prefix argument
27071     and not clear it.  This is used for executing special events (*note
27072     Special Events::).
27073
27074 -- Command: execute-extended-command prefix-argument
27075     This function reads a command name from the minibuffer using
27076     ‘completing-read’ (*note Completion::).  Then it uses
27077     ‘command-execute’ to call the specified command.  Whatever that
27078     command returns becomes the value of ‘execute-extended-command’.
27079
27080     If the command asks for a prefix argument, it receives the value
27081     PREFIX-ARGUMENT.  If ‘execute-extended-command’ is called
27082     interactively, the current raw prefix argument is used for
27083     PREFIX-ARGUMENT, and thus passed on to whatever command is run.
27084
27085     ‘execute-extended-command’ is the normal definition of ‘M-x’, so it
27086     uses the string ‘M-x ’ as a prompt.  (It would be better to take
27087     the prompt from the events used to invoke
27088     ‘execute-extended-command’, but that is painful to implement.)  A
27089     description of the value of the prefix argument, if any, also
27090     becomes part of the prompt.
27091
27092          (execute-extended-command 3)
27093          ---------- Buffer: Minibuffer ----------
27094          3 M-x forward-word <RET>
27095          ---------- Buffer: Minibuffer ----------
27096               ⇒ t
27097
27098
27099File: elisp.info,  Node: Distinguish Interactive,  Next: Command Loop Info,  Prev: Interactive Call,  Up: Command Loop
27100
2710121.4 Distinguish Interactive Calls
27102==================================
27103
27104Sometimes a command should display additional visual feedback (such as
27105an informative message in the echo area) for interactive calls only.
27106There are three ways to do this.  The recommended way to test whether
27107the function was called using ‘call-interactively’ is to give it an
27108optional argument ‘print-message’ and use the ‘interactive’ spec to make
27109it non-‘nil’ in interactive calls.  Here’s an example:
27110
27111     (defun foo (&optional print-message)
27112       (interactive "p")
27113       (when print-message
27114         (message "foo")))
27115
27116We use ‘"p"’ because the numeric prefix argument is never ‘nil’.
27117Defined in this way, the function does display the message when called
27118from a keyboard macro.
27119
27120   The above method with the additional argument is usually best,
27121because it allows callers to say “treat this call as interactive”.  But
27122you can also do the job by testing ‘called-interactively-p’.
27123
27124 -- Function: called-interactively-p kind
27125     This function returns ‘t’ when the calling function was called
27126     using ‘call-interactively’.
27127
27128     The argument KIND should be either the symbol ‘interactive’ or the
27129     symbol ‘any’.  If it is ‘interactive’, then
27130     ‘called-interactively-p’ returns ‘t’ only if the call was made
27131     directly by the user—e.g., if the user typed a key sequence bound
27132     to the calling function, but _not_ if the user ran a keyboard macro
27133     that called the function (*note Keyboard Macros::).  If KIND is
27134     ‘any’, ‘called-interactively-p’ returns ‘t’ for any kind of
27135     interactive call, including keyboard macros.
27136
27137     If in doubt, use ‘any’; the only known proper use of ‘interactive’
27138     is if you need to decide whether to display a helpful message while
27139     a function is running.
27140
27141     A function is never considered to be called interactively if it was
27142     called via Lisp evaluation (or with ‘apply’ or ‘funcall’).
27143
27144Here is an example of using ‘called-interactively-p’:
27145
27146     (defun foo ()
27147       (interactive)
27148       (when (called-interactively-p 'any)
27149         (message "Interactive!")
27150         'foo-called-interactively))
27151
27152     ;; Type ‘M-x foo’.
27153          ⊣ Interactive!
27154
27155     (foo)
27156          ⇒ nil
27157
27158Here is another example that contrasts direct and indirect calls to
27159‘called-interactively-p’.
27160
27161     (defun bar ()
27162       (interactive)
27163       (message "%s" (list (foo) (called-interactively-p 'any))))
27164
27165     ;; Type ‘M-x bar’.
27166          ⊣ (nil t)
27167
27168
27169File: elisp.info,  Node: Command Loop Info,  Next: Adjusting Point,  Prev: Distinguish Interactive,  Up: Command Loop
27170
2717121.5 Information from the Command Loop
27172======================================
27173
27174The editor command loop sets several Lisp variables to keep status
27175records for itself and for commands that are run.  With the exception of
27176‘this-command’ and ‘last-command’ it’s generally a bad idea to change
27177any of these variables in a Lisp program.
27178
27179 -- Variable: last-command
27180     This variable records the name of the previous command executed by
27181     the command loop (the one before the current command).  Normally
27182     the value is a symbol with a function definition, but this is not
27183     guaranteed.
27184
27185     The value is copied from ‘this-command’ when a command returns to
27186     the command loop, except when the command has specified a prefix
27187     argument for the following command.
27188
27189     This variable is always local to the current terminal and cannot be
27190     buffer-local.  *Note Multiple Terminals::.
27191
27192 -- Variable: real-last-command
27193     This variable is set up by Emacs just like ‘last-command’, but
27194     never altered by Lisp programs.
27195
27196 -- Variable: last-repeatable-command
27197     This variable stores the most recently executed command that was
27198     not part of an input event.  This is the command ‘repeat’ will try
27199     to repeat, *Note (emacs)Repeating::.
27200
27201 -- Variable: this-command
27202     This variable records the name of the command now being executed by
27203     the editor command loop.  Like ‘last-command’, it is normally a
27204     symbol with a function definition.
27205
27206     The command loop sets this variable just before running a command,
27207     and copies its value into ‘last-command’ when the command finishes
27208     (unless the command specified a prefix argument for the following
27209     command).
27210
27211     Some commands set this variable during their execution, as a flag
27212     for whatever command runs next.  In particular, the functions for
27213     killing text set ‘this-command’ to ‘kill-region’ so that any kill
27214     commands immediately following will know to append the killed text
27215     to the previous kill.
27216
27217   If you do not want a particular command to be recognized as the
27218previous command in the case where it got an error, you must code that
27219command to prevent this.  One way is to set ‘this-command’ to ‘t’ at the
27220beginning of the command, and set ‘this-command’ back to its proper
27221value at the end, like this:
27222
27223     (defun foo (args...)
27224       (interactive ...)
27225       (let ((old-this-command this-command))
27226         (setq this-command t)
27227         ...do the work...
27228         (setq this-command old-this-command)))
27229
27230We do not bind ‘this-command’ with ‘let’ because that would restore the
27231old value in case of error—a feature of ‘let’ which in this case does
27232precisely what we want to avoid.
27233
27234 -- Variable: this-original-command
27235     This has the same value as ‘this-command’ except when command
27236     remapping occurs (*note Remapping Commands::).  In that case,
27237     ‘this-command’ gives the command actually run (the result of
27238     remapping), and ‘this-original-command’ gives the command that was
27239     specified to run but remapped into another command.
27240
27241 -- Function: this-command-keys
27242     This function returns a string or vector containing the key
27243     sequence that invoked the present command, plus any previous
27244     commands that generated the prefix argument for this command.  Any
27245     events read by the command using ‘read-event’ without a timeout get
27246     tacked on to the end.
27247
27248     However, if the command has called ‘read-key-sequence’, it returns
27249     the last read key sequence.  *Note Key Sequence Input::.  The value
27250     is a string if all events in the sequence were characters that fit
27251     in a string.  *Note Input Events::.
27252
27253          (this-command-keys)
27254          ;; Now use ‘C-u C-x C-e’ to evaluate that.
27255               ⇒ "^U^X^E"
27256
27257 -- Function: this-command-keys-vector
27258     Like ‘this-command-keys’, except that it always returns the events
27259     in a vector, so you don’t need to deal with the complexities of
27260     storing input events in a string (*note Strings of Events::).
27261
27262 -- Function: clear-this-command-keys &optional keep-record
27263     This function empties out the table of events for
27264     ‘this-command-keys’ to return.  Unless KEEP-RECORD is non-‘nil’, it
27265     also empties the records that the function ‘recent-keys’ (*note
27266     Recording Input::) will subsequently return.  This is useful after
27267     reading a password, to prevent the password from echoing
27268     inadvertently as part of the next command in certain cases.
27269
27270 -- Variable: last-nonmenu-event
27271     This variable holds the last input event read as part of a key
27272     sequence, not counting events resulting from mouse menus.
27273
27274     One use of this variable is for telling ‘x-popup-menu’ where to pop
27275     up a menu.  It is also used internally by ‘y-or-n-p’ (*note
27276     Yes-or-No Queries::).
27277
27278 -- Variable: last-command-event
27279     This variable is set to the last input event that was read by the
27280     command loop as part of a command.  The principal use of this
27281     variable is in ‘self-insert-command’, which uses it to decide which
27282     character to insert.
27283
27284          last-command-event
27285          ;; Now use ‘C-u C-x C-e’ to evaluate that.
27286               ⇒ 5
27287
27288     The value is 5 because that is the ASCII code for ‘C-e’.
27289
27290 -- Variable: last-event-frame
27291     This variable records which frame the last input event was directed
27292     to.  Usually this is the frame that was selected when the event was
27293     generated, but if that frame has redirected input focus to another
27294     frame, the value is the frame to which the event was redirected.
27295     *Note Input Focus::.
27296
27297     If the last event came from a keyboard macro, the value is ‘macro’.
27298
27299
27300File: elisp.info,  Node: Adjusting Point,  Next: Input Events,  Prev: Command Loop Info,  Up: Command Loop
27301
2730221.6 Adjusting Point After Commands
27303===================================
27304
27305Emacs cannot display the cursor when point is in the middle of a
27306sequence of text that has the ‘display’ or ‘composition’ property, or is
27307invisible.  Therefore, after a command finishes and returns to the
27308command loop, if point is within such a sequence, the command loop
27309normally moves point to the edge of the sequence, making this sequence
27310effectively intangible.
27311
27312   A command can inhibit this feature by setting the variable
27313‘disable-point-adjustment’:
27314
27315 -- Variable: disable-point-adjustment
27316     If this variable is non-‘nil’ when a command returns to the command
27317     loop, then the command loop does not check for those text
27318     properties, and does not move point out of sequences that have
27319     them.
27320
27321     The command loop sets this variable to ‘nil’ before each command,
27322     so if a command sets it, the effect applies only to that command.
27323
27324 -- Variable: global-disable-point-adjustment
27325     If you set this variable to a non-‘nil’ value, the feature of
27326     moving point out of these sequences is completely turned off.
27327
27328
27329File: elisp.info,  Node: Input Events,  Next: Reading Input,  Prev: Adjusting Point,  Up: Command Loop
27330
2733121.7 Input Events
27332=================
27333
27334The Emacs command loop reads a sequence of “input events” that represent
27335keyboard or mouse activity, or system events sent to Emacs.  The events
27336for keyboard activity are characters or symbols; other events are always
27337lists.  This section describes the representation and meaning of input
27338events in detail.
27339
27340 -- Function: eventp object
27341     This function returns non-‘nil’ if OBJECT is an input event or
27342     event type.
27343
27344     Note that any non-‘nil’ symbol might be used as an event or an
27345     event type; ‘eventp’ cannot distinguish whether a symbol is
27346     intended by Lisp code to be used as an event.
27347
27348* Menu:
27349
27350* Keyboard Events::             Ordinary characters – keys with symbols on them.
27351* Function Keys::               Function keys – keys with names, not symbols.
27352* Mouse Events::                Overview of mouse events.
27353* Click Events::                Pushing and releasing a mouse button.
27354* Drag Events::                 Moving the mouse before releasing the button.
27355* Button-Down Events::          A button was pushed and not yet released.
27356* Repeat Events::               Double and triple click (or drag, or down).
27357* Motion Events::               Just moving the mouse, not pushing a button.
27358* Focus Events::                Moving the mouse between frames.
27359* Misc Events::                 Other events the system can generate.
27360* Event Examples::              Examples of the lists for mouse events.
27361* Classifying Events::          Finding the modifier keys in an event symbol.
27362                                Event types.
27363* Accessing Mouse::             Functions to extract info from mouse events.
27364* Accessing Scroll::            Functions to get info from scroll bar events.
27365* Strings of Events::           Special considerations for putting
27366                                  keyboard character events in a string.
27367
27368
27369File: elisp.info,  Node: Keyboard Events,  Next: Function Keys,  Up: Input Events
27370
2737121.7.1 Keyboard Events
27372----------------------
27373
27374There are two kinds of input you can get from the keyboard: ordinary
27375keys, and function keys.  Ordinary keys correspond to (possibly
27376modified) characters; the events they generate are represented in Lisp
27377as characters.  The event type of a “character event” is the character
27378itself (an integer), which might have some modifier bits set; see *note
27379Classifying Events::.
27380
27381   An input character event consists of a “basic code” between 0 and
27382524287, plus any or all of these “modifier bits”:
27383
27384meta
27385     The 2**27 bit in the character code indicates a character typed
27386     with the meta key held down.
27387
27388control
27389     The 2**26 bit in the character code indicates a non-ASCII control
27390     character.
27391
27392     ASCII control characters such as ‘C-a’ have special basic codes of
27393     their own, so Emacs needs no special bit to indicate them.  Thus,
27394     the code for ‘C-a’ is just 1.
27395
27396     But if you type a control combination not in ASCII, such as ‘%’
27397     with the control key, the numeric value you get is the code for ‘%’
27398     plus 2**26 (assuming the terminal supports non-ASCII control
27399     characters), i.e. with the 27th bit set.
27400
27401shift
27402     The 2**25 bit (the 26th bit) in the character event code indicates
27403     an ASCII control character typed with the shift key held down.
27404
27405     For letters, the basic code itself indicates upper versus lower
27406     case; for digits and punctuation, the shift key selects an entirely
27407     different character with a different basic code.  In order to keep
27408     within the ASCII character set whenever possible, Emacs avoids
27409     using the 2**25 bit for those character events.
27410
27411     However, ASCII provides no way to distinguish ‘C-A’ from ‘C-a’, so
27412     Emacs uses the 2**25 bit in ‘C-A’ and not in ‘C-a’.
27413
27414hyper
27415     The 2**24 bit in the character event code indicates a character
27416     typed with the hyper key held down.
27417
27418super
27419     The 2**23 bit in the character event code indicates a character
27420     typed with the super key held down.
27421
27422alt
27423     The 2**22 bit in the character event code indicates a character
27424     typed with the alt key held down.  (The key labeled <Alt> on most
27425     keyboards is actually treated as the meta key, not this.)
27426
27427   It is best to avoid mentioning specific bit numbers in your program.
27428To test the modifier bits of a character, use the function
27429‘event-modifiers’ (*note Classifying Events::).  When making key
27430bindings, you can use the read syntax for characters with modifier bits
27431(‘\C-’, ‘\M-’, and so on).  For making key bindings with ‘define-key’,
27432you can use lists such as ‘(control hyper ?x)’ to specify the characters
27433(*note Changing Key Bindings::).  The function ‘event-convert-list’
27434converts such a list into an event type (*note Classifying Events::).
27435
27436
27437File: elisp.info,  Node: Function Keys,  Next: Mouse Events,  Prev: Keyboard Events,  Up: Input Events
27438
2743921.7.2 Function Keys
27440--------------------
27441
27442Most keyboards also have “function keys”—keys that have names or symbols
27443that are not characters.  Function keys are represented in Emacs Lisp as
27444symbols; the symbol’s name is the function key’s label, in lower case.
27445For example, pressing a key labeled <F1> generates an input event
27446represented by the symbol ‘f1’.
27447
27448   The event type of a function key event is the event symbol itself.
27449*Note Classifying Events::.
27450
27451   Here are a few special cases in the symbol-naming convention for
27452function keys:
27453
27454‘backspace’, ‘tab’, ‘newline’, ‘return’, ‘delete’
27455     These keys correspond to common ASCII control characters that have
27456     special keys on most keyboards.
27457
27458     In ASCII, ‘C-i’ and <TAB> are the same character.  If the terminal
27459     can distinguish between them, Emacs conveys the distinction to Lisp
27460     programs by representing the former as the integer 9, and the
27461     latter as the symbol ‘tab’.
27462
27463     Most of the time, it’s not useful to distinguish the two.  So
27464     normally ‘local-function-key-map’ (*note Translation Keymaps::) is
27465     set up to map ‘tab’ into 9.  Thus, a key binding for character code
27466     9 (the character ‘C-i’) also applies to ‘tab’.  Likewise for the
27467     other symbols in this group.  The function ‘read-char’ likewise
27468     converts these events into characters.
27469
27470     In ASCII, <BS> is really ‘C-h’.  But ‘backspace’ converts into the
27471     character code 127 (<DEL>), not into code 8 (<BS>).  This is what
27472     most users prefer.
27473
27474‘left’, ‘up’, ‘right’, ‘down’
27475     Cursor arrow keys
27476‘kp-add’, ‘kp-decimal’, ‘kp-divide’, ...
27477     Keypad keys (to the right of the regular keyboard).
27478‘kp-0’, ‘kp-1’, ...
27479     Keypad keys with digits.
27480‘kp-f1’, ‘kp-f2’, ‘kp-f3’, ‘kp-f4’
27481     Keypad PF keys.
27482‘kp-home’, ‘kp-left’, ‘kp-up’, ‘kp-right’, ‘kp-down’
27483     Keypad arrow keys.  Emacs normally translates these into the
27484     corresponding non-keypad keys ‘home’, ‘left’, ...
27485‘kp-prior’, ‘kp-next’, ‘kp-end’, ‘kp-begin’, ‘kp-insert’, ‘kp-delete’
27486     Additional keypad duplicates of keys ordinarily found elsewhere.
27487     Emacs normally translates these into the like-named non-keypad
27488     keys.
27489
27490   You can use the modifier keys <ALT>, <CTRL>, <HYPER>, <META>,
27491<SHIFT>, and <SUPER> with function keys.  The way to represent them is
27492with prefixes in the symbol name:
27493
27494‘A-’
27495     The alt modifier.
27496‘C-’
27497     The control modifier.
27498‘H-’
27499     The hyper modifier.
27500‘M-’
27501     The meta modifier.
27502‘S-’
27503     The shift modifier.
27504‘s-’
27505     The super modifier.
27506
27507   Thus, the symbol for the key <F3> with <META> held down is ‘M-f3’.
27508When you use more than one prefix, we recommend you write them in
27509alphabetical order; but the order does not matter in arguments to the
27510key-binding lookup and modification functions.
27511
27512
27513File: elisp.info,  Node: Mouse Events,  Next: Click Events,  Prev: Function Keys,  Up: Input Events
27514
2751521.7.3 Mouse Events
27516-------------------
27517
27518Emacs supports four kinds of mouse events: click events, drag events,
27519button-down events, and motion events.  All mouse events are represented
27520as lists.  The CAR of the list is the event type; this says which mouse
27521button was involved, and which modifier keys were used with it.  The
27522event type can also distinguish double or triple button presses (*note
27523Repeat Events::).  The rest of the list elements give position and time
27524information.
27525
27526   For key lookup, only the event type matters: two events of the same
27527type necessarily run the same command.  The command can access the full
27528values of these events using the ‘e’ interactive code.  *Note
27529Interactive Codes::.
27530
27531   A key sequence that starts with a mouse event is read using the
27532keymaps of the buffer in the window that the mouse was in, not the
27533current buffer.  This does not imply that clicking in a window selects
27534that window or its buffer—that is entirely under the control of the
27535command binding of the key sequence.
27536
27537
27538File: elisp.info,  Node: Click Events,  Next: Drag Events,  Prev: Mouse Events,  Up: Input Events
27539
2754021.7.4 Click Events
27541-------------------
27542
27543When the user presses a mouse button and releases it at the same
27544location, that generates a “click” event.  All mouse click event share
27545the same format:
27546
27547     (EVENT-TYPE POSITION CLICK-COUNT)
27548
27549EVENT-TYPE
27550     This is a symbol that indicates which mouse button was used.  It is
27551     one of the symbols ‘mouse-1’, ‘mouse-2’, ..., where the buttons are
27552     numbered left to right.
27553
27554     You can also use prefixes ‘A-’, ‘C-’, ‘H-’, ‘M-’, ‘S-’ and ‘s-’ for
27555     modifiers alt, control, hyper, meta, shift and super, just as you
27556     would with function keys.
27557
27558     This symbol also serves as the event type of the event.  Key
27559     bindings describe events by their types; thus, if there is a key
27560     binding for ‘mouse-1’, that binding would apply to all events whose
27561     EVENT-TYPE is ‘mouse-1’.
27562
27563POSITION
27564     This is a “mouse position list” specifying where the mouse click
27565     occurred; see below for details.
27566
27567CLICK-COUNT
27568     This is the number of rapid repeated presses so far of the same
27569     mouse button.  *Note Repeat Events::.
27570
27571   To access the contents of a mouse position list in the POSITION slot
27572of a click event, you should typically use the functions documented in
27573*note Accessing Mouse::.
27574
27575   The explicit format of the list depends on where the click occurred.
27576For clicks in the text area, mode line, header line, tab line, or in the
27577fringe or marginal areas, the mouse position list has the form
27578
27579     (WINDOW POS-OR-AREA (X . Y) TIMESTAMP
27580      OBJECT TEXT-POS (COL . ROW)
27581      IMAGE (DX . DY) (WIDTH . HEIGHT))
27582
27583The meanings of these list elements are as follows:
27584
27585WINDOW
27586     The window in which the click occurred.
27587
27588POS-OR-AREA
27589     The buffer position of the character clicked on in the text area;
27590     or, if the click was outside the text area, the window area where
27591     it occurred.  It is one of the symbols ‘mode-line’, ‘header-line’,
27592     ‘tab-line’, ‘vertical-line’, ‘left-margin’, ‘right-margin’,
27593     ‘left-fringe’, or ‘right-fringe’.
27594
27595     In one special case, POS-OR-AREA is a list containing a symbol (one
27596     of the symbols listed above) instead of just the symbol.  This
27597     happens after the imaginary prefix keys for the event are
27598     registered by Emacs.  *Note Key Sequence Input::.
27599
27600X, Y
27601     The relative pixel coordinates of the click.  For clicks in the
27602     text area of a window, the coordinate origin ‘(0 . 0)’ is taken to
27603     be the top left corner of the text area.  *Note Window Sizes::.
27604     For clicks in a mode line, header line or tab line, the coordinate
27605     origin is the top left corner of the window itself.  For fringes,
27606     margins, and the vertical border, X does not have meaningful data.
27607     For fringes and margins, Y is relative to the bottom edge of the
27608     header line.  In all cases, the X and Y coordinates increase
27609     rightward and downward respectively.
27610
27611TIMESTAMP
27612     The time at which the event occurred, as an integer number of
27613     milliseconds since a system-dependent initial time.
27614
27615OBJECT
27616     Either ‘nil’, which means the click occurred on buffer text, or a
27617     cons cell of the form (STRING . STRING-POS) if there is a string
27618     from a text property or an overlay at the click position.
27619
27620     STRING
27621          The string which was clicked on, including any properties.
27622
27623     STRING-POS
27624          The position in the string where the click occurred.
27625
27626TEXT-POS
27627     For clicks on a marginal area or on a fringe, this is the buffer
27628     position of the first visible character in the corresponding line
27629     in the window.  For clicks on the mode line, the header line or the
27630     tab line, this is ‘nil’.  For other events, it is the buffer
27631     position closest to the click.
27632
27633COL, ROW
27634     These are the actual column and row coordinate numbers of the glyph
27635     under the X, Y position.  If X lies beyond the last column of
27636     actual text on its line, COL is reported by adding fictional extra
27637     columns that have the default character width.  Row 0 is taken to
27638     be the header line if the window has one, or Row 1 if the window
27639     also has the tab line, or the topmost row of the text area
27640     otherwise.  Column 0 is taken to be the leftmost column of the text
27641     area for clicks on a window text area, or the leftmost mode line or
27642     header line column for clicks there.  For clicks on fringes or
27643     vertical borders, these have no meaningful data.  For clicks on
27644     margins, COL is measured from the left edge of the margin area and
27645     ROW is measured from the top of the margin area.
27646
27647IMAGE
27648     If there is an image at the click location, this is the image
27649     object as returned by ‘find-image’ (*note Defining Images::);
27650     otherwise this is ‘nil’.
27651
27652DX, DY
27653     These are the pixel coordinates of the click, relative to the top
27654     left corner of OBJECT, which is ‘(0 . 0)’.  If OBJECT is ‘nil’,
27655     which stands for a buffer, the coordinates are relative to the top
27656     left corner of the character glyph clicked on.
27657
27658WIDTH, HEIGHT
27659     These are the pixel width and height of OBJECT or, if this is
27660     ‘nil’, those of the character glyph clicked on.
27661
27662   For clicks on a scroll bar, POSITION has this form:
27663
27664     (WINDOW AREA (PORTION . WHOLE) TIMESTAMP PART)
27665
27666WINDOW
27667     The window whose scroll bar was clicked on.
27668
27669AREA
27670     This is the symbol ‘vertical-scroll-bar’.
27671
27672PORTION
27673     The number of pixels from the top of the scroll bar to the click
27674     position.  On some toolkits, including GTK+, Emacs cannot extract
27675     this data, so the value is always ‘0’.
27676
27677WHOLE
27678     The total length, in pixels, of the scroll bar.  On some toolkits,
27679     including GTK+, Emacs cannot extract this data, so the value is
27680     always ‘0’.
27681
27682TIMESTAMP
27683     The time at which the event occurred, in milliseconds.  On some
27684     toolkits, including GTK+, Emacs cannot extract this data, so the
27685     value is always ‘0’.
27686
27687PART
27688     The part of the scroll bar on which the click occurred.  It is one
27689     of the symbols ‘handle’ (the scroll bar handle), ‘above-handle’
27690     (the area above the handle), ‘below-handle’ (the area below the
27691     handle), ‘up’ (the up arrow at one end of the scroll bar), or
27692     ‘down’ (the down arrow at one end of the scroll bar).
27693
27694   For clicks on the frame’s internal border (*note Frame Layout::),
27695POSITION has this form:
27696
27697      (FRAME PART (X . Y) TIMESTAMP)
27698
27699FRAME
27700     The frame whose internal border was clicked on.
27701
27702PART
27703     The part of the internal border which was clicked on.  This can be
27704     one of the following:
27705
27706     ‘nil’
27707          The frame does not have an internal border.  This usually
27708          happens on text-mode frames.  This can also happen on GUI
27709          frames with internal border if the frame doesn’t have its
27710          ‘drag-internal-border’ parameter (*note Mouse Dragging
27711          Parameters::) set to a non-‘nil’ value.
27712
27713     ‘left-edge’
27714     ‘top-edge’
27715     ‘right-edge’
27716     ‘bottom-edge’
27717          The click was on the corresponding border at an offset of at
27718          least one canonical character from the border’s nearest
27719          corner.
27720
27721     ‘top-left-corner’
27722     ‘top-right-corner’
27723     ‘bottom-right-corner’
27724     ‘bottom-left-corner’
27725          The click was on the corresponding corner of the internal
27726          border.
27727
27728
27729File: elisp.info,  Node: Drag Events,  Next: Button-Down Events,  Prev: Click Events,  Up: Input Events
27730
2773121.7.5 Drag Events
27732------------------
27733
27734With Emacs, you can have a drag event without even changing your
27735clothes.  A “drag event” happens every time the user presses a mouse
27736button and then moves the mouse to a different character position before
27737releasing the button.  Like all mouse events, drag events are
27738represented in Lisp as lists.  The lists record both the starting mouse
27739position and the final position, like this:
27740
27741     (EVENT-TYPE
27742      (WINDOW1 START-POSITION)
27743      (WINDOW2 END-POSITION))
27744
27745   For a drag event, the name of the symbol EVENT-TYPE contains the
27746prefix ‘drag-’.  For example, dragging the mouse with button 2 held down
27747generates a ‘drag-mouse-2’ event.  The second and third elements of the
27748event give the starting and ending position of the drag, as mouse
27749position lists (*note Click Events::).  You can access the second
27750element of any mouse event in the same way.  However, the drag event may
27751end outside the boundaries of the frame that was initially selected.  In
27752that case, the third element’s position list contains that frame in
27753place of a window.
27754
27755   The ‘drag-’ prefix follows the modifier key prefixes such as ‘C-’ and
27756‘M-’.
27757
27758   If ‘read-key-sequence’ receives a drag event that has no key binding,
27759and the corresponding click event does have a binding, it changes the
27760drag event into a click event at the drag’s starting position.  This
27761means that you don’t have to distinguish between click and drag events
27762unless you want to.
27763
27764
27765File: elisp.info,  Node: Button-Down Events,  Next: Repeat Events,  Prev: Drag Events,  Up: Input Events
27766
2776721.7.6 Button-Down Events
27768-------------------------
27769
27770Click and drag events happen when the user releases a mouse button.
27771They cannot happen earlier, because there is no way to distinguish a
27772click from a drag until the button is released.
27773
27774   If you want to take action as soon as a button is pressed, you need
27775to handle “button-down” events.(1)  These occur as soon as a button is
27776pressed.  They are represented by lists that look exactly like click
27777events (*note Click Events::), except that the EVENT-TYPE symbol name
27778contains the prefix ‘down-’.  The ‘down-’ prefix follows modifier key
27779prefixes such as ‘C-’ and ‘M-’.
27780
27781   The function ‘read-key-sequence’ ignores any button-down events that
27782don’t have command bindings; therefore, the Emacs command loop ignores
27783them too.  This means that you need not worry about defining button-down
27784events unless you want them to do something.  The usual reason to define
27785a button-down event is so that you can track mouse motion (by reading
27786motion events) until the button is released.  *Note Motion Events::.
27787
27788   ---------- Footnotes ----------
27789
27790   (1) Button-down is the conservative antithesis of drag.
27791
27792
27793File: elisp.info,  Node: Repeat Events,  Next: Motion Events,  Prev: Button-Down Events,  Up: Input Events
27794
2779521.7.7 Repeat Events
27796--------------------
27797
27798If you press the same mouse button more than once in quick succession
27799without moving the mouse, Emacs generates special “repeat” mouse events
27800for the second and subsequent presses.
27801
27802   The most common repeat events are “double-click” events.  Emacs
27803generates a double-click event when you click a button twice; the event
27804happens when you release the button (as is normal for all click events).
27805
27806   The event type of a double-click event contains the prefix ‘double-’.
27807Thus, a double click on the second mouse button with <meta> held down
27808comes to the Lisp program as ‘M-double-mouse-2’.  If a double-click
27809event has no binding, the binding of the corresponding ordinary click
27810event is used to execute it.  Thus, you need not pay attention to the
27811double click feature unless you really want to.
27812
27813   When the user performs a double click, Emacs generates first an
27814ordinary click event, and then a double-click event.  Therefore, you
27815must design the command binding of the double click event to assume that
27816the single-click command has already run.  It must produce the desired
27817results of a double click, starting from the results of a single click.
27818
27819   This is convenient, if the meaning of a double click somehow builds
27820on the meaning of a single click—which is recommended user interface
27821design practice for double clicks.
27822
27823   If you click a button, then press it down again and start moving the
27824mouse with the button held down, then you get a “double-drag” event when
27825you ultimately release the button.  Its event type contains
27826‘double-drag’ instead of just ‘drag’.  If a double-drag event has no
27827binding, Emacs looks for an alternate binding as if the event were an
27828ordinary drag.
27829
27830   Before the double-click or double-drag event, Emacs generates a
27831“double-down” event when the user presses the button down for the second
27832time.  Its event type contains ‘double-down’ instead of just ‘down’.  If
27833a double-down event has no binding, Emacs looks for an alternate binding
27834as if the event were an ordinary button-down event.  If it finds no
27835binding that way either, the double-down event is ignored.
27836
27837   To summarize, when you click a button and then press it again right
27838away, Emacs generates a down event and a click event for the first
27839click, a double-down event when you press the button again, and finally
27840either a double-click or a double-drag event.
27841
27842   If you click a button twice and then press it again, all in quick
27843succession, Emacs generates a “triple-down” event, followed by either a
27844“triple-click” or a “triple-drag”.  The event types of these events
27845contain ‘triple’ instead of ‘double’.  If any triple event has no
27846binding, Emacs uses the binding that it would use for the corresponding
27847double event.
27848
27849   If you click a button three or more times and then press it again,
27850the events for the presses beyond the third are all triple events.
27851Emacs does not have separate event types for quadruple, quintuple, etc.
27852events.  However, you can look at the event list to find out precisely
27853how many times the button was pressed.
27854
27855 -- Function: event-click-count event
27856     This function returns the number of consecutive button presses that
27857     led up to EVENT.  If EVENT is a double-down, double-click or
27858     double-drag event, the value is 2.  If EVENT is a triple event, the
27859     value is 3 or greater.  If EVENT is an ordinary mouse event (not a
27860     repeat event), the value is 1.
27861
27862 -- User Option: double-click-fuzz
27863     To generate repeat events, successive mouse button presses must be
27864     at approximately the same screen position.  The value of
27865     ‘double-click-fuzz’ specifies the maximum number of pixels the
27866     mouse may be moved (horizontally or vertically) between two
27867     successive clicks to make a double-click.
27868
27869     This variable is also the threshold for motion of the mouse to
27870     count as a drag.
27871
27872 -- User Option: double-click-time
27873     To generate repeat events, the number of milliseconds between
27874     successive button presses must be less than the value of
27875     ‘double-click-time’.  Setting ‘double-click-time’ to ‘nil’ disables
27876     multi-click detection entirely.  Setting it to ‘t’ removes the time
27877     limit; Emacs then detects multi-clicks by position only.
27878
27879
27880File: elisp.info,  Node: Motion Events,  Next: Focus Events,  Prev: Repeat Events,  Up: Input Events
27881
2788221.7.8 Motion Events
27883--------------------
27884
27885Emacs sometimes generates “mouse motion” events to describe motion of
27886the mouse without any button activity.  Mouse motion events are
27887represented by lists that look like this:
27888
27889     (mouse-movement POSITION)
27890
27891POSITION is a mouse position list (*note Click Events::), specifying the
27892current position of the mouse cursor.  As with the end-position of a
27893drag event, this position list may represent a location outside the
27894boundaries of the initially selected frame, in which case the list
27895contains that frame in place of a window.
27896
27897   The special form ‘track-mouse’ enables generation of motion events
27898within its body.  Outside of ‘track-mouse’ forms, Emacs does not
27899generate events for mere motion of the mouse, and these events do not
27900appear.  *Note Mouse Tracking::.
27901
27902 -- Variable: mouse-fine-grained-tracking
27903     When non-‘nil’, mouse motion events are generated even for very
27904     small movements.  Otherwise, motion events are not generated as
27905     long as the mouse cursor remains pointing to the same glyph in the
27906     text.
27907
27908
27909File: elisp.info,  Node: Focus Events,  Next: Misc Events,  Prev: Motion Events,  Up: Input Events
27910
2791121.7.9 Focus Events
27912-------------------
27913
27914Window systems provide general ways for the user to control which window
27915gets keyboard input.  This choice of window is called the “focus”.  When
27916the user does something to switch between Emacs frames, that generates a
27917“focus event”.  The normal definition of a focus event, in the global
27918keymap, is to select a new frame within Emacs, as the user would expect.
27919*Note Input Focus::, which also describes hooks related to focus events.
27920
27921   Focus events are represented in Lisp as lists that look like this:
27922
27923     (switch-frame NEW-FRAME)
27924
27925where NEW-FRAME is the frame switched to.
27926
27927   Some X window managers are set up so that just moving the mouse into
27928a window is enough to set the focus there.  Usually, there is no need
27929for a Lisp program to know about the focus change until some other kind
27930of input arrives.  Emacs generates a focus event only when the user
27931actually types a keyboard key or presses a mouse button in the new
27932frame; just moving the mouse between frames does not generate a focus
27933event.
27934
27935   A focus event in the middle of a key sequence would garble the
27936sequence.  So Emacs never generates a focus event in the middle of a key
27937sequence.  If the user changes focus in the middle of a key
27938sequence—that is, after a prefix key—then Emacs reorders the events so
27939that the focus event comes either before or after the multi-event key
27940sequence, and not within it.
27941
27942
27943File: elisp.info,  Node: Misc Events,  Next: Event Examples,  Prev: Focus Events,  Up: Input Events
27944
2794521.7.10 Miscellaneous System Events
27946-----------------------------------
27947
27948A few other event types represent occurrences within the system.
27949
27950‘(delete-frame (FRAME))’
27951     This kind of event indicates that the user gave the window manager
27952     a command to delete a particular window, which happens to be an
27953     Emacs frame.
27954
27955     The standard definition of the ‘delete-frame’ event is to delete
27956     FRAME.
27957
27958‘(iconify-frame (FRAME))’
27959     This kind of event indicates that the user iconified FRAME using
27960     the window manager.  Its standard definition is ‘ignore’; since the
27961     frame has already been iconified, Emacs has no work to do.  The
27962     purpose of this event type is so that you can keep track of such
27963     events if you want to.
27964
27965‘(make-frame-visible (FRAME))’
27966     This kind of event indicates that the user deiconified FRAME using
27967     the window manager.  Its standard definition is ‘ignore’; since the
27968     frame has already been made visible, Emacs has no work to do.
27969
27970‘(wheel-up POSITION)’
27971‘(wheel-down POSITION)’
27972     These kinds of event are generated by moving a mouse wheel.  The
27973     POSITION element is a mouse position list (*note Click Events::),
27974     specifying the position of the mouse cursor when the event
27975     occurred.
27976
27977     This kind of event is generated only on some kinds of systems.  On
27978     some systems, ‘mouse-4’ and ‘mouse-5’ are used instead.  For
27979     portable code, use the variables ‘mouse-wheel-up-event’ and
27980     ‘mouse-wheel-down-event’ defined in ‘mwheel.el’ to determine what
27981     event types to expect for the mouse wheel.
27982
27983‘(drag-n-drop POSITION FILES)’
27984     This kind of event is generated when a group of files is selected
27985     in an application outside of Emacs, and then dragged and dropped
27986     onto an Emacs frame.
27987
27988     The element POSITION is a list describing the position of the
27989     event, in the same format as used in a mouse-click event (*note
27990     Click Events::), and FILES is the list of file names that were
27991     dragged and dropped.  The usual way to handle this event is by
27992     visiting these files.
27993
27994     This kind of event is generated, at present, only on some kinds of
27995     systems.
27996
27997‘help-echo’
27998     This kind of event is generated when a mouse pointer moves onto a
27999     portion of buffer text which has a ‘help-echo’ text property.  The
28000     generated event has this form:
28001
28002          (help-echo FRAME HELP WINDOW OBJECT POS)
28003
28004     The precise meaning of the event parameters and the way these
28005     parameters are used to display the help-echo text are described in
28006     *note Text help-echo::.
28007
28008‘sigusr1’
28009‘sigusr2’
28010     These events are generated when the Emacs process receives the
28011     signals ‘SIGUSR1’ and ‘SIGUSR2’.  They contain no additional data
28012     because signals do not carry additional information.  They can be
28013     useful for debugging (*note Error Debugging::).
28014
28015     To catch a user signal, bind the corresponding event to an
28016     interactive command in the ‘special-event-map’ (*note Controlling
28017     Active Maps::).  The command is called with no arguments, and the
28018     specific signal event is available in ‘last-input-event’ (*note
28019     Event Input Misc::.  For example:
28020
28021          (defun sigusr-handler ()
28022            (interactive)
28023            (message "Caught signal %S" last-input-event))
28024
28025          (define-key special-event-map [sigusr1] 'sigusr-handler)
28026
28027     To test the signal handler, you can make Emacs send a signal to
28028     itself:
28029
28030          (signal-process (emacs-pid) 'sigusr1)
28031
28032‘language-change’
28033     This kind of event is generated on MS-Windows when the input
28034     language has changed.  This typically means that the keyboard keys
28035     will send to Emacs characters from a different language.  The
28036     generated event has this form:
28037
28038          (language-change FRAME CODEPAGE LANGUAGE-ID)
28039
28040     Here FRAME is the frame which was current when the input language
28041     changed; CODEPAGE is the new codepage number; and LANGUAGE-ID is
28042     the numerical ID of the new input language.  The coding-system
28043     (*note Coding Systems::) that corresponds to CODEPAGE is
28044     ‘cpCODEPAGE’ or ‘windows-CODEPAGE’.  To convert LANGUAGE-ID to a
28045     string (e.g., to use it for various language-dependent features,
28046     such as ‘set-language-environment’), use the ‘w32-get-locale-info’
28047     function, like this:
28048
28049          ;; Get the abbreviated language name, such as "ENU" for English
28050          (w32-get-locale-info language-id)
28051          ;; Get the full English name of the language,
28052          ;; such as "English (United States)"
28053          (w32-get-locale-info language-id 4097)
28054          ;; Get the full localized name of the language
28055          (w32-get-locale-info language-id t)
28056
28057   If one of these events arrives in the middle of a key sequence—that
28058is, after a prefix key—then Emacs reorders the events so that this event
28059comes either before or after the multi-event key sequence, not within
28060it.
28061
28062   Some of these special events, such as ‘delete-frame’, invoke Emacs
28063commands by default; others are not bound.  If you want to arrange for a
28064special event to invoke a command, you can do that via
28065‘special-event-map’.  The command you bind to a function key in that map
28066can then examine the full event which invoked it in ‘last-input-event’.
28067*Note Special Events::.
28068
28069
28070File: elisp.info,  Node: Event Examples,  Next: Classifying Events,  Prev: Misc Events,  Up: Input Events
28071
2807221.7.11 Event Examples
28073----------------------
28074
28075If the user presses and releases the left mouse button over the same
28076location, that generates a sequence of events like this:
28077
28078     (down-mouse-1 (#<window 18 on NEWS> 2613 (0 . 38) -864320))
28079     (mouse-1      (#<window 18 on NEWS> 2613 (0 . 38) -864180))
28080
28081   While holding the control key down, the user might hold down the
28082second mouse button, and drag the mouse from one line to the next.  That
28083produces two events, as shown here:
28084
28085     (C-down-mouse-2 (#<window 18 on NEWS> 3440 (0 . 27) -731219))
28086     (C-drag-mouse-2 (#<window 18 on NEWS> 3440 (0 . 27) -731219)
28087                     (#<window 18 on NEWS> 3510 (0 . 28) -729648))
28088
28089   While holding down the meta and shift keys, the user might press the
28090second mouse button on the window’s mode line, and then drag the mouse
28091into another window.  That produces a pair of events like these:
28092
28093     (M-S-down-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844))
28094     (M-S-drag-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844)
28095                       (#<window 20 on carlton-sanskrit.tex> 161 (33 . 3)
28096                        -453816))
28097
28098   The frame with input focus might not take up the entire screen, and
28099the user might move the mouse outside the scope of the frame.  Inside
28100the ‘track-mouse’ special form, that produces an event like this:
28101
28102     (mouse-movement (#<frame *ielm* 0x102849a30> nil (563 . 205) 532301936))
28103
28104   To handle a SIGUSR1 signal, define an interactive function, and bind
28105it to the ‘signal usr1’ event sequence:
28106
28107     (defun usr1-handler ()
28108       (interactive)
28109       (message "Got USR1 signal"))
28110     (global-set-key [signal usr1] 'usr1-handler)
28111
28112
28113File: elisp.info,  Node: Classifying Events,  Next: Accessing Mouse,  Prev: Event Examples,  Up: Input Events
28114
2811521.7.12 Classifying Events
28116--------------------------
28117
28118Every event has an “event type”, which classifies the event for key
28119binding purposes.  For a keyboard event, the event type equals the event
28120value; thus, the event type for a character is the character, and the
28121event type for a function key symbol is the symbol itself.  For events
28122that are lists, the event type is the symbol in the CAR of the list.
28123Thus, the event type is always a symbol or a character.
28124
28125   Two events of the same type are equivalent where key bindings are
28126concerned; thus, they always run the same command.  That does not
28127necessarily mean they do the same things, however, as some commands look
28128at the whole event to decide what to do.  For example, some commands use
28129the location of a mouse event to decide where in the buffer to act.
28130
28131   Sometimes broader classifications of events are useful.  For example,
28132you might want to ask whether an event involved the <META> key,
28133regardless of which other key or mouse button was used.
28134
28135   The functions ‘event-modifiers’ and ‘event-basic-type’ are provided
28136to get such information conveniently.
28137
28138 -- Function: event-modifiers event
28139     This function returns a list of the modifiers that EVENT has.  The
28140     modifiers are symbols; they include ‘shift’, ‘control’, ‘meta’,
28141     ‘alt’, ‘hyper’ and ‘super’.  In addition, the modifiers list of a
28142     mouse event symbol always contains one of ‘click’, ‘drag’, and
28143     ‘down’.  For double or triple events, it also contains ‘double’ or
28144     ‘triple’.
28145
28146     The argument EVENT may be an entire event object, or just an event
28147     type.  If EVENT is a symbol that has never been used in an event
28148     that has been read as input in the current Emacs session, then
28149     ‘event-modifiers’ can return ‘nil’, even when EVENT actually has
28150     modifiers.
28151
28152     Here are some examples:
28153
28154          (event-modifiers ?a)
28155               ⇒ nil
28156          (event-modifiers ?A)
28157               ⇒ (shift)
28158          (event-modifiers ?\C-a)
28159               ⇒ (control)
28160          (event-modifiers ?\C-%)
28161               ⇒ (control)
28162          (event-modifiers ?\C-\S-a)
28163               ⇒ (control shift)
28164          (event-modifiers 'f5)
28165               ⇒ nil
28166          (event-modifiers 's-f5)
28167               ⇒ (super)
28168          (event-modifiers 'M-S-f5)
28169               ⇒ (meta shift)
28170          (event-modifiers 'mouse-1)
28171               ⇒ (click)
28172          (event-modifiers 'down-mouse-1)
28173               ⇒ (down)
28174
28175     The modifiers list for a click event explicitly contains ‘click’,
28176     but the event symbol name itself does not contain ‘click’.
28177     Similarly, the modifiers list for an ASCII control character, such
28178     as ‘C-a’, contains ‘control’, even though reading such an event via
28179     ‘read-char’ will return the value 1 with the control modifier bit
28180     removed.
28181
28182 -- Function: event-basic-type event
28183     This function returns the key or mouse button that EVENT describes,
28184     with all modifiers removed.  The EVENT argument is as in
28185     ‘event-modifiers’.  For example:
28186
28187          (event-basic-type ?a)
28188               ⇒ 97
28189          (event-basic-type ?A)
28190               ⇒ 97
28191          (event-basic-type ?\C-a)
28192               ⇒ 97
28193          (event-basic-type ?\C-\S-a)
28194               ⇒ 97
28195          (event-basic-type 'f5)
28196               ⇒ f5
28197          (event-basic-type 's-f5)
28198               ⇒ f5
28199          (event-basic-type 'M-S-f5)
28200               ⇒ f5
28201          (event-basic-type 'down-mouse-1)
28202               ⇒ mouse-1
28203
28204 -- Function: mouse-movement-p object
28205     This function returns non-‘nil’ if OBJECT is a mouse movement
28206     event.  *Note Motion Events::.
28207
28208 -- Function: event-convert-list list
28209     This function converts a list of modifier names and a basic event
28210     type to an event type which specifies all of them.  The basic event
28211     type must be the last element of the list.  For example,
28212
28213          (event-convert-list '(control ?a))
28214               ⇒ 1
28215          (event-convert-list '(control meta ?a))
28216               ⇒ -134217727
28217          (event-convert-list '(control super f1))
28218               ⇒ C-s-f1
28219
28220
28221File: elisp.info,  Node: Accessing Mouse,  Next: Accessing Scroll,  Prev: Classifying Events,  Up: Input Events
28222
2822321.7.13 Accessing Mouse Events
28224------------------------------
28225
28226This section describes convenient functions for accessing the data in a
28227mouse button or motion event.  Keyboard event data can be accessed using
28228the same functions, but data elements that aren’t applicable to keyboard
28229events are zero or ‘nil’.
28230
28231   The following two functions return a mouse position list (*note Click
28232Events::), specifying the position of a mouse event.
28233
28234 -- Function: event-start event
28235     This returns the starting position of EVENT.
28236
28237     If EVENT is a click or button-down event, this returns the location
28238     of the event.  If EVENT is a drag event, this returns the drag’s
28239     starting position.
28240
28241 -- Function: event-end event
28242     This returns the ending position of EVENT.
28243
28244     If EVENT is a drag event, this returns the position where the user
28245     released the mouse button.  If EVENT is a click or button-down
28246     event, the value is actually the starting position, which is the
28247     only position such events have.
28248
28249 -- Function: posnp object
28250     This function returns non-‘nil’ if OBJECT is a mouse position list,
28251     in the format documented in *note Click Events::); and ‘nil’
28252     otherwise.
28253
28254   These functions take a mouse position list as argument, and return
28255various parts of it:
28256
28257 -- Function: posn-window position
28258     Return the window that POSITION is in.  If POSITION represents a
28259     location outside the frame where the event was initiated, return
28260     that frame instead.
28261
28262 -- Function: posn-area position
28263     Return the window area recorded in POSITION.  It returns ‘nil’ when
28264     the event occurred in the text area of the window; otherwise, it is
28265     a symbol identifying the area in which the event occurred.
28266
28267 -- Function: posn-point position
28268     Return the buffer position in POSITION.  When the event occurred in
28269     the text area of the window, in a marginal area, or on a fringe,
28270     this is an integer specifying a buffer position.  Otherwise, the
28271     value is undefined.
28272
28273 -- Function: posn-x-y position
28274     Return the pixel-based x and y coordinates in POSITION, as a cons
28275     cell ‘(X . Y)’.  These coordinates are relative to the window given
28276     by ‘posn-window’.
28277
28278     This example shows how to convert the window-relative coordinates
28279     in the text area of a window into frame-relative coordinates:
28280
28281          (defun frame-relative-coordinates (position)
28282            "Return frame-relative coordinates from POSITION.
28283          POSITION is assumed to lie in a window text area."
28284            (let* ((x-y (posn-x-y position))
28285                   (window (posn-window position))
28286                   (edges (window-inside-pixel-edges window)))
28287              (cons (+ (car x-y) (car edges))
28288                    (+ (cdr x-y) (cadr edges)))))
28289
28290 -- Function: posn-col-row position
28291     This function returns a cons cell ‘(COL .  ROW)’, containing the
28292     estimated column and row corresponding to buffer position described
28293     by POSITION.  The return value is given in units of the frame’s
28294     default character width and default line height (including
28295     spacing), as computed from the X and Y values corresponding to
28296     POSITION.  (So, if the actual characters have non-default sizes,
28297     the actual row and column may differ from these computed values.)
28298
28299     Note that ROW is counted from the top of the text area.  If the
28300     window given by POSITION possesses a header line (*note Header
28301     Lines::) or a tab line, they are _not_ included in the ROW count.
28302
28303 -- Function: posn-actual-col-row position
28304     Return the actual row and column in POSITION, as a cons cell
28305     ‘(COL . ROW)’.  The values are the actual row and column numbers in
28306     the window given by POSITION.  *Note Click Events::, for details.
28307     The function returns ‘nil’ if POSITION does not include actual
28308     position values; in that case ‘posn-col-row’ can be used to get
28309     approximate values.
28310
28311     Note that this function doesn’t account for the visual width of
28312     characters on display, like the number of visual columns taken by a
28313     tab character or an image.  If you need the coordinates in
28314     canonical character units, use ‘posn-col-row’ instead.
28315
28316 -- Function: posn-string position
28317     Return the string object described by POSITION, either ‘nil’ (which
28318     means POSITION describes buffer text), or a cons cell
28319     ‘(STRING . STRING-POS)’.
28320
28321 -- Function: posn-image position
28322     Return the image object in POSITION, either ‘nil’ (if there’s no
28323     image at POSITION), or an image spec ‘(image ...)’.
28324
28325 -- Function: posn-object position
28326     Return the image or string object described by POSITION, either
28327     ‘nil’ (which means POSITION describes buffer text), an image
28328     ‘(image ...)’, or a cons cell ‘(STRING . STRING-POS)’.
28329
28330 -- Function: posn-object-x-y position
28331     Return the pixel-based x and y coordinates relative to the upper
28332     left corner of the object described by POSITION, as a cons cell
28333     ‘(DX . DY)’.  If the POSITION describes buffer text, return the
28334     relative coordinates of the buffer-text character closest to that
28335     position.
28336
28337 -- Function: posn-object-width-height position
28338     Return the pixel width and height of the object described by
28339     POSITION, as a cons cell ‘(WIDTH . HEIGHT)’.  If the POSITION
28340     describes a buffer position, return the size of the character at
28341     that position.
28342
28343 -- Function: posn-timestamp position
28344     Return the timestamp in POSITION.  This is the time at which the
28345     event occurred, in milliseconds.
28346
28347   These functions compute a position list given particular buffer
28348position or screen position.  You can access the data in this position
28349list with the functions described above.
28350
28351 -- Function: posn-at-point &optional pos window
28352     This function returns a position list for position POS in WINDOW.
28353     POS defaults to point in WINDOW; WINDOW defaults to the selected
28354     window.
28355
28356     ‘posn-at-point’ returns ‘nil’ if POS is not visible in WINDOW.
28357
28358 -- Function: posn-at-x-y x y &optional frame-or-window whole
28359     This function returns position information corresponding to pixel
28360     coordinates X and Y in a specified frame or window,
28361     FRAME-OR-WINDOW, which defaults to the selected window.  The
28362     coordinates X and Y are relative to the frame or window used.  If
28363     WHOLE is ‘nil’, the coordinates are relative to the window text
28364     area, otherwise they are relative to the entire window area
28365     including scroll bars, margins and fringes.
28366
28367
28368File: elisp.info,  Node: Accessing Scroll,  Next: Strings of Events,  Prev: Accessing Mouse,  Up: Input Events
28369
2837021.7.14 Accessing Scroll Bar Events
28371-----------------------------------
28372
28373These functions are useful for decoding scroll bar events.
28374
28375 -- Function: scroll-bar-event-ratio event
28376     This function returns the fractional vertical position of a scroll
28377     bar event within the scroll bar.  The value is a cons cell
28378     ‘(PORTION . WHOLE)’ containing two integers whose ratio is the
28379     fractional position.
28380
28381 -- Function: scroll-bar-scale ratio total
28382     This function multiplies (in effect) RATIO by TOTAL, rounding the
28383     result to an integer.  The argument RATIO is not a number, but
28384     rather a pair ‘(NUM . DENOM)’—typically a value returned by
28385     ‘scroll-bar-event-ratio’.
28386
28387     This function is handy for scaling a position on a scroll bar into
28388     a buffer position.  Here’s how to do that:
28389
28390          (+ (point-min)
28391             (scroll-bar-scale
28392                (posn-x-y (event-start event))
28393                (- (point-max) (point-min))))
28394
28395     Recall that scroll bar events have two integers forming a ratio, in
28396     place of a pair of x and y coordinates.
28397
28398
28399File: elisp.info,  Node: Strings of Events,  Prev: Accessing Scroll,  Up: Input Events
28400
2840121.7.15 Putting Keyboard Events in Strings
28402------------------------------------------
28403
28404In most of the places where strings are used, we conceptualize the
28405string as containing text characters—the same kind of characters found
28406in buffers or files.  Occasionally Lisp programs use strings that
28407conceptually contain keyboard characters; for example, they may be key
28408sequences or keyboard macro definitions.  However, storing keyboard
28409characters in a string is a complex matter, for reasons of historical
28410compatibility, and it is not always possible.
28411
28412   We recommend that new programs avoid dealing with these complexities
28413by not storing keyboard events in strings.  Here is how to do that:
28414
28415   • Use vectors instead of strings for key sequences, when you plan to
28416     use them for anything other than as arguments to ‘lookup-key’ and
28417     ‘define-key’.  For example, you can use ‘read-key-sequence-vector’
28418     instead of ‘read-key-sequence’, and ‘this-command-keys-vector’
28419     instead of ‘this-command-keys’.
28420
28421   • Use vectors to write key sequence constants containing meta
28422     characters, even when passing them directly to ‘define-key’.
28423
28424   • When you have to look at the contents of a key sequence that might
28425     be a string, use ‘listify-key-sequence’ (*note Event Input Misc::)
28426     first, to convert it to a list.
28427
28428   The complexities stem from the modifier bits that keyboard input
28429characters can include.  Aside from the Meta modifier, none of these
28430modifier bits can be included in a string, and the Meta modifier is
28431allowed only in special cases.
28432
28433   The earliest GNU Emacs versions represented meta characters as codes
28434in the range of 128 to 255.  At that time, the basic character codes
28435ranged from 0 to 127, so all keyboard character codes did fit in a
28436string.  Many Lisp programs used ‘\M-’ in string constants to stand for
28437meta characters, especially in arguments to ‘define-key’ and similar
28438functions, and key sequences and sequences of events were always
28439represented as strings.
28440
28441   When we added support for larger basic character codes beyond 127,
28442and additional modifier bits, we had to change the representation of
28443meta characters.  Now the flag that represents the Meta modifier in a
28444character is 2**27 and such numbers cannot be included in a string.
28445
28446   To support programs with ‘\M-’ in string constants, there are special
28447rules for including certain meta characters in a string.  Here are the
28448rules for interpreting a string as a sequence of input characters:
28449
28450   • If the keyboard character value is in the range of 0 to 127, it can
28451     go in the string unchanged.
28452
28453   • The meta variants of those characters, with codes in the range of
28454     2**27 to 2**27+127, can also go in the string, but you must change
28455     their numeric values.  You must set the 2**7 bit instead of the
28456     2**27 bit, resulting in a value between 128 and 255.  Only a
28457     unibyte string can include these codes.
28458
28459   • Non-ASCII characters above 256 can be included in a multibyte
28460     string.
28461
28462   • Other keyboard character events cannot fit in a string.  This
28463     includes keyboard events in the range of 128 to 255.
28464
28465   Functions such as ‘read-key-sequence’ that construct strings of
28466keyboard input characters follow these rules: they construct vectors
28467instead of strings, when the events won’t fit in a string.
28468
28469   When you use the read syntax ‘\M-’ in a string, it produces a code in
28470the range of 128 to 255—the same code that you get if you modify the
28471corresponding keyboard event to put it in the string.  Thus, meta events
28472in strings work consistently regardless of how they get into the
28473strings.
28474
28475   However, most programs would do well to avoid these issues by
28476following the recommendations at the beginning of this section.
28477
28478
28479File: elisp.info,  Node: Reading Input,  Next: Special Events,  Prev: Input Events,  Up: Command Loop
28480
2848121.8 Reading Input
28482==================
28483
28484The editor command loop reads key sequences using the function
28485‘read-key-sequence’, which uses ‘read-event’.  These and other functions
28486for event input are also available for use in Lisp programs.  See also
28487‘momentary-string-display’ in *note Temporary Displays::, and ‘sit-for’
28488in *note Waiting::.  *Note Terminal Input::, for functions and variables
28489for controlling terminal input modes and debugging terminal input.
28490
28491   For higher-level input facilities, see *note Minibuffers::.
28492
28493* Menu:
28494
28495* Key Sequence Input::          How to read one key sequence.
28496* Reading One Event::           How to read just one event.
28497* Event Mod::                   How Emacs modifies events as they are read.
28498* Invoking the Input Method::   How reading an event uses the input method.
28499* Quoted Character Input::      Asking the user to specify a character.
28500* Event Input Misc::            How to reread or throw away input events.
28501
28502
28503File: elisp.info,  Node: Key Sequence Input,  Next: Reading One Event,  Up: Reading Input
28504
2850521.8.1 Key Sequence Input
28506-------------------------
28507
28508The command loop reads input a key sequence at a time, by calling
28509‘read-key-sequence’.  Lisp programs can also call this function; for
28510example, ‘describe-key’ uses it to read the key to describe.
28511
28512 -- Function: read-key-sequence prompt &optional continue-echo
28513          dont-downcase-last switch-frame-ok command-loop
28514     This function reads a key sequence and returns it as a string or
28515     vector.  It keeps reading events until it has accumulated a
28516     complete key sequence; that is, enough to specify a non-prefix
28517     command using the currently active keymaps.  (Remember that a key
28518     sequence that starts with a mouse event is read using the keymaps
28519     of the buffer in the window that the mouse was in, not the current
28520     buffer.)
28521
28522     If the events are all characters and all can fit in a string, then
28523     ‘read-key-sequence’ returns a string (*note Strings of Events::).
28524     Otherwise, it returns a vector, since a vector can hold all kinds
28525     of events—characters, symbols, and lists.  The elements of the
28526     string or vector are the events in the key sequence.
28527
28528     Reading a key sequence includes translating the events in various
28529     ways.  *Note Translation Keymaps::.
28530
28531     The argument PROMPT is either a string to be displayed in the echo
28532     area as a prompt, or ‘nil’, meaning not to display a prompt.  The
28533     argument CONTINUE-ECHO, if non-‘nil’, means to echo this key as a
28534     continuation of the previous key.
28535
28536     Normally any upper case event is converted to lower case if the
28537     original event is undefined and the lower case equivalent is
28538     defined.  The argument DONT-DOWNCASE-LAST, if non-‘nil’, means do
28539     not convert the last event to lower case.  This is appropriate for
28540     reading a key sequence to be defined.
28541
28542     The argument SWITCH-FRAME-OK, if non-‘nil’, means that this
28543     function should process a ‘switch-frame’ event if the user switches
28544     frames before typing anything.  If the user switches frames in the
28545     middle of a key sequence, or at the start of the sequence but
28546     SWITCH-FRAME-OK is ‘nil’, then the event will be put off until
28547     after the current key sequence.
28548
28549     The argument COMMAND-LOOP, if non-‘nil’, means that this key
28550     sequence is being read by something that will read commands one
28551     after another.  It should be ‘nil’ if the caller will read just one
28552     key sequence.
28553
28554     In the following example, Emacs displays the prompt ‘?’ in the echo
28555     area, and then the user types ‘C-x C-f’.
28556
28557          (read-key-sequence "?")
28558
28559          ---------- Echo Area ----------
28560          ?C-x C-f
28561          ---------- Echo Area ----------
28562
28563               ⇒ "^X^F"
28564
28565     The function ‘read-key-sequence’ suppresses quitting: ‘C-g’ typed
28566     while reading with this function works like any other character,
28567     and does not set ‘quit-flag’.  *Note Quitting::.
28568
28569 -- Function: read-key-sequence-vector prompt &optional continue-echo
28570          dont-downcase-last switch-frame-ok command-loop
28571     This is like ‘read-key-sequence’ except that it always returns the
28572     key sequence as a vector, never as a string.  *Note Strings of
28573     Events::.
28574
28575   If an input character is upper-case (or has the shift modifier) and
28576has no key binding, but its lower-case equivalent has one, then
28577‘read-key-sequence’ converts the character to lower case.  Note that
28578‘lookup-key’ does not perform case conversion in this way.
28579
28580   When reading input results in such a “shift-translation”, Emacs sets
28581the variable ‘this-command-keys-shift-translated’ to a non-‘nil’ value.
28582Lisp programs can examine this variable if they need to modify their
28583behavior when invoked by shift-translated keys.  For example, the
28584function ‘handle-shift-selection’ examines the value of this variable to
28585determine how to activate or deactivate the region (*note
28586handle-shift-selection: The Mark.).
28587
28588   The function ‘read-key-sequence’ also transforms some mouse events.
28589It converts unbound drag events into click events, and discards unbound
28590button-down events entirely.  It also reshuffles focus events and
28591miscellaneous window events so that they never appear in a key sequence
28592with any other events.
28593
28594   When mouse events occur in special parts of a window or frame, such
28595as a mode line or a scroll bar, the event type shows nothing special—it
28596is the same symbol that would normally represent that combination of
28597mouse button and modifier keys.  The information about the window part
28598is kept elsewhere in the event—in the coordinates.  But
28599‘read-key-sequence’ translates this information into imaginary prefix
28600keys, all of which are symbols: ‘tab-line’, ‘header-line’,
28601‘horizontal-scroll-bar’, ‘menu-bar’, ‘tab-bar’, ‘mode-line’,
28602‘vertical-line’, ‘vertical-scroll-bar’, ‘left-margin’, ‘right-margin’,
28603‘left-fringe’, ‘right-fringe’, ‘right-divider’, and ‘bottom-divider’.
28604You can define meanings for mouse clicks in special window parts by
28605defining key sequences using these imaginary prefix keys.
28606
28607   For example, if you call ‘read-key-sequence’ and then click the mouse
28608on the window’s mode line, you get two events, like this:
28609
28610     (read-key-sequence "Click on the mode line: ")
28611          ⇒ [mode-line
28612              (mouse-1
28613               (#<window 6 on NEWS> mode-line
28614                (40 . 63) 5959987))]
28615
28616 -- Variable: num-input-keys
28617     This variable’s value is the number of key sequences processed so
28618     far in this Emacs session.  This includes key sequences read from
28619     the terminal and key sequences read from keyboard macros being
28620     executed.
28621
28622
28623File: elisp.info,  Node: Reading One Event,  Next: Event Mod,  Prev: Key Sequence Input,  Up: Reading Input
28624
2862521.8.2 Reading One Event
28626------------------------
28627
28628The lowest level functions for command input are ‘read-event’,
28629‘read-char’, and ‘read-char-exclusive’.
28630
28631   If you need a function to read a character using the minibuffer, use
28632‘read-char-from-minibuffer’ (*note Multiple Queries::).
28633
28634 -- Function: read-event &optional prompt inherit-input-method seconds
28635     This function reads and returns the next event of command input,
28636     waiting if necessary until an event is available.
28637
28638     The returned event may come directly from the user, or from a
28639     keyboard macro.  It is not decoded by the keyboard’s input coding
28640     system (*note Terminal I/O Encoding::).
28641
28642     If the optional argument PROMPT is non-‘nil’, it should be a string
28643     to display in the echo area as a prompt.  If PROMPT is ‘nil’ or the
28644     string ‘""’, ‘read-event’ does not display any message to indicate
28645     it is waiting for input; instead, it prompts by echoing: it
28646     displays descriptions of the events that led to or were read by the
28647     current command.  *Note The Echo Area::.
28648
28649     If INHERIT-INPUT-METHOD is non-‘nil’, then the current input method
28650     (if any) is employed to make it possible to enter a non-ASCII
28651     character.  Otherwise, input method handling is disabled for
28652     reading this event.
28653
28654     If ‘cursor-in-echo-area’ is non-‘nil’, then ‘read-event’ moves the
28655     cursor temporarily to the echo area, to the end of any message
28656     displayed there.  Otherwise ‘read-event’ does not move the cursor.
28657
28658     If SECONDS is non-‘nil’, it should be a number specifying the
28659     maximum time to wait for input, in seconds.  If no input arrives
28660     within that time, ‘read-event’ stops waiting and returns ‘nil’.  A
28661     floating point SECONDS means to wait for a fractional number of
28662     seconds.  Some systems support only a whole number of seconds; on
28663     these systems, SECONDS is rounded down.  If SECONDS is ‘nil’,
28664     ‘read-event’ waits as long as necessary for input to arrive.
28665
28666     If SECONDS is ‘nil’, Emacs is considered idle while waiting for
28667     user input to arrive.  Idle timers—those created with
28668     ‘run-with-idle-timer’ (*note Idle Timers::)—can run during this
28669     period.  However, if SECONDS is non-‘nil’, the state of idleness
28670     remains unchanged.  If Emacs is non-idle when ‘read-event’ is
28671     called, it remains non-idle throughout the operation of
28672     ‘read-event’; if Emacs is idle (which can happen if the call
28673     happens inside an idle timer), it remains idle.
28674
28675     If ‘read-event’ gets an event that is defined as a help character,
28676     then in some cases ‘read-event’ processes the event directly
28677     without returning.  *Note Help Functions::.  Certain other events,
28678     called “special events”, are also processed directly within
28679     ‘read-event’ (*note Special Events::).
28680
28681     Here is what happens if you call ‘read-event’ and then press the
28682     right-arrow function key:
28683
28684          (read-event)
28685               ⇒ right
28686
28687 -- Function: read-char &optional prompt inherit-input-method seconds
28688     This function reads and returns a character input event.  If the
28689     user generates an event which is not a character (i.e., a mouse
28690     click or function key event), ‘read-char’ signals an error.  The
28691     arguments work as in ‘read-event’.
28692
28693     If the event has modifiers, Emacs attempts to resolve them and
28694     return the code of the corresponding character.  For example, if
28695     the user types ‘C-a’, the function returns 1, which is the ASCII
28696     code of the ‘C-a’ character.  If some of the modifiers cannot be
28697     reflected in the character code, ‘read-char’ leaves the unresolved
28698     modifier bits set in the returned event.  For example, if the user
28699     types ‘C-M-a’, the function returns 134217729, 8000001 in hex, i.e.
28700     ‘C-a’ with the Meta modifier bit set.  This value is not a valid
28701     character code: it fails the ‘characterp’ test (*note Character
28702     Codes::).  Use ‘event-basic-type’ (*note Classifying Events::) to
28703     recover the character code with the modifier bits removed; use
28704     ‘event-modifiers’ to test for modifiers in the character event
28705     returned by ‘read-char’.
28706
28707     In the first example below, the user types the character ‘1’ (ASCII
28708     code 49).  The second example shows a keyboard macro definition
28709     that calls ‘read-char’ from the minibuffer using ‘eval-expression’.
28710     ‘read-char’ reads the keyboard macro’s very next character, which
28711     is ‘1’.  Then ‘eval-expression’ displays its return value in the
28712     echo area.
28713
28714          (read-char)
28715               ⇒ 49
28716
28717          ;; We assume here you use ‘M-:’ to evaluate this.
28718          (symbol-function 'foo)
28719               ⇒ "^[:(read-char)^M1"
28720          (execute-kbd-macro 'foo)
28721               ⊣ 49
28722               ⇒ nil
28723
28724 -- Function: read-char-exclusive &optional prompt inherit-input-method
28725          seconds
28726     This function reads and returns a character input event.  If the
28727     user generates an event which is not a character event,
28728     ‘read-char-exclusive’ ignores it and reads another event, until it
28729     gets a character.  The arguments work as in ‘read-event’.  The
28730     returned value may include modifier bits, as with ‘read-char’.
28731
28732   None of the above functions suppress quitting.
28733
28734 -- Variable: num-nonmacro-input-events
28735     This variable holds the total number of input events received so
28736     far from the terminal—not counting those generated by keyboard
28737     macros.
28738
28739   We emphasize that, unlike ‘read-key-sequence’, the functions
28740‘read-event’, ‘read-char’, and ‘read-char-exclusive’ do not perform the
28741translations described in *note Translation Keymaps::.  If you wish to
28742read a single key taking these translations into account, use the
28743function ‘read-key’:
28744
28745 -- Function: read-key &optional prompt
28746     This function reads a single key.  It is intermediate between
28747     ‘read-key-sequence’ and ‘read-event’.  Unlike the former, it reads
28748     a single key, not a key sequence.  Unlike the latter, it does not
28749     return a raw event, but decodes and translates the user input
28750     according to ‘input-decode-map’, ‘local-function-key-map’, and
28751     ‘key-translation-map’ (*note Translation Keymaps::).
28752
28753     The argument PROMPT is either a string to be displayed in the echo
28754     area as a prompt, or ‘nil’, meaning not to display a prompt.
28755
28756 -- Function: read-char-choice prompt chars &optional inhibit-quit
28757     This function uses ‘read-key’ to read and return a single
28758     character.  It ignores any input that is not a member of CHARS, a
28759     list of accepted characters.  Optionally, it will also ignore
28760     keyboard-quit events while it is waiting for valid input.  If you
28761     bind ‘help-form’ (*note Help Functions::) to a non-‘nil’ value
28762     while calling ‘read-char-choice’, then pressing ‘help-char’ causes
28763     it to evaluate ‘help-form’ and display the result.  It then
28764     continues to wait for a valid input character, or keyboard-quit.
28765
28766 -- Function: read-multiple-choice prompt choices
28767     Ask user a multiple choice question.  PROMPT should be a string
28768     that will be displayed as the prompt.
28769
28770     CHOICES is an alist where the first element in each entry is a
28771     character to be entered, the second element is a short name for the
28772     entry to be displayed while prompting (if there’s room, it might be
28773     shortened), and the third, optional entry is a longer explanation
28774     that will be displayed in a help buffer if the user requests more
28775     help.
28776
28777     The return value is the matching value from CHOICES.
28778
28779          (read-multiple-choice
28780           "Continue connecting?"
28781           '((?a "always" "Accept certificate for this and future sessions.")
28782             (?s "session only" "Accept certificate this session only.")
28783             (?n "no" "Refuse to use certificate, close connection.")))
28784
28785     The ‘read-multiple-choice-face’ face is used to highlight the
28786     matching characters in the name string on graphical terminals.
28787
28788
28789File: elisp.info,  Node: Event Mod,  Next: Invoking the Input Method,  Prev: Reading One Event,  Up: Reading Input
28790
2879121.8.3 Modifying and Translating Input Events
28792---------------------------------------------
28793
28794Emacs modifies every event it reads according to
28795‘extra-keyboard-modifiers’, then translates it through
28796‘keyboard-translate-table’ (if applicable), before returning it from
28797‘read-event’.
28798
28799 -- Variable: extra-keyboard-modifiers
28800     This variable lets Lisp programs “press” the modifier keys on the
28801     keyboard.  The value is a character.  Only the modifiers of the
28802     character matter.  Each time the user types a keyboard key, it is
28803     altered as if those modifier keys were held down.  For instance, if
28804     you bind ‘extra-keyboard-modifiers’ to ‘?\C-\M-a’, then all
28805     keyboard input characters typed during the scope of the binding
28806     will have the control and meta modifiers applied to them.  The
28807     character ‘?\C-@’, equivalent to the integer 0, does not count as a
28808     control character for this purpose, but as a character with no
28809     modifiers.  Thus, setting ‘extra-keyboard-modifiers’ to zero
28810     cancels any modification.
28811
28812     When using a window system, the program can press any of the
28813     modifier keys in this way.  Otherwise, only the <CTL> and <META>
28814     keys can be virtually pressed.
28815
28816     Note that this variable applies only to events that really come
28817     from the keyboard, and has no effect on mouse events or any other
28818     events.
28819
28820 -- Variable: keyboard-translate-table
28821     This terminal-local variable is the translate table for keyboard
28822     characters.  It lets you reshuffle the keys on the keyboard without
28823     changing any command bindings.  Its value is normally a char-table,
28824     or else ‘nil’.  (It can also be a string or vector, but this is
28825     considered obsolete.)
28826
28827     If ‘keyboard-translate-table’ is a char-table (*note
28828     Char-Tables::), then each character read from the keyboard is
28829     looked up in this char-table.  If the value found there is
28830     non-‘nil’, then it is used instead of the actual input character.
28831
28832     Note that this translation is the first thing that happens to a
28833     character after it is read from the terminal.  Record-keeping
28834     features such as ‘recent-keys’ and dribble files record the
28835     characters after translation.
28836
28837     Note also that this translation is done before the characters are
28838     supplied to input methods (*note Input Methods::).  Use
28839     ‘translation-table-for-input’ (*note Translation of Characters::),
28840     if you want to translate characters after input methods operate.
28841
28842 -- Function: keyboard-translate from to
28843     This function modifies ‘keyboard-translate-table’ to translate
28844     character code FROM into character code TO.  It creates the
28845     keyboard translate table if necessary.
28846
28847   Here’s an example of using the ‘keyboard-translate-table’ to make
28848‘C-x’, ‘C-c’ and ‘C-v’ perform the cut, copy and paste operations:
28849
28850     (keyboard-translate ?\C-x 'control-x)
28851     (keyboard-translate ?\C-c 'control-c)
28852     (keyboard-translate ?\C-v 'control-v)
28853     (global-set-key [control-x] 'kill-region)
28854     (global-set-key [control-c] 'kill-ring-save)
28855     (global-set-key [control-v] 'yank)
28856
28857On a graphical terminal that supports extended ASCII input, you can
28858still get the standard Emacs meanings of one of those characters by
28859typing it with the shift key.  That makes it a different character as
28860far as keyboard translation is concerned, but it has the same usual
28861meaning.
28862
28863   *Note Translation Keymaps::, for mechanisms that translate event
28864sequences at the level of ‘read-key-sequence’.
28865
28866
28867File: elisp.info,  Node: Invoking the Input Method,  Next: Quoted Character Input,  Prev: Event Mod,  Up: Reading Input
28868
2886921.8.4 Invoking the Input Method
28870--------------------------------
28871
28872The event-reading functions invoke the current input method, if any
28873(*note Input Methods::).  If the value of ‘input-method-function’ is
28874non-‘nil’, it should be a function; when ‘read-event’ reads a printing
28875character (including <SPC>) with no modifier bits, it calls that
28876function, passing the character as an argument.
28877
28878 -- Variable: input-method-function
28879     If this is non-‘nil’, its value specifies the current input method
28880     function.
28881
28882     *Warning:* don’t bind this variable with ‘let’.  It is often
28883     buffer-local, and if you bind it around reading input (which is
28884     exactly when you _would_ bind it), switching buffers asynchronously
28885     while Emacs is waiting will cause the value to be restored in the
28886     wrong buffer.
28887
28888   The input method function should return a list of events which should
28889be used as input.  (If the list is ‘nil’, that means there is no input,
28890so ‘read-event’ waits for another event.)  These events are processed
28891before the events in ‘unread-command-events’ (*note Event Input Misc::).
28892Events returned by the input method function are not passed to the input
28893method function again, even if they are printing characters with no
28894modifier bits.
28895
28896   If the input method function calls ‘read-event’ or
28897‘read-key-sequence’, it should bind ‘input-method-function’ to ‘nil’
28898first, to prevent recursion.
28899
28900   The input method function is not called when reading the second and
28901subsequent events of a key sequence.  Thus, these characters are not
28902subject to input method processing.  The input method function should
28903test the values of ‘overriding-local-map’ and
28904‘overriding-terminal-local-map’; if either of these variables is
28905non-‘nil’, the input method should put its argument into a list and
28906return that list with no further processing.
28907
28908
28909File: elisp.info,  Node: Quoted Character Input,  Next: Event Input Misc,  Prev: Invoking the Input Method,  Up: Reading Input
28910
2891121.8.5 Quoted Character Input
28912-----------------------------
28913
28914You can use the function ‘read-quoted-char’ to ask the user to specify a
28915character, and allow the user to specify a control or meta character
28916conveniently, either literally or as an octal character code.  The
28917command ‘quoted-insert’ uses this function.
28918
28919 -- Function: read-quoted-char &optional prompt
28920     This function is like ‘read-char’, except that if the first
28921     character read is an octal digit (0–7), it reads any number of
28922     octal digits (but stopping if a non-octal digit is found), and
28923     returns the character represented by that numeric character code.
28924     If the character that terminates the sequence of octal digits is
28925     <RET>, it is discarded.  Any other terminating character is used as
28926     input after this function returns.
28927
28928     Quitting is suppressed when the first character is read, so that
28929     the user can enter a ‘C-g’.  *Note Quitting::.
28930
28931     If PROMPT is supplied, it specifies a string for prompting the
28932     user.  The prompt string is always displayed in the echo area,
28933     followed by a single ‘-’.
28934
28935     In the following example, the user types in the octal number 177
28936     (which is 127 in decimal).
28937
28938          (read-quoted-char "What character")
28939
28940          ---------- Echo Area ----------
28941          What character 1 7 7-
28942          ---------- Echo Area ----------
28943
28944               ⇒ 127
28945
28946
28947File: elisp.info,  Node: Event Input Misc,  Prev: Quoted Character Input,  Up: Reading Input
28948
2894921.8.6 Miscellaneous Event Input Features
28950-----------------------------------------
28951
28952This section describes how to peek ahead at events without using them
28953up, how to check for pending input, and how to discard pending input.
28954See also the function ‘read-passwd’ (*note Reading a Password::).
28955
28956 -- Variable: unread-command-events
28957     This variable holds a list of events waiting to be read as command
28958     input.  The events are used in the order they appear in the list,
28959     and removed one by one as they are used.
28960
28961     The variable is needed because in some cases a function reads an
28962     event and then decides not to use it.  Storing the event in this
28963     variable causes it to be processed normally, by the command loop or
28964     by the functions to read command input.
28965
28966     For example, the function that implements numeric prefix arguments
28967     reads any number of digits.  When it finds a non-digit event, it
28968     must unread the event so that it can be read normally by the
28969     command loop.  Likewise, incremental search uses this feature to
28970     unread events with no special meaning in a search, because these
28971     events should exit the search and then execute normally.
28972
28973     The reliable and easy way to extract events from a key sequence so
28974     as to put them in ‘unread-command-events’ is to use
28975     ‘listify-key-sequence’ (see below).
28976
28977     Normally you add events to the front of this list, so that the
28978     events most recently unread will be reread first.
28979
28980     Events read from this list are not normally added to the current
28981     command’s key sequence (as returned by, e.g., ‘this-command-keys’),
28982     as the events will already have been added once as they were read
28983     for the first time.  An element of the form ‘(t . EVENT)’ forces
28984     EVENT to be added to the current command’s key sequence.
28985
28986     Elements read from this list are normally recorded by the
28987     record-keeping features (*note Recording Input::) and while
28988     defining a keyboard macro (*note Keyboard Macros::).  However, an
28989     element of the form ‘(no-record . EVENT)’ causes EVENT to be
28990     processed normally without recording it.
28991
28992 -- Function: listify-key-sequence key
28993     This function converts the string or vector KEY to a list of
28994     individual events, which you can put in ‘unread-command-events’.
28995
28996 -- Function: input-pending-p &optional check-timers
28997     This function determines whether any command input is currently
28998     available to be read.  It returns immediately, with value ‘t’ if
28999     there is available input, ‘nil’ otherwise.  On rare occasions it
29000     may return ‘t’ when no input is available.
29001
29002     If the optional argument CHECK-TIMERS is non-‘nil’, then if no
29003     input is available, Emacs runs any timers which are ready.  *Note
29004     Timers::.
29005
29006 -- Variable: last-input-event
29007     This variable records the last terminal input event read, whether
29008     as part of a command or explicitly by a Lisp program.
29009
29010     In the example below, the Lisp program reads the character ‘1’,
29011     ASCII code 49.  It becomes the value of ‘last-input-event’, while
29012     ‘C-e’ (we assume ‘C-x C-e’ command is used to evaluate this
29013     expression) remains the value of ‘last-command-event’.
29014
29015          (progn (print (read-char))
29016                 (print last-command-event)
29017                 last-input-event)
29018               ⊣ 49
29019               ⊣ 5
29020               ⇒ 49
29021
29022 -- Macro: while-no-input body...
29023     This construct runs the BODY forms and returns the value of the
29024     last one—but only if no input arrives.  If any input arrives during
29025     the execution of the BODY forms, it aborts them (working much like
29026     a quit).  The ‘while-no-input’ form returns ‘nil’ if aborted by a
29027     real quit, and returns ‘t’ if aborted by arrival of other input.
29028
29029     If a part of BODY binds ‘inhibit-quit’ to non-‘nil’, arrival of
29030     input during those parts won’t cause an abort until the end of that
29031     part.
29032
29033     If you want to be able to distinguish all possible values computed
29034     by BODY from both kinds of abort conditions, write the code like
29035     this:
29036
29037          (while-no-input
29038            (list
29039              (progn . BODY)))
29040
29041 -- Variable: while-no-input-ignore-events
29042     This variable allow setting which special events ‘while-no-input’
29043     should ignore.  It is a list of event symbols (*note Event
29044     Examples::).
29045
29046 -- Function: discard-input
29047     This function discards the contents of the terminal input buffer
29048     and cancels any keyboard macro that might be in the process of
29049     definition.  It returns ‘nil’.
29050
29051     In the following example, the user may type a number of characters
29052     right after starting the evaluation of the form.  After the
29053     ‘sleep-for’ finishes sleeping, ‘discard-input’ discards any
29054     characters typed during the sleep.
29055
29056          (progn (sleep-for 2)
29057                 (discard-input))
29058               ⇒ nil
29059
29060
29061File: elisp.info,  Node: Special Events,  Next: Waiting,  Prev: Reading Input,  Up: Command Loop
29062
2906321.9 Special Events
29064===================
29065
29066Certain “special events” are handled at a very low level—as soon as they
29067are read.  The ‘read-event’ function processes these events itself, and
29068never returns them.  Instead, it keeps waiting for the first event that
29069is not special and returns that one.
29070
29071   Special events do not echo, they are never grouped into key
29072sequences, and they never appear in the value of ‘last-command-event’ or
29073‘(this-command-keys)’.  They do not discard a numeric argument, they
29074cannot be unread with ‘unread-command-events’, they may not appear in a
29075keyboard macro, and they are not recorded in a keyboard macro while you
29076are defining one.
29077
29078   Special events do, however, appear in ‘last-input-event’ immediately
29079after they are read, and this is the way for the event’s definition to
29080find the actual event.
29081
29082   The events types ‘iconify-frame’, ‘make-frame-visible’,
29083‘delete-frame’, ‘drag-n-drop’, ‘language-change’, and user signals like
29084‘sigusr1’ are normally handled in this way.  The keymap which defines
29085how to handle special events—and which events are special—is in the
29086variable ‘special-event-map’ (*note Controlling Active Maps::).
29087
29088
29089File: elisp.info,  Node: Waiting,  Next: Quitting,  Prev: Special Events,  Up: Command Loop
29090
2909121.10 Waiting for Elapsed Time or Input
29092=======================================
29093
29094The wait functions are designed to wait for a certain amount of time to
29095pass or until there is input.  For example, you may wish to pause in the
29096middle of a computation to allow the user time to view the display.
29097‘sit-for’ pauses and updates the screen, and returns immediately if
29098input comes in, while ‘sleep-for’ pauses without updating the screen.
29099
29100 -- Function: sit-for seconds &optional nodisp
29101     This function performs redisplay (provided there is no pending
29102     input from the user), then waits SECONDS seconds, or until input is
29103     available.  The usual purpose of ‘sit-for’ is to give the user time
29104     to read text that you display.  The value is ‘t’ if ‘sit-for’
29105     waited the full time with no input arriving (*note Event Input
29106     Misc::).  Otherwise, the value is ‘nil’.
29107
29108     The argument SECONDS need not be an integer.  If it is floating
29109     point, ‘sit-for’ waits for a fractional number of seconds.  Some
29110     systems support only a whole number of seconds; on these systems,
29111     SECONDS is rounded down.
29112
29113     The expression ‘(sit-for 0)’ is equivalent to ‘(redisplay)’, i.e.,
29114     it requests a redisplay, without any delay, if there is no pending
29115     input.  *Note Forcing Redisplay::.
29116
29117     If NODISP is non-‘nil’, then ‘sit-for’ does not redisplay, but it
29118     still returns as soon as input is available (or when the timeout
29119     elapses).
29120
29121     In batch mode (*note Batch Mode::), ‘sit-for’ cannot be
29122     interrupted, even by input from the standard input descriptor.  It
29123     is thus equivalent to ‘sleep-for’, which is described below.
29124
29125     It is also possible to call ‘sit-for’ with three arguments, as
29126     ‘(sit-for SECONDS MILLISEC NODISP)’, but that is considered
29127     obsolete.
29128
29129 -- Function: sleep-for seconds &optional millisec
29130     This function simply pauses for SECONDS seconds without updating
29131     the display.  It pays no attention to available input.  It returns
29132     ‘nil’.
29133
29134     The argument SECONDS need not be an integer.  If it is floating
29135     point, ‘sleep-for’ waits for a fractional number of seconds.  Some
29136     systems support only a whole number of seconds; on these systems,
29137     SECONDS is rounded down.
29138
29139     The optional argument MILLISEC specifies an additional waiting
29140     period measured in milliseconds.  This adds to the period specified
29141     by SECONDS.  If the system doesn’t support waiting fractions of a
29142     second, you get an error if you specify nonzero MILLISEC.
29143
29144     Use ‘sleep-for’ when you wish to guarantee a delay.
29145
29146   *Note Time of Day::, for functions to get the current time.
29147
29148
29149File: elisp.info,  Node: Quitting,  Next: Prefix Command Arguments,  Prev: Waiting,  Up: Command Loop
29150
2915121.11 Quitting
29152==============
29153
29154Typing ‘C-g’ while a Lisp function is running causes Emacs to “quit”
29155whatever it is doing.  This means that control returns to the innermost
29156active command loop.
29157
29158   Typing ‘C-g’ while the command loop is waiting for keyboard input
29159does not cause a quit; it acts as an ordinary input character.  In the
29160simplest case, you cannot tell the difference, because ‘C-g’ normally
29161runs the command ‘keyboard-quit’, whose effect is to quit.  However,
29162when ‘C-g’ follows a prefix key, they combine to form an undefined key.
29163The effect is to cancel the prefix key as well as any prefix argument.
29164
29165   In the minibuffer, ‘C-g’ has a different definition: it aborts out of
29166the minibuffer.  This means, in effect, that it exits the minibuffer and
29167then quits.  (Simply quitting would return to the command loop _within_
29168the minibuffer.)  The reason why ‘C-g’ does not quit directly when the
29169command reader is reading input is so that its meaning can be redefined
29170in the minibuffer in this way.  ‘C-g’ following a prefix key is not
29171redefined in the minibuffer, and it has its normal effect of canceling
29172the prefix key and prefix argument.  This too would not be possible if
29173‘C-g’ always quit directly.
29174
29175   When ‘C-g’ does directly quit, it does so by setting the variable
29176‘quit-flag’ to ‘t’.  Emacs checks this variable at appropriate times and
29177quits if it is not ‘nil’.  Setting ‘quit-flag’ non-‘nil’ in any way thus
29178causes a quit.
29179
29180   At the level of C code, quitting cannot happen just anywhere; only at
29181the special places that check ‘quit-flag’.  The reason for this is that
29182quitting at other places might leave an inconsistency in Emacs’s
29183internal state.  Because quitting is delayed until a safe place,
29184quitting cannot make Emacs crash.
29185
29186   Certain functions such as ‘read-key-sequence’ or ‘read-quoted-char’
29187prevent quitting entirely even though they wait for input.  Instead of
29188quitting, ‘C-g’ serves as the requested input.  In the case of
29189‘read-key-sequence’, this serves to bring about the special behavior of
29190‘C-g’ in the command loop.  In the case of ‘read-quoted-char’, this is
29191so that ‘C-q’ can be used to quote a ‘C-g’.
29192
29193   You can prevent quitting for a portion of a Lisp function by binding
29194the variable ‘inhibit-quit’ to a non-‘nil’ value.  Then, although ‘C-g’
29195still sets ‘quit-flag’ to ‘t’ as usual, the usual result of this—a
29196quit—is prevented.  Eventually, ‘inhibit-quit’ will become ‘nil’ again,
29197such as when its binding is unwound at the end of a ‘let’ form.  At that
29198time, if ‘quit-flag’ is still non-‘nil’, the requested quit happens
29199immediately.  This behavior is ideal when you wish to make sure that
29200quitting does not happen within a critical section of the program.
29201
29202   In some functions (such as ‘read-quoted-char’), ‘C-g’ is handled in a
29203special way that does not involve quitting.  This is done by reading the
29204input with ‘inhibit-quit’ bound to ‘t’, and setting ‘quit-flag’ to ‘nil’
29205before ‘inhibit-quit’ becomes ‘nil’ again.  This excerpt from the
29206definition of ‘read-quoted-char’ shows how this is done; it also shows
29207that normal quitting is permitted after the first character of input.
29208
29209     (defun read-quoted-char (&optional prompt)
29210       "...DOCUMENTATION..."
29211       (let ((message-log-max nil) done (first t) (code 0) char)
29212         (while (not done)
29213           (let ((inhibit-quit first)
29214                 ...)
29215             (and prompt (message "%s-" prompt))
29216             (setq char (read-event))
29217             (if inhibit-quit (setq quit-flag nil)))
29218           ...set the variable ‘code’...)
29219         code))
29220
29221 -- Variable: quit-flag
29222     If this variable is non-‘nil’, then Emacs quits immediately, unless
29223     ‘inhibit-quit’ is non-‘nil’.  Typing ‘C-g’ ordinarily sets
29224     ‘quit-flag’ non-‘nil’, regardless of ‘inhibit-quit’.
29225
29226 -- Variable: inhibit-quit
29227     This variable determines whether Emacs should quit when ‘quit-flag’
29228     is set to a value other than ‘nil’.  If ‘inhibit-quit’ is
29229     non-‘nil’, then ‘quit-flag’ has no special effect.
29230
29231 -- Macro: with-local-quit body...
29232     This macro executes BODY forms in sequence, but allows quitting, at
29233     least locally, within BODY even if ‘inhibit-quit’ was non-‘nil’
29234     outside this construct.  It returns the value of the last form in
29235     BODY, unless exited by quitting, in which case it returns ‘nil’.
29236
29237     If ‘inhibit-quit’ is ‘nil’ on entry to ‘with-local-quit’, it only
29238     executes the BODY, and setting ‘quit-flag’ causes a normal quit.
29239     However, if ‘inhibit-quit’ is non-‘nil’ so that ordinary quitting
29240     is delayed, a non-‘nil’ ‘quit-flag’ triggers a special kind of
29241     local quit.  This ends the execution of BODY and exits the
29242     ‘with-local-quit’ body with ‘quit-flag’ still non-‘nil’, so that
29243     another (ordinary) quit will happen as soon as that is allowed.  If
29244     ‘quit-flag’ is already non-‘nil’ at the beginning of BODY, the
29245     local quit happens immediately and the body doesn’t execute at all.
29246
29247     This macro is mainly useful in functions that can be called from
29248     timers, process filters, process sentinels, ‘pre-command-hook’,
29249     ‘post-command-hook’, and other places where ‘inhibit-quit’ is
29250     normally bound to ‘t’.
29251
29252 -- Command: keyboard-quit
29253     This function signals the ‘quit’ condition with ‘(signal 'quit
29254     nil)’.  This is the same thing that quitting does.  (See ‘signal’
29255     in *note Errors::.)
29256
29257   You can specify a character other than ‘C-g’ to use for quitting.
29258See the function ‘set-input-mode’ in *note Input Modes::.
29259
29260
29261File: elisp.info,  Node: Prefix Command Arguments,  Next: Recursive Editing,  Prev: Quitting,  Up: Command Loop
29262
2926321.12 Prefix Command Arguments
29264==============================
29265
29266Most Emacs commands can use a “prefix argument”, a number specified
29267before the command itself.  (Don’t confuse prefix arguments with prefix
29268keys.)  The prefix argument is at all times represented by a value,
29269which may be ‘nil’, meaning there is currently no prefix argument.  Each
29270command may use the prefix argument or ignore it.
29271
29272   There are two representations of the prefix argument: “raw” and
29273“numeric”.  The editor command loop uses the raw representation
29274internally, and so do the Lisp variables that store the information, but
29275commands can request either representation.
29276
29277   Here are the possible values of a raw prefix argument:
29278
29279   • ‘nil’, meaning there is no prefix argument.  Its numeric value is
29280     1, but numerous commands make a distinction between ‘nil’ and the
29281     integer 1.
29282
29283   • An integer, which stands for itself.
29284
29285   • A list of one element, which is an integer.  This form of prefix
29286     argument results from one or a succession of ‘C-u’s with no digits.
29287     The numeric value is the integer in the list, but some commands
29288     make a distinction between such a list and an integer alone.
29289
29290   • The symbol ‘-’.  This indicates that ‘M--’ or ‘C-u -’ was typed,
29291     without following digits.  The equivalent numeric value is −1, but
29292     some commands make a distinction between the integer −1 and the
29293     symbol ‘-’.
29294
29295   We illustrate these possibilities by calling the following function
29296with various prefixes:
29297
29298     (defun display-prefix (arg)
29299       "Display the value of the raw prefix arg."
29300       (interactive "P")
29301       (message "%s" arg))
29302
29303Here are the results of calling ‘display-prefix’ with various raw prefix
29304arguments:
29305
29306             M-x display-prefix  ⊣ nil
29307
29308     C-u     M-x display-prefix  ⊣ (4)
29309
29310     C-u C-u M-x display-prefix  ⊣ (16)
29311
29312     C-u 3   M-x display-prefix  ⊣ 3
29313
29314     M-3     M-x display-prefix  ⊣ 3      ; (Same as ‘C-u 3’.)
29315
29316     C-u -   M-x display-prefix  ⊣ -
29317
29318     M--     M-x display-prefix  ⊣ -      ; (Same as ‘C-u -’.)
29319
29320     C-u - 7 M-x display-prefix  ⊣ -7
29321
29322     M-- 7   M-x display-prefix  ⊣ -7     ; (Same as ‘C-u -7’.)
29323
29324   Emacs uses two variables to store the prefix argument: ‘prefix-arg’
29325and ‘current-prefix-arg’.  Commands such as ‘universal-argument’ that
29326set up prefix arguments for other commands store them in ‘prefix-arg’.
29327In contrast, ‘current-prefix-arg’ conveys the prefix argument to the
29328current command, so setting it has no effect on the prefix arguments for
29329future commands.
29330
29331   Normally, commands specify which representation to use for the prefix
29332argument, either numeric or raw, in the ‘interactive’ specification.
29333(*Note Using Interactive::.)  Alternatively, functions may look at the
29334value of the prefix argument directly in the variable
29335‘current-prefix-arg’, but this is less clean.
29336
29337 -- Function: prefix-numeric-value arg
29338     This function returns the numeric meaning of a valid raw prefix
29339     argument value, ARG.  The argument may be a symbol, a number, or a
29340     list.  If it is ‘nil’, the value 1 is returned; if it is ‘-’, the
29341     value −1 is returned; if it is a number, that number is returned;
29342     if it is a list, the CAR of that list (which should be a number) is
29343     returned.
29344
29345 -- Variable: current-prefix-arg
29346     This variable holds the raw prefix argument for the _current_
29347     command.  Commands may examine it directly, but the usual method
29348     for accessing it is with ‘(interactive "P")’.
29349
29350 -- Variable: prefix-arg
29351     The value of this variable is the raw prefix argument for the
29352     _next_ editing command.  Commands such as ‘universal-argument’ that
29353     specify prefix arguments for the following command work by setting
29354     this variable.
29355
29356 -- Variable: last-prefix-arg
29357     The raw prefix argument value used by the previous command.
29358
29359   The following commands exist to set up prefix arguments for the
29360following command.  Do not call them for any other reason.
29361
29362 -- Command: universal-argument
29363     This command reads input and specifies a prefix argument for the
29364     following command.  Don’t call this command yourself unless you
29365     know what you are doing.
29366
29367 -- Command: digit-argument arg
29368     This command adds to the prefix argument for the following command.
29369     The argument ARG is the raw prefix argument as it was before this
29370     command; it is used to compute the updated prefix argument.  Don’t
29371     call this command yourself unless you know what you are doing.
29372
29373 -- Command: negative-argument arg
29374     This command adds to the numeric argument for the next command.
29375     The argument ARG is the raw prefix argument as it was before this
29376     command; its value is negated to form the new prefix argument.
29377     Don’t call this command yourself unless you know what you are
29378     doing.
29379
29380
29381File: elisp.info,  Node: Recursive Editing,  Next: Disabling Commands,  Prev: Prefix Command Arguments,  Up: Command Loop
29382
2938321.13 Recursive Editing
29384=======================
29385
29386The Emacs command loop is entered automatically when Emacs starts up.
29387This top-level invocation of the command loop never exits; it keeps
29388running as long as Emacs does.  Lisp programs can also invoke the
29389command loop.  Since this makes more than one activation of the command
29390loop, we call it “recursive editing”.  A recursive editing level has the
29391effect of suspending whatever command invoked it and permitting the user
29392to do arbitrary editing before resuming that command.
29393
29394   The commands available during recursive editing are the same ones
29395available in the top-level editing loop and defined in the keymaps.
29396Only a few special commands exit the recursive editing level; the others
29397return to the recursive editing level when they finish.  (The special
29398commands for exiting are always available, but they do nothing when
29399recursive editing is not in progress.)
29400
29401   All command loops, including recursive ones, set up all-purpose error
29402handlers so that an error in a command run from the command loop will
29403not exit the loop.
29404
29405   Minibuffer input is a special kind of recursive editing.  It has a
29406few special wrinkles, such as enabling display of the minibuffer and the
29407minibuffer window, but fewer than you might suppose.  Certain keys
29408behave differently in the minibuffer, but that is only because of the
29409minibuffer’s local map; if you switch windows, you get the usual Emacs
29410commands.
29411
29412   To invoke a recursive editing level, call the function
29413‘recursive-edit’.  This function contains the command loop; it also
29414contains a call to ‘catch’ with tag ‘exit’, which makes it possible to
29415exit the recursive editing level by throwing to ‘exit’ (*note Catch and
29416Throw::).  If you throw a value other than ‘t’, then ‘recursive-edit’
29417returns normally to the function that called it.  The command ‘C-M-c’
29418(‘exit-recursive-edit’) does this.  Throwing a ‘t’ value causes
29419‘recursive-edit’ to quit, so that control returns to the command loop
29420one level up.  This is called “aborting”, and is done by ‘C-]’
29421(‘abort-recursive-edit’).
29422
29423   Most applications should not use recursive editing, except as part of
29424using the minibuffer.  Usually it is more convenient for the user if you
29425change the major mode of the current buffer temporarily to a special
29426major mode, which should have a command to go back to the previous mode.
29427(The ‘e’ command in Rmail uses this technique.)  Or, if you wish to give
29428the user different text to edit recursively, create and select a new
29429buffer in a special mode.  In this mode, define a command to complete
29430the processing and go back to the previous buffer.  (The ‘m’ command in
29431Rmail does this.)
29432
29433   Recursive edits are useful in debugging.  You can insert a call to
29434‘debug’ into a function definition as a sort of breakpoint, so that you
29435can look around when the function gets there.  ‘debug’ invokes a
29436recursive edit but also provides the other features of the debugger.
29437
29438   Recursive editing levels are also used when you type ‘C-r’ in
29439‘query-replace’ or use ‘C-x q’ (‘kbd-macro-query’).
29440
29441 -- Command: recursive-edit
29442     This function invokes the editor command loop.  It is called
29443     automatically by the initialization of Emacs, to let the user begin
29444     editing.  When called from a Lisp program, it enters a recursive
29445     editing level.
29446
29447     If the current buffer is not the same as the selected window’s
29448     buffer, ‘recursive-edit’ saves and restores the current buffer.
29449     Otherwise, if you switch buffers, the buffer you switched to is
29450     current after ‘recursive-edit’ returns.
29451
29452     In the following example, the function ‘simple-rec’ first advances
29453     point one word, then enters a recursive edit, printing out a
29454     message in the echo area.  The user can then do any editing
29455     desired, and then type ‘C-M-c’ to exit and continue executing
29456     ‘simple-rec’.
29457
29458          (defun simple-rec ()
29459            (forward-word 1)
29460            (message "Recursive edit in progress")
29461            (recursive-edit)
29462            (forward-word 1))
29463               ⇒ simple-rec
29464          (simple-rec)
29465               ⇒ nil
29466
29467 -- Command: exit-recursive-edit
29468     This function exits from the innermost recursive edit (including
29469     minibuffer input).  Its definition is effectively ‘(throw 'exit
29470     nil)’.
29471
29472 -- Command: abort-recursive-edit
29473     This function aborts the command that requested the innermost
29474     recursive edit (including minibuffer input), by signaling ‘quit’
29475     after exiting the recursive edit.  Its definition is effectively
29476     ‘(throw 'exit t)’.  *Note Quitting::.
29477
29478 -- Command: top-level
29479     This function exits all recursive editing levels; it does not
29480     return a value, as it jumps completely out of any computation
29481     directly back to the main command loop.
29482
29483 -- Function: recursion-depth
29484     This function returns the current depth of recursive edits.  When
29485     no recursive edit is active, it returns 0.
29486
29487
29488File: elisp.info,  Node: Disabling Commands,  Next: Command History,  Prev: Recursive Editing,  Up: Command Loop
29489
2949021.14 Disabling Commands
29491========================
29492
29493“Disabling a command” marks the command as requiring user confirmation
29494before it can be executed.  Disabling is used for commands which might
29495be confusing to beginning users, to prevent them from using the commands
29496by accident.
29497
29498   The low-level mechanism for disabling a command is to put a non-‘nil’
29499‘disabled’ property on the Lisp symbol for the command.  These
29500properties are normally set up by the user’s init file (*note Init
29501File::) with Lisp expressions such as this:
29502
29503     (put 'upcase-region 'disabled t)
29504
29505For a few commands, these properties are present by default (you can
29506remove them in your init file if you wish).
29507
29508   If the value of the ‘disabled’ property is a string, the message
29509saying the command is disabled includes that string.  For example:
29510
29511     (put 'delete-region 'disabled
29512          "Text deleted this way cannot be yanked back!\n")
29513
29514   *Note (emacs)Disabling::, for the details on what happens when a
29515disabled command is invoked interactively.  Disabling a command has no
29516effect on calling it as a function from Lisp programs.
29517
29518 -- Command: enable-command command
29519     Allow COMMAND (a symbol) to be executed without special
29520     confirmation from now on, and alter the user’s init file (*note
29521     Init File::) so that this will apply to future sessions.
29522
29523 -- Command: disable-command command
29524     Require special confirmation to execute COMMAND from now on, and
29525     alter the user’s init file so that this will apply to future
29526     sessions.
29527
29528 -- Variable: disabled-command-function
29529     The value of this variable should be a function.  When the user
29530     invokes a disabled command interactively, this function is called
29531     instead of the disabled command.  It can use ‘this-command-keys’ to
29532     determine what the user typed to run the command, and thus find the
29533     command itself.
29534
29535     The value may also be ‘nil’.  Then all commands work normally, even
29536     disabled ones.
29537
29538     By default, the value is a function that asks the user whether to
29539     proceed.
29540
29541
29542File: elisp.info,  Node: Command History,  Next: Keyboard Macros,  Prev: Disabling Commands,  Up: Command Loop
29543
2954421.15 Command History
29545=====================
29546
29547The command loop keeps a history of the complex commands that have been
29548executed, to make it convenient to repeat these commands.  A “complex
29549command” is one for which the interactive argument reading uses the
29550minibuffer.  This includes any ‘M-x’ command, any ‘M-:’ command, and any
29551command whose ‘interactive’ specification reads an argument from the
29552minibuffer.  Explicit use of the minibuffer during the execution of the
29553command itself does not cause the command to be considered complex.
29554
29555 -- Variable: command-history
29556     This variable’s value is a list of recent complex commands, each
29557     represented as a form to evaluate.  It continues to accumulate all
29558     complex commands for the duration of the editing session, but when
29559     it reaches the maximum size (*note Minibuffer History::), the
29560     oldest elements are deleted as new ones are added.
29561
29562          command-history
29563          ⇒ ((switch-to-buffer "chistory.texi")
29564              (describe-key "^X^[")
29565              (visit-tags-table "~/emacs/src/")
29566              (find-tag "repeat-complex-command"))
29567
29568   This history list is actually a special case of minibuffer history
29569(*note Minibuffer History::), with one special twist: the elements are
29570expressions rather than strings.
29571
29572   There are a number of commands devoted to the editing and recall of
29573previous commands.  The commands ‘repeat-complex-command’, and
29574‘list-command-history’ are described in the user manual (*note
29575(emacs)Repetition::).  Within the minibuffer, the usual minibuffer
29576history commands are available.
29577
29578
29579File: elisp.info,  Node: Keyboard Macros,  Prev: Command History,  Up: Command Loop
29580
2958121.16 Keyboard Macros
29582=====================
29583
29584A “keyboard macro” is a canned sequence of input events that can be
29585considered a command and made the definition of a key.  The Lisp
29586representation of a keyboard macro is a string or vector containing the
29587events.  Don’t confuse keyboard macros with Lisp macros (*note
29588Macros::).
29589
29590 -- Function: execute-kbd-macro kbdmacro &optional count loopfunc
29591     This function executes KBDMACRO as a sequence of events.  If
29592     KBDMACRO is a string or vector, then the events in it are executed
29593     exactly as if they had been input by the user.  The sequence is
29594     _not_ expected to be a single key sequence; normally a keyboard
29595     macro definition consists of several key sequences concatenated.
29596
29597     If KBDMACRO is a symbol, then its function definition is used in
29598     place of KBDMACRO.  If that is another symbol, this process
29599     repeats.  Eventually the result should be a string or vector.  If
29600     the result is not a symbol, string, or vector, an error is
29601     signaled.
29602
29603     The argument COUNT is a repeat count; KBDMACRO is executed that
29604     many times.  If COUNT is omitted or ‘nil’, KBDMACRO is executed
29605     once.  If it is 0, KBDMACRO is executed over and over until it
29606     encounters an error or a failing search.
29607
29608     If LOOPFUNC is non-‘nil’, it is a function that is called, without
29609     arguments, prior to each iteration of the macro.  If LOOPFUNC
29610     returns ‘nil’, then this stops execution of the macro.
29611
29612     *Note Reading One Event::, for an example of using
29613     ‘execute-kbd-macro’.
29614
29615 -- Variable: executing-kbd-macro
29616     This variable contains the string or vector that defines the
29617     keyboard macro that is currently executing.  It is ‘nil’ if no
29618     macro is currently executing.  A command can test this variable so
29619     as to behave differently when run from an executing macro.  Do not
29620     set this variable yourself.
29621
29622 -- Variable: defining-kbd-macro
29623     This variable is non-‘nil’ if and only if a keyboard macro is being
29624     defined.  A command can test this variable so as to behave
29625     differently while a macro is being defined.  The value is ‘append’
29626     while appending to the definition of an existing macro.  The
29627     commands ‘start-kbd-macro’, ‘kmacro-start-macro’ and
29628     ‘end-kbd-macro’ set this variable—do not set it yourself.
29629
29630     The variable is always local to the current terminal and cannot be
29631     buffer-local.  *Note Multiple Terminals::.
29632
29633 -- Variable: last-kbd-macro
29634     This variable is the definition of the most recently defined
29635     keyboard macro.  Its value is a string or vector, or ‘nil’.
29636
29637     The variable is always local to the current terminal and cannot be
29638     buffer-local.  *Note Multiple Terminals::.
29639
29640 -- Variable: kbd-macro-termination-hook
29641     This normal hook is run when a keyboard macro terminates,
29642     regardless of what caused it to terminate (reaching the macro end
29643     or an error which ended the macro prematurely).
29644
29645
29646File: elisp.info,  Node: Keymaps,  Next: Modes,  Prev: Command Loop,  Up: Top
29647
2964822 Keymaps
29649**********
29650
29651The command bindings of input events are recorded in data structures
29652called “keymaps”.  Each entry in a keymap associates (or “binds”) an
29653individual event type, either to another keymap or to a command.  When
29654an event type is bound to a keymap, that keymap is used to look up the
29655next input event; this continues until a command is found.  The whole
29656process is called “key lookup”.
29657
29658* Menu:
29659
29660* Key Sequences::               Key sequences as Lisp objects.
29661* Keymap Basics::               Basic concepts of keymaps.
29662* Format of Keymaps::           What a keymap looks like as a Lisp object.
29663* Creating Keymaps::            Functions to create and copy keymaps.
29664* Inheritance and Keymaps::     How one keymap can inherit the bindings
29665                                   of another keymap.
29666* Prefix Keys::                 Defining a key with a keymap as its definition.
29667* Active Keymaps::              How Emacs searches the active keymaps
29668                                   for a key binding.
29669* Searching Keymaps::           A pseudo-Lisp summary of searching active maps.
29670* Controlling Active Maps::     Each buffer has a local keymap
29671                                   to override the standard (global) bindings.
29672                                   A minor mode can also override them.
29673* Key Lookup::                  Finding a key’s binding in one keymap.
29674* Functions for Key Lookup::    How to request key lookup.
29675* Changing Key Bindings::       Redefining a key in a keymap.
29676* Remapping Commands::          A keymap can translate one command to another.
29677* Translation Keymaps::         Keymaps for translating sequences of events.
29678* Key Binding Commands::        Interactive interfaces for redefining keys.
29679* Scanning Keymaps::            Looking through all keymaps, for printing help.
29680* Menu Keymaps::                Defining a menu as a keymap.
29681
29682
29683File: elisp.info,  Node: Key Sequences,  Next: Keymap Basics,  Up: Keymaps
29684
2968522.1 Key Sequences
29686==================
29687
29688A “key sequence”, or “key” for short, is a sequence of one or more input
29689events that form a unit.  Input events include characters, function
29690keys, mouse actions, or system events external to Emacs, such as
29691‘iconify-frame’ (*note Input Events::).  The Emacs Lisp representation
29692for a key sequence is a string or vector.  Unless otherwise stated, any
29693Emacs Lisp function that accepts a key sequence as an argument can
29694handle both representations.
29695
29696   In the string representation, alphanumeric characters ordinarily
29697stand for themselves; for example, ‘"a"’ represents ‘a’ and ‘"2"’
29698represents ‘2’.  Control character events are prefixed by the substring
29699‘"\C-"’, and meta characters by ‘"\M-"’; for example, ‘"\C-x"’
29700represents the key ‘C-x’.  In addition, the <TAB>, <RET>, <ESC>, and
29701<DEL> events are represented by ‘"\t"’, ‘"\r"’, ‘"\e"’, and ‘"\d"’
29702respectively.  The string representation of a complete key sequence is
29703the concatenation of the string representations of the constituent
29704events; thus, ‘"\C-xl"’ represents the key sequence ‘C-x l’.
29705
29706   Key sequences containing function keys, mouse button events, system
29707events, or non-ASCII characters such as ‘C-=’ or ‘H-a’ cannot be
29708represented as strings; they have to be represented as vectors.
29709
29710   In the vector representation, each element of the vector represents
29711an input event, in its Lisp form.  *Note Input Events::.  For example,
29712the vector ‘[?\C-x ?l]’ represents the key sequence ‘C-x l’.
29713
29714   For examples of key sequences written in string and vector
29715representations, *note (emacs)Init Rebinding::.
29716
29717 -- Function: kbd keyseq-text
29718     This function converts the text KEYSEQ-TEXT (a string constant)
29719     into a key sequence (a string or vector constant).  The contents of
29720     KEYSEQ-TEXT should use the same syntax as in the buffer invoked by
29721     the ‘C-x C-k <RET>’ (‘kmacro-edit-macro’) command; in particular,
29722     you must surround function key names with ‘<...>’.  *Note
29723     (emacs)Edit Keyboard Macro::.
29724
29725          (kbd "C-x") ⇒ "\C-x"
29726          (kbd "C-x C-f") ⇒ "\C-x\C-f"
29727          (kbd "C-x 4 C-f") ⇒ "\C-x4\C-f"
29728          (kbd "X") ⇒ "X"
29729          (kbd "RET") ⇒ "\^M"
29730          (kbd "C-c SPC") ⇒ "\C-c "
29731          (kbd "<f1> SPC") ⇒ [f1 32]
29732          (kbd "C-M-<down>") ⇒ [C-M-down]
29733
29734
29735File: elisp.info,  Node: Keymap Basics,  Next: Format of Keymaps,  Prev: Key Sequences,  Up: Keymaps
29736
2973722.2 Keymap Basics
29738==================
29739
29740A keymap is a Lisp data structure that specifies “key bindings” for
29741various key sequences.
29742
29743   A single keymap directly specifies definitions for individual events.
29744When a key sequence consists of a single event, its binding in a keymap
29745is the keymap’s definition for that event.  The binding of a longer key
29746sequence is found by an iterative process: first find the definition of
29747the first event (which must itself be a keymap); then find the second
29748event’s definition in that keymap, and so on until all the events in the
29749key sequence have been processed.
29750
29751   If the binding of a key sequence is a keymap, we call the key
29752sequence a “prefix key”.  Otherwise, we call it a “complete key”
29753(because no more events can be added to it).  If the binding is ‘nil’,
29754we call the key “undefined”.  Examples of prefix keys are ‘C-c’, ‘C-x’,
29755and ‘C-x 4’.  Examples of defined complete keys are ‘X’, <RET>, and ‘C-x
297564 C-f’.  Examples of undefined complete keys are ‘C-x C-g’, and ‘C-c 3’.
29757*Note Prefix Keys::, for more details.
29758
29759   The rule for finding the binding of a key sequence assumes that the
29760intermediate bindings (found for the events before the last) are all
29761keymaps; if this is not so, the sequence of events does not form a
29762unit—it is not really one key sequence.  In other words, removing one or
29763more events from the end of any valid key sequence must always yield a
29764prefix key.  For example, ‘C-f C-n’ is not a key sequence; ‘C-f’ is not
29765a prefix key, so a longer sequence starting with ‘C-f’ cannot be a key
29766sequence.
29767
29768   The set of possible multi-event key sequences depends on the bindings
29769for prefix keys; therefore, it can be different for different keymaps,
29770and can change when bindings are changed.  However, a one-event sequence
29771is always a key sequence, because it does not depend on any prefix keys
29772for its well-formedness.
29773
29774   At any time, several primary keymaps are “active”—that is, in use for
29775finding key bindings.  These are the “global map”, which is shared by
29776all buffers; the “local keymap”, which is usually associated with a
29777specific major mode; and zero or more “minor mode keymaps”, which belong
29778to currently enabled minor modes.  (Not all minor modes have keymaps.)
29779The local keymap bindings shadow (i.e., take precedence over) the
29780corresponding global bindings.  The minor mode keymaps shadow both local
29781and global keymaps.  *Note Active Keymaps::, for details.
29782
29783
29784File: elisp.info,  Node: Format of Keymaps,  Next: Creating Keymaps,  Prev: Keymap Basics,  Up: Keymaps
29785
2978622.3 Format of Keymaps
29787======================
29788
29789Each keymap is a list whose CAR is the symbol ‘keymap’.  The remaining
29790elements of the list define the key bindings of the keymap.  A symbol
29791whose function definition is a keymap is also a keymap.  Use the
29792function ‘keymapp’ (see below) to test whether an object is a keymap.
29793
29794   Several kinds of elements may appear in a keymap, after the symbol
29795‘keymap’ that begins it:
29796
29797‘(TYPE . BINDING)’
29798     This specifies one binding, for events of type TYPE.  Each ordinary
29799     binding applies to events of a particular “event type”, which is
29800     always a character or a symbol.  *Note Classifying Events::.  In
29801     this kind of binding, BINDING is a command.
29802
29803‘(TYPE ITEM-NAME . BINDING)’
29804     This specifies a binding which is also a simple menu item that
29805     displays as ITEM-NAME in the menu.  *Note Simple Menu Items::.
29806
29807‘(TYPE ITEM-NAME HELP-STRING . BINDING)’
29808     This is a simple menu item with help string HELP-STRING.
29809
29810‘(TYPE menu-item . DETAILS)’
29811     This specifies a binding which is also an extended menu item.  This
29812     allows use of other features.  *Note Extended Menu Items::.
29813
29814‘(t . BINDING)’
29815     This specifies a “default key binding”; any event not bound by
29816     other elements of the keymap is given BINDING as its binding.
29817     Default bindings allow a keymap to bind all possible event types
29818     without having to enumerate all of them.  A keymap that has a
29819     default binding completely masks any lower-precedence keymap,
29820     except for events explicitly bound to ‘nil’ (see below).
29821
29822‘CHAR-TABLE’
29823     If an element of a keymap is a char-table, it counts as holding
29824     bindings for all character events with no modifier bits (*note
29825     modifier bits::): the element whose index is C is the binding for
29826     the character C.  This is a compact way to record lots of bindings.
29827     A keymap with such a char-table is called a “full keymap”.  Other
29828     keymaps are called “sparse keymaps”.
29829
29830‘VECTOR’
29831     This kind of element is similar to a char-table: the element whose
29832     index is C is the binding for the character C.  Since the range of
29833     characters that can be bound this way is limited by the vector
29834     size, and vector creation allocates space for all character codes
29835     from 0 up, this format should not be used except for creating menu
29836     keymaps (*note Menu Keymaps::), where the bindings themselves don’t
29837     matter.
29838
29839‘STRING’
29840     Aside from elements that specify bindings for keys, a keymap can
29841     also have a string as an element.  This is called the “overall
29842     prompt string” and makes it possible to use the keymap as a menu.
29843     *Note Defining Menus::.
29844
29845‘(keymap ...)’
29846     If an element of a keymap is itself a keymap, it counts as if this
29847     inner keymap were inlined in the outer keymap.  This is used for
29848     multiple-inheritance, such as in ‘make-composed-keymap’.
29849
29850   When the binding is ‘nil’, it doesn’t constitute a definition but it
29851does take precedence over a default binding or a binding in the parent
29852keymap.  On the other hand, a binding of ‘nil’ does _not_ override
29853lower-precedence keymaps; thus, if the local map gives a binding of
29854‘nil’, Emacs uses the binding from the global map.
29855
29856   Keymaps do not directly record bindings for the meta characters.
29857Instead, meta characters are regarded for purposes of key lookup as
29858sequences of two characters, the first of which is <ESC> (or whatever is
29859currently the value of ‘meta-prefix-char’).  Thus, the key ‘M-a’ is
29860internally represented as ‘<ESC> a’, and its global binding is found at
29861the slot for ‘a’ in ‘esc-map’ (*note Prefix Keys::).
29862
29863   This conversion applies only to characters, not to function keys or
29864other input events; thus, ‘M-<end>’ has nothing to do with ‘<ESC>
29865<end>’.
29866
29867   Here as an example is the local keymap for Lisp mode, a sparse
29868keymap.  It defines bindings for <DEL>, ‘C-c C-z’, ‘C-M-q’, and ‘C-M-x’
29869(the actual value also contains a menu binding, which is omitted here
29870for the sake of brevity).
29871
29872     lisp-mode-map
2987329874     (keymap
29875      (3 keymap
29876         ;; C-c C-z
29877         (26 . run-lisp))
29878      (27 keymap
29879          ;; ‘C-M-x’, treated as ‘<ESC> C-x’
29880          (24 . lisp-send-defun))
29881      ;; This part is inherited from ‘lisp-mode-shared-map’.
29882      keymap
29883      ;; <DEL>
29884      (127 . backward-delete-char-untabify)
29885      (27 keymap
29886          ;; ‘C-M-q’, treated as ‘<ESC> C-q’
29887          (17 . indent-sexp)))
29888
29889 -- Function: keymapp object
29890     This function returns ‘t’ if OBJECT is a keymap, ‘nil’ otherwise.
29891     More precisely, this function tests for a list whose CAR is
29892     ‘keymap’, or for a symbol whose function definition satisfies
29893     ‘keymapp’.
29894
29895          (keymapp '(keymap))
29896              ⇒ t
29897          (fset 'foo '(keymap))
29898          (keymapp 'foo)
29899              ⇒ t
29900          (keymapp (current-global-map))
29901              ⇒ t
29902
29903
29904File: elisp.info,  Node: Creating Keymaps,  Next: Inheritance and Keymaps,  Prev: Format of Keymaps,  Up: Keymaps
29905
2990622.4 Creating Keymaps
29907=====================
29908
29909Here we describe the functions for creating keymaps.
29910
29911 -- Function: make-sparse-keymap &optional prompt
29912     This function creates and returns a new sparse keymap with no
29913     entries.  (A sparse keymap is the kind of keymap you usually want.)
29914     The new keymap does not contain a char-table, unlike ‘make-keymap’,
29915     and does not bind any events.
29916
29917          (make-sparse-keymap)
29918              ⇒ (keymap)
29919
29920     If you specify PROMPT, that becomes the overall prompt string for
29921     the keymap.  You should specify this only for menu keymaps (*note
29922     Defining Menus::).  A keymap with an overall prompt string will
29923     always present a mouse menu or a keyboard menu if it is active for
29924     looking up the next input event.  Don’t specify an overall prompt
29925     string for the main map of a major or minor mode, because that
29926     would cause the command loop to present a keyboard menu every time.
29927
29928 -- Function: make-keymap &optional prompt
29929     This function creates and returns a new full keymap.  That keymap
29930     contains a char-table (*note Char-Tables::) with slots for all
29931     characters without modifiers.  The new keymap initially binds all
29932     these characters to ‘nil’, and does not bind any other kind of
29933     event.  The argument PROMPT specifies a prompt string, as in
29934     ‘make-sparse-keymap’.
29935
29936          (make-keymap)
29937              ⇒ (keymap #^[nil nil keymap nil nil nil ...])
29938
29939     A full keymap is more efficient than a sparse keymap when it holds
29940     lots of bindings; for just a few, the sparse keymap is better.
29941
29942 -- Function: copy-keymap keymap
29943     This function returns a copy of KEYMAP.  This is almost never
29944     needed.  If you want a keymap that’s like another yet with a few
29945     changes, you should use map inheritance rather than copying.  I.e.,
29946     something like:
29947
29948          (let ((map (make-sparse-keymap)))
29949            (set-keymap-parent map <theirmap>)
29950            (define-key map ...)
29951            ...)
29952
29953     When performing ‘copy-keymap’, any keymaps that appear directly as
29954     bindings in KEYMAP are also copied recursively, and so on to any
29955     number of levels.  However, recursive copying does not take place
29956     when the definition of a character is a symbol whose function
29957     definition is a keymap; the same symbol appears in the new copy.
29958
29959          (setq map (copy-keymap (current-local-map)))
29960          ⇒ (keymap
29961               ;; (This implements meta characters.)
29962               (27 keymap
29963                   (83 . center-paragraph)
29964                   (115 . center-line))
29965               (9 . tab-to-tab-stop))
29966
29967          (eq map (current-local-map))
29968              ⇒ nil
29969          (equal map (current-local-map))
29970              ⇒ t
29971
29972
29973File: elisp.info,  Node: Inheritance and Keymaps,  Next: Prefix Keys,  Prev: Creating Keymaps,  Up: Keymaps
29974
2997522.5 Inheritance and Keymaps
29976============================
29977
29978A keymap can inherit the bindings of another keymap, which we call the
29979“parent keymap”.  Such a keymap looks like this:
29980
29981     (keymap ELEMENTS... . PARENT-KEYMAP)
29982
29983The effect is that this keymap inherits all the bindings of
29984PARENT-KEYMAP, whatever they may be at the time a key is looked up, but
29985can add to them or override them with ELEMENTS.
29986
29987   If you change the bindings in PARENT-KEYMAP using ‘define-key’ or
29988other key-binding functions, these changed bindings are visible in the
29989inheriting keymap, unless shadowed by the bindings made by ELEMENTS.
29990The converse is not true: if you use ‘define-key’ to change bindings in
29991the inheriting keymap, these changes are recorded in ELEMENTS, but have
29992no effect on PARENT-KEYMAP.
29993
29994   The proper way to construct a keymap with a parent is to use
29995‘set-keymap-parent’; if you have code that directly constructs a keymap
29996with a parent, please convert the program to use ‘set-keymap-parent’
29997instead.
29998
29999 -- Function: keymap-parent keymap
30000     This returns the parent keymap of KEYMAP.  If KEYMAP has no parent,
30001     ‘keymap-parent’ returns ‘nil’.
30002
30003 -- Function: set-keymap-parent keymap parent
30004     This sets the parent keymap of KEYMAP to PARENT, and returns
30005     PARENT.  If PARENT is ‘nil’, this function gives KEYMAP no parent
30006     at all.
30007
30008     If KEYMAP has submaps (bindings for prefix keys), they too receive
30009     new parent keymaps that reflect what PARENT specifies for those
30010     prefix keys.
30011
30012   Here is an example showing how to make a keymap that inherits from
30013‘text-mode-map’:
30014
30015     (let ((map (make-sparse-keymap)))
30016       (set-keymap-parent map text-mode-map)
30017       map)
30018
30019   A non-sparse keymap can have a parent too, but this is not very
30020useful.  A non-sparse keymap always specifies something as the binding
30021for every numeric character code without modifier bits, even if it is
30022‘nil’, so these character’s bindings are never inherited from the parent
30023keymap.
30024
30025   Sometimes you want to make a keymap that inherits from more than one
30026map.  You can use the function ‘make-composed-keymap’ for this.
30027
30028 -- Function: make-composed-keymap maps &optional parent
30029     This function returns a new keymap composed of the existing
30030     keymap(s) MAPS, and optionally inheriting from a parent keymap
30031     PARENT.  MAPS can be a single keymap or a list of more than one.
30032     When looking up a key in the resulting new map, Emacs searches in
30033     each of the MAPS in turn, and then in PARENT, stopping at the first
30034     match.  A ‘nil’ binding in any one of MAPS overrides any binding in
30035     PARENT, but it does not override any non-‘nil’ binding in any other
30036     of the MAPS.
30037
30038For example, here is how Emacs sets the parent of ‘help-mode-map’, such
30039that it inherits from both ‘button-buffer-map’ and ‘special-mode-map’:
30040
30041     (defvar help-mode-map
30042       (let ((map (make-sparse-keymap)))
30043         (set-keymap-parent map
30044           (make-composed-keymap button-buffer-map special-mode-map))
30045         ... map) ... )
30046
30047
30048File: elisp.info,  Node: Prefix Keys,  Next: Active Keymaps,  Prev: Inheritance and Keymaps,  Up: Keymaps
30049
3005022.6 Prefix Keys
30051================
30052
30053A “prefix key” is a key sequence whose binding is a keymap.  The keymap
30054defines what to do with key sequences that extend the prefix key.  For
30055example, ‘C-x’ is a prefix key, and it uses a keymap that is also stored
30056in the variable ‘ctl-x-map’.  This keymap defines bindings for key
30057sequences starting with ‘C-x’.
30058
30059   Some of the standard Emacs prefix keys use keymaps that are also
30060found in Lisp variables:
30061
30062   • ‘esc-map’ is the global keymap for the <ESC> prefix key.  Thus, the
30063     global definitions of all meta characters are actually found here.
30064     This map is also the function definition of ‘ESC-prefix’.
30065
30066   • ‘help-map’ is the global keymap for the ‘C-h’ prefix key.
30067
30068   • ‘mode-specific-map’ is the global keymap for the prefix key ‘C-c’.
30069     This map is actually global, not mode-specific, but its name
30070     provides useful information about ‘C-c’ in the output of ‘C-h b’
30071     (‘display-bindings’), since the main use of this prefix key is for
30072     mode-specific bindings.
30073
30074   • ‘ctl-x-map’ is the global keymap used for the ‘C-x’ prefix key.
30075     This map is found via the function cell of the symbol
30076     ‘Control-X-prefix’.
30077
30078   • ‘mule-keymap’ is the global keymap used for the ‘C-x <RET>’ prefix
30079     key.
30080
30081   • ‘ctl-x-4-map’ is the global keymap used for the ‘C-x 4’ prefix key.
30082
30083   • ‘ctl-x-5-map’ is the global keymap used for the ‘C-x 5’ prefix key.
30084
30085   • ‘2C-mode-map’ is the global keymap used for the ‘C-x 6’ prefix key.
30086
30087   • ‘tab-prefix-map’ is the global keymap used for the ‘C-x t’ prefix
30088     key.
30089
30090   • ‘vc-prefix-map’ is the global keymap used for the ‘C-x v’ prefix
30091     key.
30092
30093   • ‘goto-map’ is the global keymap used for the ‘M-g’ prefix key.
30094
30095   • ‘search-map’ is the global keymap used for the ‘M-s’ prefix key.
30096
30097   • ‘facemenu-keymap’ is the global keymap used for the ‘M-o’ prefix
30098     key.
30099
30100   • The other Emacs prefix keys are ‘C-x @’, ‘C-x a i’, ‘C-x <ESC>’ and
30101     ‘<ESC> <ESC>’.  They use keymaps that have no special names.
30102
30103   The keymap binding of a prefix key is used for looking up the event
30104that follows the prefix key.  (It may instead be a symbol whose function
30105definition is a keymap.  The effect is the same, but the symbol serves
30106as a name for the prefix key.)  Thus, the binding of ‘C-x’ is the symbol
30107‘Control-X-prefix’, whose function cell holds the keymap for ‘C-x’
30108commands.  (The same keymap is also the value of ‘ctl-x-map’.)
30109
30110   Prefix key definitions can appear in any active keymap.  The
30111definitions of ‘C-c’, ‘C-x’, ‘C-h’ and <ESC> as prefix keys appear in
30112the global map, so these prefix keys are always available.  Major and
30113minor modes can redefine a key as a prefix by putting a prefix key
30114definition for it in the local map or the minor mode’s map.  *Note
30115Active Keymaps::.
30116
30117   If a key is defined as a prefix in more than one active map, then its
30118various definitions are in effect merged: the commands defined in the
30119minor mode keymaps come first, followed by those in the local map’s
30120prefix definition, and then by those from the global map.
30121
30122   In the following example, we make ‘C-p’ a prefix key in the local
30123keymap, in such a way that ‘C-p’ is identical to ‘C-x’.  Then the
30124binding for ‘C-p C-f’ is the function ‘find-file’, just like ‘C-x C-f’.
30125The key sequence ‘C-p 6’ is not found in any active keymap.
30126
30127     (use-local-map (make-sparse-keymap))
30128         ⇒ nil
30129     (local-set-key "\C-p" ctl-x-map)
30130         ⇒ nil
30131     (key-binding "\C-p\C-f")
30132         ⇒ find-file
30133
30134     (key-binding "\C-p6")
30135         ⇒ nil
30136
30137 -- Function: define-prefix-command symbol &optional mapvar prompt
30138     This function prepares SYMBOL for use as a prefix key’s binding: it
30139     creates a sparse keymap and stores it as SYMBOL’s function
30140     definition.  Subsequently binding a key sequence to SYMBOL will
30141     make that key sequence into a prefix key.  The return value is
30142     ‘symbol’.
30143
30144     This function also sets SYMBOL as a variable, with the keymap as
30145     its value.  But if MAPVAR is non-‘nil’, it sets MAPVAR as a
30146     variable instead.
30147
30148     If PROMPT is non-‘nil’, that becomes the overall prompt string for
30149     the keymap.  The prompt string should be given for menu keymaps
30150     (*note Defining Menus::).
30151
30152
30153File: elisp.info,  Node: Active Keymaps,  Next: Searching Keymaps,  Prev: Prefix Keys,  Up: Keymaps
30154
3015522.7 Active Keymaps
30156===================
30157
30158Emacs contains many keymaps, but at any time only a few keymaps are
30159“active”.  When Emacs receives user input, it translates the input event
30160(*note Translation Keymaps::), and looks for a key binding in the active
30161keymaps.
30162
30163   Usually, the active keymaps are: (i) the keymap specified by the
30164‘keymap’ property, (ii) the keymaps of enabled minor modes, (iii) the
30165current buffer’s local keymap, and (iv) the global keymap, in that
30166order.  Emacs searches for each input key sequence in all these keymaps.
30167
30168   Of these usual keymaps, the highest-precedence one is specified by
30169the ‘keymap’ text or overlay property at point, if any.  (For a mouse
30170input event, Emacs uses the event position instead of point; *note
30171Searching Keymaps::.)
30172
30173   Next in precedence are keymaps specified by enabled minor modes.
30174These keymaps, if any, are specified by the variables
30175‘emulation-mode-map-alists’, ‘minor-mode-overriding-map-alist’, and
30176‘minor-mode-map-alist’.  *Note Controlling Active Maps::.
30177
30178   Next in precedence is the buffer’s “local keymap”, containing key
30179bindings specific to the buffer.  The minibuffer also has a local keymap
30180(*note Intro to Minibuffers::).  If there is a ‘local-map’ text or
30181overlay property at point, that specifies the local keymap to use, in
30182place of the buffer’s default local keymap.
30183
30184   The local keymap is normally set by the buffer’s major mode, and
30185every buffer with the same major mode shares the same local keymap.
30186Hence, if you call ‘local-set-key’ (*note Key Binding Commands::) to
30187change the local keymap in one buffer, that also affects the local
30188keymaps in other buffers with the same major mode.
30189
30190   Finally, the “global keymap” contains key bindings that are defined
30191regardless of the current buffer, such as ‘C-f’.  It is always active,
30192and is bound to the variable ‘global-map’.
30193
30194   Apart from the above usual keymaps, Emacs provides special ways for
30195programs to make other keymaps active.  Firstly, the variable
30196‘overriding-local-map’ specifies a keymap that replaces the usual active
30197keymaps, except for the global keymap.  Secondly, the terminal-local
30198variable ‘overriding-terminal-local-map’ specifies a keymap that takes
30199precedence over _all_ other keymaps (including ‘overriding-local-map’);
30200this is normally used for modal/transient keybindings (the function
30201‘set-transient-map’ provides a convenient interface for this).  *Note
30202Controlling Active Maps::, for details.
30203
30204   Making keymaps active is not the only way to use them.  Keymaps are
30205also used in other ways, such as for translating events within
30206‘read-key-sequence’.  *Note Translation Keymaps::.
30207
30208   *Note Standard Keymaps::, for a list of some standard keymaps.
30209
30210 -- Function: current-active-maps &optional olp position
30211     This returns the list of active keymaps that would be used by the
30212     command loop in the current circumstances to look up a key
30213     sequence.  Normally it ignores ‘overriding-local-map’ and
30214     ‘overriding-terminal-local-map’, but if OLP is non-‘nil’ then it
30215     pays attention to them.  POSITION can optionally be either an event
30216     position as returned by ‘event-start’ or a buffer position, and may
30217     change the keymaps as described for ‘key-binding’.
30218
30219 -- Function: key-binding key &optional accept-defaults no-remap
30220          position
30221     This function returns the binding for KEY according to the current
30222     active keymaps.  The result is ‘nil’ if KEY is undefined in the
30223     keymaps.
30224
30225     The argument ACCEPT-DEFAULTS controls checking for default
30226     bindings, as in ‘lookup-key’ (*note Functions for Key Lookup::).
30227
30228     When commands are remapped (*note Remapping Commands::),
30229     ‘key-binding’ normally processes command remappings so as to return
30230     the remapped command that will actually be executed.  However, if
30231     NO-REMAP is non-‘nil’, ‘key-binding’ ignores remappings and returns
30232     the binding directly specified for KEY.
30233
30234     If KEY starts with a mouse event (perhaps following a prefix
30235     event), the maps to be consulted are determined based on the
30236     event’s position.  Otherwise, they are determined based on the
30237     value of point.  However, you can override either of them by
30238     specifying POSITION.  If POSITION is non-‘nil’, it should be either
30239     a buffer position or an event position like the value of
30240     ‘event-start’.  Then the maps consulted are determined based on
30241     POSITION.
30242
30243     Emacs signals an error if KEY is not a string or a vector.
30244
30245          (key-binding "\C-x\C-f")
30246              ⇒ find-file
30247
30248
30249File: elisp.info,  Node: Searching Keymaps,  Next: Controlling Active Maps,  Prev: Active Keymaps,  Up: Keymaps
30250
3025122.8 Searching the Active Keymaps
30252=================================
30253
30254Here is a pseudo-Lisp summary of how Emacs searches the active keymaps:
30255
30256     (or (if overriding-terminal-local-map
30257             (FIND-IN overriding-terminal-local-map))
30258         (if overriding-local-map
30259             (FIND-IN overriding-local-map)
30260           (or (FIND-IN (get-char-property (point) 'keymap))
30261               (FIND-IN-ANY emulation-mode-map-alists)
30262               (FIND-IN-ANY minor-mode-overriding-map-alist)
30263               (FIND-IN-ANY minor-mode-map-alist)
30264               (if (get-text-property (point) 'local-map)
30265                   (FIND-IN (get-char-property (point) 'local-map))
30266                 (FIND-IN (current-local-map)))))
30267         (FIND-IN (current-global-map)))
30268
30269Here, FIND-IN and FIND-IN-ANY are pseudo functions that search in one
30270keymap and in an alist of keymaps, respectively.  Note that the
30271‘set-transient-map’ function works by setting
30272‘overriding-terminal-local-map’ (*note Controlling Active Maps::).
30273
30274   In the above pseudo-code, if a key sequence starts with a mouse event
30275(*note Mouse Events::), that event’s position is used instead of point,
30276and the event’s buffer is used instead of the current buffer.  In
30277particular, this affects how the ‘keymap’ and ‘local-map’ properties are
30278looked up.  If a mouse event occurs on a string embedded with a
30279‘display’, ‘before-string’, or ‘after-string’ property (*note Special
30280Properties::), and the string has a non-‘nil’ ‘keymap’ or ‘local-map’
30281property, that overrides the corresponding property in the underlying
30282buffer text (i.e., the property specified by the underlying text is
30283ignored).
30284
30285   When a key binding is found in one of the active keymaps, and that
30286binding is a command, the search is over—the command is executed.
30287However, if the binding is a symbol with a value or a string, Emacs
30288replaces the input key sequences with the variable’s value or the
30289string, and restarts the search of the active keymaps.  *Note Key
30290Lookup::.
30291
30292   The command which is finally found might also be remapped.  *Note
30293Remapping Commands::.
30294
30295
30296File: elisp.info,  Node: Controlling Active Maps,  Next: Key Lookup,  Prev: Searching Keymaps,  Up: Keymaps
30297
3029822.9 Controlling the Active Keymaps
30299===================================
30300
30301 -- Variable: global-map
30302     This variable contains the default global keymap that maps Emacs
30303     keyboard input to commands.  The global keymap is normally this
30304     keymap.  The default global keymap is a full keymap that binds
30305     ‘self-insert-command’ to all of the printing characters.
30306
30307     It is normal practice to change the bindings in the global keymap,
30308     but you should not assign this variable any value other than the
30309     keymap it starts out with.
30310
30311 -- Function: current-global-map
30312     This function returns the current global keymap.  This is the same
30313     as the value of ‘global-map’ unless you change one or the other.
30314     The return value is a reference, not a copy; if you use
30315     ‘define-key’ or other functions on it you will alter global
30316     bindings.
30317
30318          (current-global-map)
30319          ⇒ (keymap [set-mark-command beginning-of-line ...
30320                      delete-backward-char])
30321
30322 -- Function: current-local-map
30323     This function returns the current buffer’s local keymap, or ‘nil’
30324     if it has none.  In the following example, the keymap for the
30325     ‘*scratch*’ buffer (using Lisp Interaction mode) is a sparse keymap
30326     in which the entry for <ESC>, ASCII code 27, is another sparse
30327     keymap.
30328
30329          (current-local-map)
30330          ⇒ (keymap
30331              (10 . eval-print-last-sexp)
30332              (9 . lisp-indent-line)
30333              (127 . backward-delete-char-untabify)
30334              (27 keymap
30335                  (24 . eval-defun)
30336                  (17 . indent-sexp)))
30337
30338   ‘current-local-map’ returns a reference to the local keymap, not a
30339copy of it; if you use ‘define-key’ or other functions on it you will
30340alter local bindings.
30341
30342 -- Function: current-minor-mode-maps
30343     This function returns a list of the keymaps of currently enabled
30344     minor modes.
30345
30346 -- Function: use-global-map keymap
30347     This function makes KEYMAP the new current global keymap.  It
30348     returns ‘nil’.
30349
30350     It is very unusual to change the global keymap.
30351
30352 -- Function: use-local-map keymap
30353     This function makes KEYMAP the new local keymap of the current
30354     buffer.  If KEYMAP is ‘nil’, then the buffer has no local keymap.
30355     ‘use-local-map’ returns ‘nil’.  Most major mode commands use this
30356     function.
30357
30358 -- Variable: minor-mode-map-alist
30359     This variable is an alist describing keymaps that may or may not be
30360     active according to the values of certain variables.  Its elements
30361     look like this:
30362
30363          (VARIABLE . KEYMAP)
30364
30365     The keymap KEYMAP is active whenever VARIABLE has a non-‘nil’
30366     value.  Typically VARIABLE is the variable that enables or disables
30367     a minor mode.  *Note Keymaps and Minor Modes::.
30368
30369     Note that elements of ‘minor-mode-map-alist’ do not have the same
30370     structure as elements of ‘minor-mode-alist’.  The map must be the
30371     CDR of the element; a list with the map as the second element will
30372     not do.  The CDR can be either a keymap (a list) or a symbol whose
30373     function definition is a keymap.
30374
30375     When more than one minor mode keymap is active, the earlier one in
30376     ‘minor-mode-map-alist’ takes priority.  But you should design minor
30377     modes so that they don’t interfere with each other.  If you do this
30378     properly, the order will not matter.
30379
30380     See *note Keymaps and Minor Modes::, for more information about
30381     minor modes.  See also ‘minor-mode-key-binding’ (*note Functions
30382     for Key Lookup::).
30383
30384 -- Variable: minor-mode-overriding-map-alist
30385     This variable allows major modes to override the key bindings for
30386     particular minor modes.  The elements of this alist look like the
30387     elements of ‘minor-mode-map-alist’: ‘(VARIABLE . KEYMAP)’.
30388
30389     If a variable appears as an element of
30390     ‘minor-mode-overriding-map-alist’, the map specified by that
30391     element totally replaces any map specified for the same variable in
30392     ‘minor-mode-map-alist’.
30393
30394     ‘minor-mode-overriding-map-alist’ is automatically buffer-local in
30395     all buffers.
30396
30397 -- Variable: overriding-local-map
30398     If non-‘nil’, this variable holds a keymap to use instead of the
30399     buffer’s local keymap, any text property or overlay keymaps, and
30400     any minor mode keymaps.  This keymap, if specified, overrides all
30401     other maps that would have been active, except for the current
30402     global map.
30403
30404 -- Variable: overriding-terminal-local-map
30405     If non-‘nil’, this variable holds a keymap to use instead of
30406     ‘overriding-local-map’, the buffer’s local keymap, text property or
30407     overlay keymaps, and all the minor mode keymaps.
30408
30409     This variable is always local to the current terminal and cannot be
30410     buffer-local.  *Note Multiple Terminals::.  It is used to implement
30411     incremental search mode.
30412
30413 -- Variable: overriding-local-map-menu-flag
30414     If this variable is non-‘nil’, the value of ‘overriding-local-map’
30415     or ‘overriding-terminal-local-map’ can affect the display of the
30416     menu bar.  The default value is ‘nil’, so those map variables have
30417     no effect on the menu bar.
30418
30419     Note that these two map variables do affect the execution of key
30420     sequences entered using the menu bar, even if they do not affect
30421     the menu bar display.  So if a menu bar key sequence comes in, you
30422     should clear the variables before looking up and executing that key
30423     sequence.  Modes that use the variables would typically do this
30424     anyway; normally they respond to events that they do not handle by
30425     “unreading” them and exiting.
30426
30427 -- Variable: special-event-map
30428     This variable holds a keymap for special events.  If an event type
30429     has a binding in this keymap, then it is special, and the binding
30430     for the event is run directly by ‘read-event’.  *Note Special
30431     Events::.
30432
30433 -- Variable: emulation-mode-map-alists
30434     This variable holds a list of keymap alists to use for emulation
30435     modes.  It is intended for modes or packages using multiple
30436     minor-mode keymaps.  Each element is a keymap alist which has the
30437     same format and meaning as ‘minor-mode-map-alist’, or a symbol with
30438     a variable binding which is such an alist.  The active keymaps in
30439     each alist are used before ‘minor-mode-map-alist’ and
30440     ‘minor-mode-overriding-map-alist’.
30441
30442 -- Function: set-transient-map keymap &optional keep-pred on-exit
30443     This function adds KEYMAP as a “transient” keymap, which takes
30444     precedence over other keymaps for one (or more) subsequent keys.
30445
30446     Normally, KEYMAP is used just once, to look up the very next key.
30447     If the optional argument KEEP-PRED is ‘t’, the map stays active as
30448     long as the user types keys defined in KEYMAP; when the user types
30449     a key that is not in KEYMAP, the transient keymap is deactivated
30450     and normal key lookup continues for that key.
30451
30452     The KEEP-PRED argument can also be a function.  In that case, the
30453     function is called with no arguments, prior to running each
30454     command, while KEYMAP is active; it should return non-‘nil’ if
30455     KEYMAP should stay active.
30456
30457     The optional argument ON-EXIT, if non-‘nil’, specifies a function
30458     that is called, with no arguments, after KEYMAP is deactivated.
30459
30460     This function works by adding and removing KEYMAP from the variable
30461     ‘overriding-terminal-local-map’, which takes precedence over all
30462     other active keymaps (*note Searching Keymaps::).
30463
30464
30465File: elisp.info,  Node: Key Lookup,  Next: Functions for Key Lookup,  Prev: Controlling Active Maps,  Up: Keymaps
30466
3046722.10 Key Lookup
30468================
30469
30470“Key lookup” is the process of finding the binding of a key sequence
30471from a given keymap.  The execution or use of the binding is not part of
30472key lookup.
30473
30474   Key lookup uses just the event type of each event in the key
30475sequence; the rest of the event is ignored.  In fact, a key sequence
30476used for key lookup may designate a mouse event with just its types (a
30477symbol) instead of the entire event (a list).  *Note Input Events::.
30478Such a key sequence is insufficient for ‘command-execute’ to run, but it
30479is sufficient for looking up or rebinding a key.
30480
30481   When the key sequence consists of multiple events, key lookup
30482processes the events sequentially: the binding of the first event is
30483found, and must be a keymap; then the second event’s binding is found in
30484that keymap, and so on until all the events in the key sequence are used
30485up.  (The binding thus found for the last event may or may not be a
30486keymap.)  Thus, the process of key lookup is defined in terms of a
30487simpler process for looking up a single event in a keymap.  How that is
30488done depends on the type of object associated with the event in that
30489keymap.
30490
30491   Let’s use the term “keymap entry” to describe the value found by
30492looking up an event type in a keymap.  (This doesn’t include the item
30493string and other extra elements in a keymap element for a menu item,
30494because ‘lookup-key’ and other key lookup functions don’t include them
30495in the returned value.)  While any Lisp object may be stored in a keymap
30496as a keymap entry, not all make sense for key lookup.  Here is a table
30497of the meaningful types of keymap entries:
30498
30499‘nil’
30500     ‘nil’ means that the events used so far in the lookup form an
30501     undefined key.  When a keymap fails to mention an event type at
30502     all, and has no default binding, that is equivalent to a binding of
30503     ‘nil’ for that event type.
30504
30505COMMAND
30506     The events used so far in the lookup form a complete key, and
30507     COMMAND is its binding.  *Note What Is a Function::.
30508
30509ARRAY
30510     The array (either a string or a vector) is a keyboard macro.  The
30511     events used so far in the lookup form a complete key, and the array
30512     is its binding.  See *note Keyboard Macros::, for more information.
30513
30514KEYMAP
30515     The events used so far in the lookup form a prefix key.  The next
30516     event of the key sequence is looked up in KEYMAP.
30517
30518LIST
30519     The meaning of a list depends on what it contains:
30520
30521        • If the CAR of LIST is the symbol ‘keymap’, then the list is a
30522          keymap, and is treated as a keymap (see above).
30523
30524        • If the CAR of LIST is ‘lambda’, then the list is a lambda
30525          expression.  This is presumed to be a function, and is treated
30526          as such (see above).  In order to execute properly as a key
30527          binding, this function must be a command—it must have an
30528          ‘interactive’ specification.  *Note Defining Commands::.
30529
30530SYMBOL
30531     The function definition of SYMBOL is used in place of SYMBOL.  If
30532     that too is a symbol, then this process is repeated, any number of
30533     times.  Ultimately this should lead to an object that is a keymap,
30534     a command, or a keyboard macro.
30535
30536     Note that keymaps and keyboard macros (strings and vectors) are not
30537     valid functions, so a symbol with a keymap, string, or vector as
30538     its function definition is invalid as a function.  It is, however,
30539     valid as a key binding.  If the definition is a keyboard macro,
30540     then the symbol is also valid as an argument to ‘command-execute’
30541     (*note Interactive Call::).
30542
30543     The symbol ‘undefined’ is worth special mention: it means to treat
30544     the key as undefined.  Strictly speaking, the key is defined, and
30545     its binding is the command ‘undefined’; but that command does the
30546     same thing that is done automatically for an undefined key: it
30547     rings the bell (by calling ‘ding’) but does not signal an error.
30548
30549     ‘undefined’ is used in local keymaps to override a global key
30550     binding and make the key undefined locally.  A local binding of
30551     ‘nil’ would fail to do this because it would not override the
30552     global binding.
30553
30554ANYTHING ELSE
30555     If any other type of object is found, the events used so far in the
30556     lookup form a complete key, and the object is its binding, but the
30557     binding is not executable as a command.
30558
30559   In short, a keymap entry may be a keymap, a command, a keyboard
30560macro, a symbol that leads to one of them, or ‘nil’.
30561
30562
30563File: elisp.info,  Node: Functions for Key Lookup,  Next: Changing Key Bindings,  Prev: Key Lookup,  Up: Keymaps
30564
3056522.11 Functions for Key Lookup
30566==============================
30567
30568Here are the functions and variables pertaining to key lookup.
30569
30570 -- Function: lookup-key keymap key &optional accept-defaults
30571     This function returns the definition of KEY in KEYMAP.  All the
30572     other functions described in this chapter that look up keys use
30573     ‘lookup-key’.  Here are examples:
30574
30575          (lookup-key (current-global-map) "\C-x\C-f")
30576              ⇒ find-file
30577          (lookup-key (current-global-map) (kbd "C-x C-f"))
30578              ⇒ find-file
30579          (lookup-key (current-global-map) "\C-x\C-f12345")
30580              ⇒ 2
30581
30582     If the string or vector KEY is not a valid key sequence according
30583     to the prefix keys specified in KEYMAP, it must be too long and
30584     have extra events at the end that do not fit into a single key
30585     sequence.  Then the value is a number, the number of events at the
30586     front of KEY that compose a complete key.
30587
30588     If ACCEPT-DEFAULTS is non-‘nil’, then ‘lookup-key’ considers
30589     default bindings as well as bindings for the specific events in
30590     KEY.  Otherwise, ‘lookup-key’ reports only bindings for the
30591     specific sequence KEY, ignoring default bindings except when you
30592     explicitly ask about them.  (To do this, supply ‘t’ as an element
30593     of KEY; see *note Format of Keymaps::.)
30594
30595     If KEY contains a meta character (not a function key), that
30596     character is implicitly replaced by a two-character sequence: the
30597     value of ‘meta-prefix-char’, followed by the corresponding non-meta
30598     character.  Thus, the first example below is handled by conversion
30599     into the second example.
30600
30601          (lookup-key (current-global-map) "\M-f")
30602              ⇒ forward-word
30603          (lookup-key (current-global-map) "\ef")
30604              ⇒ forward-word
30605
30606     The KEYMAP argument can also be a list of keymaps.
30607
30608     Unlike ‘read-key-sequence’, this function does not modify the
30609     specified events in ways that discard information (*note Key
30610     Sequence Input::).  In particular, it does not convert letters to
30611     lower case and it does not change drag events to clicks.
30612
30613 -- Command: undefined
30614     Used in keymaps to undefine keys.  It calls ‘ding’, but does not
30615     cause an error.
30616
30617 -- Function: local-key-binding key &optional accept-defaults
30618     This function returns the binding for KEY in the current local
30619     keymap, or ‘nil’ if it is undefined there.
30620
30621     The argument ACCEPT-DEFAULTS controls checking for default
30622     bindings, as in ‘lookup-key’ (above).
30623
30624 -- Function: global-key-binding key &optional accept-defaults
30625     This function returns the binding for command KEY in the current
30626     global keymap, or ‘nil’ if it is undefined there.
30627
30628     The argument ACCEPT-DEFAULTS controls checking for default
30629     bindings, as in ‘lookup-key’ (above).
30630
30631 -- Function: minor-mode-key-binding key &optional accept-defaults
30632     This function returns a list of all the active minor mode bindings
30633     of KEY.  More precisely, it returns an alist of pairs ‘(MODENAME .
30634     BINDING)’, where MODENAME is the variable that enables the minor
30635     mode, and BINDING is KEY’s binding in that mode.  If KEY has no
30636     minor-mode bindings, the value is ‘nil’.
30637
30638     If the first binding found is not a prefix definition (a keymap or
30639     a symbol defined as a keymap), all subsequent bindings from other
30640     minor modes are omitted, since they would be completely shadowed.
30641     Similarly, the list omits non-prefix bindings that follow prefix
30642     bindings.
30643
30644     The argument ACCEPT-DEFAULTS controls checking for default
30645     bindings, as in ‘lookup-key’ (above).
30646
30647 -- User Option: meta-prefix-char
30648     This variable is the meta-prefix character code.  It is used for
30649     translating a meta character to a two-character sequence so it can
30650     be looked up in a keymap.  For useful results, the value should be
30651     a prefix event (*note Prefix Keys::).  The default value is 27,
30652     which is the ASCII code for <ESC>.
30653
30654     As long as the value of ‘meta-prefix-char’ remains 27, key lookup
30655     translates ‘M-b’ into ‘<ESC> b’, which is normally defined as the
30656     ‘backward-word’ command.  However, if you were to set
30657     ‘meta-prefix-char’ to 24, the code for ‘C-x’, then Emacs will
30658     translate ‘M-b’ into ‘C-x b’, whose standard binding is the
30659     ‘switch-to-buffer’ command.  (Don’t actually do this!)  Here is an
30660     illustration of what would happen:
30661
30662          meta-prefix-char                    ; The default value.
30663               ⇒ 27
30664          (key-binding "\M-b")
30665               ⇒ backward-word
30666          ?\C-x                               ; The print representation
30667               ⇒ 24                          ;   of a character.
30668          (setq meta-prefix-char 24)
30669               ⇒ 24
30670          (key-binding "\M-b")
30671               ⇒ switch-to-buffer            ; Now, typing ‘M-b’ is
30672                                              ;   like typing ‘C-x b’.
30673
30674          (setq meta-prefix-char 27)          ; Avoid confusion!
30675               ⇒ 27                          ; Restore the default value!
30676
30677     This translation of one event into two happens only for characters,
30678     not for other kinds of input events.  Thus, ‘M-<F1>’, a function
30679     key, is not converted into ‘<ESC> <F1>’.
30680
30681
30682File: elisp.info,  Node: Changing Key Bindings,  Next: Remapping Commands,  Prev: Functions for Key Lookup,  Up: Keymaps
30683
3068422.12 Changing Key Bindings
30685===========================
30686
30687The way to rebind a key is to change its entry in a keymap.  If you
30688change a binding in the global keymap, the change is effective in all
30689buffers (though it has no direct effect in buffers that shadow the
30690global binding with a local one).  If you change the current buffer’s
30691local map, that usually affects all buffers using the same major mode.
30692The ‘global-set-key’ and ‘local-set-key’ functions are convenient
30693interfaces for these operations (*note Key Binding Commands::).  You can
30694also use ‘define-key’, a more general function; then you must explicitly
30695specify the map to change.
30696
30697   When choosing the key sequences for Lisp programs to rebind, please
30698follow the Emacs conventions for use of various keys (*note Key Binding
30699Conventions::).
30700
30701   In writing the key sequence to rebind, it is good to use the special
30702escape sequences for control and meta characters (*note String Type::).
30703The syntax ‘\C-’ means that the following character is a control
30704character and ‘\M-’ means that the following character is a meta
30705character.  Thus, the string ‘"\M-x"’ is read as containing a single
30706‘M-x’, ‘"\C-f"’ is read as containing a single ‘C-f’, and ‘"\M-\C-x"’
30707and ‘"\C-\M-x"’ are both read as containing a single ‘C-M-x’.  You can
30708also use this escape syntax in vectors, as well as others that aren’t
30709allowed in strings; one example is ‘[?\C-\H-x home]’.  *Note Character
30710Type::.
30711
30712   The key definition and lookup functions accept an alternate syntax
30713for event types in a key sequence that is a vector: you can use a list
30714containing modifier names plus one base event (a character or function
30715key name).  For example, ‘(control ?a)’ is equivalent to ‘?\C-a’ and
30716‘(hyper control left)’ is equivalent to ‘C-H-left’.  One advantage of
30717such lists is that the precise numeric codes for the modifier bits don’t
30718appear in compiled files.
30719
30720   The functions below signal an error if KEYMAP is not a keymap, or if
30721KEY is not a string or vector representing a key sequence.  You can use
30722event types (symbols) as shorthand for events that are lists.  The ‘kbd’
30723function (*note Key Sequences::) is a convenient way to specify the key
30724sequence.
30725
30726 -- Function: define-key keymap key binding
30727     This function sets the binding for KEY in KEYMAP.  (If KEY is more
30728     than one event long, the change is actually made in another keymap
30729     reached from KEYMAP.)  The argument BINDING can be any Lisp object,
30730     but only certain types are meaningful.  (For a list of meaningful
30731     types, see *note Key Lookup::.)  The value returned by ‘define-key’
30732     is BINDING.
30733
30734     If KEY is ‘[t]’, this sets the default binding in KEYMAP.  When an
30735     event has no binding of its own, the Emacs command loop uses the
30736     keymap’s default binding, if there is one.
30737
30738     Every prefix of KEY must be a prefix key (i.e., bound to a keymap)
30739     or undefined; otherwise an error is signaled.  If some prefix of
30740     KEY is undefined, then ‘define-key’ defines it as a prefix key so
30741     that the rest of KEY can be defined as specified.
30742
30743     If there was previously no binding for KEY in KEYMAP, the new
30744     binding is added at the beginning of KEYMAP.  The order of bindings
30745     in a keymap makes no difference for keyboard input, but it does
30746     matter for menu keymaps (*note Menu Keymaps::).
30747
30748   This example creates a sparse keymap and makes a number of bindings
30749in it:
30750
30751     (setq map (make-sparse-keymap))
30752         ⇒ (keymap)
30753     (define-key map "\C-f" 'forward-char)
30754         ⇒ forward-char
30755     map
30756         ⇒ (keymap (6 . forward-char))
30757
30758     ;; Build sparse submap for ‘C-x’ and bind ‘f’ in that.
30759     (define-key map (kbd "C-x f") 'forward-word)
30760         ⇒ forward-word
30761     map
30762     ⇒ (keymap
30763         (24 keymap                ; C-x
30764             (102 . forward-word)) ;      f
30765         (6 . forward-char))       ; C-f
30766
30767     ;; Bind ‘C-p’ to the ‘ctl-x-map’.
30768     (define-key map (kbd "C-p") ctl-x-map)
30769     ;; ctl-x-map
30770     ⇒ [nil ... find-file ... backward-kill-sentence]
30771
30772     ;; Bind ‘C-f’ to ‘foo’ in the ‘ctl-x-map’.
30773     (define-key map (kbd "C-p C-f") 'foo)
30774     ⇒ 'foo
30775     map
30776     ⇒ (keymap     ; Note ‘foo’ in ‘ctl-x-map’.
30777         (16 keymap [nil ... foo ... backward-kill-sentence])
30778         (24 keymap
30779             (102 . forward-word))
30780         (6 . forward-char))
30781
30782Note that storing a new binding for ‘C-p C-f’ actually works by changing
30783an entry in ‘ctl-x-map’, and this has the effect of changing the
30784bindings of both ‘C-p C-f’ and ‘C-x C-f’ in the default global map.
30785
30786   The function ‘substitute-key-definition’ scans a keymap for keys that
30787have a certain binding and rebinds them with a different binding.
30788Another feature which is cleaner and can often produce the same results
30789is to remap one command into another (*note Remapping Commands::).
30790
30791 -- Function: substitute-key-definition olddef newdef keymap &optional
30792          oldmap
30793     This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
30794     that were bound to OLDDEF.  In other words, OLDDEF is replaced with
30795     NEWDEF wherever it appears.  The function returns ‘nil’.
30796
30797     For example, this redefines ‘C-x C-f’, if you do it in an Emacs
30798     with standard bindings:
30799
30800          (substitute-key-definition
30801           'find-file 'find-file-read-only (current-global-map))
30802
30803     If OLDMAP is non-‘nil’, that changes the behavior of
30804     ‘substitute-key-definition’: the bindings in OLDMAP determine which
30805     keys to rebind.  The rebindings still happen in KEYMAP, not in
30806     OLDMAP.  Thus, you can change one map under the control of the
30807     bindings in another.  For example,
30808
30809          (substitute-key-definition
30810            'delete-backward-char 'my-funny-delete
30811            my-map global-map)
30812
30813     puts the special deletion command in ‘my-map’ for whichever keys
30814     are globally bound to the standard deletion command.
30815
30816     Here is an example showing a keymap before and after substitution:
30817
30818          (setq map (list 'keymap
30819                          (cons ?1 olddef-1)
30820                          (cons ?2 olddef-2)
30821                          (cons ?3 olddef-1)))
30822          ⇒ (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1))
30823
30824          (substitute-key-definition 'olddef-1 'newdef map)
30825          ⇒ nil
30826          map
30827          ⇒ (keymap (49 . newdef) (50 . olddef-2) (51 . newdef))
30828
30829 -- Function: suppress-keymap keymap &optional nodigits
30830     This function changes the contents of the full keymap KEYMAP by
30831     remapping ‘self-insert-command’ to the command ‘undefined’ (*note
30832     Remapping Commands::).  This has the effect of undefining all
30833     printing characters, thus making ordinary insertion of text
30834     impossible.  ‘suppress-keymap’ returns ‘nil’.
30835
30836     If NODIGITS is ‘nil’, then ‘suppress-keymap’ defines digits to run
30837     ‘digit-argument’, and ‘-’ to run ‘negative-argument’.  Otherwise it
30838     makes them undefined like the rest of the printing characters.
30839
30840     The ‘suppress-keymap’ function does not make it impossible to
30841     modify a buffer, as it does not suppress commands such as ‘yank’
30842     and ‘quoted-insert’.  To prevent any modification of a buffer, make
30843     it read-only (*note Read Only Buffers::).
30844
30845     Since this function modifies KEYMAP, you would normally use it on a
30846     newly created keymap.  Operating on an existing keymap that is used
30847     for some other purpose is likely to cause trouble; for example,
30848     suppressing ‘global-map’ would make it impossible to use most of
30849     Emacs.
30850
30851     This function can be used to initialize the local keymap of a major
30852     mode for which insertion of text is not desirable.  But usually
30853     such a mode should be derived from ‘special-mode’ (*note Basic
30854     Major Modes::); then its keymap will automatically inherit from
30855     ‘special-mode-map’, which is already suppressed.  Here is how
30856     ‘special-mode-map’ is defined:
30857
30858          (defvar special-mode-map
30859            (let ((map (make-sparse-keymap)))
30860              (suppress-keymap map)
30861              (define-key map "q" 'quit-window)
30862              ...
30863              map))
30864
30865
30866File: elisp.info,  Node: Remapping Commands,  Next: Translation Keymaps,  Prev: Changing Key Bindings,  Up: Keymaps
30867
3086822.13 Remapping Commands
30869========================
30870
30871A special kind of key binding can be used to “remap” one command to
30872another, without having to refer to the key sequence(s) bound to the
30873original command.  To use this feature, make a key binding for a key
30874sequence that starts with the dummy event ‘remap’, followed by the
30875command name you want to remap; for the binding, specify the new
30876definition (usually a command name, but possibly any other valid
30877definition for a key binding).
30878
30879   For example, suppose My mode provides a special command
30880‘my-kill-line’, which should be invoked instead of ‘kill-line’.  To
30881establish this, its mode keymap should contain the following remapping:
30882
30883     (define-key my-mode-map [remap kill-line] 'my-kill-line)
30884
30885Then, whenever ‘my-mode-map’ is active, if the user types ‘C-k’ (the
30886default global key sequence for ‘kill-line’) Emacs will instead run
30887‘my-kill-line’.
30888
30889   Note that remapping only takes place through active keymaps; for
30890example, putting a remapping in a prefix keymap like ‘ctl-x-map’
30891typically has no effect, as such keymaps are not themselves active.  In
30892addition, remapping only works through a single level; in the following
30893example,
30894
30895     (define-key my-mode-map [remap kill-line] 'my-kill-line)
30896     (define-key my-mode-map [remap my-kill-line] 'my-other-kill-line)
30897
30898‘kill-line’ is _not_ remapped to ‘my-other-kill-line’.  Instead, if an
30899ordinary key binding specifies ‘kill-line’, it is remapped to
30900‘my-kill-line’; if an ordinary binding specifies ‘my-kill-line’, it is
30901remapped to ‘my-other-kill-line’.
30902
30903   To undo the remapping of a command, remap it to ‘nil’; e.g.,
30904
30905     (define-key my-mode-map [remap kill-line] nil)
30906
30907 -- Function: command-remapping command &optional position keymaps
30908     This function returns the remapping for COMMAND (a symbol), given
30909     the current active keymaps.  If COMMAND is not remapped (which is
30910     the usual situation), or not a symbol, the function returns ‘nil’.
30911     ‘position’ can optionally specify a buffer position or an event
30912     position to determine the keymaps to use, as in ‘key-binding’.
30913
30914     If the optional argument ‘keymaps’ is non-‘nil’, it specifies a
30915     list of keymaps to search in.  This argument is ignored if
30916     ‘position’ is non-‘nil’.
30917
30918
30919File: elisp.info,  Node: Translation Keymaps,  Next: Key Binding Commands,  Prev: Remapping Commands,  Up: Keymaps
30920
3092122.14 Keymaps for Translating Sequences of Events
30922=================================================
30923
30924When the ‘read-key-sequence’ function reads a key sequence (*note Key
30925Sequence Input::), it uses “translation keymaps” to translate certain
30926event sequences into others.  The translation keymaps are
30927‘input-decode-map’, ‘local-function-key-map’, and ‘key-translation-map’
30928(in order of priority).
30929
30930   Translation keymaps have the same structure as other keymaps, but are
30931used differently: they specify translations to make while reading key
30932sequences, rather than bindings for complete key sequences.  As each key
30933sequence is read, it is checked against each translation keymap.  If one
30934of the translation keymaps binds K to a vector V, then whenever K
30935appears as a sub-sequence _anywhere_ in a key sequence, that
30936sub-sequence is replaced with the events in V.
30937
30938   For example, VT100 terminals send ‘<ESC> O P’ when the keypad key
30939<PF1> is pressed.  On such terminals, Emacs must translate that sequence
30940of events into a single event ‘pf1’.  This is done by binding ‘<ESC> O
30941P’ to ‘[pf1]’ in ‘input-decode-map’.  Thus, when you type ‘C-c <PF1>’ on
30942the terminal, the terminal emits the character sequence ‘C-c <ESC> O P’,
30943and ‘read-key-sequence’ translates this back into ‘C-c <PF1>’ and
30944returns it as the vector ‘[?\C-c pf1]’.
30945
30946   Translation keymaps take effect only after Emacs has decoded the
30947keyboard input (via the input coding system specified by
30948‘keyboard-coding-system’).  *Note Terminal I/O Encoding::.
30949
30950 -- Variable: input-decode-map
30951     This variable holds a keymap that describes the character sequences
30952     sent by function keys on an ordinary character terminal.
30953
30954     The value of ‘input-decode-map’ is usually set up automatically
30955     according to the terminal’s Terminfo or Termcap entry, but
30956     sometimes those need help from terminal-specific Lisp files.  Emacs
30957     comes with terminal-specific files for many common terminals; their
30958     main purpose is to make entries in ‘input-decode-map’ beyond those
30959     that can be deduced from Termcap and Terminfo.  *Note
30960     Terminal-Specific::.
30961
30962 -- Variable: local-function-key-map
30963     This variable holds a keymap similar to ‘input-decode-map’ except
30964     that it describes key sequences which should be translated to
30965     alternative interpretations that are usually preferred.  It applies
30966     after ‘input-decode-map’ and before ‘key-translation-map’.
30967
30968     Entries in ‘local-function-key-map’ are ignored if they conflict
30969     with bindings made in the minor mode, local, or global keymaps.
30970     I.e., the remapping only applies if the original key sequence would
30971     otherwise not have any binding.
30972
30973     ‘local-function-key-map’ inherits from ‘function-key-map’.  The
30974     latter should only be altered if you want the binding to apply in
30975     all terminals, so using the former is almost always preferred.
30976
30977 -- Variable: key-translation-map
30978     This variable is another keymap used just like ‘input-decode-map’
30979     to translate input events into other events.  It differs from
30980     ‘input-decode-map’ in that it goes to work after
30981     ‘local-function-key-map’ is finished rather than before; it
30982     receives the results of translation by ‘local-function-key-map’.
30983
30984     Just like ‘input-decode-map’, but unlike ‘local-function-key-map’,
30985     this keymap is applied regardless of whether the input key-sequence
30986     has a normal binding.  Note however that actual key bindings can
30987     have an effect on ‘key-translation-map’, even though they are
30988     overridden by it.  Indeed, actual key bindings override
30989     ‘local-function-key-map’ and thus may alter the key sequence that
30990     ‘key-translation-map’ receives.  Clearly, it is better to avoid
30991     this type of situation.
30992
30993     The intent of ‘key-translation-map’ is for users to map one
30994     character set to another, including ordinary characters normally
30995     bound to ‘self-insert-command’.
30996
30997   You can use ‘input-decode-map’, ‘local-function-key-map’, and
30998‘key-translation-map’ for more than simple aliases, by using a function,
30999instead of a key sequence, as the translation of a key.  Then this
31000function is called to compute the translation of that key.
31001
31002   The key translation function receives one argument, which is the
31003prompt that was specified in ‘read-key-sequence’—or ‘nil’ if the key
31004sequence is being read by the editor command loop.  In most cases you
31005can ignore the prompt value.
31006
31007   If the function reads input itself, it can have the effect of
31008altering the event that follows.  For example, here’s how to define ‘C-c
31009h’ to turn the character that follows into a Hyper character:
31010
31011     (defun hyperify (prompt)
31012       (let ((e (read-event)))
31013         (vector (if (numberp e)
31014                     (logior (ash 1 24) e)
31015                   (if (memq 'hyper (event-modifiers e))
31016                       e
31017                     (add-event-modifier "H-" e))))))
31018
31019     (defun add-event-modifier (string e)
31020       (let ((symbol (if (symbolp e) e (car e))))
31021         (setq symbol (intern (concat string
31022                                      (symbol-name symbol))))
31023         (if (symbolp e)
31024             symbol
31025           (cons symbol (cdr e)))))
31026
31027     (define-key local-function-key-map "\C-ch" 'hyperify)
31028
3102922.14.1 Interaction with normal keymaps
31030---------------------------------------
31031
31032The end of a key sequence is detected when that key sequence either is
31033bound to a command, or when Emacs determines that no additional event
31034can lead to a sequence that is bound to a command.
31035
31036   This means that, while ‘input-decode-map’ and ‘key-translation-map’
31037apply regardless of whether the original key sequence would have a
31038binding, the presence of such a binding can still prevent translation
31039from taking place.  For example, let us return to our VT100 example
31040above and add a binding for ‘C-c <ESC>’ to the global map; now when the
31041user hits ‘C-c <PF1>’ Emacs will fail to decode ‘C-c <ESC> O P’ into
31042‘C-c <PF1>’ because it will stop reading keys right after ‘C-x <ESC>’,
31043leaving ‘O P’ for later.  This is in case the user really hit ‘C-c
31044<ESC>’, in which case Emacs should not sit there waiting for the next
31045key to decide whether the user really pressed ‘<ESC>’ or ‘<PF1>’.
31046
31047   For that reason, it is better to avoid binding commands to key
31048sequences where the end of the key sequence is a prefix of a key
31049translation.  The main such problematic suffixes/prefixes are ‘<ESC>’,
31050‘M-O’ (which is really ‘<ESC> O’) and ‘M-[’ (which is really ‘<ESC> [’).
31051
31052
31053File: elisp.info,  Node: Key Binding Commands,  Next: Scanning Keymaps,  Prev: Translation Keymaps,  Up: Keymaps
31054
3105522.15 Commands for Binding Keys
31056===============================
31057
31058This section describes some convenient interactive interfaces for
31059changing key bindings.  They work by calling ‘define-key’.
31060
31061   People often use ‘global-set-key’ in their init files (*note Init
31062File::) for simple customization.  For example,
31063
31064     (global-set-key (kbd "C-x C-\\") 'next-line)
31065
31066or
31067
31068     (global-set-key [?\C-x ?\C-\\] 'next-line)
31069
31070or
31071
31072     (global-set-key [(control ?x) (control ?\\)] 'next-line)
31073
31074redefines ‘C-x C-\’ to move down a line.
31075
31076     (global-set-key [M-mouse-1] 'mouse-set-point)
31077
31078redefines the first (leftmost) mouse button, entered with the Meta key,
31079to set point where you click.
31080
31081   Be careful when using non-ASCII text characters in Lisp
31082specifications of keys to bind.  If these are read as multibyte text, as
31083they usually will be in a Lisp file (*note Loading Non-ASCII::), you
31084must type the keys as multibyte too.  For instance, if you use this:
31085
31086     (global-set-key "ö" 'my-function) ; bind o-umlaut
31087
31088or
31089
31090     (global-set-key ?ö 'my-function) ; bind o-umlaut
31091
31092and your language environment is multibyte Latin-1, these commands
31093actually bind the multibyte character with code 246, not the byte code
31094246 (‘M-v’) sent by a Latin-1 terminal.  In order to use this binding,
31095you need to teach Emacs how to decode the keyboard by using an
31096appropriate input method (*note Input Methods: (emacs)Input Methods.).
31097
31098 -- Command: global-set-key key binding
31099     This function sets the binding of KEY in the current global map to
31100     BINDING.
31101
31102          (global-set-key KEY BINDING)
3110331104          (define-key (current-global-map) KEY BINDING)
31105
31106 -- Command: global-unset-key key
31107     This function removes the binding of KEY from the current global
31108     map.
31109
31110     One use of this function is in preparation for defining a longer
31111     key that uses KEY as a prefix—which would not be allowed if KEY has
31112     a non-prefix binding.  For example:
31113
31114          (global-unset-key "\C-l")
31115              ⇒ nil
31116          (global-set-key "\C-l\C-l" 'redraw-display)
31117              ⇒ nil
31118
31119     This function is equivalent to using ‘define-key’ as follows:
31120
31121          (global-unset-key KEY)
3112231123          (define-key (current-global-map) KEY nil)
31124
31125 -- Command: local-set-key key binding
31126     This function sets the binding of KEY in the current local keymap
31127     to BINDING.
31128
31129          (local-set-key KEY BINDING)
3113031131          (define-key (current-local-map) KEY BINDING)
31132
31133 -- Command: local-unset-key key
31134     This function removes the binding of KEY from the current local
31135     map.
31136
31137          (local-unset-key KEY)
3113831139          (define-key (current-local-map) KEY nil)
31140
31141
31142File: elisp.info,  Node: Scanning Keymaps,  Next: Menu Keymaps,  Prev: Key Binding Commands,  Up: Keymaps
31143
3114422.16 Scanning Keymaps
31145======================
31146
31147This section describes functions used to scan all the current keymaps
31148for the sake of printing help information.
31149
31150 -- Function: accessible-keymaps keymap &optional prefix
31151     This function returns a list of all the keymaps that can be reached
31152     (via zero or more prefix keys) from KEYMAP.  The value is an
31153     association list with elements of the form ‘(KEY . MAP)’, where KEY
31154     is a prefix key whose definition in KEYMAP is MAP.
31155
31156     The elements of the alist are ordered so that the KEY increases in
31157     length.  The first element is always ‘([] . KEYMAP)’, because the
31158     specified keymap is accessible from itself with a prefix of no
31159     events.
31160
31161     If PREFIX is given, it should be a prefix key sequence; then
31162     ‘accessible-keymaps’ includes only the submaps whose prefixes start
31163     with PREFIX.  These elements look just as they do in the value of
31164     ‘(accessible-keymaps)’; the only difference is that some elements
31165     are omitted.
31166
31167     In the example below, the returned alist indicates that the key
31168     <ESC>, which is displayed as ‘^[’, is a prefix key whose definition
31169     is the sparse keymap ‘(keymap (83 . center-paragraph) (115 .
31170     foo))’.
31171
31172          (accessible-keymaps (current-local-map))
31173          ⇒(([] keymap
31174                (27 keymap   ; Note this keymap for <ESC> is repeated below.
31175                    (83 . center-paragraph)
31176                    (115 . center-line))
31177                (9 . tab-to-tab-stop))
31178
31179             ("^[" keymap
31180              (83 . center-paragraph)
31181              (115 . foo)))
31182
31183     In the following example, ‘C-h’ is a prefix key that uses a sparse
31184     keymap starting with ‘(keymap (118 . describe-variable)...)’.
31185     Another prefix, ‘C-x 4’, uses a keymap which is also the value of
31186     the variable ‘ctl-x-4-map’.  The event ‘mode-line’ is one of
31187     several dummy events used as prefixes for mouse actions in special
31188     parts of a window.
31189
31190          (accessible-keymaps (current-global-map))
31191          ⇒ (([] keymap [set-mark-command beginning-of-line ...
31192                             delete-backward-char])
31193              ("^H" keymap (118 . describe-variable) ...
31194               (8 . help-for-help))
31195              ("^X" keymap [x-flush-mouse-queue ...
31196               backward-kill-sentence])
31197              ("^[" keymap [mark-sexp backward-sexp ...
31198               backward-kill-word])
31199              ("^X4" keymap (15 . display-buffer) ...)
31200              ([mode-line] keymap
31201               (S-mouse-2 . mouse-split-window-horizontally) ...))
31202
31203     These are not all the keymaps you would see in actuality.
31204
31205 -- Function: map-keymap function keymap
31206     The function ‘map-keymap’ calls FUNCTION once for each binding in
31207     KEYMAP.  It passes two arguments, the event type and the value of
31208     the binding.  If KEYMAP has a parent, the parent’s bindings are
31209     included as well.  This works recursively: if the parent has itself
31210     a parent, then the grandparent’s bindings are also included and so
31211     on.
31212
31213     This function is the cleanest way to examine all the bindings in a
31214     keymap.
31215
31216 -- Function: where-is-internal command &optional keymap firstonly
31217          noindirect no-remap
31218     This function is a subroutine used by the ‘where-is’ command (*note
31219     Help: (emacs)Help.).  It returns a list of all key sequences (of
31220     any length) that are bound to COMMAND in a set of keymaps.
31221
31222     The argument COMMAND can be any object; it is compared with all
31223     keymap entries using ‘eq’.
31224
31225     If KEYMAP is ‘nil’, then the maps used are the current active
31226     keymaps, disregarding ‘overriding-local-map’ (that is, pretending
31227     its value is ‘nil’).  If KEYMAP is a keymap, then the maps searched
31228     are KEYMAP and the global keymap.  If KEYMAP is a list of keymaps,
31229     only those keymaps are searched.
31230
31231     Usually it’s best to use ‘overriding-local-map’ as the expression
31232     for KEYMAP.  Then ‘where-is-internal’ searches precisely the
31233     keymaps that are active.  To search only the global map, pass the
31234     value ‘(keymap)’ (an empty keymap) as KEYMAP.
31235
31236     If FIRSTONLY is ‘non-ascii’, then the value is a single vector
31237     representing the first key sequence found, rather than a list of
31238     all possible key sequences.  If FIRSTONLY is ‘t’, then the value is
31239     the first key sequence, except that key sequences consisting
31240     entirely of ASCII characters (or meta variants of ASCII characters)
31241     are preferred to all other key sequences and that the return value
31242     can never be a menu binding.
31243
31244     If NOINDIRECT is non-‘nil’, ‘where-is-internal’ doesn’t look inside
31245     menu-items to find their commands.  This makes it possible to
31246     search for a menu-item itself.
31247
31248     The fifth argument, NO-REMAP, determines how this function treats
31249     command remappings (*note Remapping Commands::).  There are two
31250     cases of interest:
31251
31252     If a command OTHER-COMMAND is remapped to COMMAND:
31253          If NO-REMAP is ‘nil’, find the bindings for OTHER-COMMAND and
31254          treat them as though they are also bindings for COMMAND.  If
31255          NO-REMAP is non-‘nil’, include the vector ‘[remap
31256          OTHER-COMMAND]’ in the list of possible key sequences, instead
31257          of finding those bindings.
31258
31259     If COMMAND is remapped to OTHER-COMMAND:
31260          If NO-REMAP is ‘nil’, return the bindings for OTHER-COMMAND
31261          rather than COMMAND.  If NO-REMAP is non-‘nil’, return the
31262          bindings for COMMAND, ignoring the fact that it is remapped.
31263
31264 -- Command: describe-bindings &optional prefix buffer-or-name
31265     This function creates a listing of all current key bindings, and
31266     displays it in a buffer named ‘*Help*’.  The text is grouped by
31267     modes—minor modes first, then the major mode, then global bindings.
31268
31269     If PREFIX is non-‘nil’, it should be a prefix key; then the listing
31270     includes only keys that start with PREFIX.
31271
31272     When several characters with consecutive ASCII codes have the same
31273     definition, they are shown together, as ‘FIRSTCHAR..LASTCHAR’.  In
31274     this instance, you need to know the ASCII codes to understand which
31275     characters this means.  For example, in the default global map, the
31276     characters ‘<SPC> .. ~’ are described by a single line.  <SPC> is
31277     ASCII 32, ‘~’ is ASCII 126, and the characters between them include
31278     all the normal printing characters, (e.g., letters, digits,
31279     punctuation, etc.); all these characters are bound to
31280     ‘self-insert-command’.
31281
31282     If BUFFER-OR-NAME is non-‘nil’, it should be a buffer or a buffer
31283     name.  Then ‘describe-bindings’ lists that buffer’s bindings,
31284     instead of the current buffer’s.
31285
31286
31287File: elisp.info,  Node: Menu Keymaps,  Prev: Scanning Keymaps,  Up: Keymaps
31288
3128922.17 Menu Keymaps
31290==================
31291
31292A keymap can operate as a menu as well as defining bindings for keyboard
31293keys and mouse buttons.  Menus are usually actuated with the mouse, but
31294they can function with the keyboard also.  If a menu keymap is active
31295for the next input event, that activates the keyboard menu feature.
31296
31297* Menu:
31298
31299* Defining Menus::     How to make a keymap that defines a menu.
31300* Mouse Menus::        How users actuate the menu with the mouse.
31301* Keyboard Menus::     How users actuate the menu with the keyboard.
31302* Menu Example::       Making a simple menu.
31303* Menu Bar::           How to customize the menu bar.
31304* Tool Bar::           A tool bar is a row of images.
31305* Modifying Menus::    How to add new items to a menu.
31306* Easy Menu::      A convenience macro for making menus.
31307
31308
31309File: elisp.info,  Node: Defining Menus,  Next: Mouse Menus,  Up: Menu Keymaps
31310
3131122.17.1 Defining Menus
31312----------------------
31313
31314A keymap acts as a menu if it has an “overall prompt string”, which is a
31315string that appears as an element of the keymap.  (*Note Format of
31316Keymaps::.)  The string should describe the purpose of the menu’s
31317commands.  Emacs displays the overall prompt string as the menu title in
31318some cases, depending on the toolkit (if any) used for displaying
31319menus.(1)  Keyboard menus also display the overall prompt string.
31320
31321   The easiest way to construct a keymap with a prompt string is to
31322specify the string as an argument when you call ‘make-keymap’,
31323‘make-sparse-keymap’ (*note Creating Keymaps::), or
31324‘define-prefix-command’ (*note Definition of define-prefix-command::).
31325If you do not want the keymap to operate as a menu, don’t specify a
31326prompt string for it.
31327
31328 -- Function: keymap-prompt keymap
31329     This function returns the overall prompt string of KEYMAP, or ‘nil’
31330     if it has none.
31331
31332   The menu’s items are the bindings in the keymap.  Each binding
31333associates an event type to a definition, but the event types have no
31334significance for the menu appearance.  (Usually we use pseudo-events,
31335symbols that the keyboard cannot generate, as the event types for menu
31336item bindings.)  The menu is generated entirely from the bindings that
31337correspond in the keymap to these events.
31338
31339   The order of items in the menu is the same as the order of bindings
31340in the keymap.  Since ‘define-key’ puts new bindings at the front, you
31341should define the menu items starting at the bottom of the menu and
31342moving to the top, if you care about the order.  When you add an item to
31343an existing menu, you can specify its position in the menu using
31344‘define-key-after’ (*note Modifying Menus::).
31345
31346* Menu:
31347
31348* Simple Menu Items::       A simple kind of menu key binding.
31349* Extended Menu Items::     More complex menu item definitions.
31350* Menu Separators::         Drawing a horizontal line through a menu.
31351* Alias Menu Items::        Using command aliases in menu items.
31352
31353   ---------- Footnotes ----------
31354
31355   (1) It is required for menus which do not use a toolkit, e.g., on a
31356text terminal.
31357
31358
31359File: elisp.info,  Node: Simple Menu Items,  Next: Extended Menu Items,  Up: Defining Menus
31360
3136122.17.1.1 Simple Menu Items
31362...........................
31363
31364The simpler (and original) way to define a menu item is to bind some
31365event type (it doesn’t matter what event type) to a binding like this:
31366
31367     (ITEM-STRING . REAL-BINDING)
31368
31369The CAR, ITEM-STRING, is the string to be displayed in the menu.  It
31370should be short—preferably one to three words.  It should describe the
31371action of the command it corresponds to.  Note that not all graphical
31372toolkits can display non-ASCII text in menus (it will work for keyboard
31373menus and will work to a large extent with the GTK+ toolkit).
31374
31375   You can also supply a second string, called the help string, as
31376follows:
31377
31378     (ITEM-STRING HELP . REAL-BINDING)
31379
31380HELP specifies a help-echo string to display while the mouse is on that
31381item in the same way as ‘help-echo’ text properties (*note Help
31382display::).
31383
31384   As far as ‘define-key’ is concerned, ITEM-STRING and HELP-STRING are
31385part of the event’s binding.  However, ‘lookup-key’ returns just
31386REAL-BINDING, and only REAL-BINDING is used for executing the key.
31387
31388   If REAL-BINDING is ‘nil’, then ITEM-STRING appears in the menu but
31389cannot be selected.
31390
31391   If REAL-BINDING is a symbol and has a non-‘nil’ ‘menu-enable’
31392property, that property is an expression that controls whether the menu
31393item is enabled.  Every time the keymap is used to display a menu, Emacs
31394evaluates the expression, and it enables the menu item only if the
31395expression’s value is non-‘nil’.  When a menu item is disabled, it is
31396displayed in a fuzzy fashion, and cannot be selected.
31397
31398   The menu bar does not recalculate which items are enabled every time
31399you look at a menu.  This is because the X toolkit requires the whole
31400tree of menus in advance.  To force recalculation of the menu bar, call
31401‘force-mode-line-update’ (*note Mode Line Format::).
31402
31403
31404File: elisp.info,  Node: Extended Menu Items,  Next: Menu Separators,  Prev: Simple Menu Items,  Up: Defining Menus
31405
3140622.17.1.2 Extended Menu Items
31407.............................
31408
31409An extended-format menu item is a more flexible and also cleaner
31410alternative to the simple format.  You define an event type with a
31411binding that’s a list starting with the symbol ‘menu-item’.  For a
31412non-selectable string, the binding looks like this:
31413
31414     (menu-item ITEM-NAME)
31415
31416A string starting with two or more dashes specifies a separator line;
31417see *note Menu Separators::.
31418
31419   To define a real menu item which can be selected, the extended format
31420binding looks like this:
31421
31422     (menu-item ITEM-NAME REAL-BINDING
31423         . ITEM-PROPERTY-LIST)
31424
31425Here, ITEM-NAME is an expression which evaluates to the menu item
31426string.  Thus, the string need not be a constant.
31427
31428   The third element, REAL-BINDING, can be the command to execute (in
31429which case you get a normal menu item).  It can also be a keymap, which
31430will result in a submenu.  Finally, it can be ‘nil’, in which case you
31431will get a non-selectable menu item.  This is mostly useful when
31432creating separator lines and the like.
31433
31434   The tail of the list, ITEM-PROPERTY-LIST, has the form of a property
31435list which contains other information.
31436
31437   Here is a table of the properties that are supported:
31438
31439‘:enable FORM’
31440     The result of evaluating FORM determines whether the item is
31441     enabled (non-‘nil’ means yes).  If the item is not enabled, you
31442     can’t really click on it.
31443
31444‘:visible FORM’
31445     The result of evaluating FORM determines whether the item should
31446     actually appear in the menu (non-‘nil’ means yes).  If the item
31447     does not appear, then the menu is displayed as if this item were
31448     not defined at all.
31449
31450‘:help HELP’
31451     The value of this property, HELP, specifies a help-echo string to
31452     display while the mouse is on that item.  This is displayed in the
31453     same way as ‘help-echo’ text properties (*note Help display::).
31454     Note that this must be a constant string, unlike the ‘help-echo’
31455     property for text and overlays.
31456
31457‘:button (TYPE . SELECTED)’
31458     This property provides a way to define radio buttons and toggle
31459     buttons.  The CAR, TYPE, says which: it should be ‘:toggle’ or
31460     ‘:radio’.  The CDR, SELECTED, should be a form; the result of
31461     evaluating it says whether this button is currently selected.
31462
31463     A “toggle” is a menu item which is labeled as either on or off
31464     according to the value of SELECTED.  The command itself should
31465     toggle SELECTED, setting it to ‘t’ if it is ‘nil’, and to ‘nil’ if
31466     it is ‘t’.  Here is how the menu item to toggle the
31467     ‘debug-on-error’ flag is defined:
31468
31469          (menu-item "Debug on Error" toggle-debug-on-error
31470                     :button (:toggle
31471                              . (and (boundp 'debug-on-error)
31472                                     debug-on-error)))
31473
31474     This works because ‘toggle-debug-on-error’ is defined as a command
31475     which toggles the variable ‘debug-on-error’.
31476
31477     “Radio buttons” are a group of menu items, in which at any time one
31478     and only one is selected.  There should be a variable whose value
31479     says which one is selected at any time.  The SELECTED form for each
31480     radio button in the group should check whether the variable has the
31481     right value for selecting that button.  Clicking on the button
31482     should set the variable so that the button you clicked on becomes
31483     selected.
31484
31485‘:key-sequence KEY-SEQUENCE’
31486     This property specifies which key sequence to display as keyboard
31487     equivalent.  Before Emacs displays KEY-SEQUENCE in the menu, it
31488     verifies that KEY-SEQUENCE is really equivalent to this menu item,
31489     so it only has an effect if you specify a correct key sequence.
31490     Specifying ‘nil’ for KEY-SEQUENCE is equivalent to the
31491     ‘:key-sequence’ attribute being absent.
31492
31493‘:keys STRING’
31494     This property specifies that STRING is the string to display as the
31495     keyboard equivalent for this menu item.  You can use the ‘\\[...]’
31496     documentation construct in STRING.
31497
31498‘:filter FILTER-FN’
31499     This property provides a way to compute the menu item dynamically.
31500     The property value FILTER-FN should be a function of one argument;
31501     when it is called, its argument will be REAL-BINDING.  The function
31502     should return the binding to use instead.
31503
31504     Emacs can call this function at any time that it does redisplay or
31505     operates on menu data structures, so you should write it so it can
31506     safely be called at any time.
31507
31508
31509File: elisp.info,  Node: Menu Separators,  Next: Alias Menu Items,  Prev: Extended Menu Items,  Up: Defining Menus
31510
3151122.17.1.3 Menu Separators
31512.........................
31513
31514A menu separator is a kind of menu item that doesn’t display any
31515text—instead, it divides the menu into subparts with a horizontal line.
31516A separator looks like this in the menu keymap:
31517
31518     (menu-item SEPARATOR-TYPE)
31519
31520where SEPARATOR-TYPE is a string starting with two or more dashes.
31521
31522   In the simplest case, SEPARATOR-TYPE consists of only dashes.  That
31523specifies the default kind of separator.  (For compatibility, ‘""’ and
31524‘-’ also count as separators.)
31525
31526   Certain other values of SEPARATOR-TYPE specify a different style of
31527separator.  Here is a table of them:
31528
31529‘"--no-line"’
31530‘"--space"’
31531     An extra vertical space, with no actual line.
31532
31533‘"--single-line"’
31534     A single line in the menu’s foreground color.
31535
31536‘"--double-line"’
31537     A double line in the menu’s foreground color.
31538
31539‘"--single-dashed-line"’
31540     A single dashed line in the menu’s foreground color.
31541
31542‘"--double-dashed-line"’
31543     A double dashed line in the menu’s foreground color.
31544
31545‘"--shadow-etched-in"’
31546     A single line with a 3D sunken appearance.  This is the default,
31547     used separators consisting of dashes only.
31548
31549‘"--shadow-etched-out"’
31550     A single line with a 3D raised appearance.
31551
31552‘"--shadow-etched-in-dash"’
31553     A single dashed line with a 3D sunken appearance.
31554
31555‘"--shadow-etched-out-dash"’
31556     A single dashed line with a 3D raised appearance.
31557
31558‘"--shadow-double-etched-in"’
31559     Two lines with a 3D sunken appearance.
31560
31561‘"--shadow-double-etched-out"’
31562     Two lines with a 3D raised appearance.
31563
31564‘"--shadow-double-etched-in-dash"’
31565     Two dashed lines with a 3D sunken appearance.
31566
31567‘"--shadow-double-etched-out-dash"’
31568     Two dashed lines with a 3D raised appearance.
31569
31570   You can also give these names in another style, adding a colon after
31571the double-dash and replacing each single dash with capitalization of
31572the following word.  Thus, ‘"--:singleLine"’, is equivalent to
31573‘"--single-line"’.
31574
31575   You can use a longer form to specify keywords such as ‘:enable’ and
31576‘:visible’ for a menu separator:
31577
31578   ‘(menu-item SEPARATOR-TYPE nil . ITEM-PROPERTY-LIST)’
31579
31580   For example:
31581
31582     (menu-item "--" nil :visible (boundp 'foo))
31583
31584   Some systems and display toolkits don’t really handle all of these
31585separator types.  If you use a type that isn’t supported, the menu
31586displays a similar kind of separator that is supported.
31587
31588
31589File: elisp.info,  Node: Alias Menu Items,  Prev: Menu Separators,  Up: Defining Menus
31590
3159122.17.1.4 Alias Menu Items
31592..........................
31593
31594Sometimes it is useful to make menu items that use the same command but
31595with different enable conditions.  The best way to do this in Emacs now
31596is with extended menu items; before that feature existed, it could be
31597done by defining alias commands and using them in menu items.  Here’s an
31598example that makes two aliases for ‘read-only-mode’ and gives them
31599different enable conditions:
31600
31601     (defalias 'make-read-only 'read-only-mode)
31602     (put 'make-read-only 'menu-enable '(not buffer-read-only))
31603     (defalias 'make-writable 'read-only-mode)
31604     (put 'make-writable 'menu-enable 'buffer-read-only)
31605
31606   When using aliases in menus, often it is useful to display the
31607equivalent key bindings for the real command name, not the aliases
31608(which typically don’t have any key bindings except for the menu
31609itself).  To request this, give the alias symbol a non-‘nil’
31610‘menu-alias’ property.  Thus,
31611
31612     (put 'make-read-only 'menu-alias t)
31613     (put 'make-writable 'menu-alias t)
31614
31615causes menu items for ‘make-read-only’ and ‘make-writable’ to show the
31616keyboard bindings for ‘read-only-mode’.
31617
31618
31619File: elisp.info,  Node: Mouse Menus,  Next: Keyboard Menus,  Prev: Defining Menus,  Up: Menu Keymaps
31620
3162122.17.2 Menus and the Mouse
31622---------------------------
31623
31624The usual way to make a menu keymap produce a menu is to make it the
31625definition of a prefix key.  (A Lisp program can explicitly pop up a
31626menu and receive the user’s choice—see *note Pop-Up Menus::.)
31627
31628   If the prefix key ends with a mouse event, Emacs handles the menu
31629keymap by popping up a visible menu, so that the user can select a
31630choice with the mouse.  When the user clicks on a menu item, the event
31631generated is whatever character or symbol has the binding that brought
31632about that menu item.  (A menu item may generate a series of events if
31633the menu has multiple levels or comes from the menu bar.)
31634
31635   It’s often best to use a button-down event to trigger the menu.  Then
31636the user can select a menu item by releasing the button.
31637
31638   If the menu keymap contains a binding to a nested keymap, the nested
31639keymap specifies a “submenu”.  There will be a menu item, labeled by the
31640nested keymap’s item string, and clicking on this item automatically
31641pops up the specified submenu.  As a special exception, if the menu
31642keymap contains a single nested keymap and no other menu items, the menu
31643shows the contents of the nested keymap directly, not as a submenu.
31644
31645   However, if Emacs is compiled without X toolkit support, or on text
31646terminals, submenus are not supported.  Each nested keymap is shown as a
31647menu item, but clicking on it does not automatically pop up the submenu.
31648If you wish to imitate the effect of submenus, you can do that by giving
31649a nested keymap an item string which starts with ‘@’.  This causes Emacs
31650to display the nested keymap using a separate “menu pane”; the rest of
31651the item string after the ‘@’ is the pane label.  If Emacs is compiled
31652without X toolkit support, or if a menu is displayed on a text terminal,
31653menu panes are not used; in that case, a ‘@’ at the beginning of an item
31654string is omitted when the menu label is displayed, and has no other
31655effect.
31656
31657
31658File: elisp.info,  Node: Keyboard Menus,  Next: Menu Example,  Prev: Mouse Menus,  Up: Menu Keymaps
31659
3166022.17.3 Menus and the Keyboard
31661------------------------------
31662
31663When a prefix key ending with a keyboard event (a character or function
31664key) has a definition that is a menu keymap, the keymap operates as a
31665keyboard menu; the user specifies the next event by choosing a menu item
31666with the keyboard.
31667
31668   Emacs displays the keyboard menu with the map’s overall prompt
31669string, followed by the alternatives (the item strings of the map’s
31670bindings), in the echo area.  If the bindings don’t all fit at once, the
31671user can type <SPC> to see the next line of alternatives.  Successive
31672uses of <SPC> eventually get to the end of the menu and then cycle
31673around to the beginning.  (The variable ‘menu-prompt-more-char’
31674specifies which character is used for this; <SPC> is the default.)
31675
31676   When the user has found the desired alternative from the menu, he or
31677she should type the corresponding character—the one whose binding is
31678that alternative.
31679
31680 -- Variable: menu-prompt-more-char
31681     This variable specifies the character to use to ask to see the next
31682     line of a menu.  Its initial value is 32, the code for <SPC>.
31683
31684
31685File: elisp.info,  Node: Menu Example,  Next: Menu Bar,  Prev: Keyboard Menus,  Up: Menu Keymaps
31686
3168722.17.4 Menu Example
31688--------------------
31689
31690Here is a complete example of defining a menu keymap.  It is the
31691definition of the ‘Replace’ submenu in the ‘Edit’ menu in the menu bar,
31692and it uses the extended menu item format (*note Extended Menu Items::).
31693First we create the keymap, and give it a name:
31694
31695     (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
31696
31697Next we define the menu items:
31698
31699     (define-key menu-bar-replace-menu [tags-repl-continue]
31700       '(menu-item "Continue Replace" multifile-continue
31701                   :help "Continue last tags replace operation"))
31702     (define-key menu-bar-replace-menu [tags-repl]
31703       '(menu-item "Replace in tagged files" tags-query-replace
31704                   :help "Interactively replace a regexp in all tagged files"))
31705     (define-key menu-bar-replace-menu [separator-replace-tags]
31706       '(menu-item "--"))
31707     ;; ...
31708
31709Note the symbols which the bindings are made for; these appear inside
31710square brackets, in the key sequence being defined.  In some cases, this
31711symbol is the same as the command name; sometimes it is different.
31712These symbols are treated as function keys, but they are not real
31713function keys on the keyboard.  They do not affect the functioning of
31714the menu itself, but they are echoed in the echo area when the user
31715selects from the menu, and they appear in the output of ‘where-is’ and
31716‘apropos’.
31717
31718   The menu in this example is intended for use with the mouse.  If a
31719menu is intended for use with the keyboard, that is, if it is bound to a
31720key sequence ending with a keyboard event, then the menu items should be
31721bound to characters or real function keys, that can be typed with the
31722keyboard.
31723
31724   The binding whose definition is ‘("--")’ is a separator line.  Like a
31725real menu item, the separator has a key symbol, in this case
31726‘separator-replace-tags’.  If one menu has two separators, they must
31727have two different key symbols.
31728
31729   Here is how we make this menu appear as an item in the parent menu:
31730
31731     (define-key menu-bar-edit-menu [replace]
31732       (list 'menu-item "Replace" menu-bar-replace-menu))
31733
31734Note that this incorporates the submenu keymap, which is the value of
31735the variable ‘menu-bar-replace-menu’, rather than the symbol
31736‘menu-bar-replace-menu’ itself.  Using that symbol in the parent menu
31737item would be meaningless because ‘menu-bar-replace-menu’ is not a
31738command.
31739
31740   If you wanted to attach the same replace menu to a mouse click, you
31741can do it this way:
31742
31743     (define-key global-map [C-S-down-mouse-1]
31744        menu-bar-replace-menu)
31745
31746
31747File: elisp.info,  Node: Menu Bar,  Next: Tool Bar,  Prev: Menu Example,  Up: Menu Keymaps
31748
3174922.17.5 The Menu Bar
31750--------------------
31751
31752Emacs usually shows a “menu bar” at the top of each frame.  *Note
31753(emacs)Menu Bars::.  Menu bar items are subcommands of the fake function
31754key <MENU-BAR>, as defined in the active keymaps.
31755
31756   To add an item to the menu bar, invent a fake function key of your
31757own (let’s call it KEY), and make a binding for the key sequence
31758‘[menu-bar KEY]’.  Most often, the binding is a menu keymap, so that
31759pressing a button on the menu bar item leads to another menu.
31760
31761   When more than one active keymap defines the same function key for
31762the menu bar, the item appears just once.  If the user clicks on that
31763menu bar item, it brings up a single, combined menu containing all the
31764subcommands of that item—the global subcommands, the local subcommands,
31765and the minor mode subcommands.
31766
31767   The variable ‘overriding-local-map’ is normally ignored when
31768determining the menu bar contents.  That is, the menu bar is computed
31769from the keymaps that would be active if ‘overriding-local-map’ were
31770‘nil’.  *Note Active Keymaps::.
31771
31772   Here’s an example of setting up a menu bar item:
31773
31774     ;; Make a menu keymap (with a prompt string)
31775     ;; and make it the menu bar item’s definition.
31776     (define-key global-map [menu-bar words]
31777       (cons "Words" (make-sparse-keymap "Words")))
31778
31779     ;; Define specific subcommands in this menu.
31780     (define-key global-map
31781       [menu-bar words forward]
31782       '("Forward word" . forward-word))
31783     (define-key global-map
31784       [menu-bar words backward]
31785       '("Backward word" . backward-word))
31786
31787   A local keymap can cancel a menu bar item made by the global keymap
31788by rebinding the same fake function key with ‘undefined’ as the binding.
31789For example, this is how Dired suppresses the ‘Edit’ menu bar item:
31790
31791     (define-key dired-mode-map [menu-bar edit] 'undefined)
31792
31793Here, ‘edit’ is the symbol produced by a fake function key, it is used
31794by the global map for the ‘Edit’ menu bar item.  The main reason to
31795suppress a global menu bar item is to regain space for mode-specific
31796items.
31797
31798 -- Variable: menu-bar-final-items
31799     Normally the menu bar shows global items followed by items defined
31800     by the local maps.
31801
31802     This variable holds a list of fake function keys for items to
31803     display at the end of the menu bar rather than in normal sequence.
31804     The default value is ‘(help-menu)’; thus, the ‘Help’ menu item
31805     normally appears at the end of the menu bar, following local menu
31806     items.
31807
31808 -- Variable: menu-bar-update-hook
31809     This normal hook is run by redisplay to update the menu bar
31810     contents, before redisplaying the menu bar.  You can use it to
31811     update menus whose contents should vary.  Since this hook is run
31812     frequently, we advise you to ensure that the functions it calls do
31813     not take much time in the usual case.
31814
31815   Next to every menu bar item, Emacs displays a key binding that runs
31816the same command (if such a key binding exists).  This serves as a
31817convenient hint for users who do not know the key binding.  If a command
31818has multiple bindings, Emacs normally displays the first one it finds.
31819You can specify one particular key binding by assigning an
31820‘:advertised-binding’ symbol property to the command.  *Note Keys in
31821Documentation::.
31822
31823
31824File: elisp.info,  Node: Tool Bar,  Next: Modifying Menus,  Prev: Menu Bar,  Up: Menu Keymaps
31825
3182622.17.6 Tool bars
31827-----------------
31828
31829A “tool bar” is a row of clickable icons at the top of a frame, just
31830below the menu bar.  *Note (emacs)Tool Bars::.  Emacs normally shows a
31831tool bar on graphical displays.
31832
31833   On each frame, the frame parameter ‘tool-bar-lines’ controls how many
31834lines’ worth of height to reserve for the tool bar.  A zero value
31835suppresses the tool bar.  If the value is nonzero, and
31836‘auto-resize-tool-bars’ is non-‘nil’, the tool bar expands and contracts
31837automatically as needed to hold the specified contents.  If the value is
31838‘grow-only’, the tool bar expands automatically, but does not contract
31839automatically.
31840
31841   The tool bar contents are controlled by a menu keymap attached to a
31842fake function key called <TOOL-BAR> (much like the way the menu bar is
31843controlled).  So you define a tool bar item using ‘define-key’, like
31844this:
31845
31846     (define-key global-map [tool-bar KEY] ITEM)
31847
31848where KEY is a fake function key to distinguish this item from other
31849items, and ITEM is a menu item key binding (*note Extended Menu
31850Items::), which says how to display this item and how it behaves.
31851
31852   The usual menu keymap item properties, ‘:visible’, ‘:enable’,
31853‘:button’, and ‘:filter’, are useful in tool bar bindings and have their
31854normal meanings.  The REAL-BINDING in the item must be a command, not a
31855keymap; in other words, it does not work to define a tool bar icon as a
31856prefix key.
31857
31858   The ‘:help’ property specifies a help-echo string to display while
31859the mouse is on that item.  This is displayed in the same way as
31860‘help-echo’ text properties (*note Help display::).
31861
31862   In addition, you should use the ‘:image’ property; this is how you
31863specify the image to display in the tool bar:
31864
31865‘:image IMAGE’
31866     IMAGE is either a single image specification (*note Images::) or a
31867     vector of four image specifications.  If you use a vector of four,
31868     one of them is used, depending on circumstances:
31869
31870     item 0
31871          Used when the item is enabled and selected.
31872     item 1
31873          Used when the item is enabled and deselected.
31874     item 2
31875          Used when the item is disabled and selected.
31876     item 3
31877          Used when the item is disabled and deselected.
31878
31879   The GTK+ and NS versions of Emacs ignores items 1 to 3, because
31880disabled and/or deselected images are autocomputed from item 0.
31881
31882   If IMAGE is a single image specification, Emacs draws the tool bar
31883button in disabled state by applying an edge-detection algorithm to the
31884image.
31885
31886   The ‘:rtl’ property specifies an alternative image to use for
31887right-to-left languages.  Only the GTK+ version of Emacs supports this
31888at present.
31889
31890   Like the menu bar, the tool bar can display separators (*note Menu
31891Separators::).  Tool bar separators are vertical rather than horizontal,
31892though, and only a single style is supported.  They are represented in
31893the tool bar keymap by ‘(menu-item "--")’ entries; properties like
31894‘:visible’ are not supported for tool bar separators.  Separators are
31895rendered natively in GTK+ and Nextstep tool bars; in the other cases,
31896they are rendered using an image of a vertical line.
31897
31898   The default tool bar is defined so that items specific to editing do
31899not appear for major modes whose command symbol has a ‘mode-class’
31900property of ‘special’ (*note Major Mode Conventions::).  Major modes may
31901add items to the global bar by binding ‘[tool-bar FOO]’ in their local
31902map.  It makes sense for some major modes to replace the default tool
31903bar items completely, since not many can be accommodated conveniently,
31904and the default bindings make this easy by using an indirection through
31905‘tool-bar-map’.
31906
31907 -- Variable: tool-bar-map
31908     By default, the global map binds ‘[tool-bar]’ as follows:
31909
31910          (global-set-key [tool-bar]
31911                          `(menu-item ,(purecopy "tool bar") ignore
31912                                      :filter tool-bar-make-keymap))
31913
31914     The function ‘tool-bar-make-keymap’, in turn, derives the actual
31915     tool bar map dynamically from the value of the variable
31916     ‘tool-bar-map’.  Hence, you should normally adjust the default
31917     (global) tool bar by changing that map.  Some major modes, such as
31918     Info mode, completely replace the global tool bar by making
31919     ‘tool-bar-map’ buffer-local and setting it to a different keymap.
31920
31921   There are two convenience functions for defining tool bar items, as
31922follows.
31923
31924 -- Function: tool-bar-add-item icon def key &rest props
31925     This function adds an item to the tool bar by modifying
31926     ‘tool-bar-map’.  The image to use is defined by ICON, which is the
31927     base name of an XPM, XBM or PBM image file to be located by
31928     ‘find-image’.  Given a value ‘"exit"’, say, ‘exit.xpm’, ‘exit.pbm31929     and ‘exit.xbm’ would be searched for in that order on a color
31930     display.  On a monochrome display, the search order is ‘.pbm’,
31931     ‘.xbm’ and ‘.xpm’.  The binding to use is the command DEF, and KEY
31932     is the fake function key symbol in the prefix keymap.  The
31933     remaining arguments PROPS are additional property list elements to
31934     add to the menu item specification.
31935
31936     To define items in some local map, bind ‘tool-bar-map’ with ‘let’
31937     around calls of this function:
31938          (defvar foo-tool-bar-map
31939            (let ((tool-bar-map (make-sparse-keymap)))
31940              (tool-bar-add-item ...)
31941              ...
31942              tool-bar-map))
31943
31944 -- Function: tool-bar-add-item-from-menu command icon &optional map
31945          &rest props
31946     This function is a convenience for defining tool bar items which
31947     are consistent with existing menu bar bindings.  The binding of
31948     COMMAND is looked up in the menu bar in MAP (default ‘global-map’)
31949     and modified to add an image specification for ICON, which is found
31950     in the same way as by ‘tool-bar-add-item’.  The resulting binding
31951     is then placed in ‘tool-bar-map’, so use this function only for
31952     global tool bar items.
31953
31954     MAP must contain an appropriate keymap bound to ‘[menu-bar]’.  The
31955     remaining arguments PROPS are additional property list elements to
31956     add to the menu item specification.
31957
31958 -- Function: tool-bar-local-item-from-menu command icon in-map
31959          &optional from-map &rest props
31960     This function is used for making non-global tool bar items.  Use it
31961     like ‘tool-bar-add-item-from-menu’ except that IN-MAP specifies the
31962     local map to make the definition in.  The argument FROM-MAP is like
31963     the MAP argument of ‘tool-bar-add-item-from-menu’.
31964
31965 -- Variable: auto-resize-tool-bars
31966     If this variable is non-‘nil’, the tool bar automatically resizes
31967     to show all defined tool bar items—but not larger than a quarter of
31968     the frame’s height.
31969
31970     If the value is ‘grow-only’, the tool bar expands automatically,
31971     but does not contract automatically.  To contract the tool bar, the
31972     user has to redraw the frame by entering ‘C-l’.
31973
31974     If Emacs is built with GTK+ or Nextstep, the tool bar can only show
31975     one line, so this variable has no effect.
31976
31977 -- Variable: auto-raise-tool-bar-buttons
31978     If this variable is non-‘nil’, tool bar items display in raised
31979     form when the mouse moves over them.
31980
31981 -- Variable: tool-bar-button-margin
31982     This variable specifies an extra margin to add around tool bar
31983     items.  The value is an integer, a number of pixels.  The default
31984     is 4.
31985
31986 -- Variable: tool-bar-button-relief
31987     This variable specifies the shadow width for tool bar items.  The
31988     value is an integer, a number of pixels.  The default is 1.
31989
31990 -- Variable: tool-bar-border
31991     This variable specifies the height of the border drawn below the
31992     tool bar area.  An integer specifies height as a number of pixels.
31993     If the value is one of ‘internal-border-width’ (the default) or
31994     ‘border-width’, the tool bar border height corresponds to the
31995     corresponding frame parameter.
31996
31997   You can define a special meaning for clicking on a tool bar item with
31998the shift, control, meta, etc., modifiers.  You do this by setting up
31999additional items that relate to the original item through the fake
32000function keys.  Specifically, the additional items should use the
32001modified versions of the same fake function key used to name the
32002original item.
32003
32004   Thus, if the original item was defined this way,
32005
32006     (define-key global-map [tool-bar shell]
32007       '(menu-item "Shell" shell
32008                   :image (image :type xpm :file "shell.xpm")))
32009
32010then here is how you can define clicking on the same tool bar image with
32011the shift modifier:
32012
32013     (define-key global-map [tool-bar S-shell] 'some-command)
32014
32015   *Note Function Keys::, for more information about how to add
32016modifiers to function keys.
32017
32018
32019File: elisp.info,  Node: Modifying Menus,  Next: Easy Menu,  Prev: Tool Bar,  Up: Menu Keymaps
32020
3202122.17.7 Modifying Menus
32022-----------------------
32023
32024When you insert a new item in an existing menu, you probably want to put
32025it in a particular place among the menu’s existing items.  If you use
32026‘define-key’ to add the item, it normally goes at the front of the menu.
32027To put it elsewhere in the menu, use ‘define-key-after’:
32028
32029 -- Function: define-key-after map key binding &optional after
32030     Define a binding in MAP for KEY, with value BINDING, just like
32031     ‘define-key’, but position the binding in MAP after the binding for
32032     the event AFTER.  The argument KEY should be of length one—a vector
32033     or string with just one element.  But AFTER should be a single
32034     event type—a symbol or a character, not a sequence.  The new
32035     binding goes after the binding for AFTER.  If AFTER is ‘t’ or is
32036     omitted, then the new binding goes last, at the end of the keymap.
32037     However, new bindings are added before any inherited keymap.
32038
32039     Here is an example:
32040
32041          (define-key-after my-menu [drink]
32042            '("Drink" . drink-command) 'eat)
32043
32044     makes a binding for the fake function key <DRINK> and puts it right
32045     after the binding for <EAT>.
32046
32047     Here is how to insert an item called ‘Work’ in the ‘Signals’ menu
32048     of Shell mode, after the item ‘break’:
32049
32050          (define-key-after
32051            (lookup-key shell-mode-map [menu-bar signals])
32052            [work] '("Work" . work-command) 'break)
32053
32054
32055File: elisp.info,  Node: Easy Menu,  Prev: Modifying Menus,  Up: Menu Keymaps
32056
3205722.17.8 Easy Menu
32058-----------------
32059
32060The following macro provides a convenient way to define pop-up menus
32061and/or menu bar menus.
32062
32063 -- Macro: easy-menu-define symbol maps doc menu
32064     This macro defines a pop-up menu and/or menu bar submenu, whose
32065     contents are given by MENU.
32066
32067     If SYMBOL is non-‘nil’, it should be a symbol; then this macro
32068     defines SYMBOL as a function for popping up the menu (*note Pop-Up
32069     Menus::), with DOC as its documentation string.  SYMBOL should not
32070     be quoted.
32071
32072     Regardless of the value of SYMBOL, if MAPS is a keymap, the menu is
32073     added to that keymap, as a top-level menu for the menu bar (*note
32074     Menu Bar::).  It can also be a list of keymaps, in which case the
32075     menu is added separately to each of those keymaps.
32076
32077     The first element of MENU must be a string, which serves as the
32078     menu label.  It may be followed by any number of the following
32079     keyword-argument pairs:
32080
32081     ‘:filter FUNCTION’
32082          FUNCTION must be a function which, if called with one
32083          argument—the list of the other menu items—returns the actual
32084          items to be displayed in the menu.
32085
32086     ‘:visible INCLUDE’
32087          INCLUDE is an expression; if it evaluates to ‘nil’, the menu
32088          is made invisible.  ‘:included’ is an alias for ‘:visible’.
32089
32090     ‘:active ENABLE’
32091          ENABLE is an expression; if it evaluates to ‘nil’, the menu is
32092          not selectable.  ‘:enable’ is an alias for ‘:active’.
32093
32094     The remaining elements in MENU are menu items.
32095
32096     A menu item can be a vector of three elements, ‘[NAME CALLBACK
32097     ENABLE]’.  NAME is the menu item name (a string).  CALLBACK is a
32098     command to run, or an expression to evaluate, when the item is
32099     chosen.  ENABLE is an expression; if it evaluates to ‘nil’, the
32100     item is disabled for selection.
32101
32102     Alternatively, a menu item may have the form:
32103
32104             [ NAME CALLBACK [ KEYWORD ARG ]... ]
32105
32106     where NAME and CALLBACK have the same meanings as above, and each
32107     optional KEYWORD and ARG pair should be one of the following:
32108
32109     ‘:keys KEYS’
32110          KEYS is a string to display as keyboard equivalent to the menu
32111          item.  This is normally not needed, as keyboard equivalents
32112          are computed automatically.  KEYS is expanded with
32113          ‘substitute-command-keys’ before it is displayed (*note Keys
32114          in Documentation::).
32115
32116     ‘:key-sequence KEYS’
32117          KEYS is a hint indicating which key sequence to display as
32118          keyboard equivalent, in case the command is bound to several
32119          key sequences.  It has no effect if KEYS is not bound to same
32120          command as this menu item.
32121
32122     ‘:active ENABLE’
32123          ENABLE is an expression; if it evaluates to ‘nil’, the item is
32124          make unselectable..  ‘:enable’ is an alias for ‘:active’.
32125
32126     ‘:visible INCLUDE’
32127          INCLUDE is an expression; if it evaluates to ‘nil’, the item
32128          is made invisible.  ‘:included’ is an alias for ‘:visible’.
32129
32130     ‘:label FORM’
32131          FORM is an expression that is evaluated to obtain a value
32132          which serves as the menu item’s label (the default is NAME).
32133
32134     ‘:suffix FORM’
32135          FORM is an expression that is dynamically evaluated and whose
32136          value is concatenated with the menu entry’s label.
32137
32138     ‘:style STYLE’
32139          STYLE is a symbol describing the type of menu item; it should
32140          be ‘toggle’ (a checkbox), or ‘radio’ (a radio button), or
32141          anything else (meaning an ordinary menu item).
32142
32143     ‘:selected SELECTED’
32144          SELECTED is an expression; the checkbox or radio button is
32145          selected whenever the expression’s value is non-‘nil’.
32146
32147     ‘:help HELP’
32148          HELP is a string describing the menu item.
32149
32150     Alternatively, a menu item can be a string.  Then that string
32151     appears in the menu as unselectable text.  A string consisting of
32152     dashes is displayed as a separator (*note Menu Separators::).
32153
32154     Alternatively, a menu item can be a list with the same format as
32155     MENU.  This is a submenu.
32156
32157   Here is an example of using ‘easy-menu-define’ to define a menu
32158similar to the one defined in the example in *note Menu Bar:::
32159
32160     (easy-menu-define words-menu global-map
32161       "Menu for word navigation commands."
32162       '("Words"
32163          ["Forward word" forward-word]
32164          ["Backward word" backward-word]))
32165
32166
32167File: elisp.info,  Node: Modes,  Next: Documentation,  Prev: Keymaps,  Up: Top
32168
3216923 Major and Minor Modes
32170************************
32171
32172A “mode” is a set of definitions that customize Emacs behavior in useful
32173ways.  There are two varieties of modes: “minor modes”, which provide
32174features that users can turn on and off while editing; and “major
32175modes”, which are used for editing or interacting with a particular kind
32176of text.  Each buffer has exactly one “major mode” at a time.
32177
32178   This chapter describes how to write both major and minor modes, how
32179to indicate them in the mode line, and how they run hooks supplied by
32180the user.  For related topics such as keymaps and syntax tables, see
32181*note Keymaps::, and *note Syntax Tables::.
32182
32183* Menu:
32184
32185* Hooks::             How to use hooks; how to write code that provides hooks.
32186* Major Modes::       Defining major modes.
32187* Minor Modes::       Defining minor modes.
32188* Mode Line Format::  Customizing the text that appears in the mode line.
32189* Imenu::             Providing a menu of definitions made in a buffer.
32190* Font Lock Mode::    How modes can highlight text according to syntax.
32191* Auto-Indentation::  How to teach Emacs to indent for a major mode.
32192* Desktop Save Mode:: How modes can have buffer state saved between
32193                        Emacs sessions.
32194
32195
32196File: elisp.info,  Node: Hooks,  Next: Major Modes,  Up: Modes
32197
3219823.1 Hooks
32199==========
32200
32201A “hook” is a variable where you can store a function or functions to be
32202called on a particular occasion by an existing program.  Emacs provides
32203hooks for the sake of customization.  Most often, hooks are set up in
32204the init file (*note Init File::), but Lisp programs can set them also.
32205*Note Standard Hooks::, for a list of some standard hook variables.
32206
32207   Most of the hooks in Emacs are “normal hooks”.  These variables
32208contain lists of functions to be called with no arguments.  By
32209convention, whenever the hook name ends in ‘-hook’, that tells you it is
32210normal.  We try to make all hooks normal, as much as possible, so that
32211you can use them in a uniform way.
32212
32213   Every major mode command is supposed to run a normal hook called the
32214“mode hook” as one of the last steps of initialization.  This makes it
32215easy for a user to customize the behavior of the mode, by overriding the
32216buffer-local variable assignments already made by the mode.  Most minor
32217mode functions also run a mode hook at the end.  But hooks are used in
32218other contexts too.  For example, the hook ‘suspend-hook’ runs just
32219before Emacs suspends itself (*note Suspending Emacs::).
32220
32221   The recommended way to add a hook function to a hook is by calling
32222‘add-hook’ (*note Setting Hooks::).  The hook functions may be any of
32223the valid kinds of functions that ‘funcall’ accepts (*note What Is a
32224Function::).  Most normal hook variables are initially void; ‘add-hook’
32225knows how to deal with this.  You can add hooks either globally or
32226buffer-locally with ‘add-hook’.
32227
32228   If the hook variable’s name does not end with ‘-hook’, that indicates
32229it is probably an “abnormal hook”.  That means the hook functions are
32230called with arguments, or their return values are used in some way.  The
32231hook’s documentation says how the functions are called.  You can use
32232‘add-hook’ to add a function to an abnormal hook, but you must write the
32233function to follow the hook’s calling convention.  By convention,
32234abnormal hook names end in ‘-functions’.
32235
32236   If the variable’s name ends in ‘-function’, then its value is just a
32237single function, not a list of functions.  ‘add-hook’ cannot be used to
32238modify such a _single function hook_, and you have to use ‘add-function’
32239instead (*note Advising Functions::).
32240
32241* Menu:
32242
32243* Running Hooks::    How to run a hook.
32244* Setting Hooks::    How to put functions on a hook, or remove them.
32245
32246
32247File: elisp.info,  Node: Running Hooks,  Next: Setting Hooks,  Up: Hooks
32248
3224923.1.1 Running Hooks
32250--------------------
32251
32252In this section, we document the ‘run-hooks’ function, which is used to
32253run a normal hook.  We also document the functions for running various
32254kinds of abnormal hooks.
32255
32256 -- Function: run-hooks &rest hookvars
32257     This function takes one or more normal hook variable names as
32258     arguments, and runs each hook in turn.  Each argument should be a
32259     symbol that is a normal hook variable.  These arguments are
32260     processed in the order specified.
32261
32262     If a hook variable has a non-‘nil’ value, that value should be a
32263     list of functions.  ‘run-hooks’ calls all the functions, one by
32264     one, with no arguments.
32265
32266     The hook variable’s value can also be a single function—either a
32267     lambda expression or a symbol with a function definition—which
32268     ‘run-hooks’ calls.  But this usage is obsolete.
32269
32270     If the hook variable is buffer-local, the buffer-local variable
32271     will be used instead of the global variable.  However, if the
32272     buffer-local variable contains the element ‘t’, the global hook
32273     variable will be run as well.
32274
32275 -- Function: run-hook-with-args hook &rest args
32276     This function runs an abnormal hook by calling all the hook
32277     functions in HOOK, passing each one the arguments ARGS.
32278
32279 -- Function: run-hook-with-args-until-failure hook &rest args
32280     This function runs an abnormal hook by calling each hook function
32281     in turn, stopping if one of them fails by returning ‘nil’.  Each
32282     hook function is passed the arguments ARGS.  If this function stops
32283     because one of the hook functions fails, it returns ‘nil’;
32284     otherwise it returns a non-‘nil’ value.
32285
32286 -- Function: run-hook-with-args-until-success hook &rest args
32287     This function runs an abnormal hook by calling each hook function,
32288     stopping if one of them succeeds by returning a non-‘nil’ value.
32289     Each hook function is passed the arguments ARGS.  If this function
32290     stops because one of the hook functions returns a non-‘nil’ value,
32291     it returns that value; otherwise it returns ‘nil’.
32292
32293
32294File: elisp.info,  Node: Setting Hooks,  Prev: Running Hooks,  Up: Hooks
32295
3229623.1.2 Setting Hooks
32297--------------------
32298
32299Here’s an example that adds a function to a mode hook to turn on Auto
32300Fill mode when in Lisp Interaction mode:
32301
32302     (add-hook 'lisp-interaction-mode-hook 'auto-fill-mode)
32303
32304   The value of a hook variable should be a list of functions.  You can
32305manipulate that list using the normal Lisp facilities, but the modular
32306way is to use the functions ‘add-hook’ and ‘remove-hook’, defined below.
32307They take care to handle some unusual situations and avoid problems.
32308
32309   It works to put a ‘lambda’-expression function on a hook, but we
32310recommend avoiding this because it can lead to confusion.  If you add
32311the same ‘lambda’-expression a second time but write it slightly
32312differently, you will get two equivalent but distinct functions on the
32313hook.  If you then remove one of them, the other will still be on it.
32314
32315 -- Function: add-hook hook function &optional depth local
32316     This function is the handy way to add function FUNCTION to hook
32317     variable HOOK.  You can use it for abnormal hooks as well as for
32318     normal hooks.  FUNCTION can be any Lisp function that can accept
32319     the proper number of arguments for HOOK.  For example,
32320
32321          (add-hook 'text-mode-hook 'my-text-hook-function)
32322
32323     adds ‘my-text-hook-function’ to the hook called ‘text-mode-hook’.
32324
32325     If FUNCTION is already present in HOOK (comparing using ‘equal’),
32326     then ‘add-hook’ does not add it a second time.
32327
32328     If FUNCTION has a non-‘nil’ property ‘permanent-local-hook’, then
32329     ‘kill-all-local-variables’ (or changing major modes) won’t delete
32330     it from the hook variable’s local value.
32331
32332     For a normal hook, hook functions should be designed so that the
32333     order in which they are executed does not matter.  Any dependence
32334     on the order is asking for trouble.  However, the order is
32335     predictable: normally, FUNCTION goes at the front of the hook list,
32336     so it is executed first (barring another ‘add-hook’ call).
32337
32338     In some cases, it is important to control the relative ordering of
32339     functions on the hook.  The optional argument DEPTH lets you
32340     indicate where the function should be inserted in the list: it
32341     should then be a number between -100 and 100 where the higher the
32342     value, the closer to the end of the list the function should go.
32343     The DEPTH defaults to 0 and for backward compatibility when DEPTH
32344     is a non-nil symbol it is interpreted as a depth of 90.
32345     Furthermore, when DEPTH is strictly greater than 0 the function is
32346     added _after_ rather than before functions of the same depth.  One
32347     should never use a depth of 100 (or -100), because one can never be
32348     sure that no other function will ever need to come before (or
32349     after) us.
32350
32351     ‘add-hook’ can handle the cases where HOOK is void or its value is
32352     a single function; it sets or changes the value to a list of
32353     functions.
32354
32355     If LOCAL is non-‘nil’, that says to add FUNCTION to the
32356     buffer-local hook list instead of to the global hook list.  This
32357     makes the hook buffer-local and adds ‘t’ to the buffer-local value.
32358     The latter acts as a flag to run the hook functions in the default
32359     value as well as in the local value.
32360
32361 -- Function: remove-hook hook function &optional local
32362     This function removes FUNCTION from the hook variable HOOK.  It
32363     compares FUNCTION with elements of HOOK using ‘equal’, so it works
32364     for both symbols and lambda expressions.
32365
32366     If LOCAL is non-‘nil’, that says to remove FUNCTION from the
32367     buffer-local hook list instead of from the global hook list.
32368
32369
32370File: elisp.info,  Node: Major Modes,  Next: Minor Modes,  Prev: Hooks,  Up: Modes
32371
3237223.2 Major Modes
32373================
32374
32375Major modes specialize Emacs for editing or interacting with particular
32376kinds of text.  Each buffer has exactly one major mode at a time.  Every
32377major mode is associated with a “major mode command”, whose name should
32378end in ‘-mode’.  This command takes care of switching to that mode in
32379the current buffer, by setting various buffer-local variables such as a
32380local keymap.  *Note Major Mode Conventions::.  Note that unlike minor
32381modes there is no way to “turn off” a major mode, instead the buffer
32382must be switched to a different one.  However, you can temporarily
32383“suspend” a major mode and later “restore” the suspended mode, see
32384below.
32385
32386   The least specialized major mode is called “Fundamental mode”, which
32387has no mode-specific definitions or variable settings.
32388
32389 -- Command: fundamental-mode
32390     This is the major mode command for Fundamental mode.  Unlike other
32391     mode commands, it does _not_ run any mode hooks (*note Major Mode
32392     Conventions::), since you are not supposed to customize this mode.
32393
32394 -- Function: major-mode-suspend
32395     This function works like ‘fundamental-mode’, in that it kills all
32396     buffer-local variables, but it also records the major mode in
32397     effect, so that it could subsequently be restored.  This function
32398     and ‘major-mode-restore’ (described next) are useful when you need
32399     to put a buffer under some specialized mode other than the one
32400     Emacs chooses for it automatically (*note Auto Major Mode::), but
32401     would also like to be able to switch back to the original mode
32402     later.
32403
32404 -- Function: major-mode-restore &optional avoided-modes
32405     This function restores the major mode recorded by
32406     ‘major-mode-suspend’.  If no major mode was recorded, this function
32407     calls ‘normal-mode’ (*note normal-mode: Auto Major Mode.), but
32408     tries to force it not to choose any modes in AVOIDED-MODES, if that
32409     argument is non-‘nil’.
32410
32411   The easiest way to write a major mode is to use the macro
32412‘define-derived-mode’, which sets up the new mode as a variant of an
32413existing major mode.  *Note Derived Modes::.  We recommend using
32414‘define-derived-mode’ even if the new mode is not an obvious derivative
32415of another mode, as it automatically enforces many coding conventions
32416for you.  *Note Basic Major Modes::, for common modes to derive from.
32417
32418   The standard GNU Emacs Lisp directory tree contains the code for
32419several major modes, in files such as ‘text-mode.el’, ‘texinfo.el’,
32420lisp-mode.el’, and ‘rmail.el’.  You can study these libraries to see
32421how modes are written.
32422
32423 -- User Option: major-mode
32424     The buffer-local value of this variable holds the symbol for the
32425     current major mode.  Its default value holds the default major mode
32426     for new buffers.  The standard default value is ‘fundamental-mode’.
32427
32428     If the default value is ‘nil’, then whenever Emacs creates a new
32429     buffer via a command such as ‘C-x b’ (‘switch-to-buffer’), the new
32430     buffer is put in the major mode of the previously current buffer.
32431     As an exception, if the major mode of the previous buffer has a
32432     ‘mode-class’ symbol property with value ‘special’, the new buffer
32433     is put in Fundamental mode (*note Major Mode Conventions::).
32434
32435* Menu:
32436
32437* Major Mode Conventions::  Coding conventions for keymaps, etc.
32438* Auto Major Mode::         How Emacs chooses the major mode automatically.
32439* Mode Help::               Finding out how to use a mode.
32440* Derived Modes::           Defining a new major mode based on another major
32441                              mode.
32442* Basic Major Modes::       Modes that other modes are often derived from.
32443* Mode Hooks::              Hooks run at the end of major mode functions.
32444* Tabulated List Mode::     Parent mode for buffers containing tabulated data.
32445* Generic Modes::           Defining a simple major mode that supports
32446                              comment syntax and Font Lock mode.
32447* Example Major Modes::     Text mode and Lisp modes.
32448
32449
32450File: elisp.info,  Node: Major Mode Conventions,  Next: Auto Major Mode,  Up: Major Modes
32451
3245223.2.1 Major Mode Conventions
32453-----------------------------
32454
32455The code for every major mode should follow various coding conventions,
32456including conventions for local keymap and syntax table initialization,
32457function and variable names, and hooks.
32458
32459   If you use the ‘define-derived-mode’ macro, it will take care of many
32460of these conventions automatically.  *Note Derived Modes::.  Note also
32461that Fundamental mode is an exception to many of these conventions,
32462because it represents the default state of Emacs.
32463
32464   The following list of conventions is only partial.  Each major mode
32465should aim for consistency in general with other Emacs major modes, as
32466this makes Emacs as a whole more coherent.  It is impossible to list
32467here all the possible points where this issue might come up; if the
32468Emacs developers point out an area where your major mode deviates from
32469the usual conventions, please make it compatible.
32470
32471   • Define a major mode command whose name ends in ‘-mode’.  When
32472     called with no arguments, this command should switch to the new
32473     mode in the current buffer by setting up the keymap, syntax table,
32474     and buffer-local variables in an existing buffer.  It should not
32475     change the buffer’s contents.
32476
32477   • Write a documentation string for this command that describes the
32478     special commands available in this mode.  *Note Mode Help::.
32479
32480     The documentation string may include the special documentation
32481     substrings, ‘\[COMMAND]’, ‘\{KEYMAP}’, and ‘\<KEYMAP>’, which allow
32482     the help display to adapt automatically to the user’s own key
32483     bindings.  *Note Keys in Documentation::.
32484
32485   • The major mode command should start by calling
32486     ‘kill-all-local-variables’.  This runs the normal hook
32487     ‘change-major-mode-hook’, then gets rid of the buffer-local
32488     variables of the major mode previously in effect.  *Note Creating
32489     Buffer-Local::.
32490
32491   • The major mode command should set the variable ‘major-mode’ to the
32492     major mode command symbol.  This is how ‘describe-mode’ discovers
32493     which documentation to print.
32494
32495   • The major mode command should set the variable ‘mode-name’ to the
32496     “pretty” name of the mode, usually a string (but see *note Mode
32497     Line Data::, for other possible forms).  The name of the mode
32498     appears in the mode line.
32499
32500   • Calling the major mode command twice in direct succession should
32501     not fail and should do the same thing as calling the command only
32502     once.  In other words, the major mode command should be idempotent.
32503
32504   • Since all global names are in the same name space, all the global
32505     variables, constants, and functions that are part of the mode
32506     should have names that start with the major mode name (or with an
32507     abbreviation of it if the name is long).  *Note Coding
32508     Conventions::.
32509
32510   • In a major mode for editing some kind of structured text, such as a
32511     programming language, indentation of text according to structure is
32512     probably useful.  So the mode should set ‘indent-line-function’ to
32513     a suitable function, and probably customize other variables for
32514     indentation.  *Note Auto-Indentation::.
32515
32516   • The major mode should usually have its own keymap, which is used as
32517     the local keymap in all buffers in that mode.  The major mode
32518     command should call ‘use-local-map’ to install this local map.
32519     *Note Active Keymaps::, for more information.
32520
32521     This keymap should be stored permanently in a global variable named
32522     ‘MODENAME-mode-map’.  Normally the library that defines the mode
32523     sets this variable.
32524
32525     *Note Tips for Defining::, for advice about how to write the code
32526     to set up the mode’s keymap variable.
32527
32528   • The key sequences bound in a major mode keymap should usually start
32529     with ‘C-c’, followed by a control character, a digit, or ‘{’, ‘}’,
32530     ‘<’, ‘>’, ‘:’ or ‘;’.  The other punctuation characters are
32531     reserved for minor modes, and ordinary letters are reserved for
32532     users.
32533
32534     A major mode can also rebind the keys ‘M-n’, ‘M-p’ and ‘M-s’.  The
32535     bindings for ‘M-n’ and ‘M-p’ should normally be some kind of moving
32536     forward and backward, but this does not necessarily mean cursor
32537     motion.
32538
32539     It is legitimate for a major mode to rebind a standard key sequence
32540     if it provides a command that does the same job in a way better
32541     suited to the text this mode is used for.  For example, a major
32542     mode for editing a programming language might redefine ‘C-M-a’ to
32543     move to the beginning of a function in a way that works better for
32544     that language.  The recommended way of tailoring ‘C-M-a’ to the
32545     needs of a major mode is to set ‘beginning-of-defun-function’
32546     (*note List Motion::) to invoke the function specific to the mode.
32547
32548     It is also legitimate for a major mode to rebind a standard key
32549     sequence whose standard meaning is rarely useful in that mode.  For
32550     instance, minibuffer modes rebind ‘M-r’, whose standard meaning is
32551     rarely of any use in the minibuffer.  Major modes such as Dired or
32552     Rmail that do not allow self-insertion of text can reasonably
32553     redefine letters and other printing characters as special commands.
32554
32555   • Major modes for editing text should not define <RET> to do anything
32556     other than insert a newline.  However, it is ok for specialized
32557     modes for text that users don’t directly edit, such as Dired and
32558     Info modes, to redefine <RET> to do something entirely different.
32559
32560   • Major modes should not alter options that are primarily a matter of
32561     user preference, such as whether Auto-Fill mode is enabled.  Leave
32562     this to each user to decide.  However, a major mode should
32563     customize other variables so that Auto-Fill mode will work usefully
32564     _if_ the user decides to use it.
32565
32566   • The mode may have its own syntax table or may share one with other
32567     related modes.  If it has its own syntax table, it should store
32568     this in a variable named ‘MODENAME-mode-syntax-table’.  *Note
32569     Syntax Tables::.
32570
32571   • If the mode handles a language that has a syntax for comments, it
32572     should set the variables that define the comment syntax.  *Note
32573     Options Controlling Comments: (emacs)Options for Comments.
32574
32575   • The mode may have its own abbrev table or may share one with other
32576     related modes.  If it has its own abbrev table, it should store
32577     this in a variable named ‘MODENAME-mode-abbrev-table’.  If the
32578     major mode command defines any abbrevs itself, it should pass ‘t’
32579     for the SYSTEM-FLAG argument to ‘define-abbrev’.  *Note Defining
32580     Abbrevs::.
32581
32582   • The mode should specify how to do highlighting for Font Lock mode,
32583     by setting up a buffer-local value for the variable
32584     ‘font-lock-defaults’ (*note Font Lock Mode::).
32585
32586   • Each face that the mode defines should, if possible, inherit from
32587     an existing Emacs face.  *Note Basic Faces::, and *note Faces for
32588     Font Lock::.
32589
32590   • The mode should specify how Imenu should find the definitions or
32591     sections of a buffer, by setting up a buffer-local value for the
32592     variable ‘imenu-generic-expression’, for the two variables
32593     ‘imenu-prev-index-position-function’ and
32594     ‘imenu-extract-index-name-function’, or for the variable
32595     ‘imenu-create-index-function’ (*note Imenu::).
32596
32597   • The mode can specify a local value for
32598     ‘eldoc-documentation-function’ to tell ElDoc mode how to handle
32599     this mode.
32600
32601   • The mode can specify how to complete various keywords by adding one
32602     or more buffer-local entries to the special hook
32603     ‘completion-at-point-functions’.  *Note Completion in Buffers::.
32604
32605   • To make a buffer-local binding for an Emacs customization variable,
32606     use ‘make-local-variable’ in the major mode command, not
32607     ‘make-variable-buffer-local’.  The latter function would make the
32608     variable local to every buffer in which it is subsequently set,
32609     which would affect buffers that do not use this mode.  It is
32610     undesirable for a mode to have such global effects.  *Note
32611     Buffer-Local Variables::.
32612
32613     With rare exceptions, the only reasonable way to use
32614     ‘make-variable-buffer-local’ in a Lisp package is for a variable
32615     which is used only within that package.  Using it on a variable
32616     used by other packages would interfere with them.
32617
32618   • Each major mode should have a normal “mode hook” named
32619     ‘MODENAME-mode-hook’.  The very last thing the major mode command
32620     should do is to call ‘run-mode-hooks’.  This runs the normal hook
32621     ‘change-major-mode-after-body-hook’, the mode hook, the function
32622     ‘hack-local-variables’ (when the buffer is visiting a file), and
32623     then the normal hook ‘after-change-major-mode-hook’.  *Note Mode
32624     Hooks::.
32625
32626   • The major mode command may start by calling some other major mode
32627     command (called the “parent mode”) and then alter some of its
32628     settings.  A mode that does this is called a “derived mode”.  The
32629     recommended way to define one is to use the ‘define-derived-mode’
32630     macro, but this is not required.  Such a mode should call the
32631     parent mode command inside a ‘delay-mode-hooks’ form.  (Using
32632     ‘define-derived-mode’ does this automatically.)  *Note Derived
32633     Modes::, and *note Mode Hooks::.
32634
32635   • If something special should be done if the user switches a buffer
32636     from this mode to any other major mode, this mode can set up a
32637     buffer-local value for ‘change-major-mode-hook’ (*note Creating
32638     Buffer-Local::).
32639
32640   • If this mode is appropriate only for specially-prepared text
32641     produced by the mode itself (rather than by the user typing at the
32642     keyboard or by an external file), then the major mode command
32643     symbol should have a property named ‘mode-class’ with value
32644     ‘special’, put on as follows:
32645
32646          (put 'funny-mode 'mode-class 'special)
32647
32648     This tells Emacs that new buffers created while the current buffer
32649     is in Funny mode should not be put in Funny mode, even though the
32650     default value of ‘major-mode’ is ‘nil’.  By default, the value of
32651     ‘nil’ for ‘major-mode’ means to use the current buffer’s major mode
32652     when creating new buffers (*note Auto Major Mode::), but with such
32653     ‘special’ modes, Fundamental mode is used instead.  Modes such as
32654     Dired, Rmail, and Buffer List use this feature.
32655
32656     The function ‘view-buffer’ does not enable View mode in buffers
32657     whose mode-class is special, because such modes usually provide
32658     their own View-like bindings.
32659
32660     The ‘define-derived-mode’ macro automatically marks the derived
32661     mode as special if the parent mode is special.  Special mode is a
32662     convenient parent for such modes to inherit from; *Note Basic Major
32663     Modes::.
32664
32665   • If you want to make the new mode the default for files with certain
32666     recognizable names, add an element to ‘auto-mode-alist’ to select
32667     the mode for those file names (*note Auto Major Mode::).  If you
32668     define the mode command to autoload, you should add this element in
32669     the same file that calls ‘autoload’.  If you use an autoload cookie
32670     for the mode command, you can also use an autoload cookie for the
32671     form that adds the element (*note autoload cookie::).  If you do
32672     not autoload the mode command, it is sufficient to add the element
32673     in the file that contains the mode definition.
32674
32675   • The top-level forms in the file defining the mode should be written
32676     so that they may be evaluated more than once without adverse
32677     consequences.  For instance, use ‘defvar’ or ‘defcustom’ to set
32678     mode-related variables, so that they are not reinitialized if they
32679     already have a value (*note Defining Variables::).
32680
32681
32682File: elisp.info,  Node: Auto Major Mode,  Next: Mode Help,  Prev: Major Mode Conventions,  Up: Major Modes
32683
3268423.2.2 How Emacs Chooses a Major Mode
32685-------------------------------------
32686
32687When Emacs visits a file, it automatically selects a major mode for the
32688buffer based on information in the file name or in the file itself.  It
32689also processes local variables specified in the file text.
32690
32691 -- Command: normal-mode &optional find-file
32692     This function establishes the proper major mode and buffer-local
32693     variable bindings for the current buffer.  It calls ‘set-auto-mode’
32694     (see below).  As of Emacs 26.1, it no longer runs
32695     ‘hack-local-variables’, this now being done in ‘run-mode-hooks’ at
32696     the initialization of major modes (*note Mode Hooks::).
32697
32698     If the FIND-FILE argument to ‘normal-mode’ is non-‘nil’,
32699     ‘normal-mode’ assumes that the ‘find-file’ function is calling it.
32700     In this case, it may process local variables in the ‘-*-’ line or
32701     at the end of the file.  The variable ‘enable-local-variables’
32702     controls whether to do so.  *Note Local Variables in Files:
32703     (emacs)File Variables, for the syntax of the local variables
32704     section of a file.
32705
32706     If you run ‘normal-mode’ interactively, the argument FIND-FILE is
32707     normally ‘nil’.  In this case, ‘normal-mode’ unconditionally
32708     processes any file local variables.
32709
32710     The function calls ‘set-auto-mode’ to choose and set a major mode.
32711     If this does not specify a mode, the buffer stays in the major mode
32712     determined by the default value of ‘major-mode’ (see below).
32713
32714     ‘normal-mode’ uses ‘condition-case’ around the call to the major
32715     mode command, so errors are caught and reported as a ‘File mode
32716     specification error’, followed by the original error message.
32717
32718 -- Function: set-auto-mode &optional keep-mode-if-same
32719     This function selects and sets the major mode that is appropriate
32720     for the current buffer.  It bases its decision (in order of
32721     precedence) on the ‘-*-’ line, on any ‘mode:’ local variable near
32722     the end of a file, on the ‘#!’ line (using
32723     ‘interpreter-mode-alist’), on the text at the beginning of the
32724     buffer (using ‘magic-mode-alist’), and finally on the visited file
32725     name (using ‘auto-mode-alist’).  *Note How Major Modes are Chosen:
32726     (emacs)Choosing Modes.  If ‘enable-local-variables’ is ‘nil’,
32727     ‘set-auto-mode’ does not check the ‘-*-’ line, or near the end of
32728     the file, for any mode tag.
32729
32730     There are some file types where it is not appropriate to scan the
32731     file contents for a mode specifier.  For example, a tar archive may
32732     happen to contain, near the end of the file, a member file that has
32733     a local variables section specifying a mode for that particular
32734     file.  This should not be applied to the containing tar file.
32735     Similarly, a tiff image file might just happen to contain a first
32736     line that seems to match the ‘-*-’ pattern.  For these reasons,
32737     both these file extensions are members of the list
32738     ‘inhibit-local-variables-regexps’.  Add patterns to this list to
32739     prevent Emacs searching them for local variables of any kind (not
32740     just mode specifiers).
32741
32742     If KEEP-MODE-IF-SAME is non-‘nil’, this function does not call the
32743     mode command if the buffer is already in the proper major mode.
32744     For instance, ‘set-visited-file-name’ sets this to ‘t’ to avoid
32745     killing buffer local variables that the user may have set.
32746
32747 -- Function: set-buffer-major-mode buffer
32748     This function sets the major mode of BUFFER to the default value of
32749     ‘major-mode’; if that is ‘nil’, it uses the current buffer’s major
32750     mode (if that is suitable).  As an exception, if BUFFER’s name is
32751     ‘*scratch*’, it sets the mode to ‘initial-major-mode’.
32752
32753     The low-level primitives for creating buffers do not use this
32754     function, but medium-level commands such as ‘switch-to-buffer’ and
32755     ‘find-file-noselect’ use it whenever they create buffers.
32756
32757 -- User Option: initial-major-mode
32758     The value of this variable determines the major mode of the initial
32759     ‘*scratch*’ buffer.  The value should be a symbol that is a major
32760     mode command.  The default value is ‘lisp-interaction-mode’.
32761
32762 -- Variable: interpreter-mode-alist
32763     This variable specifies major modes to use for scripts that specify
32764     a command interpreter in a ‘#!’ line.  Its value is an alist with
32765     elements of the form ‘(REGEXP . MODE)’; this says to use mode MODE
32766     if the file specifies an interpreter which matches ‘\\`REGEXP\\'’.
32767     For example, one of the default elements is ‘("python[0-9.]*" .
32768     python-mode)’.
32769
32770 -- Variable: magic-mode-alist
32771     This variable’s value is an alist with elements of the form
32772     ‘(REGEXP . FUNCTION)’, where REGEXP is a regular expression and
32773     FUNCTION is a function or ‘nil’.  After visiting a file,
32774     ‘set-auto-mode’ calls FUNCTION if the text at the beginning of the
32775     buffer matches REGEXP and FUNCTION is non-‘nil’; if FUNCTION is
32776     ‘nil’, ‘auto-mode-alist’ gets to decide the mode.
32777
32778 -- Variable: magic-fallback-mode-alist
32779     This works like ‘magic-mode-alist’, except that it is handled only
32780     if ‘auto-mode-alist’ does not specify a mode for this file.
32781
32782 -- Variable: auto-mode-alist
32783     This variable contains an association list of file name patterns
32784     (regular expressions) and corresponding major mode commands.
32785     Usually, the file name patterns test for suffixes, such as ‘.el’
32786     and ‘.c’, but this need not be the case.  An ordinary element of
32787     the alist looks like ‘(REGEXP . MODE-FUNCTION)’.
32788
32789     For example,
32790
32791          (("\\`/tmp/fol/" . text-mode)
32792           ("\\.texinfo\\'" . texinfo-mode)
32793           ("\\.texi\\'" . texinfo-mode)
32794           ("\\.el\\'" . emacs-lisp-mode)
32795           ("\\.c\\'" . c-mode)
32796           ("\\.h\\'" . c-mode)
32797           ...)
32798
32799     When you visit a file whose expanded file name (*note File Name
32800     Expansion::), with version numbers and backup suffixes removed
32801     using ‘file-name-sans-versions’ (*note File Name Components::),
32802     matches a REGEXP, ‘set-auto-mode’ calls the corresponding
32803     MODE-FUNCTION.  This feature enables Emacs to select the proper
32804     major mode for most files.
32805
32806     If an element of ‘auto-mode-alist’ has the form ‘(REGEXP FUNCTION
32807     t)’, then after calling FUNCTION, Emacs searches ‘auto-mode-alist’
32808     again for a match against the portion of the file name that did not
32809     match before.  This feature is useful for uncompression packages:
32810     an entry of the form ‘("\\.gz\\'" FUNCTION t)’ can uncompress the
32811     file and then put the uncompressed file in the proper mode
32812     according to the name sans ‘.gz’.
32813
32814     Here is an example of how to prepend several pattern pairs to
32815     ‘auto-mode-alist’.  (You might use this sort of expression in your
32816     init file.)
32817
32818          (setq auto-mode-alist
32819            (append
32820             ;; File name (within directory) starts with a dot.
32821             '(("/\\.[^/]*\\'" . fundamental-mode)
32822               ;; File name has no dot.
32823               ("/[^\\./]*\\'" . fundamental-mode)
32824               ;; File name ends in ‘.C’.
32825               ("\\.C\\'" . c++-mode))
32826             auto-mode-alist))
32827
32828
32829File: elisp.info,  Node: Mode Help,  Next: Derived Modes,  Prev: Auto Major Mode,  Up: Major Modes
32830
3283123.2.3 Getting Help about a Major Mode
32832--------------------------------------
32833
32834The ‘describe-mode’ function provides information about major modes.  It
32835is normally bound to ‘C-h m’.  It uses the value of the variable
32836‘major-mode’ (*note Major Modes::), which is why every major mode
32837command needs to set that variable.
32838
32839 -- Command: describe-mode &optional buffer
32840     This command displays the documentation of the current buffer’s
32841     major mode and minor modes.  It uses the ‘documentation’ function
32842     to retrieve the documentation strings of the major and minor mode
32843     commands (*note Accessing Documentation::).
32844
32845     If called from Lisp with a non-‘nil’ BUFFER argument, this function
32846     displays the documentation for that buffer’s major and minor modes,
32847     rather than those of the current buffer.
32848
32849
32850File: elisp.info,  Node: Derived Modes,  Next: Basic Major Modes,  Prev: Mode Help,  Up: Major Modes
32851
3285223.2.4 Defining Derived Modes
32853-----------------------------
32854
32855The recommended way to define a new major mode is to derive it from an
32856existing one using ‘define-derived-mode’.  If there is no closely
32857related mode, you should inherit from either ‘text-mode’,
32858‘special-mode’, or ‘prog-mode’.  *Note Basic Major Modes::.  If none of
32859these are suitable, you can inherit from ‘fundamental-mode’ (*note Major
32860Modes::).
32861
32862 -- Macro: define-derived-mode variant parent name docstring
32863          keyword-args... body...
32864     This macro defines VARIANT as a major mode command, using NAME as
32865     the string form of the mode name.  VARIANT and PARENT should be
32866     unquoted symbols.
32867
32868     The new command VARIANT is defined to call the function PARENT,
32869     then override certain aspects of that parent mode:
32870
32871        • The new mode has its own sparse keymap, named ‘VARIANT-map’.
32872          ‘define-derived-mode’ makes the parent mode’s keymap the
32873          parent of the new map, unless ‘VARIANT-map’ is already set and
32874          already has a parent.
32875
32876        • The new mode has its own syntax table, kept in the variable
32877          ‘VARIANT-syntax-table’, unless you override this using the
32878          ‘:syntax-table’ keyword (see below).  ‘define-derived-mode’
32879          makes the parent mode’s syntax-table the parent of
32880          ‘VARIANT-syntax-table’, unless the latter is already set and
32881          already has a parent different from the standard syntax table.
32882
32883        • The new mode has its own abbrev table, kept in the variable
32884          ‘VARIANT-abbrev-table’, unless you override this using the
32885          ‘:abbrev-table’ keyword (see below).
32886
32887        • The new mode has its own mode hook, ‘VARIANT-hook’.  It runs
32888          this hook, after running the hooks of its ancestor modes, with
32889          ‘run-mode-hooks’, as the last thing it does, apart from
32890          running any ‘:after-hook’ form it may have.  *Note Mode
32891          Hooks::.
32892
32893     In addition, you can specify how to override other aspects of
32894     PARENT with BODY.  The command VARIANT evaluates the forms in BODY
32895     after setting up all its usual overrides, just before running the
32896     mode hooks.
32897
32898     If PARENT has a non-‘nil’ ‘mode-class’ symbol property, then
32899     ‘define-derived-mode’ sets the ‘mode-class’ property of VARIANT to
32900     the same value.  This ensures, for example, that if PARENT is a
32901     special mode, then VARIANT is also a special mode (*note Major Mode
32902     Conventions::).
32903
32904     You can also specify ‘nil’ for PARENT.  This gives the new mode no
32905     parent.  Then ‘define-derived-mode’ behaves as described above,
32906     but, of course, omits all actions connected with PARENT.
32907
32908     The argument DOCSTRING specifies the documentation string for the
32909     new mode.  ‘define-derived-mode’ adds some general information
32910     about the mode’s hook, followed by the mode’s keymap, at the end of
32911     this documentation string.  If you omit DOCSTRING,
32912     ‘define-derived-mode’ generates a documentation string.
32913
32914     The KEYWORD-ARGS are pairs of keywords and values.  The values,
32915     except for ‘:after-hook’’s, are evaluated.  The following keywords
32916     are currently supported:
32917
32918     ‘:syntax-table’
32919          You can use this to explicitly specify a syntax table for the
32920          new mode.  If you specify a ‘nil’ value, the new mode uses the
32921          same syntax table as PARENT, or the standard syntax table if
32922          PARENT is ‘nil’.  (Note that this does _not_ follow the
32923          convention used for non-keyword arguments that a ‘nil’ value
32924          is equivalent with not specifying the argument.)
32925
32926     ‘:abbrev-table’
32927          You can use this to explicitly specify an abbrev table for the
32928          new mode.  If you specify a ‘nil’ value, the new mode uses the
32929          same abbrev table as PARENT, or
32930          ‘fundamental-mode-abbrev-table’ if PARENT is ‘nil’.  (Again, a
32931          ‘nil’ value is _not_ equivalent to not specifying this
32932          keyword.)
32933
32934     ‘:group’
32935          If this is specified, the value should be the customization
32936          group for this mode.  (Not all major modes have one.)  The
32937          command ‘customize-mode’ uses this.  ‘define-derived-mode’
32938          does _not_ automatically define the specified customization
32939          group.
32940
32941     ‘:after-hook’
32942          This optional keyword specifies a single Lisp form to evaluate
32943          as the final act of the mode function, after the mode hooks
32944          have been run.  It should not be quoted.  Since the form might
32945          be evaluated after the mode function has terminated, it should
32946          not access any element of the mode function’s local state.  An
32947          ‘:after-hook’ form is useful for setting up aspects of the
32948          mode which depend on the user’s settings, which in turn may
32949          have been changed in a mode hook.
32950
32951     Here is a hypothetical example:
32952
32953          (defvar hypertext-mode-map
32954            (let ((map (make-sparse-keymap)))
32955              (define-key map [down-mouse-3] 'do-hyper-link)
32956              map))
32957
32958          (define-derived-mode hypertext-mode
32959            text-mode "Hypertext"
32960            "Major mode for hypertext."
32961            (setq-local case-fold-search nil))
32962
32963     Do not write an ‘interactive’ spec in the definition;
32964     ‘define-derived-mode’ does that automatically.
32965
32966 -- Function: derived-mode-p &rest modes
32967     This function returns non-‘nil’ if the current major mode is
32968     derived from any of the major modes given by the symbols MODES.
32969
32970
32971File: elisp.info,  Node: Basic Major Modes,  Next: Mode Hooks,  Prev: Derived Modes,  Up: Major Modes
32972
3297323.2.5 Basic Major Modes
32974------------------------
32975
32976Apart from Fundamental mode, there are three major modes that other
32977major modes commonly derive from: Text mode, Prog mode, and Special
32978mode.  While Text mode is useful in its own right (e.g., for editing
32979files ending in ‘.txt’), Prog mode and Special mode exist mainly to let
32980other modes derive from them.
32981
32982   As far as possible, new major modes should be derived, either
32983directly or indirectly, from one of these three modes.  One reason is
32984that this allows users to customize a single mode hook (e.g.,
32985‘prog-mode-hook’) for an entire family of relevant modes (e.g., all
32986programming language modes).
32987
32988 -- Command: text-mode
32989     Text mode is a major mode for editing human languages.  It defines
32990     the ‘"’ and ‘\’ characters as having punctuation syntax (*note
32991     Syntax Class Table::), and binds ‘M-<TAB>’ to
32992     ‘ispell-complete-word’ (*note (emacs)Spelling::).
32993
32994     An example of a major mode derived from Text mode is HTML mode.
32995     *Note SGML and HTML Modes: (emacs)HTML Mode.
32996
32997 -- Command: prog-mode
32998     Prog mode is a basic major mode for buffers containing programming
32999     language source code.  Most of the programming language major modes
33000     built into Emacs are derived from it.
33001
33002     Prog mode binds ‘parse-sexp-ignore-comments’ to ‘t’ (*note Motion
33003     via Parsing::) and ‘bidi-paragraph-direction’ to ‘left-to-right’
33004     (*note Bidirectional Display::).
33005
33006 -- Command: special-mode
33007     Special mode is a basic major mode for buffers containing text that
33008     is produced specially by Emacs, rather than directly from a file.
33009     Major modes derived from Special mode are given a ‘mode-class’
33010     property of ‘special’ (*note Major Mode Conventions::).
33011
33012     Special mode sets the buffer to read-only.  Its keymap defines
33013     several common bindings, including ‘q’ for ‘quit-window’ and ‘g’
33014     for ‘revert-buffer’ (*note Reverting::).
33015
33016     An example of a major mode derived from Special mode is Buffer Menu
33017     mode, which is used by the ‘*Buffer List*’ buffer.  *Note Listing
33018     Existing Buffers: (emacs)List Buffers.
33019
33020   In addition, modes for buffers of tabulated data can inherit from
33021Tabulated List mode, which is in turn derived from Special mode.  *Note
33022Tabulated List Mode::.
33023
33024
33025File: elisp.info,  Node: Mode Hooks,  Next: Tabulated List Mode,  Prev: Basic Major Modes,  Up: Major Modes
33026
3302723.2.6 Mode Hooks
33028-----------------
33029
33030Every major mode command should finish by running the mode-independent
33031normal hook ‘change-major-mode-after-body-hook’, its mode hook, and the
33032normal hook ‘after-change-major-mode-hook’.  It does this by calling
33033‘run-mode-hooks’.  If the major mode is a derived mode, that is if it
33034calls another major mode (the parent mode) in its body, it should do
33035this inside ‘delay-mode-hooks’ so that the parent won’t run these hooks
33036itself.  Instead, the derived mode’s call to ‘run-mode-hooks’ runs the
33037parent’s mode hook too.  *Note Major Mode Conventions::.
33038
33039   Emacs versions before Emacs 22 did not have ‘delay-mode-hooks’.
33040Versions before 24 did not have ‘change-major-mode-after-body-hook’.
33041When user-implemented major modes do not use ‘run-mode-hooks’ and have
33042not been updated to use these newer features, they won’t entirely follow
33043these conventions: they may run the parent’s mode hook too early, or
33044fail to run ‘after-change-major-mode-hook’.  If you encounter such a
33045major mode, please correct it to follow these conventions.
33046
33047   When you define a major mode using ‘define-derived-mode’, it
33048automatically makes sure these conventions are followed.  If you define
33049a major mode “by hand”, not using ‘define-derived-mode’, use the
33050following functions to handle these conventions automatically.
33051
33052 -- Function: run-mode-hooks &rest hookvars
33053     Major modes should run their mode hook using this function.  It is
33054     similar to ‘run-hooks’ (*note Hooks::), but it also runs
33055     ‘change-major-mode-after-body-hook’, ‘hack-local-variables’ (when
33056     the buffer is visiting a file) (*note File Local Variables::), and
33057     ‘after-change-major-mode-hook’.  The last thing it does is to
33058     evaluate any ‘:after-hook’ forms declared by parent modes (*note
33059     Derived Modes::).
33060
33061     When this function is called during the execution of a
33062     ‘delay-mode-hooks’ form, it does not run the hooks or
33063     ‘hack-local-variables’ or evaluate the forms immediately.  Instead,
33064     it arranges for the next call to ‘run-mode-hooks’ to run them.
33065
33066 -- Macro: delay-mode-hooks body...
33067     When one major mode command calls another, it should do so inside
33068     of ‘delay-mode-hooks’.
33069
33070     This macro executes BODY, but tells all ‘run-mode-hooks’ calls
33071     during the execution of BODY to delay running their hooks.  The
33072     hooks will actually run during the next call to ‘run-mode-hooks’
33073     after the end of the ‘delay-mode-hooks’ construct.
33074
33075 -- Variable: change-major-mode-after-body-hook
33076     This is a normal hook run by ‘run-mode-hooks’.  It is run before
33077     the mode hooks.
33078
33079 -- Variable: after-change-major-mode-hook
33080     This is a normal hook run by ‘run-mode-hooks’.  It is run at the
33081     very end of every properly-written major mode command.
33082
33083
33084File: elisp.info,  Node: Tabulated List Mode,  Next: Generic Modes,  Prev: Mode Hooks,  Up: Major Modes
33085
3308623.2.7 Tabulated List mode
33087--------------------------
33088
33089Tabulated List mode is a major mode for displaying tabulated data, i.e.,
33090data consisting of “entries”, each entry occupying one row of text with
33091its contents divided into columns.  Tabulated List mode provides
33092facilities for pretty-printing rows and columns, and sorting the rows
33093according to the values in each column.  It is derived from Special mode
33094(*note Basic Major Modes::).
33095
33096   Tabulated List mode is intended to be used as a parent mode by a more
33097specialized major mode.  Examples include Process Menu mode (*note
33098Process Information::) and Package Menu mode (*note (emacs)Package
33099Menu::).
33100
33101   Such a derived mode should use ‘define-derived-mode’ in the usual
33102way, specifying ‘tabulated-list-mode’ as the second argument (*note
33103Derived Modes::).  The body of the ‘define-derived-mode’ form should
33104specify the format of the tabulated data, by assigning values to the
33105variables documented below; optionally, it can then call the function
33106‘tabulated-list-init-header’, which will populate a header with the
33107names of the columns.
33108
33109   The derived mode should also define a “listing command”.  This, not
33110the mode command, is what the user calls (e.g., ‘M-x list-processes’).
33111The listing command should create or switch to a buffer, turn on the
33112derived mode, specify the tabulated data, and finally call
33113‘tabulated-list-print’ to populate the buffer.
33114
33115 -- User Option: tabulated-list-gui-sort-indicator-asc
33116     This variable specifies the character to be used on GUI frames as
33117     an indication that the column is sorted in the ascending order.
33118
33119     Whenever you change the sort direction in Tabulated List buffers,
33120     this indicator toggles between ascending (“asc”) and descending
33121     (“desc”).
33122
33123 -- User Option: tabulated-list-gui-sort-indicator-desc
33124     Like ‘tabulated-list-gui-sort-indicator-asc’, but used when the
33125     column is sorted in the descending order.
33126
33127 -- User Option: tabulated-list-tty-sort-indicator-asc
33128     Like ‘tabulated-list-gui-sort-indicator-asc’, but used for
33129     text-mode frames.
33130
33131 -- User Option: tabulated-list-tty-sort-indicator-desc
33132     Like ‘tabulated-list-tty-sort-indicator-asc’, but used when the
33133     column is sorted in the descending order.
33134
33135 -- Variable: tabulated-list-format
33136     This buffer-local variable specifies the format of the Tabulated
33137     List data.  Its value should be a vector.  Each element of the
33138     vector represents a data column, and should be a list ‘(NAME WIDTH
33139     SORT)’, where
33140
33141        • NAME is the column’s name (a string).
33142
33143        • WIDTH is the width to reserve for the column (an integer).
33144          This is meaningless for the last column, which runs to the end
33145          of each line.
33146
33147        • SORT specifies how to sort entries by the column.  If ‘nil’,
33148          the column cannot be used for sorting.  If ‘t’, the column is
33149          sorted by comparing string values.  Otherwise, this should be
33150          a predicate function for ‘sort’ (*note Rearrangement::), which
33151          accepts two arguments with the same form as the elements of
33152          ‘tabulated-list-entries’ (see below).
33153
33154 -- Variable: tabulated-list-entries
33155     This buffer-local variable specifies the entries displayed in the
33156     Tabulated List buffer.  Its value should be either a list, or a
33157     function.
33158
33159     If the value is a list, each list element corresponds to one entry,
33160     and should have the form ‘(ID CONTENTS)’, where
33161
33162        • ID is either ‘nil’, or a Lisp object that identifies the
33163          entry.  If the latter, the cursor stays on the same entry when
33164          re-sorting entries.  Comparison is done with ‘equal’.
33165
33166        • CONTENTS is a vector with the same number of elements as
33167          ‘tabulated-list-format’.  Each vector element is either a
33168          string, which is inserted into the buffer as-is, or a list
33169          ‘(LABEL . PROPERTIES)’, which means to insert a text button by
33170          calling ‘insert-text-button’ with LABEL and PROPERTIES as
33171          arguments (*note Making Buttons::).
33172
33173          There should be no newlines in any of these strings.
33174
33175     Otherwise, the value should be a function which returns a list of
33176     the above form when called with no arguments.
33177
33178 -- Variable: tabulated-list-revert-hook
33179     This normal hook is run prior to reverting a Tabulated List buffer.
33180     A derived mode can add a function to this hook to recompute
33181     ‘tabulated-list-entries’.
33182
33183 -- Variable: tabulated-list-printer
33184     The value of this variable is the function called to insert an
33185     entry at point, including its terminating newline.  The function
33186     should accept two arguments, ID and CONTENTS, having the same
33187     meanings as in ‘tabulated-list-entries’.  The default value is a
33188     function which inserts an entry in a straightforward way; a mode
33189     which uses Tabulated List mode in a more complex way can specify
33190     another function.
33191
33192 -- Variable: tabulated-list-sort-key
33193     The value of this variable specifies the current sort key for the
33194     Tabulated List buffer.  If it is ‘nil’, no sorting is done.
33195     Otherwise, it should have the form ‘(NAME . FLIP)’, where NAME is a
33196     string matching one of the column names in ‘tabulated-list-format’,
33197     and FLIP, if non-‘nil’, means to invert the sort order.
33198
33199 -- Function: tabulated-list-init-header
33200     This function computes and sets ‘header-line-format’ for the
33201     Tabulated List buffer (*note Header Lines::), and assigns a keymap
33202     to the header line to allow sorting entries by clicking on column
33203     headers.
33204
33205     Modes derived from Tabulated List mode should call this after
33206     setting the above variables (in particular, only after setting
33207     ‘tabulated-list-format’).
33208
33209 -- Function: tabulated-list-print &optional remember-pos update
33210     This function populates the current buffer with entries.  It should
33211     be called by the listing command.  It erases the buffer, sorts the
33212     entries specified by ‘tabulated-list-entries’ according to
33213     ‘tabulated-list-sort-key’, then calls the function specified by
33214     ‘tabulated-list-printer’ to insert each entry.
33215
33216     If the optional argument REMEMBER-POS is non-‘nil’, this function
33217     looks for the ID element on the current line, if any, and tries to
33218     move to that entry after all the entries are (re)inserted.
33219
33220     If the optional argument UPDATE is non-‘nil’, this function will
33221     only erase or add entries that have changed since the last print.
33222     This is several times faster if most entries haven’t changed since
33223     the last time this function was called.  The only difference in
33224     outcome is that tags placed via ‘tabulated-list-put-tag’ will not
33225     be removed from entries that haven’t changed (normally all tags are
33226     removed).
33227
33228 -- Function: tabulated-list-delete-entry
33229     This function deletes the entry at point.
33230
33231     It returns a list ‘(ID COLS)’, where ID is the ID of the deleted
33232     entry and COLS is a vector of its column descriptors.  It moves
33233     point to the beginning of the current line.  It returns ‘nil’ if
33234     there is no entry at point.
33235
33236     Note that this function only changes the buffer contents; it does
33237     not alter ‘tabulated-list-entries’.
33238
33239 -- Function: tabulated-list-get-id &optional pos
33240     This ‘defsubst’ returns the ID object from ‘tabulated-list-entries’
33241     (if that is a list) or from the list returned by
33242     ‘tabulated-list-entries’ (if it is a function).  If omitted or
33243     ‘nil’, POS defaults to point.
33244
33245 -- Function: tabulated-list-get-entry &optional pos
33246     This ‘defsubst’ returns the entry object from
33247     ‘tabulated-list-entries’ (if that is a list) or from the list
33248     returned by ‘tabulated-list-entries’ (if it is a function).  This
33249     will be a vector for the ID at POS.  If there is no entry at POS,
33250     then the function returns ‘nil’.
33251
33252 -- Function: tabulated-list-header-overlay-p &optional POS
33253     This ‘defsubst’ returns non-nil if there is a fake header at POS.
33254     A fake header is used if ‘tabulated-list-use-header-line’ is ‘nil’
33255     to put the column names at the beginning of the buffer.  If omitted
33256     or ‘nil’, POS defaults to ‘point-min’.
33257
33258 -- Function: tabulated-list-put-tag tag &optional advance
33259     This function puts TAG in the padding area of the current line.
33260     The padding area can be empty space at the beginning of the line,
33261     the width of which is governed by ‘tabulated-list-padding’.  TAG
33262     should be a string, with a length less than or equal to
33263     ‘tabulated-list-padding’.  If ADVANCE is non-nil, this function
33264     advances point by one line.
33265
33266 -- Function: tabulated-list-clear-all-tags
33267     This function clears all tags from the padding area in the current
33268     buffer.
33269
33270 -- Function: tabulated-list-set-col col desc &optional
33271          change-entry-data
33272     This function changes the tabulated list entry at point, setting
33273     COL to DESC.  COL is the column number to change, or the name of
33274     the column to change.  DESC is the new column descriptor, which is
33275     inserted via ‘tabulated-list-print-col’.
33276
33277     If CHANGE-ENTRY-DATA is non-nil, this function modifies the
33278     underlying data (usually the column descriptor in the list
33279     ‘tabulated-list-entries’) by setting the column descriptor of the
33280     vector to ‘desc’.
33281
33282
33283File: elisp.info,  Node: Generic Modes,  Next: Example Major Modes,  Prev: Tabulated List Mode,  Up: Major Modes
33284
3328523.2.8 Generic Modes
33286--------------------
33287
33288“Generic modes” are simple major modes with basic support for comment
33289syntax and Font Lock mode.  To define a generic mode, use the macro
33290‘define-generic-mode’.  See the file ‘generic-x.el’ for some examples of
33291the use of ‘define-generic-mode’.
33292
33293 -- Macro: define-generic-mode mode comment-list keyword-list
33294          font-lock-list auto-mode-list function-list &optional
33295          docstring
33296     This macro defines a generic mode command named MODE (a symbol, not
33297     quoted).  The optional argument DOCSTRING is the documentation for
33298     the mode command.  If you do not supply it, ‘define-generic-mode’
33299     generates one by default.
33300
33301     The argument COMMENT-LIST is a list in which each element is either
33302     a character, a string of one or two characters, or a cons cell.  A
33303     character or a string is set up in the mode’s syntax table as a
33304     comment starter.  If the entry is a cons cell, the CAR is set up as
33305     a comment starter and the CDR as a comment ender.  (Use ‘nil’ for
33306     the latter if you want comments to end at the end of the line.)
33307     Note that the syntax table mechanism has limitations about what
33308     comment starters and enders are actually possible.  *Note Syntax
33309     Tables::.
33310
33311     The argument KEYWORD-LIST is a list of keywords to highlight with
33312     ‘font-lock-keyword-face’.  Each keyword should be a string.
33313     Meanwhile, FONT-LOCK-LIST is a list of additional expressions to
33314     highlight.  Each element of this list should have the same form as
33315     an element of ‘font-lock-keywords’.  *Note Search-based
33316     Fontification::.
33317
33318     The argument AUTO-MODE-LIST is a list of regular expressions to add
33319     to the variable ‘auto-mode-alist’.  They are added by the execution
33320     of the ‘define-generic-mode’ form, not by expanding the macro call.
33321
33322     Finally, FUNCTION-LIST is a list of functions for the mode command
33323     to call for additional setup.  It calls these functions just before
33324     it runs the mode hook variable ‘MODE-hook’.
33325
33326
33327File: elisp.info,  Node: Example Major Modes,  Prev: Generic Modes,  Up: Major Modes
33328
3332923.2.9 Major Mode Examples
33330--------------------------
33331
33332Text mode is perhaps the simplest mode besides Fundamental mode.  Here
33333are excerpts from ‘text-mode.el’ that illustrate many of the conventions
33334listed above:
33335
33336     ;; Create the syntax table for this mode.
33337     (defvar text-mode-syntax-table
33338       (let ((st (make-syntax-table)))
33339         (modify-syntax-entry ?\" ".   " st)
33340         (modify-syntax-entry ?\\ ".   " st)
33341         ;; Add 'p' so M-c on 'hello' leads to 'Hello', not 'hello'.
33342         (modify-syntax-entry ?' "w p" st)
33343         ...
33344         st)
33345       "Syntax table used while in `text-mode'.")
33346
33347     ;; Create the keymap for this mode.
33348     (defvar text-mode-map
33349       (let ((map (make-sparse-keymap)))
33350         (define-key map "\e\t" 'ispell-complete-word)
33351         ...
33352         map)
33353       "Keymap for `text-mode'.
33354     Many other modes, such as `mail-mode', `outline-mode' and
33355     `indented-text-mode', inherit all the commands defined in this map.")
33356
33357   Here is how the actual mode command is defined now:
33358
33359     (define-derived-mode text-mode nil "Text"
33360       "Major mode for editing text written for humans to read.
33361     In this mode, paragraphs are delimited only by blank or white lines.
33362     You can thus get the full benefit of adaptive filling
33363      (see the variable `adaptive-fill-mode').
33364     \\{text-mode-map}
33365     Turning on Text mode runs the normal hook `text-mode-hook'."
33366       (setq-local text-mode-variant t)
33367       (setq-local require-final-newline mode-require-final-newline))
33368
33369   The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp
33370Interaction mode) have more features than Text mode and the code is
33371correspondingly more complicated.  Here are excerpts from ‘lisp-mode.el33372that illustrate how these modes are written.
33373
33374   Here is how the Lisp mode syntax and abbrev tables are defined:
33375
33376     ;; Create mode-specific table variables.
33377     (define-abbrev-table 'lisp-mode-abbrev-table ()
33378       "Abbrev table for Lisp mode.")
33379
33380     (defvar lisp-mode-syntax-table
33381       (let ((table (make-syntax-table lisp--mode-syntax-table)))
33382         (modify-syntax-entry ?\[ "_   " table)
33383         (modify-syntax-entry ?\] "_   " table)
33384         (modify-syntax-entry ?# "' 14" table)
33385         (modify-syntax-entry ?| "\" 23bn" table)
33386         table)
33387       "Syntax table used in `lisp-mode'.")
33388
33389   The three modes for Lisp share much of their code.  For instance,
33390each calls the following function to set various variables:
33391
33392     (defun lisp-mode-variables (&optional syntax keywords-case-insensitive elisp)
33393       (when syntax
33394         (set-syntax-table lisp-mode-syntax-table))
33395       ...
33396
33397Amongst other things, this function sets up the ‘comment-start’ variable
33398to handle Lisp comments:
33399
33400       (setq-local comment-start ";")
33401       ...
33402
33403   Each of the different Lisp modes has a slightly different keymap.
33404For example, Lisp mode binds ‘C-c C-z’ to ‘run-lisp’, but the other Lisp
33405modes do not.  However, all Lisp modes have some commands in common.
33406The following code sets up the common commands:
33407
33408     (defvar lisp-mode-shared-map
33409       (let ((map (make-sparse-keymap)))
33410         (set-keymap-parent map prog-mode-map)
33411         (define-key map "\e\C-q" 'indent-sexp)
33412         (define-key map "\177" 'backward-delete-char-untabify)
33413         map)
33414       "Keymap for commands shared by all sorts of Lisp modes.")
33415
33416And here is the code to set up the keymap for Lisp mode:
33417
33418     (defvar lisp-mode-map
33419       (let ((map (make-sparse-keymap))
33420             (menu-map (make-sparse-keymap "Lisp")))
33421         (set-keymap-parent map lisp-mode-shared-map)
33422         (define-key map "\e\C-x" 'lisp-eval-defun)
33423         (define-key map "\C-c\C-z" 'run-lisp)
33424         ...
33425         map)
33426       "Keymap for ordinary Lisp mode.
33427     All commands in `lisp-mode-shared-map' are inherited by this map.")
33428
33429Finally, here is the major mode command for Lisp mode:
33430
33431     (define-derived-mode lisp-mode prog-mode "Lisp"
33432       "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
33433     Commands:
33434     Delete converts tabs to spaces as it moves back.
33435     Blank lines separate paragraphs.  Semicolons start comments.
33436
33437     \\{lisp-mode-map}
33438     Note that `run-lisp' may be used either to start an inferior Lisp job
33439     or to switch back to an existing one."
33440       (lisp-mode-variables nil t)
33441       (setq-local find-tag-default-function 'lisp-find-tag-default)
33442       (setq-local comment-start-skip
33443                   "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
33444       (setq imenu-case-fold-search t))
33445
33446
33447File: elisp.info,  Node: Minor Modes,  Next: Mode Line Format,  Prev: Major Modes,  Up: Modes
33448
3344923.3 Minor Modes
33450================
33451
33452A “minor mode” provides optional features that users may enable or
33453disable independently of the choice of major mode.  Minor modes can be
33454enabled individually or in combination.
33455
33456   Most minor modes implement features that are independent of the major
33457mode, and can thus be used with most major modes.  For example, Auto
33458Fill mode works with any major mode that permits text insertion.  A few
33459minor modes, however, are specific to a particular major mode.  For
33460example, Diff Auto Refine mode is a minor mode that is intended to be
33461used only with Diff mode.
33462
33463   Ideally, a minor mode should have its desired effect regardless of
33464the other minor modes in effect.  It should be possible to activate and
33465deactivate minor modes in any order.
33466
33467 -- Variable: minor-mode-list
33468     The value of this variable is a list of all minor mode commands.
33469
33470* Menu:
33471
33472* Minor Mode Conventions::      Tips for writing a minor mode.
33473* Keymaps and Minor Modes::     How a minor mode can have its own keymap.
33474* Defining Minor Modes::        A convenient facility for defining minor modes.
33475
33476
33477File: elisp.info,  Node: Minor Mode Conventions,  Next: Keymaps and Minor Modes,  Up: Minor Modes
33478
3347923.3.1 Conventions for Writing Minor Modes
33480------------------------------------------
33481
33482There are conventions for writing minor modes just as there are for
33483major modes (*note Major Modes::).  These conventions are described
33484below.  The easiest way to follow them is to use the macro
33485‘define-minor-mode’.  *Note Defining Minor Modes::.
33486
33487   • Define a variable whose name ends in ‘-mode’.  We call this the
33488     “mode variable”.  The minor mode command should set this variable.
33489     The value will be ‘nil’ if the mode is disabled, and non-‘nil’ if
33490     the mode is enabled.  The variable should be buffer-local if the
33491     minor mode is buffer-local.
33492
33493     This variable is used in conjunction with the ‘minor-mode-alist’ to
33494     display the minor mode name in the mode line.  It also determines
33495     whether the minor mode keymap is active, via ‘minor-mode-map-alist’
33496     (*note Controlling Active Maps::).  Individual commands or hooks
33497     can also check its value.
33498
33499   • Define a command, called the “mode command”, whose name is the same
33500     as the mode variable.  Its job is to set the value of the mode
33501     variable, plus anything else that needs to be done to actually
33502     enable or disable the mode’s features.
33503
33504     The mode command should accept one optional argument.  If called
33505     interactively with no prefix argument, it should toggle the mode
33506     (i.e., enable if it is disabled, and disable if it is enabled).  If
33507     called interactively with a prefix argument, it should enable the
33508     mode if the argument is positive and disable it otherwise.
33509
33510     If the mode command is called from Lisp (i.e., non-interactively),
33511     it should enable the mode if the argument is omitted or ‘nil’; it
33512     should toggle the mode if the argument is the symbol ‘toggle’;
33513     otherwise it should treat the argument in the same way as for an
33514     interactive call with a numeric prefix argument, as described
33515     above.
33516
33517     The following example shows how to implement this behavior (it is
33518     similar to the code generated by the ‘define-minor-mode’ macro):
33519
33520          (interactive (list (or current-prefix-arg 'toggle)))
33521          (let ((enable
33522                 (if (eq arg 'toggle)
33523                     (not foo-mode) ; this is the mode’s mode variable
33524                   (> (prefix-numeric-value arg) 0))))
33525            (if enable
33526                DO-ENABLE
33527              DO-DISABLE))
33528
33529     The reason for this somewhat complex behavior is that it lets users
33530     easily toggle the minor mode interactively, and also lets the minor
33531     mode be easily enabled in a mode hook, like this:
33532
33533          (add-hook 'text-mode-hook 'foo-mode)
33534
33535     This behaves correctly whether or not ‘foo-mode’ was already
33536     enabled, since the ‘foo-mode’ mode command unconditionally enables
33537     the minor mode when it is called from Lisp with no argument.
33538     Disabling a minor mode in a mode hook is a little uglier:
33539
33540          (add-hook 'text-mode-hook (lambda () (foo-mode -1)))
33541
33542     However, this is not very commonly done.
33543
33544     Enabling or disabling a minor mode twice in direct succession
33545     should not fail and should do the same thing as enabling or
33546     disabling it only once.  In other words, the minor mode command
33547     should be idempotent.
33548
33549   • Add an element to ‘minor-mode-alist’ for each minor mode (*note
33550     Definition of minor-mode-alist::), if you want to indicate the
33551     minor mode in the mode line.  This element should be a list of the
33552     following form:
33553
33554          (MODE-VARIABLE STRING)
33555
33556     Here MODE-VARIABLE is the variable that controls enabling of the
33557     minor mode, and STRING is a short string, starting with a space, to
33558     represent the mode in the mode line.  These strings must be short
33559     so that there is room for several of them at once.
33560
33561     When you add an element to ‘minor-mode-alist’, use ‘assq’ to check
33562     for an existing element, to avoid duplication.  For example:
33563
33564          (unless (assq 'leif-mode minor-mode-alist)
33565            (push '(leif-mode " Leif") minor-mode-alist))
33566
33567     or like this, using ‘add-to-list’ (*note List Variables::):
33568
33569          (add-to-list 'minor-mode-alist '(leif-mode " Leif"))
33570
33571   In addition, several major mode conventions (*note Major Mode
33572Conventions::) apply to minor modes as well: those regarding the names
33573of global symbols, the use of a hook at the end of the initialization
33574function, and the use of keymaps and other tables.
33575
33576   The minor mode should, if possible, support enabling and disabling
33577via Custom (*note Customization::).  To do this, the mode variable
33578should be defined with ‘defcustom’, usually with ‘:type 'boolean’.  If
33579just setting the variable is not sufficient to enable the mode, you
33580should also specify a ‘:set’ method which enables the mode by invoking
33581the mode command.  Note in the variable’s documentation string that
33582setting the variable other than via Custom may not take effect.  Also,
33583mark the definition with an autoload cookie (*note autoload cookie::),
33584and specify a ‘:require’ so that customizing the variable will load the
33585library that defines the mode.  For example:
33586
33587     ;;;###autoload
33588     (defcustom msb-mode nil
33589       "Toggle msb-mode.
33590     Setting this variable directly does not take effect;
33591     use either \\[customize] or the function `msb-mode'."
33592       :set 'custom-set-minor-mode
33593       :initialize 'custom-initialize-default
33594       :version "20.4"
33595       :type    'boolean
33596       :group   'msb
33597       :require 'msb)
33598
33599
33600File: elisp.info,  Node: Keymaps and Minor Modes,  Next: Defining Minor Modes,  Prev: Minor Mode Conventions,  Up: Minor Modes
33601
3360223.3.2 Keymaps and Minor Modes
33603------------------------------
33604
33605Each minor mode can have its own keymap, which is active when the mode
33606is enabled.  To set up a keymap for a minor mode, add an element to the
33607alist ‘minor-mode-map-alist’.  *Note Definition of
33608minor-mode-map-alist::.
33609
33610   One use of minor mode keymaps is to modify the behavior of certain
33611self-inserting characters so that they do something else as well as
33612self-insert.  (Another way to customize ‘self-insert-command’ is through
33613‘post-self-insert-hook’, see *note Commands for Insertion::.  Apart from
33614this, the facilities for customizing ‘self-insert-command’ are limited
33615to special cases, designed for abbrevs and Auto Fill mode.  Do not try
33616substituting your own definition of ‘self-insert-command’ for the
33617standard one.  The editor command loop handles this function specially.)
33618
33619   Minor modes may bind commands to key sequences consisting of ‘C-c’
33620followed by a punctuation character.  However, sequences consisting of
33621‘C-c’ followed by one of ‘{}<>:;’, or a control character or digit, are
33622reserved for major modes.  Also, ‘C-c LETTER’ is reserved for users.
33623*Note Key Binding Conventions::.
33624
33625
33626File: elisp.info,  Node: Defining Minor Modes,  Prev: Keymaps and Minor Modes,  Up: Minor Modes
33627
3362823.3.3 Defining Minor Modes
33629---------------------------
33630
33631The macro ‘define-minor-mode’ offers a convenient way of implementing a
33632mode in one self-contained definition.
33633
33634 -- Macro: define-minor-mode mode doc [init-value [lighter [keymap]]]
33635          keyword-args... body...
33636     This macro defines a new minor mode whose name is MODE (a symbol).
33637     It defines a command named MODE to toggle the minor mode, with DOC
33638     as its documentation string.
33639
33640     The toggle command takes one optional (prefix) argument.  If called
33641     interactively with no argument it toggles the mode on or off.  A
33642     positive prefix argument enables the mode, any other prefix
33643     argument disables it.  From Lisp, an argument of ‘toggle’ toggles
33644     the mode, whereas an omitted or ‘nil’ argument enables the mode.
33645     This makes it easy to enable the minor mode in a major mode hook,
33646     for example.  If DOC is ‘nil’, the macro supplies a default
33647     documentation string explaining the above.
33648
33649     By default, it also defines a variable named MODE, which is set to
33650     ‘t’ or ‘nil’ by enabling or disabling the mode.  The variable is
33651     initialized to INIT-VALUE.  Except in unusual circumstances (see
33652     below), this value must be ‘nil’.
33653
33654     The string LIGHTER says what to display in the mode line when the
33655     mode is enabled; if it is ‘nil’, the mode is not displayed in the
33656     mode line.
33657
33658     The optional argument KEYMAP specifies the keymap for the minor
33659     mode.  If non-‘nil’, it should be a variable name (whose value is a
33660     keymap), a keymap, or an alist of the form
33661
33662          (KEY-SEQUENCE . DEFINITION)
33663
33664     where each KEY-SEQUENCE and DEFINITION are arguments suitable for
33665     passing to ‘define-key’ (*note Changing Key Bindings::).  If KEYMAP
33666     is a keymap or an alist, this also defines the variable ‘MODE-map’.
33667
33668     The above three arguments INIT-VALUE, LIGHTER, and KEYMAP can be
33669     (partially) omitted when KEYWORD-ARGS are used.  The KEYWORD-ARGS
33670     consist of keywords followed by corresponding values.  A few
33671     keywords have special meanings:
33672
33673     ‘:group GROUP’
33674          Custom group name to use in all generated ‘defcustom’ forms.
33675          Defaults to MODE without the possible trailing ‘-mode’.
33676          *Warning:* don’t use this default group name unless you have
33677          written a ‘defgroup’ to define that group properly.  *Note
33678          Group Definitions::.
33679
33680     ‘:global GLOBAL’
33681          If non-‘nil’, this specifies that the minor mode should be
33682          global rather than buffer-local.  It defaults to ‘nil’.
33683
33684          One of the effects of making a minor mode global is that the
33685          MODE variable becomes a customization variable.  Toggling it
33686          through the Customize interface turns the mode on and off, and
33687          its value can be saved for future Emacs sessions (*note
33688          (emacs)Saving Customizations::.  For the saved variable to
33689          work, you should ensure that the ‘define-minor-mode’ form is
33690          evaluated each time Emacs starts; for packages that are not
33691          part of Emacs, the easiest way to do this is to specify a
33692          ‘:require’ keyword.
33693
33694     ‘:init-value INIT-VALUE’
33695          This is equivalent to specifying INIT-VALUE positionally.
33696
33697     ‘:lighter LIGHTER’
33698          This is equivalent to specifying LIGHTER positionally.
33699
33700     ‘:keymap KEYMAP’
33701          This is equivalent to specifying KEYMAP positionally.
33702
33703     ‘:variable PLACE’
33704          This replaces the default variable MODE, used to store the
33705          state of the mode.  If you specify this, the MODE variable is
33706          not defined, and any INIT-VALUE argument is unused.  PLACE can
33707          be a different named variable (which you must define
33708          yourself), or anything that can be used with the ‘setf’
33709          function (*note Generalized Variables::).  PLACE can also be a
33710          cons ‘(GET . SET)’, where GET is an expression that returns
33711          the current state, and SET is a function of one argument (a
33712          state) that sets it.
33713
33714     ‘:after-hook AFTER-HOOK’
33715          This defines a single Lisp form which is evaluated after the
33716          mode hooks have run.  It should not be quoted.
33717
33718     Any other keyword arguments are passed directly to the ‘defcustom’
33719     generated for the variable MODE.
33720
33721     The command named MODE first performs the standard actions such as
33722     setting the variable named MODE and then executes the BODY forms,
33723     if any.  It then runs the mode hook variable ‘MODE-hook’ and
33724     finishes by evaluating any form in ‘:after-hook’.
33725
33726   The initial value must be ‘nil’ except in cases where (1) the mode is
33727preloaded in Emacs, or (2) it is painless for loading to enable the mode
33728even though the user did not request it.  For instance, if the mode has
33729no effect unless something else is enabled, and will always be loaded by
33730that time, enabling it by default is harmless.  But these are unusual
33731circumstances.  Normally, the initial value must be ‘nil’.
33732
33733   The name ‘easy-mmode-define-minor-mode’ is an alias for this macro.
33734
33735   Here is an example of using ‘define-minor-mode’:
33736
33737     (define-minor-mode hungry-mode
33738       "Toggle Hungry mode.
33739     Interactively with no argument, this command toggles the mode.
33740     A positive prefix argument enables the mode, any other prefix
33741     argument disables it.  From Lisp, argument omitted or nil enables
33742     the mode, `toggle' toggles the state.
33743
33744     When Hungry mode is enabled, the control delete key
33745     gobbles all preceding whitespace except the last.
33746     See the command \\[hungry-electric-delete]."
33747      ;; The initial value.
33748      nil
33749      ;; The indicator for the mode line.
33750      " Hungry"
33751      ;; The minor mode bindings.
33752      '(([C-backspace] . hungry-electric-delete)))
33753
33754This defines a minor mode named “Hungry mode”, a command named
33755‘hungry-mode’ to toggle it, a variable named ‘hungry-mode’ which
33756indicates whether the mode is enabled, and a variable named
33757‘hungry-mode-map’ which holds the keymap that is active when the mode is
33758enabled.  It initializes the keymap with a key binding for ‘C-<DEL>’.
33759There are no BODY forms—many minor modes don’t need any.
33760
33761   Here’s an equivalent way to write it:
33762
33763     (define-minor-mode hungry-mode
33764       "Toggle Hungry mode.
33765     ...rest of documentation as before..."
33766      ;; The initial value.
33767      :init-value nil
33768      ;; The indicator for the mode line.
33769      :lighter " Hungry"
33770      ;; The minor mode bindings.
33771      :keymap
33772      '(([C-backspace] . hungry-electric-delete)
33773        ([C-M-backspace]
33774         . (lambda ()
33775             (interactive)
33776             (hungry-electric-delete t)))))
33777
33778 -- Macro: define-globalized-minor-mode global-mode mode turn-on
33779          keyword-args... body...
33780     This defines a global toggle named GLOBAL-MODE whose meaning is to
33781     enable or disable the buffer-local minor mode MODE in all buffers.
33782     It also executes the BODY forms.  To turn on the minor mode in a
33783     buffer, it uses the function TURN-ON; to turn off the minor mode,
33784     it calls MODE with −1 as argument.
33785
33786     Globally enabling the mode also affects buffers subsequently
33787     created by visiting files, and buffers that use a major mode other
33788     than Fundamental mode; but it does not detect the creation of a new
33789     buffer in Fundamental mode.
33790
33791     This defines the customization option GLOBAL-MODE (*note
33792     Customization::), which can be toggled in the Customize interface
33793     to turn the minor mode on and off.  As with ‘define-minor-mode’,
33794     you should ensure that the ‘define-globalized-minor-mode’ form is
33795     evaluated each time Emacs starts, for example by providing a
33796     ‘:require’ keyword.
33797
33798     Use ‘:group GROUP’ in KEYWORD-ARGS to specify the custom group for
33799     the mode variable of the global minor mode.
33800
33801     Generally speaking, when you define a globalized minor mode, you
33802     should also define a non-globalized version, so that people can use
33803     (or disable) it in individual buffers.  This also allows them to
33804     disable a globally enabled minor mode in a specific major mode, by
33805     using that mode’s hook.
33806
33807
33808File: elisp.info,  Node: Mode Line Format,  Next: Imenu,  Prev: Minor Modes,  Up: Modes
33809
3381023.4 Mode Line Format
33811=====================
33812
33813Each Emacs window (aside from minibuffer windows) typically has a mode
33814line at the bottom, which displays status information about the buffer
33815displayed in the window.  The mode line contains information about the
33816buffer, such as its name, associated file, depth of recursive editing,
33817and major and minor modes.  A window can also have a “header line”,
33818which is much like the mode line but appears at the top of the window.
33819
33820   This section describes how to control the contents of the mode line
33821and header line.  We include it in this chapter because much of the
33822information displayed in the mode line relates to the enabled major and
33823minor modes.
33824
33825* Menu:
33826
33827* Base: Mode Line Basics.       Basic ideas of mode line control.
33828* Data: Mode Line Data.         The data structure that controls the mode line.
33829* Top: Mode Line Top.           The top level variable, mode-line-format.
33830* Mode Line Variables::         Variables used in that data structure.
33831* %-Constructs::                Putting information into a mode line.
33832* Properties in Mode::          Using text properties in the mode line.
33833* Header Lines::                Like a mode line, but at the top.
33834* Emulating Mode Line::         Formatting text as the mode line would.
33835
33836
33837File: elisp.info,  Node: Mode Line Basics,  Next: Mode Line Data,  Up: Mode Line Format
33838
3383923.4.1 Mode Line Basics
33840-----------------------
33841
33842The contents of each mode line are specified by the buffer-local
33843variable ‘mode-line-format’ (*note Mode Line Top::).  This variable
33844holds a “mode line construct”: a template that controls what is
33845displayed on the buffer’s mode line.  The value of ‘header-line-format’
33846specifies the buffer’s header line in the same way.  All windows for the
33847same buffer use the same ‘mode-line-format’ and ‘header-line-format’
33848unless a ‘mode-line-format’ or ‘header-line-format’ parameter has been
33849specified for that window (*note Window Parameters::).
33850
33851   For efficiency, Emacs does not continuously recompute each window’s
33852mode line and header line.  It does so when circumstances appear to call
33853for it—for instance, if you change the window configuration, switch
33854buffers, narrow or widen the buffer, scroll, or modify the buffer.  If
33855you alter any of the variables referenced by ‘mode-line-format’ or
33856‘header-line-format’ (*note Mode Line Variables::), or any other data
33857structures that affect how text is displayed (*note Display::), you
33858should use the function ‘force-mode-line-update’ to update the display.
33859
33860 -- Function: force-mode-line-update &optional all
33861     This function forces Emacs to update the current buffer’s mode line
33862     and header line, based on the latest values of all relevant
33863     variables, during its next redisplay cycle.  If the optional
33864     argument ALL is non-‘nil’, it forces an update for all mode lines
33865     and header lines.
33866
33867     This function also forces an update of the menu bar and frame
33868     title.
33869
33870   The selected window’s mode line is usually displayed in a different
33871color using the face ‘mode-line’.  Other windows’ mode lines appear in
33872the face ‘mode-line-inactive’ instead.  *Note Faces::.
33873
33874
33875File: elisp.info,  Node: Mode Line Data,  Next: Mode Line Top,  Prev: Mode Line Basics,  Up: Mode Line Format
33876
3387723.4.2 The Data Structure of the Mode Line
33878------------------------------------------
33879
33880The mode line contents are controlled by a data structure called a “mode
33881line construct”, made up of lists, strings, symbols, and numbers kept in
33882buffer-local variables.  Each data type has a specific meaning for the
33883mode line appearance, as described below.  The same data structure is
33884used for constructing frame titles (*note Frame Titles::) and header
33885lines (*note Header Lines::).
33886
33887   A mode line construct may be as simple as a fixed string of text, but
33888it usually specifies how to combine fixed strings with variables’ values
33889to construct the text.  Many of these variables are themselves defined
33890to have mode line constructs as their values.
33891
33892   Here are the meanings of various data types as mode line constructs:
33893
33894‘STRING’
33895     A string as a mode line construct appears verbatim except for
33896     “‘%’-constructs” in it.  These stand for substitution of other
33897     data; see *note %-Constructs::.
33898
33899     If parts of the string have ‘face’ properties, they control display
33900     of the text just as they would text in the buffer.  Any characters
33901     which have no ‘face’ properties are displayed, by default, in the
33902     face ‘mode-line’ or ‘mode-line-inactive’ (*note (emacs)Standard
33903     Faces::).  The ‘help-echo’ and ‘keymap’ properties in STRING have
33904     special meanings.  *Note Properties in Mode::.
33905
33906‘SYMBOL’
33907     A symbol as a mode line construct stands for its value.  The value
33908     of SYMBOL is used as a mode line construct, in place of SYMBOL.
33909     However, the symbols ‘t’ and ‘nil’ are ignored, as is any symbol
33910     whose value is void.
33911
33912     There is one exception: if the value of SYMBOL is a string, it is
33913     displayed verbatim: the ‘%’-constructs are not recognized.
33914
33915     Unless SYMBOL is marked as risky (i.e., it has a non-‘nil’
33916     ‘risky-local-variable’ property), all text properties specified in
33917     SYMBOL’s value are ignored.  This includes the text properties of
33918     strings in SYMBOL’s value, as well as all ‘:eval’ and ‘:propertize’
33919     forms in it.  (The reason for this is security: non-risky variables
33920     could be set automatically from file variables without prompting
33921     the user.)
33922
33923‘(STRING REST...)’
33924‘(LIST REST...)’
33925     A list whose first element is a string or list means to process all
33926     the elements recursively and concatenate the results.  This is the
33927     most common form of mode line construct.
33928
33929‘(:eval FORM)’
33930     A list whose first element is the symbol ‘:eval’ says to evaluate
33931     FORM, and use the result as a string to display.  Make sure this
33932     evaluation cannot load any files, as doing so could cause infinite
33933     recursion.
33934
33935‘(:propertize ELT PROPS...)’
33936     A list whose first element is the symbol ‘:propertize’ says to
33937     process the mode line construct ELT recursively, then add the text
33938     properties specified by PROPS to the result.  The argument PROPS
33939     should consist of zero or more pairs TEXT-PROPERTY VALUE.  If ELT
33940     is or produces a string with text properties, all the characters of
33941     that string should have the same properties, or else some of them
33942     might be removed by ‘:propertize’.
33943
33944‘(SYMBOL THEN ELSE)’
33945     A list whose first element is a symbol that is not a keyword
33946     specifies a conditional.  Its meaning depends on the value of
33947     SYMBOL.  If SYMBOL has a non-‘nil’ value, the second element, THEN,
33948     is processed recursively as a mode line construct.  Otherwise, the
33949     third element, ELSE, is processed recursively.  You may omit ELSE;
33950     then the mode line construct displays nothing if the value of
33951     SYMBOL is ‘nil’ or void.
33952
33953‘(WIDTH REST...)’
33954     A list whose first element is an integer specifies truncation or
33955     padding of the results of REST.  The remaining elements REST are
33956     processed recursively as mode line constructs and concatenated
33957     together.  When WIDTH is positive, the result is space filled on
33958     the right if its width is less than WIDTH.  When WIDTH is negative,
33959     the result is truncated on the right to −WIDTH columns if its width
33960     exceeds −WIDTH.
33961
33962     For example, the usual way to show what percentage of a buffer is
33963     above the top of the window is to use a list like this: ‘(-3
33964     "%p")’.
33965
33966
33967File: elisp.info,  Node: Mode Line Top,  Next: Mode Line Variables,  Prev: Mode Line Data,  Up: Mode Line Format
33968
3396923.4.3 The Top Level of Mode Line Control
33970-----------------------------------------
33971
33972The variable in overall control of the mode line is ‘mode-line-format’.
33973
33974 -- User Option: mode-line-format
33975     The value of this variable is a mode line construct that controls
33976     the contents of the mode-line.  It is always buffer-local in all
33977     buffers.
33978
33979     If you set this variable to ‘nil’ in a buffer, that buffer does not
33980     have a mode line.  (A window that is just one line tall also does
33981     not display a mode line.)
33982
33983   The default value of ‘mode-line-format’ is designed to use the values
33984of other variables such as ‘mode-line-position’ and ‘mode-line-modes’
33985(which in turn incorporates the values of the variables ‘mode-name’ and
33986‘minor-mode-alist’).  Very few modes need to alter ‘mode-line-format’
33987itself.  For most purposes, it is sufficient to alter some of the
33988variables that ‘mode-line-format’ either directly or indirectly refers
33989to.
33990
33991   If you do alter ‘mode-line-format’ itself, the new value should use
33992the same variables that appear in the default value (*note Mode Line
33993Variables::), rather than duplicating their contents or displaying the
33994information in another fashion.  This way, customizations made by the
33995user or by Lisp programs (such as ‘display-time’ and major modes) via
33996changes to those variables remain effective.
33997
33998   Here is a hypothetical example of a ‘mode-line-format’ that might be
33999useful for Shell mode (in reality, Shell mode does not set
34000‘mode-line-format’):
34001
34002     (setq mode-line-format
34003       (list "-"
34004        'mode-line-mule-info
34005        'mode-line-modified
34006        'mode-line-frame-identification
34007        "%b--"
34008        ;; Note that this is evaluated while making the list.
34009        ;; It makes a mode line construct which is just a string.
34010        (getenv "HOST")
34011        ":"
34012        'default-directory
34013        "   "
34014        'global-mode-string
34015        "   %[("
34016        '(:eval (format-time-string "%F"))
34017        'mode-line-process
34018        'minor-mode-alist
34019        "%n"
34020        ")%]--"
34021        '(which-function-mode ("" which-func-format "--"))
34022        '(line-number-mode "L%l--")
34023        '(column-number-mode "C%c--")
34024        '(-3 "%p")))
34025
34026(The variables ‘line-number-mode’, ‘column-number-mode’ and
34027‘which-function-mode’ enable particular minor modes; as usual, these
34028variable names are also the minor mode command names.)
34029
34030
34031File: elisp.info,  Node: Mode Line Variables,  Next: %-Constructs,  Prev: Mode Line Top,  Up: Mode Line Format
34032
3403323.4.4 Variables Used in the Mode Line
34034--------------------------------------
34035
34036This section describes variables incorporated by the standard value of
34037‘mode-line-format’ into the text of the mode line.  There is nothing
34038inherently special about these variables; any other variables could have
34039the same effects on the mode line if the value of ‘mode-line-format’ is
34040changed to use them.  However, various parts of Emacs set these
34041variables on the understanding that they will control parts of the mode
34042line; therefore, practically speaking, it is essential for the mode line
34043to use them.  Also see *note (emacs)Optional Mode Line::.
34044
34045 -- Variable: mode-line-mule-info
34046     This variable holds the value of the mode line construct that
34047     displays information about the language environment, buffer coding
34048     system, and current input method.  *Note Non-ASCII Characters::.
34049
34050 -- Variable: mode-line-modified
34051     This variable holds the value of the mode line construct that
34052     displays whether the current buffer is modified.  Its default value
34053     displays ‘**’ if the buffer is modified, ‘--’ if the buffer is not
34054     modified, ‘%%’ if the buffer is read only, and ‘%*’ if the buffer
34055     is read only and modified.
34056
34057     Changing this variable does not force an update of the mode line.
34058
34059 -- Variable: mode-line-frame-identification
34060     This variable identifies the current frame.  Its default value
34061     displays ‘" "’ if you are using a window system which can show
34062     multiple frames, or ‘"-%F "’ on an ordinary terminal which shows
34063     only one frame at a time.
34064
34065 -- Variable: mode-line-buffer-identification
34066     This variable identifies the buffer being displayed in the window.
34067     Its default value displays the buffer name, padded with spaces to
34068     at least 12 columns.
34069
34070 -- Variable: mode-line-position
34071     This variable indicates the position in the buffer.  Its default
34072     value displays the buffer percentage and, optionally, the buffer
34073     size, the line number and the column number.
34074
34075 -- User Option: mode-line-percent-position
34076     This option is used in ‘mode-line-position’.  Its value specifies
34077     both the buffer percentage to display (one of ‘nil’, ‘"%o"’,
34078     ‘"%p"’, ‘"%P"’ or ‘"%q"’, *note %-Constructs::) and a width to
34079     space-fill or truncate to.  You are recommended to set this option
34080     with the ‘customize-variable’ facility.
34081
34082 -- Variable: vc-mode
34083     The variable ‘vc-mode’, buffer-local in each buffer, records
34084     whether the buffer’s visited file is maintained with version
34085     control, and, if so, which kind.  Its value is a string that
34086     appears in the mode line, or ‘nil’ for no version control.
34087
34088 -- Variable: mode-line-modes
34089     This variable displays the buffer’s major and minor modes.  Its
34090     default value also displays the recursive editing level,
34091     information on the process status, and whether narrowing is in
34092     effect.
34093
34094 -- Variable: mode-line-remote
34095     This variable is used to show whether ‘default-directory’ for the
34096     current buffer is remote.
34097
34098 -- Variable: mode-line-client
34099     This variable is used to identify ‘emacsclient’ frames.
34100
34101   The following three variables are used in ‘mode-line-modes’:
34102
34103 -- Variable: mode-name
34104     This buffer-local variable holds the “pretty” name of the current
34105     buffer’s major mode.  Each major mode should set this variable so
34106     that the mode name will appear in the mode line.  The value does
34107     not have to be a string, but can use any of the data types valid in
34108     a mode-line construct (*note Mode Line Data::).  To compute the
34109     string that will identify the mode name in the mode line, use
34110     ‘format-mode-line’ (*note Emulating Mode Line::).
34111
34112 -- Variable: mode-line-process
34113     This buffer-local variable contains the mode line information on
34114     process status in modes used for communicating with subprocesses.
34115     It is displayed immediately following the major mode name, with no
34116     intervening space.  For example, its value in the ‘*shell*’ buffer
34117     is ‘(":%s")’, which allows the shell to display its status along
34118     with the major mode as: ‘(Shell:run)’.  Normally this variable is
34119     ‘nil’.
34120
34121 -- Variable: mode-line-front-space
34122     This variable is displayed at the front of the mode line.  By
34123     default, this construct is displayed right at the beginning of the
34124     mode line, except that if there is a memory-full message, it is
34125     displayed first.
34126
34127 -- Variable: mode-line-end-spaces
34128     This variable is displayed at the end of the mode line.
34129
34130 -- Variable: mode-line-misc-info
34131     Mode line construct for miscellaneous information.  By default,
34132     this shows the information specified by ‘global-mode-string’.
34133
34134 -- Variable: minor-mode-alist
34135     This variable holds an association list whose elements specify how
34136     the mode line should indicate that a minor mode is active.  Each
34137     element of the ‘minor-mode-alist’ should be a two-element list:
34138
34139          (MINOR-MODE-VARIABLE MODE-LINE-STRING)
34140
34141     More generally, MODE-LINE-STRING can be any mode line construct.
34142     It appears in the mode line when the value of MINOR-MODE-VARIABLE
34143     is non-‘nil’, and not otherwise.  These strings should begin with
34144     spaces so that they don’t run together.  Conventionally, the
34145     MINOR-MODE-VARIABLE for a specific mode is set to a non-‘nil’ value
34146     when that minor mode is activated.
34147
34148     ‘minor-mode-alist’ itself is not buffer-local.  Each variable
34149     mentioned in the alist should be buffer-local if its minor mode can
34150     be enabled separately in each buffer.
34151
34152 -- Variable: global-mode-string
34153     This variable holds a mode line construct that, by default, appears
34154     in the mode line just after the ‘which-function-mode’ minor mode if
34155     set, else after ‘mode-line-modes’.  The command ‘display-time’ sets
34156     ‘global-mode-string’ to refer to the variable
34157     ‘display-time-string’, which holds a string containing the time and
34158     load information.
34159
34160     The ‘%M’ construct substitutes the value of ‘global-mode-string’,
34161     but that is obsolete, since the variable is included in the mode
34162     line from ‘mode-line-format’.
34163
34164   Here is a simplified version of the default value of
34165‘mode-line-format’.  The real default value also specifies addition of
34166text properties.
34167
34168     ("-"
34169      mode-line-mule-info
34170      mode-line-modified
34171      mode-line-frame-identification
34172      mode-line-buffer-identification
34173      "   "
34174      mode-line-position
34175      (vc-mode vc-mode)
34176      "   "
34177      mode-line-modes
34178      (which-function-mode ("" which-func-format "--"))
34179      (global-mode-string ("--" global-mode-string))
34180      "-%-")
34181
34182
34183File: elisp.info,  Node: %-Constructs,  Next: Properties in Mode,  Prev: Mode Line Variables,  Up: Mode Line Format
34184
3418523.4.5 ‘%’-Constructs in the Mode Line
34186--------------------------------------
34187
34188Strings used as mode line constructs can use certain ‘%’-constructs to
34189substitute various kinds of data.  The following is a list of the
34190defined ‘%’-constructs, and what they mean.
34191
34192   In any construct except ‘%%’, you can add a decimal integer after the
34193‘%’ to specify a minimum field width.  If the width is less, the field
34194is padded to that width.  Purely numeric constructs (‘c’, ‘i’, ‘I’, and
34195‘l’) are padded by inserting spaces to the left, and others are padded
34196by inserting spaces to the right.
34197
34198‘%b’
34199     The current buffer name, obtained with the ‘buffer-name’ function.
34200     *Note Buffer Names::.
34201
34202‘%c’
34203     The current column number of point, counting from zero starting at
34204     the left margin of the window.
34205
34206‘%C’
34207     The current column number of point, counting from one starting at
34208     the left margin of the window.
34209
34210‘%e’
34211     When Emacs is nearly out of memory for Lisp objects, a brief
34212     message saying so.  Otherwise, this is empty.
34213
34214‘%f’
34215     The visited file name, obtained with the ‘buffer-file-name’
34216     function.  *Note Buffer File Name::.
34217
34218‘%F’
34219     The title (only on a window system) or the name of the selected
34220     frame.  *Note Basic Parameters::.
34221
34222‘%i’
34223     The size of the accessible part of the current buffer; basically
34224     ‘(- (point-max) (point-min))’.
34225
34226‘%I’
34227     Like ‘%i’, but the size is printed in a more readable way by using
34228     ‘k’ for 10^3, ‘M’ for 10^6, ‘G’ for 10^9, etc., to abbreviate.
34229
34230‘%l’
34231     The current line number of point, counting within the accessible
34232     portion of the buffer.
34233
34234‘%n’
34235     ‘Narrow’ when narrowing is in effect; nothing otherwise (see
34236     ‘narrow-to-region’ in *note Narrowing::).
34237
34238‘%o’
34239     The degree of “travel” of the window through (the visible portion
34240     of) the buffer, i.e.  the size of the text above the top of the
34241     window expressed as a percentage of all the text outside the
34242     window, or ‘Top’, ‘Bottom’ or ‘All’.
34243
34244‘%p’
34245     The percentage of the buffer text above the *top* of window, or
34246     ‘Top’, ‘Bottom’ or ‘All’.  Note that the default mode line
34247     construct truncates this to three characters.
34248
34249‘%P’
34250     The percentage of the buffer text that is above the *bottom* of the
34251     window (which includes the text visible in the window, as well as
34252     the text above the top), plus ‘Top’ if the top of the buffer is
34253     visible on screen; or ‘Bottom’ or ‘All’.
34254
34255‘%q’
34256     The percentages of text above both the *top* and the *bottom* of
34257     the window, separated by ‘-’, or ‘All’.
34258
34259‘%s’
34260     The status of the subprocess belonging to the current buffer,
34261     obtained with ‘process-status’.  *Note Process Information::.
34262
34263‘%z’
34264     The mnemonics of keyboard, terminal, and buffer coding systems.
34265
34266‘%Z’
34267     Like ‘%z’, but including the end-of-line format.
34268
34269‘%*’
34270     ‘%’ if the buffer is read only (see ‘buffer-read-only’);
34271     ‘*’ if the buffer is modified (see ‘buffer-modified-p’);
34272     ‘-’ otherwise.  *Note Buffer Modification::.
34273
34274‘%+’
34275     ‘*’ if the buffer is modified (see ‘buffer-modified-p’);
34276     ‘%’ if the buffer is read only (see ‘buffer-read-only’);
34277     ‘-’ otherwise.  This differs from ‘%*’ only for a modified
34278     read-only buffer.  *Note Buffer Modification::.
34279
34280‘%&’
34281     ‘*’ if the buffer is modified, and ‘-’ otherwise.
34282
34283‘%@’
34284     ‘@’ if the buffer’s ‘default-directory’ (*note File Name
34285     Expansion::) is on a remote machine, and ‘-’ otherwise.
34286
34287‘%[’
34288     An indication of the depth of recursive editing levels (not
34289     counting minibuffer levels): one ‘[’ for each editing level.  *Note
34290     Recursive Editing::.
34291
34292‘%]’
34293     One ‘]’ for each recursive editing level (not counting minibuffer
34294     levels).
34295
34296‘%-’
34297     Dashes sufficient to fill the remainder of the mode line.
34298
34299‘%%’
34300     The character ‘%’—this is how to include a literal ‘%’ in a string
34301     in which ‘%’-constructs are allowed.
34302
34303   The following ‘%’-construct is still supported, but it is obsolete,
34304since you can get the same result using the variable ‘mode-name’.
34305
34306‘%m’
34307     The value of ‘mode-name’.
34308
34309
34310File: elisp.info,  Node: Properties in Mode,  Next: Header Lines,  Prev: %-Constructs,  Up: Mode Line Format
34311
3431223.4.6 Properties in the Mode Line
34313----------------------------------
34314
34315Certain text properties are meaningful in the mode line.  The ‘face’
34316property affects the appearance of text; the ‘help-echo’ property
34317associates help strings with the text, and ‘keymap’ can make the text
34318mouse-sensitive.
34319
34320   There are four ways to specify text properties for text in the mode
34321line:
34322
34323  1. Put a string with a text property directly into the mode line data
34324     structure.
34325
34326  2. Put a text property on a mode line %-construct such as ‘%12b’; then
34327     the expansion of the %-construct will have that same text property.
34328
34329  3. Use a ‘(:propertize ELT PROPS...)’ construct to give ELT a text
34330     property specified by PROPS.
34331
34332  4. Use a list containing ‘:eval FORM’ in the mode line data structure,
34333     and make FORM evaluate to a string that has a text property.
34334
34335   You can use the ‘keymap’ property to specify a keymap.  This keymap
34336only takes real effect for mouse clicks; binding character keys and
34337function keys to it has no effect, since it is impossible to move point
34338into the mode line.
34339
34340   When the mode line refers to a variable which does not have a
34341non-‘nil’ ‘risky-local-variable’ property, any text properties given or
34342specified within that variable’s values are ignored.  This is because
34343such properties could otherwise specify functions to be called, and
34344those functions could come from file local variables.
34345
34346
34347File: elisp.info,  Node: Header Lines,  Next: Emulating Mode Line,  Prev: Properties in Mode,  Up: Mode Line Format
34348
3434923.4.7 Window Header Lines
34350--------------------------
34351
34352A window can have a “header line” at the top, just as it can have a mode
34353line at the bottom.  The header line feature works just like the mode
34354line feature, except that it’s controlled by ‘header-line-format’:
34355
34356 -- Variable: header-line-format
34357     This variable, local in every buffer, specifies how to display the
34358     header line, for windows displaying the buffer.  The format of the
34359     value is the same as for ‘mode-line-format’ (*note Mode Line
34360     Data::).  It is normally ‘nil’, so that ordinary buffers have no
34361     header line.
34362
34363 -- Function: window-header-line-height &optional window
34364     This function returns the height in pixels of WINDOW’s header line.
34365     WINDOW must be a live window, and defaults to the selected window.
34366
34367   A window that is just one line tall never displays a header line.  A
34368window that is two lines tall cannot display both a mode line and a
34369header line at once; if it has a mode line, then it does not display a
34370header line.
34371
34372
34373File: elisp.info,  Node: Emulating Mode Line,  Prev: Header Lines,  Up: Mode Line Format
34374
3437523.4.8 Emulating Mode Line Formatting
34376-------------------------------------
34377
34378You can use the function ‘format-mode-line’ to compute the text that
34379would appear in a mode line or header line based on a certain mode line
34380construct.
34381
34382 -- Function: format-mode-line format &optional face window buffer
34383     This function formats a line of text according to FORMAT as if it
34384     were generating the mode line for WINDOW, but it also returns the
34385     text as a string.  The argument WINDOW defaults to the selected
34386     window.  If BUFFER is non-‘nil’, all the information used is taken
34387     from BUFFER; by default, it comes from WINDOW’s buffer.
34388
34389     The value string normally has text properties that correspond to
34390     the faces, keymaps, etc., that the mode line would have.  Any
34391     character for which no ‘face’ property is specified by FORMAT gets
34392     a default value determined by FACE.  If FACE is ‘t’, that stands
34393     for either ‘mode-line’ if WINDOW is selected, otherwise
34394     ‘mode-line-inactive’.  If FACE is ‘nil’ or omitted, that stands for
34395     the default face.  If FACE is an integer, the value returned by
34396     this function will have no text properties.
34397
34398     You can also specify other valid faces as the value of FACE.  If
34399     specified, that face provides the ‘face’ property for characters
34400     whose face is not specified by FORMAT.
34401
34402     Note that using ‘mode-line’, ‘mode-line-inactive’, or ‘header-line’
34403     as FACE will actually redisplay the mode line or the header line,
34404     respectively, using the current definitions of the corresponding
34405     face, in addition to returning the formatted string.  (Other faces
34406     do not cause redisplay.)
34407
34408     For example, ‘(format-mode-line header-line-format)’ returns the
34409     text that would appear in the selected window’s header line (‘""’
34410     if it has no header line).  ‘(format-mode-line header-line-format
34411     'header-line)’ returns the same text, with each character carrying
34412     the face that it will have in the header line itself, and also
34413     redraws the header line.
34414
34415
34416File: elisp.info,  Node: Imenu,  Next: Font Lock Mode,  Prev: Mode Line Format,  Up: Modes
34417
3441823.5 Imenu
34419==========
34420
34421“Imenu” is a feature that lets users select a definition or section in
34422the buffer, from a menu which lists all of them, to go directly to that
34423location in the buffer.  Imenu works by constructing a buffer index
34424which lists the names and buffer positions of the definitions, or other
34425named portions of the buffer; then the user can choose one of them and
34426move point to it.  Major modes can add a menu bar item to use Imenu
34427using ‘imenu-add-to-menubar’.
34428
34429 -- Command: imenu-add-to-menubar name
34430     This function defines a local menu bar item named NAME to run
34431     Imenu.
34432
34433   The user-level commands for using Imenu are described in the Emacs
34434Manual (*note Imenu: (emacs)Imenu.).  This section explains how to
34435customize Imenu’s method of finding definitions or buffer portions for a
34436particular major mode.
34437
34438   The usual and simplest way is to set the variable
34439‘imenu-generic-expression’:
34440
34441 -- Variable: imenu-generic-expression
34442     This variable, if non-‘nil’, is a list that specifies regular
34443     expressions for finding definitions for Imenu.  Simple elements of
34444     ‘imenu-generic-expression’ look like this:
34445
34446          (MENU-TITLE REGEXP INDEX)
34447
34448     Here, if MENU-TITLE is non-‘nil’, it says that the matches for this
34449     element should go in a submenu of the buffer index; MENU-TITLE
34450     itself specifies the name for the submenu.  If MENU-TITLE is ‘nil’,
34451     the matches for this element go directly in the top level of the
34452     buffer index.
34453
34454     The second item in the list, REGEXP, is a regular expression (*note
34455     Regular Expressions::); anything in the buffer that it matches is
34456     considered a definition, something to mention in the buffer index.
34457     The third item, INDEX, is a non-negative integer that indicates
34458     which subexpression in REGEXP matches the definition’s name.
34459
34460     An element can also look like this:
34461
34462          (MENU-TITLE REGEXP INDEX FUNCTION ARGUMENTS...)
34463
34464     Each match for this element creates an index item, and when the
34465     index item is selected by the user, it calls FUNCTION with
34466     arguments consisting of the item name, the buffer position, and
34467     ARGUMENTS.
34468
34469     For Emacs Lisp mode, ‘imenu-generic-expression’ could look like
34470     this:
34471
34472          ((nil "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\
34473          \\s-+\\([-A-Za-z0-9+]+\\)" 2)
34474           ("*Vars*" "^\\s-*(def\\(var\\|const\\)\
34475          \\s-+\\([-A-Za-z0-9+]+\\)" 2)
34476           ("*Types*"
34477            "^\\s-*\
34478          (def\\(type\\|struct\\|class\\|ine-condition\\)\
34479          \\s-+\\([-A-Za-z0-9+]+\\)" 2))
34480
34481     Setting this variable makes it buffer-local in the current buffer.
34482
34483 -- Variable: imenu-case-fold-search
34484     This variable controls whether matching against the regular
34485     expressions in the value of ‘imenu-generic-expression’ is
34486     case-sensitive: ‘t’, the default, means matching should ignore
34487     case.
34488
34489     Setting this variable makes it buffer-local in the current buffer.
34490
34491 -- Variable: imenu-syntax-alist
34492     This variable is an alist of syntax table modifiers to use while
34493     processing ‘imenu-generic-expression’, to override the syntax table
34494     of the current buffer.  Each element should have this form:
34495
34496          (CHARACTERS . SYNTAX-DESCRIPTION)
34497
34498     The CAR, CHARACTERS, can be either a character or a string.  The
34499     element says to give that character or characters the syntax
34500     specified by SYNTAX-DESCRIPTION, which is passed to
34501     ‘modify-syntax-entry’ (*note Syntax Table Functions::).
34502
34503     This feature is typically used to give word syntax to characters
34504     which normally have symbol syntax, and thus to simplify
34505     ‘imenu-generic-expression’ and speed up matching.  For example,
34506     Fortran mode uses it this way:
34507
34508          (setq imenu-syntax-alist '(("_$" . "w")))
34509
34510     The ‘imenu-generic-expression’ regular expressions can then use
34511     ‘\\sw+’ instead of ‘\\(\\sw\\|\\s_\\)+’.  Note that this technique
34512     may be inconvenient when the mode needs to limit the initial
34513     character of a name to a smaller set of characters than are allowed
34514     in the rest of a name.
34515
34516     Setting this variable makes it buffer-local in the current buffer.
34517
34518   Another way to customize Imenu for a major mode is to set the
34519variables ‘imenu-prev-index-position-function’ and
34520‘imenu-extract-index-name-function’:
34521
34522 -- Variable: imenu-prev-index-position-function
34523     If this variable is non-‘nil’, its value should be a function that
34524     finds the next definition to put in the buffer index, scanning
34525     backward in the buffer from point.  It should return ‘nil’ if it
34526     doesn’t find another definition before point.  Otherwise it should
34527     leave point at the place it finds a definition and return any
34528     non-‘nil’ value.
34529
34530     Setting this variable makes it buffer-local in the current buffer.
34531
34532 -- Variable: imenu-extract-index-name-function
34533     If this variable is non-‘nil’, its value should be a function to
34534     return the name for a definition, assuming point is in that
34535     definition as the ‘imenu-prev-index-position-function’ function
34536     would leave it.
34537
34538     Setting this variable makes it buffer-local in the current buffer.
34539
34540   The last way to customize Imenu for a major mode is to set the
34541variable ‘imenu-create-index-function’:
34542
34543 -- Variable: imenu-create-index-function
34544     This variable specifies the function to use for creating a buffer
34545     index.  The function should take no arguments, and return an index
34546     alist for the current buffer.  It is called within
34547     ‘save-excursion’, so where it leaves point makes no difference.
34548
34549     The index alist can have three types of elements.  Simple elements
34550     look like this:
34551
34552          (INDEX-NAME . INDEX-POSITION)
34553
34554     Selecting a simple element has the effect of moving to position
34555     INDEX-POSITION in the buffer.  Special elements look like this:
34556
34557          (INDEX-NAME INDEX-POSITION FUNCTION ARGUMENTS...)
34558
34559     Selecting a special element performs:
34560
34561          (funcall FUNCTION
34562                   INDEX-NAME INDEX-POSITION ARGUMENTS...)
34563
34564     A nested sub-alist element looks like this:
34565
34566          (MENU-TITLE . SUB-ALIST)
34567
34568     It creates the submenu MENU-TITLE specified by SUB-ALIST.
34569
34570     The default value of ‘imenu-create-index-function’ is
34571     ‘imenu-default-create-index-function’.  This function calls the
34572     value of ‘imenu-prev-index-position-function’ and the value of
34573     ‘imenu-extract-index-name-function’ to produce the index alist.
34574     However, if either of these two variables is ‘nil’, the default
34575     function uses ‘imenu-generic-expression’ instead.
34576
34577     Setting this variable makes it buffer-local in the current buffer.
34578
34579
34580File: elisp.info,  Node: Font Lock Mode,  Next: Auto-Indentation,  Prev: Imenu,  Up: Modes
34581
3458223.6 Font Lock Mode
34583===================
34584
34585“Font Lock mode” is a buffer-local minor mode that automatically
34586attaches ‘face’ properties to certain parts of the buffer based on their
34587syntactic role.  How it parses the buffer depends on the major mode;
34588most major modes define syntactic criteria for which faces to use in
34589which contexts.  This section explains how to customize Font Lock for a
34590particular major mode.
34591
34592   Font Lock mode finds text to highlight in two ways: through syntactic
34593parsing based on the syntax table, and through searching (usually for
34594regular expressions).  Syntactic fontification happens first; it finds
34595comments and string constants and highlights them.  Search-based
34596fontification happens second.
34597
34598* Menu:
34599
34600* Font Lock Basics::            Overview of customizing Font Lock.
34601* Search-based Fontification::  Fontification based on regexps.
34602* Customizing Keywords::        Customizing search-based fontification.
34603* Other Font Lock Variables::   Additional customization facilities.
34604* Levels of Font Lock::         Each mode can define alternative levels
34605                                  so that the user can select more or less.
34606* Precalculated Fontification::  How Lisp programs that produce the buffer
34607                                  contents can also specify how to fontify it.
34608* Faces for Font Lock::         Special faces specifically for Font Lock.
34609* Syntactic Font Lock::         Fontification based on syntax tables.
34610* Multiline Font Lock::         How to coerce Font Lock into properly
34611                                  highlighting multiline constructs.
34612
34613
34614File: elisp.info,  Node: Font Lock Basics,  Next: Search-based Fontification,  Up: Font Lock Mode
34615
3461623.6.1 Font Lock Basics
34617-----------------------
34618
34619The Font Lock functionality is based on several basic functions.  Each
34620of these calls the function specified by the corresponding variable.
34621This indirection allows major and minor modes to modify the way
34622fontification works in the buffers of that mode, and even use the Font
34623Lock mechanisms for features that have nothing to do with fontification.
34624(This is why the description below says “should” when it describes what
34625the functions do: the mode can customize the values of the corresponding
34626variables to do something entirely different.)  The variables mentioned
34627below are described in *note Other Font Lock Variables::.
34628
34629‘font-lock-fontify-buffer’
34630     This function should fontify the current buffer’s accessible
34631     portion, by calling the function specified by
34632     ‘font-lock-fontify-buffer-function’.
34633
34634‘font-lock-unfontify-buffer’
34635     Used when turning Font Lock off to remove the fontification.  Calls
34636     the function specified by ‘font-lock-unfontify-buffer-function’.
34637
34638‘font-lock-fontify-region beg end &optional loudly’
34639     Should fontify the region between BEG and END.  If LOUDLY is
34640     non-‘nil’, should display status messages while fontifying.  Calls
34641     the function specified by ‘font-lock-fontify-region-function’.
34642
34643‘font-lock-unfontify-region beg end’
34644     Should remove fontification from the region between BEG and END.
34645     Calls the function specified by
34646     ‘font-lock-unfontify-region-function’.
34647
34648‘font-lock-flush &optional beg end’
34649     This function should mark the fontification of the region between
34650     BEG and END as outdated.  If not specified or ‘nil’, BEG and END
34651     default to the beginning and end of the buffer’s accessible
34652     portion.  Calls the function specified by
34653     ‘font-lock-flush-function’.
34654
34655‘font-lock-ensure &optional beg end’
34656     This function should make sure the region between BEG and END has
34657     been fontified.  The optional arguments BEG and END default to the
34658     beginning and the end of the buffer’s accessible portion.  Calls
34659     the function specified by ‘font-lock-ensure-function’.
34660
34661‘font-lock-debug-fontify’
34662     This is a convenience command meant to be used when developing font
34663     locking for a mode, and should not be called from Lisp code.  It
34664     recomputes all the relevant variables and then calls
34665     ‘font-lock-fontify-region’ on the entire buffer.
34666
34667   There are several variables that control how Font Lock mode
34668highlights text.  But major modes should not set any of these variables
34669directly.  Instead, they should set ‘font-lock-defaults’ as a
34670buffer-local variable.  The value assigned to this variable is used, if
34671and when Font Lock mode is enabled, to set all the other variables.
34672
34673 -- Variable: font-lock-defaults
34674     This variable is set by modes to specify how to fontify text in
34675     that mode.  It automatically becomes buffer-local when set.  If its
34676     value is ‘nil’, Font Lock mode does no highlighting, and you can
34677     use the ‘Faces’ menu (under ‘Edit’ and then ‘Text Properties’ in
34678     the menu bar) to assign faces explicitly to text in the buffer.
34679
34680     If non-‘nil’, the value should look like this:
34681
34682          (KEYWORDS [KEYWORDS-ONLY [CASE-FOLD
34683           [SYNTAX-ALIST OTHER-VARS...]]])
34684
34685     The first element, KEYWORDS, indirectly specifies the value of
34686     ‘font-lock-keywords’ which directs search-based fontification.  It
34687     can be a symbol, a variable or a function whose value is the list
34688     to use for ‘font-lock-keywords’.  It can also be a list of several
34689     such symbols, one for each possible level of fontification.  The
34690     first symbol specifies the ‘mode default’ level of fontification,
34691     the next symbol level 1 fontification, the next level 2, and so on.
34692     The ‘mode default’ level is normally the same as level 1.  It is
34693     used when ‘font-lock-maximum-decoration’ has a ‘nil’ value.  *Note
34694     Levels of Font Lock::.
34695
34696     The second element, KEYWORDS-ONLY, specifies the value of the
34697     variable ‘font-lock-keywords-only’.  If this is omitted or ‘nil’,
34698     syntactic fontification (of strings and comments) is also
34699     performed.  If this is non-‘nil’, syntactic fontification is not
34700     performed.  *Note Syntactic Font Lock::.
34701
34702     The third element, CASE-FOLD, specifies the value of
34703     ‘font-lock-keywords-case-fold-search’.  If it is non-‘nil’, Font
34704     Lock mode ignores case during search-based fontification.
34705
34706     If the fourth element, SYNTAX-ALIST, is non-‘nil’, it should be a
34707     list of cons cells of the form ‘(CHAR-OR-STRING . STRING)’.  These
34708     are used to set up a syntax table for syntactic fontification; the
34709     resulting syntax table is stored in ‘font-lock-syntax-table’.  If
34710     SYNTAX-ALIST is omitted or ‘nil’, syntactic fontification uses the
34711     syntax table returned by the ‘syntax-table’ function.  *Note Syntax
34712     Table Functions::.
34713
34714     All the remaining elements (if any) are collectively called
34715     OTHER-VARS.  Each of these elements should have the form ‘(VARIABLE
34716     . VALUE)’—which means, make VARIABLE buffer-local and then set it
34717     to VALUE.  You can use these OTHER-VARS to set other variables that
34718     affect fontification, aside from those you can control with the
34719     first five elements.  *Note Other Font Lock Variables::.
34720
34721   If your mode fontifies text explicitly by adding ‘font-lock-face’
34722properties, it can specify ‘(nil t)’ for ‘font-lock-defaults’ to turn
34723off all automatic fontification.  However, this is not required; it is
34724possible to fontify some things using ‘font-lock-face’ properties and
34725set up automatic fontification for other parts of the text.
34726
34727
34728File: elisp.info,  Node: Search-based Fontification,  Next: Customizing Keywords,  Prev: Font Lock Basics,  Up: Font Lock Mode
34729
3473023.6.2 Search-based Fontification
34731---------------------------------
34732
34733The variable which directly controls search-based fontification is
34734‘font-lock-keywords’, which is typically specified via the KEYWORDS
34735element in ‘font-lock-defaults’.
34736
34737 -- Variable: font-lock-keywords
34738     The value of this variable is a list of the keywords to highlight.
34739     Lisp programs should not set this variable directly.  Normally, the
34740     value is automatically set by Font Lock mode, using the KEYWORDS
34741     element in ‘font-lock-defaults’.  The value can also be altered
34742     using the functions ‘font-lock-add-keywords’ and
34743     ‘font-lock-remove-keywords’ (*note Customizing Keywords::).
34744
34745   Each element of ‘font-lock-keywords’ specifies how to find certain
34746cases of text, and how to highlight those cases.  Font Lock mode
34747processes the elements of ‘font-lock-keywords’ one by one, and for each
34748element, it finds and handles all matches.  Ordinarily, once part of the
34749text has been fontified already, this cannot be overridden by a
34750subsequent match in the same text; but you can specify different
34751behavior using the OVERRIDE element of a SUBEXP-HIGHLIGHTER.
34752
34753   Each element of ‘font-lock-keywords’ should have one of these forms:
34754
34755‘REGEXP’
34756     Highlight all matches for REGEXP using ‘font-lock-keyword-face’.
34757     For example,
34758
34759          ;; Highlight occurrences of the word ‘foo’
34760          ;; using ‘font-lock-keyword-face’.
34761          "\\<foo\\>"
34762
34763     Be careful when composing these regular expressions; a poorly
34764     written pattern can dramatically slow things down!  The function
34765     ‘regexp-opt’ (*note Regexp Functions::) is useful for calculating
34766     optimal regular expressions to match several keywords.
34767
34768‘FUNCTION’
34769     Find text by calling FUNCTION, and highlight the matches it finds
34770     using ‘font-lock-keyword-face’.
34771
34772     When FUNCTION is called, it receives one argument, the limit of the
34773     search; it should begin searching at point, and not search beyond
34774     the limit.  It should return non-‘nil’ if it succeeds, and set the
34775     match data to describe the match that was found.  Returning ‘nil’
34776     indicates failure of the search.
34777
34778     Fontification will call FUNCTION repeatedly with the same limit,
34779     and with point where the previous invocation left it, until
34780     FUNCTION fails.  On failure, FUNCTION need not reset point in any
34781     particular way.
34782
34783‘(MATCHER . SUBEXP)’
34784     In this kind of element, MATCHER is either a regular expression or
34785     a function, as described above.  The CDR, SUBEXP, specifies which
34786     subexpression of MATCHER should be highlighted (instead of the
34787     entire text that MATCHER matched).
34788
34789          ;; Highlight the ‘bar’ in each occurrence of ‘fubar’,
34790          ;; using ‘font-lock-keyword-face’.
34791          ("fu\\(bar\\)" . 1)
34792
34793     If you use ‘regexp-opt’ to produce the regular expression MATCHER,
34794     you can use ‘regexp-opt-depth’ (*note Regexp Functions::) to
34795     calculate the value for SUBEXP.
34796
34797‘(MATCHER . FACESPEC)’
34798     In this kind of element, FACESPEC is an expression whose value
34799     specifies the face to use for highlighting.  In the simplest case,
34800     FACESPEC is a Lisp variable (a symbol) whose value is a face name.
34801
34802          ;; Highlight occurrences of ‘fubar’,
34803          ;; using the face which is the value of ‘fubar-face’.
34804          ("fubar" . fubar-face)
34805
34806     However, FACESPEC can also evaluate to a list of this form:
34807
34808          (face FACE PROP1 VAL1 PROP2 VAL2...)
34809
34810     to specify the face FACE and various additional text properties to
34811     put on the text that matches.  If you do this, be sure to add the
34812     other text property names that you set in this way to the value of
34813     ‘font-lock-extra-managed-props’ so that the properties will also be
34814     cleared out when they are no longer appropriate.  Alternatively,
34815     you can set the variable ‘font-lock-unfontify-region-function’ to a
34816     function that clears these properties.  *Note Other Font Lock
34817     Variables::.
34818
34819‘(MATCHER . SUBEXP-HIGHLIGHTER)’
34820     In this kind of element, SUBEXP-HIGHLIGHTER is a list which
34821     specifies how to highlight matches found by MATCHER.  It has the
34822     form:
34823
34824          (SUBEXP FACESPEC [OVERRIDE [LAXMATCH]])
34825
34826     The CAR, SUBEXP, is an integer specifying which subexpression of
34827     the match to fontify (0 means the entire matching text).  The
34828     second subelement, FACESPEC, is an expression whose value specifies
34829     the face, as described above.
34830
34831     The last two values in SUBEXP-HIGHLIGHTER, OVERRIDE and LAXMATCH,
34832     are optional flags.  If OVERRIDE is ‘t’, this element can override
34833     existing fontification made by previous elements of
34834     ‘font-lock-keywords’.  If it is ‘keep’, then each character is
34835     fontified if it has not been fontified already by some other
34836     element.  If it is ‘prepend’, the face specified by FACESPEC is
34837     added to the beginning of the ‘font-lock-face’ property.  If it is
34838     ‘append’, the face is added to the end of the ‘font-lock-face’
34839     property.
34840
34841     If LAXMATCH is non-‘nil’, it means there should be no error if
34842     there is no subexpression numbered SUBEXP in MATCHER.  Obviously,
34843     fontification of the subexpression numbered SUBEXP will not occur.
34844     However, fontification of other subexpressions (and other regexps)
34845     will continue.  If LAXMATCH is ‘nil’, and the specified
34846     subexpression is missing, then an error is signaled which
34847     terminates search-based fontification.
34848
34849     Here are some examples of elements of this kind, and what they do:
34850
34851          ;; Highlight occurrences of either ‘foo’ or ‘bar’, using
34852          ;; ‘foo-bar-face’, even if they have already been highlighted.
34853          ;; ‘foo-bar-face’ should be a variable whose value is a face.
34854          ("foo\\|bar" 0 foo-bar-face t)
34855
34856          ;; Highlight the first subexpression within each occurrence
34857          ;; that the function ‘fubar-match’ finds,
34858          ;; using the face which is the value of ‘fubar-face’.
34859          (fubar-match 1 fubar-face)
34860
34861‘(MATCHER . ANCHORED-HIGHLIGHTER)’
34862     In this kind of element, ANCHORED-HIGHLIGHTER specifies how to
34863     highlight text that follows a match found by MATCHER.  So a match
34864     found by MATCHER acts as the anchor for further searches specified
34865     by ANCHORED-HIGHLIGHTER.  ANCHORED-HIGHLIGHTER is a list of the
34866     following form:
34867
34868          (ANCHORED-MATCHER PRE-FORM POST-FORM
34869                                  SUBEXP-HIGHLIGHTERS...)
34870
34871     Here, ANCHORED-MATCHER, like MATCHER, is either a regular
34872     expression or a function.  After a match of MATCHER is found, point
34873     is at the end of the match.  Now, Font Lock evaluates the form
34874     PRE-FORM.  Then it searches for matches of ANCHORED-MATCHER and
34875     uses SUBEXP-HIGHLIGHTERS to highlight these.  A SUBEXP-HIGHLIGHTER
34876     is as described above.  Finally, Font Lock evaluates POST-FORM.
34877
34878     The forms PRE-FORM and POST-FORM can be used to initialize before,
34879     and cleanup after, ANCHORED-MATCHER is used.  Typically, PRE-FORM
34880     is used to move point to some position relative to the match of
34881     MATCHER, before starting with ANCHORED-MATCHER.  POST-FORM might be
34882     used to move back, before resuming with MATCHER.
34883
34884     After Font Lock evaluates PRE-FORM, it does not search for
34885     ANCHORED-MATCHER beyond the end of the line.  However, if PRE-FORM
34886     returns a buffer position that is greater than the position of
34887     point after PRE-FORM is evaluated, then the position returned by
34888     PRE-FORM is used as the limit of the search instead.  It is
34889     generally a bad idea to return a position greater than the end of
34890     the line; in other words, the ANCHORED-MATCHER search should not
34891     span lines.
34892
34893     For example,
34894
34895          ;; Highlight occurrences of the word ‘item’ following
34896          ;; an occurrence of the word ‘anchor’ (on the same line)
34897          ;; in the value of ‘item-face’.
34898          ("\\<anchor\\>" "\\<item\\>" nil nil (0 item-face))
34899
34900     Here, PRE-FORM and POST-FORM are ‘nil’.  Therefore searching for
34901     ‘item’ starts at the end of the match of ‘anchor’, and searching
34902     for subsequent instances of ‘anchor’ resumes from where searching
34903     for ‘item’ concluded.
34904
34905‘(MATCHER HIGHLIGHTERS...)’
34906     This sort of element specifies several HIGHLIGHTER lists for a
34907     single MATCHER.  A HIGHLIGHTER list can be of the type
34908     SUBEXP-HIGHLIGHTER or ANCHORED-HIGHLIGHTER as described above.
34909
34910     For example,
34911
34912          ;; Highlight occurrences of the word ‘anchor’ in the value
34913          ;; of ‘anchor-face’, and subsequent occurrences of the word
34914          ;; ‘item’ (on the same line) in the value of ‘item-face’.
34915          ("\\<anchor\\>" (0 anchor-face)
34916                          ("\\<item\\>" nil nil (0 item-face)))
34917
34918‘(eval . FORM)’
34919     Here FORM is an expression to be evaluated the first time this
34920     value of ‘font-lock-keywords’ is used in a buffer.  Its value
34921     should have one of the forms described in this table.
34922
34923   *Warning:* Do not design an element of ‘font-lock-keywords’ to match
34924text which spans lines; this does not work reliably.  For details, *note
34925Multiline Font Lock::.
34926
34927   You can use CASE-FOLD in ‘font-lock-defaults’ to specify the value of
34928‘font-lock-keywords-case-fold-search’ which says whether search-based
34929fontification should be case-insensitive.
34930
34931 -- Variable: font-lock-keywords-case-fold-search
34932     Non-‘nil’ means that regular expression matching for the sake of
34933     ‘font-lock-keywords’ should be case-insensitive.
34934
34935
34936File: elisp.info,  Node: Customizing Keywords,  Next: Other Font Lock Variables,  Prev: Search-based Fontification,  Up: Font Lock Mode
34937
3493823.6.3 Customizing Search-Based Fontification
34939---------------------------------------------
34940
34941You can use ‘font-lock-add-keywords’ to add additional search-based
34942fontification rules to a major mode, and ‘font-lock-remove-keywords’ to
34943remove rules.
34944
34945 -- Function: font-lock-add-keywords mode keywords &optional how
34946     This function adds highlighting KEYWORDS, for the current buffer or
34947     for major mode MODE.  The argument KEYWORDS should be a list with
34948     the same format as the variable ‘font-lock-keywords’.
34949
34950     If MODE is a symbol which is a major mode command name, such as
34951     ‘c-mode’, the effect is that enabling Font Lock mode in MODE will
34952     add KEYWORDS to ‘font-lock-keywords’.  Calling with a non-‘nil’
34953     value of MODE is correct only in your ‘~/.emacs’ file.
34954
34955     If MODE is ‘nil’, this function adds KEYWORDS to
34956     ‘font-lock-keywords’ in the current buffer.  This way of calling
34957     ‘font-lock-add-keywords’ is usually used in mode hook functions.
34958
34959     By default, KEYWORDS are added at the beginning of
34960     ‘font-lock-keywords’.  If the optional argument HOW is ‘set’, they
34961     are used to replace the value of ‘font-lock-keywords’.  If HOW is
34962     any other non-‘nil’ value, they are added at the end of
34963     ‘font-lock-keywords’.
34964
34965     Some modes provide specialized support you can use in additional
34966     highlighting patterns.  See the variables
34967     ‘c-font-lock-extra-types’, ‘c++-font-lock-extra-types’, and
34968     ‘java-font-lock-extra-types’, for example.
34969
34970     *Warning:* Major mode commands must not call
34971     ‘font-lock-add-keywords’ under any circumstances, either directly
34972     or indirectly, except through their mode hooks.  (Doing so would
34973     lead to incorrect behavior for some minor modes.)  They should set
34974     up their rules for search-based fontification by setting
34975     ‘font-lock-keywords’.
34976
34977 -- Function: font-lock-remove-keywords mode keywords
34978     This function removes KEYWORDS from ‘font-lock-keywords’ for the
34979     current buffer or for major mode MODE.  As in
34980     ‘font-lock-add-keywords’, MODE should be a major mode command name
34981     or ‘nil’.  All the caveats and requirements for
34982     ‘font-lock-add-keywords’ apply here too.  The argument KEYWORDS
34983     must exactly match the one used by the corresponding
34984     ‘font-lock-add-keywords’.
34985
34986   For example, the following code adds two fontification patterns for C
34987mode: one to fontify the word ‘FIXME’, even in comments, and another to
34988fontify the words ‘and’, ‘or’ and ‘not’ as keywords.
34989
34990     (font-lock-add-keywords 'c-mode
34991      '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
34992        ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face)))
34993
34994This example affects only C mode proper.  To add the same patterns to C
34995mode _and_ all modes derived from it, do this instead:
34996
34997     (add-hook 'c-mode-hook
34998      (lambda ()
34999       (font-lock-add-keywords nil
35000        '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
35001          ("\\<\\(and\\|or\\|not\\)\\>" .
35002           font-lock-keyword-face)))))
35003
35004
35005File: elisp.info,  Node: Other Font Lock Variables,  Next: Levels of Font Lock,  Prev: Customizing Keywords,  Up: Font Lock Mode
35006
3500723.6.4 Other Font Lock Variables
35008--------------------------------
35009
35010This section describes additional variables that a major mode can set by
35011means of OTHER-VARS in ‘font-lock-defaults’ (*note Font Lock Basics::).
35012
35013 -- Variable: font-lock-mark-block-function
35014     If this variable is non-‘nil’, it should be a function that is
35015     called with no arguments, to choose an enclosing range of text for
35016     refontification for the command ‘M-o M-o’
35017     (‘font-lock-fontify-block’).
35018
35019     The function should report its choice by placing the region around
35020     it.  A good choice is a range of text large enough to give proper
35021     results, but not too large so that refontification becomes slow.
35022     Typical values are ‘mark-defun’ for programming modes or
35023     ‘mark-paragraph’ for textual modes.
35024
35025 -- Variable: font-lock-extra-managed-props
35026     This variable specifies additional properties (other than
35027     ‘font-lock-face’) that are being managed by Font Lock mode.  It is
35028     used by ‘font-lock-default-unfontify-region’, which normally only
35029     manages the ‘font-lock-face’ property.  If you want Font Lock to
35030     manage other properties as well, you must specify them in a
35031     FACESPEC in ‘font-lock-keywords’ as well as add them to this list.
35032     *Note Search-based Fontification::.
35033
35034 -- Variable: font-lock-fontify-buffer-function
35035     Function to use for fontifying the buffer.  The default value is
35036     ‘font-lock-default-fontify-buffer’.
35037
35038 -- Variable: font-lock-unfontify-buffer-function
35039     Function to use for unfontifying the buffer.  This is used when
35040     turning off Font Lock mode.  The default value is
35041     ‘font-lock-default-unfontify-buffer’.
35042
35043 -- Variable: font-lock-fontify-region-function
35044     Function to use for fontifying a region.  It should take two
35045     arguments, the beginning and end of the region, and an optional
35046     third argument VERBOSE.  If VERBOSE is non-‘nil’, the function
35047     should print status messages.  The default value is
35048     ‘font-lock-default-fontify-region’.
35049
35050 -- Variable: font-lock-unfontify-region-function
35051     Function to use for unfontifying a region.  It should take two
35052     arguments, the beginning and end of the region.  The default value
35053     is ‘font-lock-default-unfontify-region’.
35054
35055 -- Variable: font-lock-flush-function
35056     Function to use for declaring that a region’s fontification is out
35057     of date.  It takes two arguments, the beginning and end of the
35058     region.  The default value of this variable is
35059     ‘font-lock-after-change-function’.
35060
35061 -- Variable: font-lock-ensure-function
35062     Function to use for making sure a region of the current buffer has
35063     been fontified.  It is called with two arguments, the beginning and
35064     end of the region.  The default value of this variable is a
35065     function that calls ‘font-lock-default-fontify-buffer’ if the
35066     buffer is not fontified; the effect is to make sure the entire
35067     accessible portion of the buffer is fontified.
35068
35069 -- Function: jit-lock-register function &optional contextual
35070     This function tells Font Lock mode to run the Lisp function
35071     FUNCTION any time it has to fontify or refontify part of the
35072     current buffer.  It calls FUNCTION before calling the default
35073     fontification functions, and gives it two arguments, START and END,
35074     which specify the region to be fontified or refontified.
35075
35076     The optional argument CONTEXTUAL, if non-‘nil’, forces Font Lock
35077     mode to always refontify a syntactically relevant part of the
35078     buffer, and not just the modified lines.  This argument can usually
35079     be omitted.
35080
35081     When Font Lock is activated in a buffer, it calls this function
35082     with a non-‘nil’ value of CONTEXTUAL if the value of
35083     ‘font-lock-keywords-only’ (*note Syntactic Font Lock::) is ‘nil’.
35084
35085 -- Function: jit-lock-unregister function
35086     If FUNCTION was previously registered as a fontification function
35087     using ‘jit-lock-register’, this function unregisters it.
35088
35089
35090File: elisp.info,  Node: Levels of Font Lock,  Next: Precalculated Fontification,  Prev: Other Font Lock Variables,  Up: Font Lock Mode
35091
3509223.6.5 Levels of Font Lock
35093--------------------------
35094
35095Some major modes offer three different levels of fontification.  You can
35096define multiple levels by using a list of symbols for KEYWORDS in
35097‘font-lock-defaults’.  Each symbol specifies one level of fontification;
35098it is up to the user to choose one of these levels, normally by setting
35099‘font-lock-maximum-decoration’ (*note (emacs)Font Lock::).  The chosen
35100level’s symbol value is used to initialize ‘font-lock-keywords’.
35101
35102   Here are the conventions for how to define the levels of
35103fontification:
35104
35105   • Level 1: highlight function declarations, file directives (such as
35106     include or import directives), strings and comments.  The idea is
35107     speed, so only the most important and top-level components are
35108     fontified.
35109
35110   • Level 2: in addition to level 1, highlight all language keywords,
35111     including type names that act like keywords, as well as named
35112     constant values.  The idea is that all keywords (either syntactic
35113     or semantic) should be fontified appropriately.
35114
35115   • Level 3: in addition to level 2, highlight the symbols being
35116     defined in function and variable declarations, and all builtin
35117     function names, wherever they appear.
35118
35119
35120File: elisp.info,  Node: Precalculated Fontification,  Next: Faces for Font Lock,  Prev: Levels of Font Lock,  Up: Font Lock Mode
35121
3512223.6.6 Precalculated Fontification
35123----------------------------------
35124
35125Some major modes such as ‘list-buffers’ and ‘occur’ construct the buffer
35126text programmatically.  The easiest way for them to support Font Lock
35127mode is to specify the faces of text when they insert the text in the
35128buffer.
35129
35130   The way to do this is to specify the faces in the text with the
35131special text property ‘font-lock-face’ (*note Special Properties::).
35132When Font Lock mode is enabled, this property controls the display, just
35133like the ‘face’ property.  When Font Lock mode is disabled,
35134‘font-lock-face’ has no effect on the display.
35135
35136   It is ok for a mode to use ‘font-lock-face’ for some text and also
35137use the normal Font Lock machinery.  But if the mode does not use the
35138normal Font Lock machinery, it should not set the variable
35139‘font-lock-defaults’.  In this case the ‘face’ property will not be
35140overridden, so using the ‘face’ property could work too.  However, using
35141‘font-lock-face’ is generally preferable as it allows the user to
35142control the fontification by toggling ‘font-lock-mode’, and lets the
35143code work regardless of whether the mode uses Font Lock machinery or
35144not.
35145
35146
35147File: elisp.info,  Node: Faces for Font Lock,  Next: Syntactic Font Lock,  Prev: Precalculated Fontification,  Up: Font Lock Mode
35148
3514923.6.7 Faces for Font Lock
35150--------------------------
35151
35152Font Lock mode can highlight using any face, but Emacs defines several
35153faces specifically for Font Lock to use to highlight text.  These “Font
35154Lock faces” are listed below.  They can also be used by major modes for
35155syntactic highlighting outside of Font Lock mode (*note Major Mode
35156Conventions::).
35157
35158   Each of these symbols is both a face name, and a variable whose
35159default value is the symbol itself.  Thus, the default value of
35160‘font-lock-comment-face’ is ‘font-lock-comment-face’.
35161
35162   The faces are listed with descriptions of their typical usage, and in
35163order of greater to lesser prominence.  If a mode’s syntactic categories
35164do not fit well with the usage descriptions, the faces can be assigned
35165using the ordering as a guide.
35166
35167‘font-lock-warning-face’
35168     for a construct that is peculiar (e.g., an unescaped confusable
35169     quote in an Emacs Lisp symbol like ‘‘foo’), or that greatly changes
35170     the meaning of other text, like ‘;;;###autoload’ in Emacs Lisp and
35171     ‘#error’ in C.
35172
35173‘font-lock-function-name-face’
35174     for the name of a function being defined or declared.
35175
35176‘font-lock-variable-name-face’
35177     for the name of a variable being defined or declared.
35178
35179‘font-lock-keyword-face’
35180     for a keyword with special syntactic significance, like ‘for’ and
35181     ‘if’ in C.
35182
35183‘font-lock-comment-face’
35184     for comments.
35185
35186‘font-lock-comment-delimiter-face’
35187     for comments delimiters, like ‘/*’ and ‘*/’ in C.  On most
35188     terminals, this inherits from ‘font-lock-comment-face’.
35189
35190‘font-lock-type-face’
35191     for the names of user-defined data types.
35192
35193‘font-lock-constant-face’
35194     for the names of constants, like ‘NULL’ in C.
35195
35196‘font-lock-builtin-face’
35197     for the names of built-in functions.
35198
35199‘font-lock-preprocessor-face’
35200     for preprocessor commands.  This inherits, by default, from
35201     ‘font-lock-builtin-face’.
35202
35203‘font-lock-string-face’
35204     for string constants.
35205
35206‘font-lock-doc-face’
35207     for documentation strings in the code.  This inherits, by default,
35208     from ‘font-lock-string-face’.
35209
35210‘font-lock-negation-char-face’
35211     for easily-overlooked negation characters.
35212
35213
35214File: elisp.info,  Node: Syntactic Font Lock,  Next: Multiline Font Lock,  Prev: Faces for Font Lock,  Up: Font Lock Mode
35215
3521623.6.8 Syntactic Font Lock
35217--------------------------
35218
35219Syntactic fontification uses a syntax table (*note Syntax Tables::) to
35220find and highlight syntactically relevant text.  If enabled, it runs
35221prior to search-based fontification.  The variable
35222‘font-lock-syntactic-face-function’, documented below, determines which
35223syntactic constructs to highlight.  There are several variables that
35224affect syntactic fontification; you should set them by means of
35225‘font-lock-defaults’ (*note Font Lock Basics::).
35226
35227   Whenever Font Lock mode performs syntactic fontification on a stretch
35228of text, it first calls the function specified by
35229‘syntax-propertize-function’.  Major modes can use this to apply
35230‘syntax-table’ text properties to override the buffer’s syntax table in
35231special cases.  *Note Syntax Properties::.
35232
35233 -- Variable: font-lock-keywords-only
35234     If the value of this variable is non-‘nil’, Font Lock does not do
35235     syntactic fontification, only search-based fontification based on
35236     ‘font-lock-keywords’.  It is normally set by Font Lock mode based
35237     on the KEYWORDS-ONLY element in ‘font-lock-defaults’.  If the value
35238     is ‘nil’, Font Lock will call ‘jit-lock-register’ (*note Other Font
35239     Lock Variables::) to set up for automatic refontification of buffer
35240     text following a modified line to reflect the new syntactic context
35241     due to the change.
35242
35243 -- Variable: font-lock-syntax-table
35244     This variable holds the syntax table to use for fontification of
35245     comments and strings.  It is normally set by Font Lock mode based
35246     on the SYNTAX-ALIST element in ‘font-lock-defaults’.  If this value
35247     is ‘nil’, syntactic fontification uses the buffer’s syntax table
35248     (the value returned by the function ‘syntax-table’; *note Syntax
35249     Table Functions::).
35250
35251 -- Variable: font-lock-syntactic-face-function
35252     If this variable is non-‘nil’, it should be a function to determine
35253     which face to use for a given syntactic element (a string or a
35254     comment).
35255
35256     The function is called with one argument, the parse state at point
35257     returned by ‘parse-partial-sexp’, and should return a face.  The
35258     default value returns ‘font-lock-comment-face’ for comments and
35259     ‘font-lock-string-face’ for strings (*note Faces for Font Lock::).
35260
35261     This variable is normally set through the “other” elements in
35262     ‘font-lock-defaults’:
35263
35264          (setq-local font-lock-defaults
35265                      `(,python-font-lock-keywords
35266                        nil nil nil nil
35267                        (font-lock-syntactic-face-function
35268                         . python-font-lock-syntactic-face-function)))
35269
35270
35271File: elisp.info,  Node: Multiline Font Lock,  Prev: Syntactic Font Lock,  Up: Font Lock Mode
35272
3527323.6.9 Multiline Font Lock Constructs
35274-------------------------------------
35275
35276Normally, elements of ‘font-lock-keywords’ should not match across
35277multiple lines; that doesn’t work reliably, because Font Lock usually
35278scans just part of the buffer, and it can miss a multi-line construct
35279that crosses the line boundary where the scan starts.  (The scan
35280normally starts at the beginning of a line.)
35281
35282   Making elements that match multiline constructs work properly has two
35283aspects: correct _identification_ and correct _rehighlighting_.  The
35284first means that Font Lock finds all multiline constructs.  The second
35285means that Font Lock will correctly rehighlight all the relevant text
35286when a multiline construct is changed—for example, if some of the text
35287that was previously part of a multiline construct ceases to be part of
35288it.  The two aspects are closely related, and often getting one of them
35289to work will appear to make the other also work.  However, for reliable
35290results you must attend explicitly to both aspects.
35291
35292   There are three ways to ensure correct identification of multiline
35293constructs:
35294
35295   • Add a function to ‘font-lock-extend-region-functions’ that does the
35296     _identification_ and extends the scan so that the scanned text
35297     never starts or ends in the middle of a multiline construct.
35298   • Use the ‘font-lock-fontify-region-function’ hook similarly to
35299     extend the scan so that the scanned text never starts or ends in
35300     the middle of a multiline construct.
35301   • Somehow identify the multiline construct right when it gets
35302     inserted into the buffer (or at any point after that but before
35303     font-lock tries to highlight it), and mark it with a
35304     ‘font-lock-multiline’ which will instruct font-lock not to start or
35305     end the scan in the middle of the construct.
35306
35307   There are three ways to do rehighlighting of multiline constructs:
35308
35309   • Place a ‘font-lock-multiline’ property on the construct.  This will
35310     rehighlight the whole construct if any part of it is changed.  In
35311     some cases you can do this automatically by setting the
35312     ‘font-lock-multiline’ variable, which see.
35313   • Make sure ‘jit-lock-contextually’ is set and rely on it doing its
35314     job.  This will only rehighlight the part of the construct that
35315     follows the actual change, and will do it after a short delay.
35316     This only works if the highlighting of the various parts of your
35317     multiline construct never depends on text in subsequent lines.
35318     Since ‘jit-lock-contextually’ is activated by default, this can be
35319     an attractive solution.
35320   • Place a ‘jit-lock-defer-multiline’ property on the construct.  This
35321     works only if ‘jit-lock-contextually’ is used, and with the same
35322     delay before rehighlighting, but like ‘font-lock-multiline’, it
35323     also handles the case where highlighting depends on subsequent
35324     lines.
35325
35326* Menu:
35327
35328* Font Lock Multiline::         Marking multiline chunks with a text property.
35329* Region to Refontify::         Controlling which region gets refontified
35330                                  after a buffer change.
35331
35332
35333File: elisp.info,  Node: Font Lock Multiline,  Next: Region to Refontify,  Up: Multiline Font Lock
35334
3533523.6.9.1 Font Lock Multiline
35336............................
35337
35338One way to ensure reliable rehighlighting of multiline Font Lock
35339constructs is to put on them the text property ‘font-lock-multiline’.
35340It should be present and non-‘nil’ for text that is part of a multiline
35341construct.
35342
35343   When Font Lock is about to highlight a range of text, it first
35344extends the boundaries of the range as necessary so that they do not
35345fall within text marked with the ‘font-lock-multiline’ property.  Then
35346it removes any ‘font-lock-multiline’ properties from the range, and
35347highlights it.  The highlighting specification (mostly
35348‘font-lock-keywords’) must reinstall this property each time, whenever
35349it is appropriate.
35350
35351   *Warning:* don’t use the ‘font-lock-multiline’ property on large
35352ranges of text, because that will make rehighlighting slow.
35353
35354 -- Variable: font-lock-multiline
35355     If the ‘font-lock-multiline’ variable is set to ‘t’, Font Lock will
35356     try to add the ‘font-lock-multiline’ property automatically on
35357     multiline constructs.  This is not a universal solution, however,
35358     since it slows down Font Lock somewhat.  It can miss some multiline
35359     constructs, or make the property larger or smaller than necessary.
35360
35361     For elements whose MATCHER is a function, the function should
35362     ensure that submatch 0 covers the whole relevant multiline
35363     construct, even if only a small subpart will be highlighted.  It is
35364     often just as easy to add the ‘font-lock-multiline’ property by
35365     hand.
35366
35367   The ‘font-lock-multiline’ property is meant to ensure proper
35368refontification; it does not automatically identify new multiline
35369constructs.  Identifying them requires that Font Lock mode operate on
35370large enough chunks at a time.  This will happen by accident on many
35371cases, which may give the impression that multiline constructs magically
35372work.  If you set the ‘font-lock-multiline’ variable non-‘nil’, this
35373impression will be even stronger, since the highlighting of those
35374constructs which are found will be properly updated from then on.  But
35375that does not work reliably.
35376
35377   To find multiline constructs reliably, you must either manually place
35378the ‘font-lock-multiline’ property on the text before Font Lock mode
35379looks at it, or use ‘font-lock-fontify-region-function’.
35380
35381
35382File: elisp.info,  Node: Region to Refontify,  Prev: Font Lock Multiline,  Up: Multiline Font Lock
35383
3538423.6.9.2 Region to Fontify after a Buffer Change
35385................................................
35386
35387When a buffer is changed, the region that Font Lock refontifies is by
35388default the smallest sequence of whole lines that spans the change.
35389While this works well most of the time, sometimes it doesn’t—for
35390example, when a change alters the syntactic meaning of text on an
35391earlier line.
35392
35393   You can enlarge (or even reduce) the region to refontify by setting
35394the following variable:
35395
35396 -- Variable: font-lock-extend-after-change-region-function
35397     This buffer-local variable is either ‘nil’ or a function for Font
35398     Lock mode to call to determine the region to scan and fontify.
35399
35400     The function is given three parameters, the standard BEG, END, and
35401     OLD-LEN from ‘after-change-functions’ (*note Change Hooks::).  It
35402     should return either a cons of the beginning and end buffer
35403     positions (in that order) of the region to fontify, or ‘nil’ (which
35404     means choose the region in the standard way).  This function needs
35405     to preserve point, the match-data, and the current restriction.
35406     The region it returns may start or end in the middle of a line.
35407
35408     Since this function is called after every buffer change, it should
35409     be reasonably fast.
35410
35411
35412File: elisp.info,  Node: Auto-Indentation,  Next: Desktop Save Mode,  Prev: Font Lock Mode,  Up: Modes
35413
3541423.7 Automatic Indentation of code
35415==================================
35416
35417For programming languages, an important feature of a major mode is to
35418provide automatic indentation.  There are two parts: one is to decide
35419what is the right indentation of a line, and the other is to decide when
35420to reindent a line.  By default, Emacs reindents a line whenever you
35421type a character in ‘electric-indent-chars’, which by default only
35422includes Newline.  Major modes can add chars to ‘electric-indent-chars’
35423according to the syntax of the language.
35424
35425   Deciding what is the right indentation is controlled in Emacs by
35426‘indent-line-function’ (*note Mode-Specific Indent::).  For some modes,
35427the _right_ indentation cannot be known reliably, typically because
35428indentation is significant so several indentations are valid but with
35429different meanings.  In that case, the mode should set
35430‘electric-indent-inhibit’ to make sure the line is not constantly
35431re-indented against the user’s wishes.
35432
35433   Writing a good indentation function can be difficult and to a large
35434extent it is still a black art.  Many major mode authors will start by
35435writing a simple indentation function that works for simple cases, for
35436example by comparing with the indentation of the previous text line.
35437For most programming languages that are not really line-based, this
35438tends to scale very poorly: improving such a function to let it handle
35439more diverse situations tends to become more and more difficult,
35440resulting in the end with a large, complex, unmaintainable indentation
35441function which nobody dares to touch.
35442
35443   A good indentation function will usually need to actually parse the
35444text, according to the syntax of the language.  Luckily, it is not
35445necessary to parse the text in as much detail as would be needed for a
35446compiler, but on the other hand, the parser embedded in the indentation
35447code will want to be somewhat friendly to syntactically incorrect code.
35448
35449   Good maintainable indentation functions usually fall into two
35450categories: either parsing forward from some safe starting point until
35451the position of interest, or parsing backward from the position of
35452interest.  Neither of the two is a clearly better choice than the other:
35453parsing backward is often more difficult than parsing forward because
35454programming languages are designed to be parsed forward, but for the
35455purpose of indentation it has the advantage of not needing to guess a
35456safe starting point, and it generally enjoys the property that only a
35457minimum of text will be analyzed to decide the indentation of a line, so
35458indentation will tend to be less affected by syntax errors in some
35459earlier unrelated piece of code.  Parsing forward on the other hand is
35460usually easier and has the advantage of making it possible to reindent
35461efficiently a whole region at a time, with a single parse.
35462
35463   Rather than write your own indentation function from scratch, it is
35464often preferable to try and reuse some existing ones or to rely on a
35465generic indentation engine.  There are sadly few such engines.  The
35466CC-mode indentation code (used with C, C++, Java, Awk and a few other
35467such modes) has been made more generic over the years, so if your
35468language seems somewhat similar to one of those languages, you might try
35469to use that engine.  Another one is SMIE which takes an approach in the
35470spirit of Lisp sexps and adapts it to non-Lisp languages.
35471
35472* Menu:
35473
35474* SMIE::                        A simple minded indentation engine.
35475
35476
35477File: elisp.info,  Node: SMIE,  Up: Auto-Indentation
35478
3547923.7.1 Simple Minded Indentation Engine
35480---------------------------------------
35481
35482SMIE is a package that provides a generic navigation and indentation
35483engine.  Based on a very simple parser using an operator precedence
35484grammar, it lets major modes extend the sexp-based navigation of Lisp to
35485non-Lisp languages as well as provide a simple to use but reliable
35486auto-indentation.
35487
35488   Operator precedence grammar is a very primitive technology for
35489parsing compared to some of the more common techniques used in
35490compilers.  It has the following characteristics: its parsing power is
35491very limited, and it is largely unable to detect syntax errors, but it
35492has the advantage of being algorithmically efficient and able to parse
35493forward just as well as backward.  In practice that means that SMIE can
35494use it for indentation based on backward parsing, that it can provide
35495both ‘forward-sexp’ and ‘backward-sexp’ functionality, and that it will
35496naturally work on syntactically incorrect code without any extra effort.
35497The downside is that it also means that most programming languages
35498cannot be parsed correctly using SMIE, at least not without resorting to
35499some special tricks (*note SMIE Tricks::).
35500
35501* Menu:
35502
35503* SMIE setup::                  SMIE setup and features.
35504* Operator Precedence Grammars::  A very simple parsing technique.
35505* SMIE Grammar::                Defining the grammar of a language.
35506* SMIE Lexer::                  Defining tokens.
35507* SMIE Tricks::                 Working around the parser’s limitations.
35508* SMIE Indentation::            Specifying indentation rules.
35509* SMIE Indentation Helpers::    Helper functions for indentation rules.
35510* SMIE Indentation Example::    Sample indentation rules.
35511* SMIE Customization::          Customizing indentation.
35512
35513
35514File: elisp.info,  Node: SMIE setup,  Next: Operator Precedence Grammars,  Up: SMIE
35515
3551623.7.1.1 SMIE Setup and Features
35517................................
35518
35519SMIE is meant to be a one-stop shop for structural navigation and
35520various other features which rely on the syntactic structure of code, in
35521particular automatic indentation.  The main entry point is ‘smie-setup’
35522which is a function typically called while setting up a major mode.
35523
35524 -- Function: smie-setup grammar rules-function &rest keywords
35525     Setup SMIE navigation and indentation.  GRAMMAR is a grammar table
35526     generated by ‘smie-prec2->grammar’.  RULES-FUNCTION is a set of
35527     indentation rules for use on ‘smie-rules-function’.  KEYWORDS are
35528     additional arguments, which can include the following keywords:
35529        • ‘:forward-token’ FUN: Specify the forward lexer to use.
35530        • ‘:backward-token’ FUN: Specify the backward lexer to use.
35531
35532   Calling this function is sufficient to make commands such as
35533‘forward-sexp’, ‘backward-sexp’, and ‘transpose-sexps’ be able to
35534properly handle structural elements other than just the paired
35535parentheses already handled by syntax tables.  For example, if the
35536provided grammar is precise enough, ‘transpose-sexps’ can correctly
35537transpose the two arguments of a ‘+’ operator, taking into account the
35538precedence rules of the language.
35539
35540   Calling ‘smie-setup’ is also sufficient to make <TAB> indentation
35541work in the expected way, extends ‘blink-matching-paren’ to apply to
35542elements like ‘begin...end’, and provides some commands that you can
35543bind in the major mode keymap.
35544
35545 -- Command: smie-close-block
35546     This command closes the most recently opened (and not yet closed)
35547     block.
35548
35549 -- Command: smie-down-list &optional arg
35550     This command is like ‘down-list’ but it also pays attention to
35551     nesting of tokens other than parentheses, such as ‘begin...end’.
35552
35553
35554File: elisp.info,  Node: Operator Precedence Grammars,  Next: SMIE Grammar,  Prev: SMIE setup,  Up: SMIE
35555
3555623.7.1.2 Operator Precedence Grammars
35557.....................................
35558
35559SMIE’s precedence grammars simply give to each token a pair of
35560precedences: the left-precedence and the right-precedence.  We say ‘T1 <
35561T2’ if the right-precedence of token ‘T1’ is less than the
35562left-precedence of token ‘T2’.  A good way to read this ‘<’ is as a kind
35563of parenthesis: if we find ‘... T1 something T2 ...’ then that should be
35564parsed as ‘... T1 (something T2 ...’ rather than as ‘... T1 something)
35565T2 ...’.  The latter interpretation would be the case if we had ‘T1 >
35566T2’.  If we have ‘T1 = T2’, it means that token T2 follows token T1 in
35567the same syntactic construction, so typically we have ‘"begin" = "end"’.
35568Such pairs of precedences are sufficient to express left-associativity
35569or right-associativity of infix operators, nesting of tokens like
35570parentheses and many other cases.
35571
35572 -- Function: smie-prec2->grammar table
35573     This function takes a _prec2_ grammar TABLE and returns an alist
35574     suitable for use in ‘smie-setup’.  The _prec2_ TABLE is itself
35575     meant to be built by one of the functions below.
35576
35577 -- Function: smie-merge-prec2s &rest tables
35578     This function takes several _prec2_ TABLES and merges them into a
35579     new _prec2_ table.
35580
35581 -- Function: smie-precs->prec2 precs
35582     This function builds a _prec2_ table from a table of precedences
35583     PRECS.  PRECS should be a list, sorted by precedence (for example
35584     ‘"+"’ will come before ‘"*"’), of elements of the form ‘(ASSOC OP
35585     ...)’, where each OP is a token that acts as an operator; ASSOC is
35586     their associativity, which can be either ‘left’, ‘right’, ‘assoc’,
35587     or ‘nonassoc’.  All operators in a given element share the same
35588     precedence level and associativity.
35589
35590 -- Function: smie-bnf->prec2 bnf &rest resolvers
35591     This function lets you specify the grammar using a BNF notation.
35592     It accepts a BNF description of the grammar along with a set of
35593     conflict resolution rules RESOLVERS, and returns a _prec2_ table.
35594
35595     BNF is a list of nonterminal definitions of the form ‘(NONTERM RHS1
35596     RHS2 ...)’ where each RHS is a (non-empty) list of terminals (aka
35597     tokens) or non-terminals.
35598
35599     Not all grammars are accepted:
35600        • An RHS cannot be an empty list (an empty list is never needed,
35601          since SMIE allows all non-terminals to match the empty string
35602          anyway).
35603        • An RHS cannot have 2 consecutive non-terminals: each pair of
35604          non-terminals needs to be separated by a terminal (aka token).
35605          This is a fundamental limitation of operator precedence
35606          grammars.
35607
35608     Additionally, conflicts can occur:
35609        • The returned _prec2_ table holds constraints between pairs of
35610          tokens, and for any given pair only one constraint can be
35611          present: T1 < T2, T1 = T2, or T1 > T2.
35612        • A token can be an ‘opener’ (something similar to an
35613          open-paren), a ‘closer’ (like a close-paren), or ‘neither’ of
35614          the two (e.g., an infix operator, or an inner token like
35615          ‘"else"’).
35616
35617     Precedence conflicts can be resolved via RESOLVERS, which is a list
35618     of _precs_ tables (see ‘smie-precs->prec2’): for each precedence
35619     conflict, if those ‘precs’ tables specify a particular constraint,
35620     then the conflict is resolved by using this constraint instead,
35621     else a conflict is reported and one of the conflicting constraints
35622     is picked arbitrarily and the others are simply ignored.
35623
35624
35625File: elisp.info,  Node: SMIE Grammar,  Next: SMIE Lexer,  Prev: Operator Precedence Grammars,  Up: SMIE
35626
3562723.7.1.3 Defining the Grammar of a Language
35628...........................................
35629
35630The usual way to define the SMIE grammar of a language is by defining a
35631new global variable that holds the precedence table by giving a set of
35632BNF rules.  For example, the grammar definition for a small Pascal-like
35633language could look like:
35634     (require 'smie)
35635     (defvar sample-smie-grammar
35636       (smie-prec2->grammar
35637        (smie-bnf->prec2
35638         '((id)
35639           (inst ("begin" insts "end")
35640                 ("if" exp "then" inst "else" inst)
35641                 (id ":=" exp)
35642                 (exp))
35643           (insts (insts ";" insts) (inst))
35644           (exp (exp "+" exp)
35645                (exp "*" exp)
35646                ("(" exps ")"))
35647           (exps (exps "," exps) (exp)))
35648         '((assoc ";"))
35649         '((assoc ","))
35650         '((assoc "+") (assoc "*")))))
35651
35652A few things to note:
35653
35654   • The above grammar does not explicitly mention the syntax of
35655     function calls: SMIE will automatically allow any sequence of
35656     sexps, such as identifiers, balanced parentheses, or ‘begin ...
35657     end’ blocks to appear anywhere anyway.
35658   • The grammar category ‘id’ has no right hand side: this does not
35659     mean that it can match only the empty string, since as mentioned
35660     any sequence of sexps can appear anywhere anyway.
35661   • Because non terminals cannot appear consecutively in the BNF
35662     grammar, it is difficult to correctly handle tokens that act as
35663     terminators, so the above grammar treats ‘";"’ as a statement
35664     _separator_ instead, which SMIE can handle very well.
35665   • Separators used in sequences (such as ‘","’ and ‘";"’ above) are
35666     best defined with BNF rules such as ‘(foo (foo "separator" foo)
35667     ...)’ which generate precedence conflicts which are then resolved
35668     by giving them an explicit ‘(assoc "separator")’.
35669   • The ‘("(" exps ")")’ rule was not needed to pair up parens, since
35670     SMIE will pair up any characters that are marked as having paren
35671     syntax in the syntax table.  What this rule does instead (together
35672     with the definition of ‘exps’) is to make it clear that ‘","’
35673     should not appear outside of parentheses.
35674   • Rather than have a single _precs_ table to resolve conflicts, it is
35675     preferable to have several tables, so as to let the BNF part of the
35676     grammar specify relative precedences where possible.
35677   • Unless there is a very good reason to prefer ‘left’ or ‘right’, it
35678     is usually preferable to mark operators as associative, using
35679     ‘assoc’.  For that reason ‘"+"’ and ‘"*"’ are defined above as
35680     ‘assoc’, although the language defines them formally as left
35681     associative.
35682
35683
35684File: elisp.info,  Node: SMIE Lexer,  Next: SMIE Tricks,  Prev: SMIE Grammar,  Up: SMIE
35685
3568623.7.1.4 Defining Tokens
35687........................
35688
35689SMIE comes with a predefined lexical analyzer which uses syntax tables
35690in the following way: any sequence of characters that have word or
35691symbol syntax is considered a token, and so is any sequence of
35692characters that have punctuation syntax.  This default lexer is often a
35693good starting point but is rarely actually correct for any given
35694language.  For example, it will consider ‘"2,+3"’ to be composed of 3
35695tokens: ‘"2"’, ‘",+"’, and ‘"3"’.
35696
35697   To describe the lexing rules of your language to SMIE, you need 2
35698functions, one to fetch the next token, and another to fetch the
35699previous token.  Those functions will usually first skip whitespace and
35700comments and then look at the next chunk of text to see if it is a
35701special token.  If so it should skip the token and return a description
35702of this token.  Usually this is simply the string extracted from the
35703buffer, but it can be anything you want.  For example:
35704     (defvar sample-keywords-regexp
35705       (regexp-opt '("+" "*" "," ";" ">" ">=" "<" "<=" ":=" "=")))
35706     (defun sample-smie-forward-token ()
35707       (forward-comment (point-max))
35708       (cond
35709        ((looking-at sample-keywords-regexp)
35710         (goto-char (match-end 0))
35711         (match-string-no-properties 0))
35712        (t (buffer-substring-no-properties
35713            (point)
35714            (progn (skip-syntax-forward "w_")
35715                   (point))))))
35716     (defun sample-smie-backward-token ()
35717       (forward-comment (- (point)))
35718       (cond
35719        ((looking-back sample-keywords-regexp (- (point) 2) t)
35720         (goto-char (match-beginning 0))
35721         (match-string-no-properties 0))
35722        (t (buffer-substring-no-properties
35723            (point)
35724            (progn (skip-syntax-backward "w_")
35725                   (point))))))
35726
35727   Notice how those lexers return the empty string when in front of
35728parentheses.  This is because SMIE automatically takes care of the
35729parentheses defined in the syntax table.  More specifically if the lexer
35730returns ‘nil’ or an empty string, SMIE tries to handle the corresponding
35731text as a sexp according to syntax tables.
35732
35733
35734File: elisp.info,  Node: SMIE Tricks,  Next: SMIE Indentation,  Prev: SMIE Lexer,  Up: SMIE
35735
3573623.7.1.5 Living With a Weak Parser
35737..................................
35738
35739The parsing technique used by SMIE does not allow tokens to behave
35740differently in different contexts.  For most programming languages, this
35741manifests itself by precedence conflicts when converting the BNF
35742grammar.
35743
35744   Sometimes, those conflicts can be worked around by expressing the
35745grammar slightly differently.  For example, for Modula-2 it might seem
35746natural to have a BNF grammar that looks like this:
35747
35748       ...
35749       (inst ("IF" exp "THEN" insts "ELSE" insts "END")
35750             ("CASE" exp "OF" cases "END")
35751             ...)
35752       (cases (cases "|" cases)
35753              (caselabel ":" insts)
35754              ("ELSE" insts))
35755       ...
35756
35757   But this will create conflicts for ‘"ELSE"’: on the one hand, the IF
35758rule implies (among many other things) that ‘"ELSE" = "END"’; but on the
35759other hand, since ‘"ELSE"’ appears within ‘cases’, which appears left of
35760‘"END"’, we also have ‘"ELSE" > "END"’.  We can solve the conflict
35761either by using:
35762       ...
35763       (inst ("IF" exp "THEN" insts "ELSE" insts "END")
35764             ("CASE" exp "OF" cases "END")
35765             ("CASE" exp "OF" cases "ELSE" insts "END")
35766             ...)
35767       (cases (cases "|" cases) (caselabel ":" insts))
35768       ...
35769   or
35770       ...
35771       (inst ("IF" exp "THEN" else "END")
35772             ("CASE" exp "OF" cases "END")
35773             ...)
35774       (else (insts "ELSE" insts))
35775       (cases (cases "|" cases) (caselabel ":" insts) (else))
35776       ...
35777
35778   Reworking the grammar to try and solve conflicts has its downsides,
35779tho, because SMIE assumes that the grammar reflects the logical
35780structure of the code, so it is preferable to keep the BNF closer to the
35781intended abstract syntax tree.
35782
35783   Other times, after careful consideration you may conclude that those
35784conflicts are not serious and simply resolve them via the RESOLVERS
35785argument of ‘smie-bnf->prec2’.  Usually this is because the grammar is
35786simply ambiguous: the conflict does not affect the set of programs
35787described by the grammar, but only the way those programs are parsed.
35788This is typically the case for separators and associative infix
35789operators, where you want to add a resolver like ‘'((assoc "|"))’.
35790Another case where this can happen is for the classic _dangling else_
35791problem, where you will use ‘'((assoc "else" "then"))’.  It can also
35792happen for cases where the conflict is real and cannot really be
35793resolved, but it is unlikely to pose a problem in practice.
35794
35795   Finally, in many cases some conflicts will remain despite all efforts
35796to restructure the grammar.  Do not despair: while the parser cannot be
35797made more clever, you can make the lexer as smart as you want.  So, the
35798solution is then to look at the tokens involved in the conflict and to
35799split one of those tokens into 2 (or more) different tokens.  E.g., if
35800the grammar needs to distinguish between two incompatible uses of the
35801token ‘"begin"’, make the lexer return different tokens (say
35802‘"begin-fun"’ and ‘"begin-plain"’) depending on which kind of ‘"begin"’
35803it finds.  This pushes the work of distinguishing the different cases to
35804the lexer, which will thus have to look at the surrounding text to find
35805ad-hoc clues.
35806
35807
35808File: elisp.info,  Node: SMIE Indentation,  Next: SMIE Indentation Helpers,  Prev: SMIE Tricks,  Up: SMIE
35809
3581023.7.1.6 Specifying Indentation Rules
35811.....................................
35812
35813Based on the provided grammar, SMIE will be able to provide automatic
35814indentation without any extra effort.  But in practice, this default
35815indentation style will probably not be good enough.  You will want to
35816tweak it in many different cases.
35817
35818   SMIE indentation is based on the idea that indentation rules should
35819be as local as possible.  To this end, it relies on the idea of
35820_virtual_ indentation, which is the indentation that a particular
35821program point would have if it were at the beginning of a line.  Of
35822course, if that program point is indeed at the beginning of a line, its
35823virtual indentation is its current indentation.  But if not, then SMIE
35824uses the indentation algorithm to compute the virtual indentation of
35825that point.  Now in practice, the virtual indentation of a program point
35826does not have to be identical to the indentation it would have if we
35827inserted a newline before it.  To see how this works, the SMIE rule for
35828indentation after a ‘{’ in C does not care whether the ‘{’ is standing
35829on a line of its own or is at the end of the preceding line.  Instead,
35830these different cases are handled in the indentation rule that decides
35831how to indent before a ‘{’.
35832
35833   Another important concept is the notion of _parent_: The _parent_ of
35834a token, is the head token of the nearest enclosing syntactic construct.
35835For example, the parent of an ‘else’ is the ‘if’ to which it belongs,
35836and the parent of an ‘if’, in turn, is the lead token of the surrounding
35837construct.  The command ‘backward-sexp’ jumps from a token to its
35838parent, but there are some caveats: for _openers_ (tokens which start a
35839construct, like ‘if’), you need to start with point before the token,
35840while for others you need to start with point after the token.
35841‘backward-sexp’ stops with point before the parent token if that is the
35842_opener_ of the token of interest, and otherwise it stops with point
35843after the parent token.
35844
35845   SMIE indentation rules are specified using a function that takes two
35846arguments METHOD and ARG where the meaning of ARG and the expected
35847return value depend on METHOD.
35848
35849   METHOD can be:
35850   • ‘:after’, in which case ARG is a token and the function should
35851     return the OFFSET to use for indentation after ARG.
35852   • ‘:before’, in which case ARG is a token and the function should
35853     return the OFFSET to use to indent ARG itself.
35854   • ‘:elem’, in which case the function should return either the offset
35855     to use to indent function arguments (if ARG is the symbol ‘arg’) or
35856     the basic indentation step (if ARG is the symbol ‘basic’).
35857   • ‘:list-intro’, in which case ARG is a token and the function should
35858     return non-‘nil’ if the token is followed by a list of expressions
35859     (not separated by any token) rather than an expression.
35860
35861   When ARG is a token, the function is called with point just before
35862that token.  A return value of ‘nil’ always means to fallback on the
35863default behavior, so the function should return ‘nil’ for arguments it
35864does not expect.
35865
35866   OFFSET can be:
35867   • ‘nil’: use the default indentation rule.
35868   • ‘(column . COLUMN)’: indent to column COLUMN.
35869   • NUMBER: offset by NUMBER, relative to a base token which is the
35870     current token for ‘:after’ and its parent for ‘:before’.
35871
35872
35873File: elisp.info,  Node: SMIE Indentation Helpers,  Next: SMIE Indentation Example,  Prev: SMIE Indentation,  Up: SMIE
35874
3587523.7.1.7 Helper Functions for Indentation Rules
35876...............................................
35877
35878SMIE provides various functions designed specifically for use in the
35879indentation rules function (several of those functions break if used in
35880another context).  These functions all start with the prefix
35881‘smie-rule-’.
35882
35883 -- Function: smie-rule-bolp
35884     Return non-‘nil’ if the current token is the first on the line.
35885
35886 -- Function: smie-rule-hanging-p
35887     Return non-‘nil’ if the current token is _hanging_.  A token is
35888     _hanging_ if it is the last token on the line and if it is preceded
35889     by other tokens: a lone token on a line is not hanging.
35890
35891 -- Function: smie-rule-next-p &rest tokens
35892     Return non-‘nil’ if the next token is among TOKENS.
35893
35894 -- Function: smie-rule-prev-p &rest tokens
35895     Return non-‘nil’ if the previous token is among TOKENS.
35896
35897 -- Function: smie-rule-parent-p &rest parents
35898     Return non-‘nil’ if the current token’s parent is among PARENTS.
35899
35900 -- Function: smie-rule-sibling-p
35901     Return non-‘nil’ if the current token’s parent is actually a
35902     sibling.  This is the case for example when the parent of a ‘","’
35903     is just the previous ‘","’.
35904
35905 -- Function: smie-rule-parent &optional offset
35906     Return the proper offset to align the current token with the
35907     parent.  If non-‘nil’, OFFSET should be an integer giving an
35908     additional offset to apply.
35909
35910 -- Function: smie-rule-separator method
35911     Indent current token as a _separator_.
35912
35913     By _separator_, we mean here a token whose sole purpose is to
35914     separate various elements within some enclosing syntactic
35915     construct, and which does not have any semantic significance in
35916     itself (i.e., it would typically not exist as a node in an abstract
35917     syntax tree).
35918
35919     Such a token is expected to have an associative syntax and be
35920     closely tied to its syntactic parent.  Typical examples are ‘","’
35921     in lists of arguments (enclosed inside parentheses), or ‘";"’ in
35922     sequences of instructions (enclosed in a ‘{...}’ or ‘begin...end35923     block).
35924
35925     METHOD should be the method name that was passed to
35926     ‘smie-rules-function’.
35927
35928
35929File: elisp.info,  Node: SMIE Indentation Example,  Next: SMIE Customization,  Prev: SMIE Indentation Helpers,  Up: SMIE
35930
3593123.7.1.8 Sample Indentation Rules
35932.................................
35933
35934Here is an example of an indentation function:
35935
35936     (defun sample-smie-rules (kind token)
35937       (pcase (cons kind token)
35938         (`(:elem . basic) sample-indent-basic)
35939         (`(,_ . ",") (smie-rule-separator kind))
35940         (`(:after . ":=") sample-indent-basic)
35941         (`(:before . ,(or `"begin" `"(" `"{"))
35942          (if (smie-rule-hanging-p) (smie-rule-parent)))
35943         (`(:before . "if")
35944          (and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
35945               (smie-rule-parent)))))
35946
35947A few things to note:
35948
35949   • The first case indicates the basic indentation increment to use.
35950     If ‘sample-indent-basic’ is ‘nil’, then SMIE uses the global
35951     setting ‘smie-indent-basic’.  The major mode could have set
35952     ‘smie-indent-basic’ buffer-locally instead, but that is
35953     discouraged.
35954
35955   • The rule for the token ‘","’ make SMIE try to be more clever when
35956     the comma separator is placed at the beginning of lines.  It tries
35957     to outdent the separator so as to align the code after the comma;
35958     for example:
35959
35960          x = longfunctionname (
35961                  arg1
35962                , arg2
35963              );
35964
35965   • The rule for indentation after ‘":="’ exists because otherwise SMIE
35966     would treat ‘":="’ as an infix operator and would align the right
35967     argument with the left one.
35968
35969   • The rule for indentation before ‘"begin"’ is an example of the use
35970     of virtual indentation: This rule is used only when ‘"begin"’ is
35971     hanging, which can happen only when ‘"begin"’ is not at the
35972     beginning of a line.  So this is not used when indenting ‘"begin"’
35973     itself but only when indenting something relative to this
35974     ‘"begin"’.  Concretely, this rule changes the indentation from:
35975
35976              if x > 0 then begin
35977                      dosomething(x);
35978                  end
35979     to
35980              if x > 0 then begin
35981                  dosomething(x);
35982              end
35983
35984   • The rule for indentation before ‘"if"’ is similar to the one for
35985     ‘"begin"’, but where the purpose is to treat ‘"else if"’ as a
35986     single unit, so as to align a sequence of tests rather than indent
35987     each test further to the right.  This function does this only in
35988     the case where the ‘"if"’ is not placed on a separate line, hence
35989     the ‘smie-rule-bolp’ test.
35990
35991     If we know that the ‘"else"’ is always aligned with its ‘"if"’ and
35992     is always at the beginning of a line, we can use a more efficient
35993     rule:
35994          ((equal token "if")
35995           (and (not (smie-rule-bolp))
35996                (smie-rule-prev-p "else")
35997                (save-excursion
35998                  (sample-smie-backward-token)
35999                  (cons 'column (current-column)))))
36000
36001     The advantage of this formulation is that it reuses the indentation
36002     of the previous ‘"else"’, rather than going all the way back to the
36003     first ‘"if"’ of the sequence.
36004
36005
36006File: elisp.info,  Node: SMIE Customization,  Prev: SMIE Indentation Example,  Up: SMIE
36007
3600823.7.1.9 Customizing Indentation
36009................................
36010
36011If you are using a mode whose indentation is provided by SMIE, you can
36012customize the indentation to suit your preferences.  You can do this on
36013a per-mode basis (using the option ‘smie-config’), or a per-file basis
36014(using the function ‘smie-config-local’ in a file-local variable
36015specification).
36016
36017 -- User Option: smie-config
36018     This option lets you customize indentation on a per-mode basis.  It
36019     is an alist with elements of the form ‘(MODE . RULES)’.  For the
36020     precise form of rules, see the variable’s documentation; but you
36021     may find it easier to use the command ‘smie-config-guess’.
36022
36023 -- Command: smie-config-guess
36024     This command tries to work out appropriate settings to produce your
36025     preferred style of indentation.  Simply call the command while
36026     visiting a file that is indented with your style.
36027
36028 -- Command: smie-config-save
36029     Call this command after using ‘smie-config-guess’, to save your
36030     settings for future sessions.
36031
36032 -- Command: smie-config-show-indent &optional move
36033     This command displays the rules that are used to indent the current
36034     line.
36035
36036 -- Command: smie-config-set-indent
36037     This command adds a local rule to adjust the indentation of the
36038     current line.
36039
36040 -- Function: smie-config-local rules
36041     This function adds RULES as indentation rules for the current
36042     buffer.  These add to any mode-specific rules defined by the
36043     ‘smie-config’ option.  To specify custom indentation rules for a
36044     specific file, add an entry to the file’s local variables of the
36045     form: ‘eval: (smie-config-local '(RULES))’.
36046
36047
36048File: elisp.info,  Node: Desktop Save Mode,  Prev: Auto-Indentation,  Up: Modes
36049
3605023.8 Desktop Save Mode
36051======================
36052
36053“Desktop Save Mode” is a feature to save the state of Emacs from one
36054session to another.  The user-level commands for using Desktop Save Mode
36055are described in the GNU Emacs Manual (*note (emacs)Saving Emacs
36056Sessions::).  Modes whose buffers visit a file, don’t have to do
36057anything to use this feature.
36058
36059   For buffers not visiting a file to have their state saved, the major
36060mode must bind the buffer local variable ‘desktop-save-buffer’ to a
36061non-‘nil’ value.
36062
36063 -- Variable: desktop-save-buffer
36064     If this buffer-local variable is non-‘nil’, the buffer will have
36065     its state saved in the desktop file at desktop save.  If the value
36066     is a function, it is called at desktop save with argument
36067     DESKTOP-DIRNAME, and its value is saved in the desktop file along
36068     with the state of the buffer for which it was called.  When file
36069     names are returned as part of the auxiliary information, they
36070     should be formatted using the call
36071
36072          (desktop-file-name FILE-NAME DESKTOP-DIRNAME)
36073
36074   For buffers not visiting a file to be restored, the major mode must
36075define a function to do the job, and that function must be listed in the
36076alist ‘desktop-buffer-mode-handlers’.
36077
36078 -- Variable: desktop-buffer-mode-handlers
36079     Alist with elements
36080
36081          (MAJOR-MODE . RESTORE-BUFFER-FUNCTION)
36082
36083     The function RESTORE-BUFFER-FUNCTION will be called with argument
36084     list
36085
36086          (BUFFER-FILE-NAME BUFFER-NAME DESKTOP-BUFFER-MISC)
36087
36088     and it should return the restored buffer.  Here DESKTOP-BUFFER-MISC
36089     is the value returned by the function optionally bound to
36090     ‘desktop-save-buffer’.
36091
36092
36093File: elisp.info,  Node: Documentation,  Next: Files,  Prev: Modes,  Up: Top
36094
3609524 Documentation
36096****************
36097
36098GNU Emacs has convenient built-in help facilities, most of which derive
36099their information from documentation strings associated with functions
36100and variables.  This chapter describes how to access documentation
36101strings in Lisp programs.
36102
36103   The contents of a documentation string should follow certain
36104conventions.  In particular, its first line should be a complete
36105sentence (or two complete sentences) that briefly describes what the
36106function or variable does.  *Note Documentation Tips::, for how to write
36107good documentation strings.
36108
36109   Note that the documentation strings for Emacs are not the same thing
36110as the Emacs manual.  Manuals have their own source files, written in
36111the Texinfo language; documentation strings are specified in the
36112definitions of the functions and variables they apply to.  A collection
36113of documentation strings is not sufficient as a manual because a good
36114manual is not organized in that fashion; it is organized in terms of
36115topics of discussion.
36116
36117   For commands to display documentation strings, see *note Help:
36118(emacs)Help.
36119
36120* Menu:
36121
36122* Documentation Basics::      Where doc strings are defined and stored.
36123* Accessing Documentation::   How Lisp programs can access doc strings.
36124* Keys in Documentation::     Substituting current key bindings.
36125* Text Quoting Style::        Quotation marks in doc strings and messages.
36126* Describing Characters::     Making printable descriptions of
36127                                non-printing characters and key sequences.
36128* Help Functions::            Subroutines used by Emacs help facilities.
36129
36130
36131File: elisp.info,  Node: Documentation Basics,  Next: Accessing Documentation,  Up: Documentation
36132
3613324.1 Documentation Basics
36134=========================
36135
36136A documentation string is written using the Lisp syntax for strings,
36137with double-quote characters surrounding the text.  It is, in fact, an
36138actual Lisp string.  When the string appears in the proper place in a
36139function or variable definition, it serves as the function’s or
36140variable’s documentation.
36141
36142   In a function definition (a ‘lambda’ or ‘defun’ form), the
36143documentation string is specified after the argument list, and is
36144normally stored directly in the function object.  *Note Function
36145Documentation::.  You can also put function documentation in the
36146‘function-documentation’ property of a function name (*note Accessing
36147Documentation::).
36148
36149   In a variable definition (a ‘defvar’ form), the documentation string
36150is specified after the initial value.  *Note Defining Variables::.  The
36151string is stored in the variable’s ‘variable-documentation’ property.
36152
36153   Sometimes, Emacs does not keep documentation strings in memory.
36154There are two such circumstances.  Firstly, to save memory, the
36155documentation for preloaded functions and variables (including
36156primitives) is kept in a file named ‘DOC’, in the directory specified by
36157‘doc-directory’ (*note Accessing Documentation::).  Secondly, when a
36158function or variable is loaded from a byte-compiled file, Emacs avoids
36159loading its documentation string (*note Docs and Compilation::).  In
36160both cases, Emacs looks up the documentation string from the file only
36161when needed, such as when the user calls ‘C-h f’ (‘describe-function’)
36162for a function.
36163
36164   Documentation strings can contain special “key substitution
36165sequences”, referring to key bindings which are looked up only when the
36166user views the documentation.  This allows the help commands to display
36167the correct keys even if a user rearranges the default key bindings.
36168*Note Keys in Documentation::.
36169
36170   In the documentation string of an autoloaded command (*note
36171Autoload::), these key-substitution sequences have an additional special
36172effect: they cause ‘C-h f’ on the command to trigger autoloading.  (This
36173is needed for correctly setting up the hyperlinks in the ‘*Help*’
36174buffer.)
36175
36176
36177File: elisp.info,  Node: Accessing Documentation,  Next: Keys in Documentation,  Prev: Documentation Basics,  Up: Documentation
36178
3617924.2 Access to Documentation Strings
36180====================================
36181
36182 -- Function: documentation-property symbol property &optional verbatim
36183     This function returns the documentation string recorded in SYMBOL’s
36184     property list under property PROPERTY.  It is most often used to
36185     look up the documentation strings of variables, for which PROPERTY
36186     is ‘variable-documentation’.  However, it can also be used to look
36187     up other kinds of documentation, such as for customization groups
36188     (but for function documentation, use the ‘documentation’ function,
36189     below).
36190
36191     If the property value refers to a documentation string stored in
36192     the ‘DOC’ file or a byte-compiled file, this function looks up that
36193     string and returns it.
36194
36195     If the property value isn’t ‘nil’, isn’t a string, and doesn’t
36196     refer to text in a file, then it is evaluated as a Lisp expression
36197     to obtain a string.
36198
36199     Finally, this function passes the string through
36200     ‘substitute-command-keys’ to substitute key bindings (*note Keys in
36201     Documentation::).  It skips this step if VERBATIM is non-‘nil’.
36202
36203          (documentation-property 'command-line-processed
36204             'variable-documentation)
36205               ⇒ "Non-nil once command line has been processed"
36206          (symbol-plist 'command-line-processed)
36207               ⇒ (variable-documentation 188902)
36208          (documentation-property 'emacs 'group-documentation)
36209               ⇒ "Customization of the One True Editor."
36210
36211 -- Function: documentation function &optional verbatim
36212     This function returns the documentation string of FUNCTION.  It
36213     handles macros, named keyboard macros, and special forms, as well
36214     as ordinary functions.
36215
36216     If FUNCTION is a symbol, this function first looks for the
36217     ‘function-documentation’ property of that symbol; if that has a
36218     non-‘nil’ value, the documentation comes from that value (if the
36219     value is not a string, it is evaluated).
36220
36221     If FUNCTION is not a symbol, or if it has no
36222     ‘function-documentation’ property, then ‘documentation’ extracts
36223     the documentation string from the actual function definition,
36224     reading it from a file if called for.
36225
36226     Finally, unless VERBATIM is non-‘nil’, this function calls
36227     ‘substitute-command-keys’.  The result is the documentation string
36228     to return.
36229
36230     The ‘documentation’ function signals a ‘void-function’ error if
36231     FUNCTION has no function definition.  However, it is OK if the
36232     function definition has no documentation string.  In that case,
36233     ‘documentation’ returns ‘nil’.
36234
36235 -- Function: face-documentation face
36236     This function returns the documentation string of FACE as a face.
36237
36238   Here is an example of using the two functions, ‘documentation’ and
36239‘documentation-property’, to display the documentation strings for
36240several symbols in a ‘*Help*’ buffer.
36241
36242     (defun describe-symbols (pattern)
36243       "Describe the Emacs Lisp symbols matching PATTERN.
36244     All symbols that have PATTERN in their name are described
36245     in the *Help* buffer."
36246       (interactive "sDescribe symbols matching: ")
36247       (let ((describe-func
36248              (lambda (s)
36249                ;; Print description of symbol.
36250                (if (fboundp s)             ; It is a function.
36251                    (princ
36252                     (format "%s\t%s\n%s\n\n" s
36253                       (if (commandp s)
36254                           (let ((keys (where-is-internal s)))
36255                             (if keys
36256                                 (concat
36257                                  "Keys: "
36258                                  (mapconcat 'key-description
36259                                             keys " "))
36260                               "Keys: none"))
36261                         "Function")
36262                       (or (documentation s)
36263                           "not documented"))))
36264
36265                (if (boundp s)              ; It is a variable.
36266                    (princ
36267                     (format "%s\t%s\n%s\n\n" s
36268                       (if (custom-variable-p s)
36269                           "Option " "Variable")
36270                       (or (documentation-property
36271                             s 'variable-documentation)
36272                           "not documented"))))))
36273             sym-list)
36274
36275         ;; Build a list of symbols that match pattern.
36276         (mapatoms (lambda (sym)
36277                     (if (string-match pattern (symbol-name sym))
36278                         (setq sym-list (cons sym sym-list)))))
36279
36280         ;; Display the data.
36281         (help-setup-xref (list 'describe-symbols pattern) (interactive-p))
36282         (with-help-window (help-buffer)
36283           (mapcar describe-func (sort sym-list 'string<)))))
36284
36285   The ‘describe-symbols’ function works like ‘apropos’, but provides
36286more information.
36287
36288     (describe-symbols "goal")
36289
36290     ---------- Buffer: *Help* ----------
36291     goal-column     Option
36292     Semipermanent goal column for vertical motion, as set by ...
36293
36294     minibuffer-temporary-goal-position      Variable
36295     not documented
36296
36297     set-goal-column Keys: C-x C-n
36298     Set the current horizontal position as a goal for C-n and C-p.
36299     Those commands will move to this position in the line moved to
36300     rather than trying to keep the same horizontal position.
36301     With a non-nil argument ARG, clears out the goal column
36302     so that C-n and C-p resume vertical motion.
36303     The goal column is stored in the variable ‘goal-column’.
36304
36305     (fn ARG)
36306
36307     temporary-goal-column   Variable
36308     Current goal column for vertical motion.
36309     It is the column where point was at the start of the current run
36310     of vertical motion commands.
36311
36312     When moving by visual lines via the function ‘line-move-visual’, it is a cons
36313     cell (COL . HSCROLL), where COL is the x-position, in pixels,
36314     divided by the default column width, and HSCROLL is the number of
36315     columns by which window is scrolled from left margin.
36316
36317     When the ‘track-eol’ feature is doing its job, the value is
36318     ‘most-positive-fixnum’.
36319     ---------- Buffer: *Help* ----------
36320
36321 -- Function: Snarf-documentation filename
36322     This function is used when building Emacs, just before the runnable
36323     Emacs is dumped.  It finds the positions of the documentation
36324     strings stored in the file FILENAME, and records those positions
36325     into memory in the function definitions and variable property
36326     lists.  *Note Building Emacs::.
36327
36328     Emacs reads the file FILENAME from the ‘emacs/etc’ directory.  When
36329     the dumped Emacs is later executed, the same file will be looked
36330     for in the directory ‘doc-directory’.  Usually FILENAME is ‘"DOC"’.
36331
36332 -- Variable: doc-directory
36333     This variable holds the name of the directory which should contain
36334     the file ‘"DOC"’ that contains documentation strings for built-in
36335     and preloaded functions and variables.
36336
36337     In most cases, this is the same as ‘data-directory’.  They may be
36338     different when you run Emacs from the directory where you built it,
36339     without actually installing it.  *Note Definition of
36340     data-directory::.
36341
36342
36343File: elisp.info,  Node: Keys in Documentation,  Next: Text Quoting Style,  Prev: Accessing Documentation,  Up: Documentation
36344
3634524.3 Substituting Key Bindings in Documentation
36346===============================================
36347
36348When documentation strings refer to key sequences, they should use the
36349current, actual key bindings.  They can do so using certain special text
36350sequences described below.  Accessing documentation strings in the usual
36351way substitutes current key binding information for these special
36352sequences.  This works by calling ‘substitute-command-keys’.  You can
36353also call that function yourself.
36354
36355   Here is a list of the special sequences and what they mean:
36356
36357‘\[COMMAND]’
36358     stands for a key sequence that will invoke COMMAND, or ‘M-x
36359     COMMAND’ if COMMAND has no key bindings.
36360
36361‘\{MAPVAR}’
36362     stands for a summary of the keymap which is the value of the
36363     variable MAPVAR.  The summary is made using ‘describe-bindings’.
36364
36365‘\<MAPVAR>’
36366     stands for no text itself.  It is used only for a side effect: it
36367     specifies MAPVAR’s value as the keymap for any following
36368     ‘\[COMMAND]’ sequences in this documentation string.
36369
36370‘`’
36371     (grave accent) stands for a left quote.  This generates a left
36372     single quotation mark, an apostrophe, or a grave accent depending
36373     on the value of ‘text-quoting-style’.  *Note Text Quoting Style::.
36374
36375‘'’
36376     (apostrophe) stands for a right quote.  This generates a right
36377     single quotation mark or an apostrophe depending on the value of
36378     ‘text-quoting-style’.
36379
36380‘\=’
36381     quotes the following character and is discarded; thus, ‘\=`’ puts
36382     ‘`’ into the output, ‘\=\[’ puts ‘\[’ into the output, and ‘\=\=’
36383     puts ‘\=’ into the output.
36384
36385   *Please note:* Each ‘\’ must be doubled when written in a string in
36386Emacs Lisp.
36387
36388 -- User Option: text-quoting-style
36389     The value of this variable is a symbol that specifies the style
36390     Emacs should use for single quotes in the wording of help and
36391     messages.  If the variable’s value is ‘curve’, the style is ‘like
36392     this’ with curved single quotes.  If the value is ‘straight’, the
36393     style is 'like this' with straight apostrophes.  If the value is
36394     ‘grave’, quotes are not translated and the style is `like this'
36395     with grave accent and apostrophe, the standard style before Emacs
36396     version 25.  The default value ‘nil’ acts like ‘curve’ if curved
36397     single quotes seem to be displayable, and like ‘grave’ otherwise.
36398
36399     This option is useful on platforms that have problems with curved
36400     quotes.  You can customize it freely according to your personal
36401     preference.
36402
36403 -- Function: substitute-command-keys string
36404     This function scans STRING for the above special sequences and
36405     replaces them by what they stand for, returning the result as a
36406     string.  This permits display of documentation that refers
36407     accurately to the user’s own customized key bindings.
36408
36409     If a command has multiple bindings, this function normally uses the
36410     first one it finds.  You can specify one particular key binding by
36411     assigning an ‘:advertised-binding’ symbol property to the command,
36412     like this:
36413
36414          (put 'undo :advertised-binding [?\C-/])
36415
36416     The ‘:advertised-binding’ property also affects the binding shown
36417     in menu items (*note Menu Bar::).  The property is ignored if it
36418     specifies a key binding that the command does not actually have.
36419
36420   Here are examples of the special sequences:
36421
36422     (substitute-command-keys
36423        "To abort recursive edit, type `\\[abort-recursive-edit]'.")
36424     ⇒ "To abort recursive edit, type ‘C-]’."
36425
36426     (substitute-command-keys
36427        "The keys that are defined for the minibuffer here are:
36428       \\{minibuffer-local-must-match-map}")
36429     ⇒ "The keys that are defined for the minibuffer here are:
36430
36431     ?               minibuffer-completion-help
36432     SPC             minibuffer-complete-word
36433     TAB             minibuffer-complete
36434     C-j             minibuffer-complete-and-exit
36435     RET             minibuffer-complete-and-exit
36436     C-g             abort-recursive-edit
36437     "
36438
36439     (substitute-command-keys
36440        "To abort a recursive edit from the minibuffer, type \
36441     `\\<minibuffer-local-must-match-map>\\[abort-recursive-edit]'.")
36442     ⇒ "To abort a recursive edit from the minibuffer, type ‘C-g’."
36443
36444   There are other special conventions for the text in documentation
36445strings—for instance, you can refer to functions, variables, and
36446sections of this manual.  *Note Documentation Tips::, for details.
36447
36448
36449File: elisp.info,  Node: Text Quoting Style,  Next: Describing Characters,  Prev: Keys in Documentation,  Up: Documentation
36450
3645124.4 Text Quoting Style
36452=======================
36453
36454Typically, grave accents and apostrophes are treated specially in
36455documentation strings and diagnostic messages, and translate to matching
36456single quotation marks (also called “curved quotes”).  For example, the
36457documentation string "Alias for `foo'." and the function call ‘(message
36458"Alias for `foo'.")’ both translate to "Alias for ‘foo’.".  Less
36459commonly, Emacs displays grave accents and apostrophes as themselves, or
36460as apostrophes only (e.g., "Alias for 'foo'.").  Documentation strings
36461and message formats should be written so that they display well with any
36462of these styles.  For example, the documentation string "Alias for
36463'foo'." is probably not what you want, as it can display as "Alias for
36464’foo’.", an unusual style in English.
36465
36466   Sometimes you may need to display a grave accent or apostrophe
36467without translation, regardless of text quoting style.  In a
36468documentation string, you can do this with escapes.  For example, in the
36469documentation string "\\=`(a ,(sin 0)) ==> (a 0.0)" the grave accent is
36470intended to denote Lisp code, so it is escaped and displays as itself
36471regardless of quoting style.  In a call to ‘message’ or ‘error’, you can
36472avoid translation by using a format "%s" with an argument that is a call
36473to ‘format’.  For example, ‘(message "%s" (format "`(a ,(sin %S)) ==> (a
36474%S)" x (sin x)))’ displays a message that starts with grave accent
36475regardless of text quoting style.
36476
36477 -- User Option: text-quoting-style
36478     The value of this user option is a symbol that specifies the style
36479     Emacs should use for single quotes in the wording of help and
36480     messages.  If the option’s value is ‘curve’, the style is ‘like
36481     this’ with curved single quotes.  If the value is ‘straight’, the
36482     style is 'like this' with straight apostrophes.  If the value is
36483     ‘grave’, quotes are not translated and the style is `like this'
36484     with grave accent and apostrophe, the standard style before Emacs
36485     version 25.  The default value ‘nil’ acts like ‘curve’ if curved
36486     single quotes seem to be displayable, and like ‘grave’ otherwise.
36487
36488     This option is useful on platforms that have problems with curved
36489     quotes.  You can customize it freely according to your personal
36490     preference.
36491
36492
36493File: elisp.info,  Node: Describing Characters,  Next: Help Functions,  Prev: Text Quoting Style,  Up: Documentation
36494
3649524.5 Describing Characters for Help Messages
36496============================================
36497
36498These functions convert events, key sequences, or characters to textual
36499descriptions.  These descriptions are useful for including arbitrary
36500text characters or key sequences in messages, because they convert
36501non-printing and whitespace characters to sequences of printing
36502characters.  The description of a non-whitespace printing character is
36503the character itself.
36504
36505 -- Function: key-description sequence &optional prefix
36506     This function returns a string containing the Emacs standard
36507     notation for the input events in SEQUENCE.  If PREFIX is non-‘nil’,
36508     it is a sequence of input events leading up to SEQUENCE and is
36509     included in the return value.  Both arguments may be strings,
36510     vectors or lists.  *Note Input Events::, for more information about
36511     valid events.
36512
36513          (key-description [?\M-3 delete])
36514               ⇒ "M-3 <delete>"
36515          (key-description [delete] "\M-3")
36516               ⇒ "M-3 <delete>"
36517
36518     See also the examples for ‘single-key-description’, below.
36519
36520 -- Function: single-key-description event &optional no-angles
36521     This function returns a string describing EVENT in the standard
36522     Emacs notation for keyboard input.  A normal printing character
36523     appears as itself, but a control character turns into a string
36524     starting with ‘C-’, a meta character turns into a string starting
36525     with ‘M-’, and space, tab, etc., appear as ‘SPC’, ‘TAB’, etc.  A
36526     function key symbol appears inside angle brackets ‘<...>’.  An
36527     event that is a list appears as the name of the symbol in the CAR
36528     of the list, inside angle brackets.
36529
36530     If the optional argument NO-ANGLES is non-‘nil’, the angle brackets
36531     around function keys and event symbols are omitted; this is for
36532     compatibility with old versions of Emacs which didn’t use the
36533     brackets.
36534
36535          (single-key-description ?\C-x)
36536               ⇒ "C-x"
36537          (key-description "\C-x \M-y \n \t \r \f123")
36538               ⇒ "C-x SPC M-y SPC C-j SPC TAB SPC RET SPC C-l 1 2 3"
36539          (single-key-description 'delete)
36540               ⇒ "<delete>"
36541          (single-key-description 'C-mouse-1)
36542               ⇒ "<C-mouse-1>"
36543          (single-key-description 'C-mouse-1 t)
36544               ⇒ "C-mouse-1"
36545
36546 -- Function: text-char-description character
36547     This function returns a string describing CHARACTER in the standard
36548     Emacs notation for characters that can appear in text—similar to
36549     ‘single-key-description’, except that the argument must be a valid
36550     character code that passes a ‘characterp’ test (*note Character
36551     Codes::).  The function produces descriptions of control characters
36552     with a leading caret (which is how Emacs usually displays control
36553     characters in buffers).  Characters with modifier bits will cause
36554     this function to signal an error (ASCII characters with the Control
36555     modifier are an exception, they are represented as control
36556     characters).
36557
36558          (text-char-description ?\C-c)
36559               ⇒ "^C"
36560          (text-char-description ?\M-m)
36561               error→ Wrong type argument: characterp, 134217837
36562
36563 -- Command: read-kbd-macro string &optional need-vector
36564     This function is used mainly for operating on keyboard macros, but
36565     it can also be used as a rough inverse for ‘key-description’.  You
36566     call it with a string containing key descriptions, separated by
36567     spaces; it returns a string or vector containing the corresponding
36568     events.  (This may or may not be a single valid key sequence,
36569     depending on what events you use; *note Key Sequences::.)  If
36570     NEED-VECTOR is non-‘nil’, the return value is always a vector.
36571
36572
36573File: elisp.info,  Node: Help Functions,  Prev: Describing Characters,  Up: Documentation
36574
3657524.6 Help Functions
36576===================
36577
36578Emacs provides a variety of built-in help functions, all accessible to
36579the user as subcommands of the prefix ‘C-h’.  For more information about
36580them, see *note Help: (emacs)Help.  Here we describe some program-level
36581interfaces to the same information.
36582
36583 -- Command: apropos pattern &optional do-all
36584     This function finds all meaningful symbols whose names contain a
36585     match for the apropos pattern PATTERN.  An apropos pattern is
36586     either a word to match, a space-separated list of words of which at
36587     least two must match, or a regular expression (if any special
36588     regular expression characters occur).  A symbol is meaningful if it
36589     has a definition as a function, variable, or face, or has
36590     properties.
36591
36592     The function returns a list of elements that look like this:
36593
36594          (SYMBOL SCORE FUNCTION-DOC VARIABLE-DOC
36595           PLIST-DOC WIDGET-DOC FACE-DOC GROUP-DOC)
36596
36597     Here, SCORE is an integer measure of how important the symbol seems
36598     to be as a match.  Each of the remaining elements is a
36599     documentation string, or ‘nil’, for SYMBOL as a function, variable,
36600     etc.
36601
36602     It also displays the symbols in a buffer named ‘*Apropos*’, each
36603     with a one-line description taken from the beginning of its
36604     documentation string.
36605
36606     If DO-ALL is non-‘nil’, or if the user option ‘apropos-do-all’ is
36607     non-‘nil’, then ‘apropos’ also shows key bindings for the functions
36608     that are found; it also shows _all_ interned symbols, not just
36609     meaningful ones (and it lists them in the return value as well).
36610
36611 -- Variable: help-map
36612     The value of this variable is a local keymap for characters
36613     following the Help key, ‘C-h’.
36614
36615 -- Prefix Command: help-command
36616     This symbol is not a function; its function definition cell holds
36617     the keymap known as ‘help-map’.  It is defined in ‘help.el’ as
36618     follows:
36619
36620          (define-key global-map (string help-char) 'help-command)
36621          (fset 'help-command help-map)
36622
36623 -- User Option: help-char
36624     The value of this variable is the help character—the character that
36625     Emacs recognizes as meaning Help.  By default, its value is 8,
36626     which stands for ‘C-h’.  When Emacs reads this character, if
36627     ‘help-form’ is a non-‘nil’ Lisp expression, it evaluates that
36628     expression, and displays the result in a window if it is a string.
36629
36630     Usually the value of ‘help-form’ is ‘nil’.  Then the help character
36631     has no special meaning at the level of command input, and it
36632     becomes part of a key sequence in the normal way.  The standard key
36633     binding of ‘C-h’ is a prefix key for several general-purpose help
36634     features.
36635
36636     The help character is special after prefix keys, too.  If it has no
36637     binding as a subcommand of the prefix key, it runs
36638     ‘describe-prefix-bindings’, which displays a list of all the
36639     subcommands of the prefix key.
36640
36641 -- User Option: help-event-list
36642     The value of this variable is a list of event types that serve as
36643     alternative help characters.  These events are handled just like
36644     the event specified by ‘help-char’.
36645
36646 -- Variable: help-form
36647     If this variable is non-‘nil’, its value is a form to evaluate
36648     whenever the character ‘help-char’ is read.  If evaluating the form
36649     produces a string, that string is displayed.
36650
36651     A command that calls ‘read-event’, ‘read-char-choice’, or
36652     ‘read-char’ probably should bind ‘help-form’ to a non-‘nil’
36653     expression while it does input.  (The time when you should not do
36654     this is when ‘C-h’ has some other meaning.)  Evaluating this
36655     expression should result in a string that explains what the input
36656     is for and how to enter it properly.
36657
36658     Entry to the minibuffer binds this variable to the value of
36659     ‘minibuffer-help-form’ (*note Definition of
36660     minibuffer-help-form::).
36661
36662 -- Variable: prefix-help-command
36663     This variable holds a function to print help for a prefix key.  The
36664     function is called when the user types a prefix key followed by the
36665     help character, and the help character has no binding after that
36666     prefix.  The variable’s default value is
36667     ‘describe-prefix-bindings’.
36668
36669 -- Command: describe-prefix-bindings
36670     This function calls ‘describe-bindings’ to display a list of all
36671     the subcommands of the prefix key of the most recent key sequence.
36672     The prefix described consists of all but the last event of that key
36673     sequence.  (The last event is, presumably, the help character.)
36674
36675   The following two functions are meant for modes that want to provide
36676help without relinquishing control, such as the electric modes.  Their
36677names begin with ‘Helper’ to distinguish them from the ordinary help
36678functions.
36679
36680 -- Command: Helper-describe-bindings
36681     This command pops up a window displaying a help buffer containing a
36682     listing of all of the key bindings from both the local and global
36683     keymaps.  It works by calling ‘describe-bindings’.
36684
36685 -- Command: Helper-help
36686     This command provides help for the current mode.  It prompts the
36687     user in the minibuffer with the message ‘Help (Type ? for further
36688     options)’, and then provides assistance in finding out what the key
36689     bindings are, and what the mode is intended for.  It returns ‘nil’.
36690
36691     This can be customized by changing the map ‘Helper-help-map’.
36692
36693 -- Variable: data-directory
36694     This variable holds the name of the directory in which Emacs finds
36695     certain documentation and text files that come with Emacs.
36696
36697 -- Function: help-buffer
36698     This function returns the name of the help buffer, which is
36699     normally ‘*Help*’; if such a buffer does not exist, it is first
36700     created.
36701
36702 -- Macro: with-help-window buffer-or-name body...
36703     This macro evaluates BODY like ‘with-output-to-temp-buffer’ (*note
36704     Temporary Displays::), inserting any output produced by its forms
36705     into a buffer specified by BUFFER-OR-NAME, which can be a buffer or
36706     the name of a buffer.  (Frequently, BUFFER-OR-NAME is the value
36707     returned by the function ‘help-buffer’.)  This macro puts the
36708     specified buffer into Help mode and displays a message telling the
36709     user how to quit and scroll the help window.  It selects the help
36710     window if the current value of the user option ‘help-window-select’
36711     has been set accordingly.  It returns the last value in BODY.
36712
36713 -- Function: help-setup-xref item interactive-p
36714     This function updates the cross reference data in the ‘*Help*’
36715     buffer, which is used to regenerate the help information when the
36716     user clicks on the ‘Back’ or ‘Forward’ buttons.  Most commands that
36717     use the ‘*Help*’ buffer should invoke this function before clearing
36718     the buffer.  The ITEM argument should have the form ‘(FUNCTION .
36719     ARGS)’, where FUNCTION is a function to call, with argument list
36720     ARGS, to regenerate the help buffer.  The INTERACTIVE-P argument is
36721     non-‘nil’ if the calling command was invoked interactively; in that
36722     case, the stack of items for the ‘*Help*’ buffer’s ‘Back’ buttons
36723     is cleared.
36724
36725   *Note describe-symbols example::, for an example of using
36726‘help-buffer’, ‘with-help-window’, and ‘help-setup-xref’.
36727
36728 -- Macro: make-help-screen fname help-line help-text help-map
36729     This macro defines a help command named FNAME that acts like a
36730     prefix key that shows a list of the subcommands it offers.
36731
36732     When invoked, FNAME displays HELP-TEXT in a window, then reads and
36733     executes a key sequence according to HELP-MAP.  The string
36734     HELP-TEXT should describe the bindings available in HELP-MAP.
36735
36736     The command FNAME is defined to handle a few events itself, by
36737     scrolling the display of HELP-TEXT.  When FNAME reads one of those
36738     special events, it does the scrolling and then reads another event.
36739     When it reads an event that is not one of those few, and which has
36740     a binding in HELP-MAP, it executes that key’s binding and then
36741     returns.
36742
36743     The argument HELP-LINE should be a single-line summary of the
36744     alternatives in HELP-MAP.  In the current version of Emacs, this
36745     argument is used only if you set the option ‘three-step-help’ to
36746     ‘t’.
36747
36748     This macro is used in the command ‘help-for-help’ which is the
36749     binding of ‘C-h C-h’.
36750
36751 -- User Option: three-step-help
36752     If this variable is non-‘nil’, commands defined with
36753     ‘make-help-screen’ display their HELP-LINE strings in the echo area
36754     at first, and display the longer HELP-TEXT strings only if the user
36755     types the help character again.
36756
36757
36758File: elisp.info,  Node: Files,  Next: Backups and Auto-Saving,  Prev: Documentation,  Up: Top
36759
3676025 Files
36761********
36762
36763This chapter describes the Emacs Lisp functions and variables to find,
36764create, view, save, and otherwise work with files and directories.  A
36765few other file-related functions are described in *note Buffers::, and
36766those related to backups and auto-saving are described in *note Backups
36767and Auto-Saving::.
36768
36769   Many of the file functions take one or more arguments that are file
36770names.  A file name is a string.  Most of these functions expand file
36771name arguments using the function ‘expand-file-name’, so that ‘~’ is
36772handled correctly, as are relative file names (including ‘../’ and the
36773empty string).  *Note File Name Expansion::.
36774
36775   In addition, certain “magic” file names are handled specially.  For
36776example, when a remote file name is specified, Emacs accesses the file
36777over the network via an appropriate protocol.  *Note Remote Files:
36778(emacs)Remote Files.  This handling is done at a very low level, so you
36779may assume that all the functions described in this chapter accept magic
36780file names as file name arguments, except where noted.  *Note Magic File
36781Names::, for details.
36782
36783   When file I/O functions signal Lisp errors, they usually use the
36784condition ‘file-error’ (*note Handling Errors::).  The error message is
36785in most cases obtained from the operating system, according to locale
36786‘system-messages-locale’, and decoded using coding system
36787‘locale-coding-system’ (*note Locales::).
36788
36789* Menu:
36790
36791* Visiting Files::           Reading files into Emacs buffers for editing.
36792* Saving Buffers::           Writing changed buffers back into files.
36793* Reading from Files::       Reading files into buffers without visiting.
36794* Writing to Files::         Writing new files from parts of buffers.
36795* File Locks::               Locking and unlocking files, to prevent
36796                               simultaneous editing by two people.
36797* Information about Files::  Testing existence, accessibility, size of files.
36798* Changing Files::           Renaming files, changing permissions, etc.
36799* Files and Storage::        Surviving power and media failures
36800* File Names::               Decomposing and expanding file names.
36801* Contents of Directories::  Getting a list of the files in a directory.
36802* Create/Delete Dirs::       Creating and Deleting Directories.
36803* Magic File Names::         Special handling for certain file names.
36804* Format Conversion::        Conversion to and from various file formats.
36805
36806
36807File: elisp.info,  Node: Visiting Files,  Next: Saving Buffers,  Up: Files
36808
3680925.1 Visiting Files
36810===================
36811
36812Visiting a file means reading a file into a buffer.  Once this is done,
36813we say that the buffer is “visiting” that file, and call the file “the
36814visited file” of the buffer.
36815
36816   A file and a buffer are two different things.  A file is information
36817recorded permanently in the computer (unless you delete it).  A buffer,
36818on the other hand, is information inside of Emacs that will vanish at
36819the end of the editing session (or when you kill the buffer).  When a
36820buffer is visiting a file, it contains information copied from the file.
36821The copy in the buffer is what you modify with editing commands.
36822Changes to the buffer do not change the file; to make the changes
36823permanent, you must “save” the buffer, which means copying the altered
36824buffer contents back into the file.
36825
36826   Despite the distinction between files and buffers, people often refer
36827to a file when they mean a buffer and vice-versa.  Indeed, we say, “I am
36828editing a file”, rather than, “I am editing a buffer that I will soon
36829save as a file of the same name”.  Humans do not usually need to make
36830the distinction explicit.  When dealing with a computer program,
36831however, it is good to keep the distinction in mind.
36832
36833* Menu:
36834
36835* Visiting Functions::         The usual interface functions for visiting.
36836* Subroutines of Visiting::    Lower-level subroutines that they use.
36837
36838
36839File: elisp.info,  Node: Visiting Functions,  Next: Subroutines of Visiting,  Up: Visiting Files
36840
3684125.1.1 Functions for Visiting Files
36842-----------------------------------
36843
36844This section describes the functions normally used to visit files.  For
36845historical reasons, these functions have names starting with ‘find-’
36846rather than ‘visit-’.  *Note Buffer File Name::, for functions and
36847variables that access the visited file name of a buffer or that find an
36848existing buffer by its visited file name.
36849
36850   In a Lisp program, if you want to look at the contents of a file but
36851not alter it, the fastest way is to use ‘insert-file-contents’ in a
36852temporary buffer.  Visiting the file is not necessary and takes longer.
36853*Note Reading from Files::.
36854
36855 -- Command: find-file filename &optional wildcards
36856     This command selects a buffer visiting the file FILENAME, using an
36857     existing buffer if there is one, and otherwise creating a new
36858     buffer and reading the file into it.  It also returns that buffer.
36859
36860     Aside from some technical details, the body of the ‘find-file’
36861     function is basically equivalent to:
36862
36863          (switch-to-buffer (find-file-noselect filename nil nil wildcards))
36864
36865     (See ‘switch-to-buffer’ in *note Switching Buffers::.)
36866
36867     If WILDCARDS is non-‘nil’, which is always true in an interactive
36868     call, then ‘find-file’ expands wildcard characters in FILENAME and
36869     visits all the matching files.
36870
36871     When ‘find-file’ is called interactively, it prompts for FILENAME
36872     in the minibuffer.
36873
36874 -- Command: find-file-literally filename
36875     This command visits FILENAME, like ‘find-file’ does, but it does
36876     not perform any format conversions (*note Format Conversion::),
36877     character code conversions (*note Coding Systems::), or end-of-line
36878     conversions (*note End of line conversion: Coding System Basics.).
36879     The buffer visiting the file is made unibyte, and its major mode is
36880     Fundamental mode, regardless of the file name.  File local variable
36881     specifications in the file (*note File Local Variables::) are
36882     ignored, and automatic decompression and adding a newline at the
36883     end of the file due to ‘require-final-newline’ (*note
36884     require-final-newline: Saving Buffers.) are also disabled.
36885
36886     Note that if Emacs already has a buffer visiting the same file
36887     non-literally, it will not visit the same file literally, but
36888     instead just switch to the existing buffer.  If you want to be sure
36889     of accessing a file’s contents literally, you should create a
36890     temporary buffer and then read the file contents into it using
36891     ‘insert-file-contents-literally’ (*note Reading from Files::).
36892
36893 -- Function: find-file-noselect filename &optional nowarn rawfile
36894          wildcards
36895     This function is the guts of all the file-visiting functions.  It
36896     returns a buffer visiting the file FILENAME.  You may make the
36897     buffer current or display it in a window if you wish, but this
36898     function does not do so.
36899
36900     The function returns an existing buffer if there is one; otherwise
36901     it creates a new buffer and reads the file into it.  When
36902     ‘find-file-noselect’ uses an existing buffer, it first verifies
36903     that the file has not changed since it was last visited or saved in
36904     that buffer.  If the file has changed, this function asks the user
36905     whether to reread the changed file.  If the user says ‘yes’, any
36906     edits previously made in the buffer are lost.
36907
36908     Reading the file involves decoding the file’s contents (*note
36909     Coding Systems::), including end-of-line conversion, and format
36910     conversion (*note Format Conversion::).  If WILDCARDS is non-‘nil’,
36911     then ‘find-file-noselect’ expands wildcard characters in FILENAME
36912     and visits all the matching files.
36913
36914     This function displays warning or advisory messages in various
36915     peculiar cases, unless the optional argument NOWARN is non-‘nil’.
36916     For example, if it needs to create a buffer, and there is no file
36917     named FILENAME, it displays the message ‘(New file)’ in the echo
36918     area, and leaves the buffer empty.
36919
36920     The ‘find-file-noselect’ function normally calls ‘after-find-file’
36921     after reading the file (*note Subroutines of Visiting::).  That
36922     function sets the buffer major mode, parses local variables, warns
36923     the user if there exists an auto-save file more recent than the
36924     file just visited, and finishes by running the functions in
36925     ‘find-file-hook’.
36926
36927     If the optional argument RAWFILE is non-‘nil’, then
36928     ‘after-find-file’ is not called, and the
36929     ‘find-file-not-found-functions’ are not run in case of failure.
36930     What’s more, a non-‘nil’ RAWFILE value suppresses coding system
36931     conversion and format conversion.
36932
36933     The ‘find-file-noselect’ function usually returns the buffer that
36934     is visiting the file FILENAME.  But, if wildcards are actually used
36935     and expanded, it returns a list of buffers that are visiting the
36936     various files.
36937
36938          (find-file-noselect "/etc/fstab")
36939               ⇒ #<buffer fstab>
36940
36941 -- Command: find-file-other-window filename &optional wildcards
36942     This command selects a buffer visiting the file FILENAME, but does
36943     so in a window other than the selected window.  It may use another
36944     existing window or split a window; see *note Switching Buffers::.
36945
36946     When this command is called interactively, it prompts for FILENAME.
36947
36948 -- Command: find-file-read-only filename &optional wildcards
36949     This command selects a buffer visiting the file FILENAME, like
36950     ‘find-file’, but it marks the buffer as read-only.  *Note Read Only
36951     Buffers::, for related functions and variables.
36952
36953     When this command is called interactively, it prompts for FILENAME.
36954
36955 -- User Option: find-file-wildcards
36956     If this variable is non-‘nil’, then the various ‘find-file’
36957     commands check for wildcard characters and visit all the files that
36958     match them (when invoked interactively or when their WILDCARDS
36959     argument is non-‘nil’).  If this option is ‘nil’, then the
36960     ‘find-file’ commands ignore their WILDCARDS argument and never
36961     treat wildcard characters specially.
36962
36963 -- User Option: find-file-hook
36964     The value of this variable is a list of functions to be called
36965     after a file is visited.  The file’s local-variables specification
36966     (if any) will have been processed before the hooks are run.  The
36967     buffer visiting the file is current when the hook functions are
36968     run.
36969
36970     This variable is a normal hook.  *Note Hooks::.
36971
36972 -- Variable: find-file-not-found-functions
36973     The value of this variable is a list of functions to be called when
36974     ‘find-file’ or ‘find-file-noselect’ is passed a nonexistent file
36975     name.  ‘find-file-noselect’ calls these functions as soon as it
36976     detects a nonexistent file.  It calls them in the order of the
36977     list, until one of them returns non-‘nil’.  ‘buffer-file-name’ is
36978     already set up.
36979
36980     This is not a normal hook because the values of the functions are
36981     used, and in many cases only some of the functions are called.
36982
36983 -- Variable: find-file-literally
36984     This buffer-local variable, if set to a non-‘nil’ value, makes
36985     ‘save-buffer’ behave as if the buffer were visiting its file
36986     literally, i.e., without conversions of any kind.  The command
36987     ‘find-file-literally’ sets this variable’s local value, but other
36988     equivalent functions and commands can do that as well, e.g., to
36989     avoid automatic addition of a newline at the end of the file.  This
36990     variable is permanent local, so it is unaffected by changes of
36991     major modes.
36992
36993
36994File: elisp.info,  Node: Subroutines of Visiting,  Prev: Visiting Functions,  Up: Visiting Files
36995
3699625.1.2 Subroutines of Visiting
36997------------------------------
36998
36999The ‘find-file-noselect’ function uses two important subroutines which
37000are sometimes useful in user Lisp code: ‘create-file-buffer’ and
37001‘after-find-file’.  This section explains how to use them.
37002
37003 -- Function: create-file-buffer filename
37004     This function creates a suitably named buffer for visiting
37005     FILENAME, and returns it.  It uses FILENAME (sans directory) as the
37006     name if that name is free; otherwise, it appends a string such as
37007     ‘<2>’ to get an unused name.  See also *note Creating Buffers::.
37008     Note that the ‘uniquify’ library affects the result of this
37009     function.  *Note (emacs)Uniquify::.
37010
37011     *Please note:* ‘create-file-buffer’ does _not_ associate the new
37012     buffer with a file and does not select the buffer.  It also does
37013     not use the default major mode.
37014
37015          (create-file-buffer "foo")
37016               ⇒ #<buffer foo>
37017          (create-file-buffer "foo")
37018               ⇒ #<buffer foo<2>>
37019          (create-file-buffer "foo")
37020               ⇒ #<buffer foo<3>>
37021
37022     This function is used by ‘find-file-noselect’.  It uses
37023     ‘generate-new-buffer’ (*note Creating Buffers::).
37024
37025 -- Function: after-find-file &optional error warn noauto
37026          after-find-file-from-revert-buffer nomodes
37027     This function sets the buffer major mode, and parses local
37028     variables (*note Auto Major Mode::).  It is called by
37029     ‘find-file-noselect’ and by the default revert function (*note
37030     Reverting::).
37031
37032     If reading the file got an error because the file does not exist,
37033     but its directory does exist, the caller should pass a non-‘nil’
37034     value for ERROR.  In that case, ‘after-find-file’ issues a warning:
37035     ‘(New file)’.  For more serious errors, the caller should usually
37036     not call ‘after-find-file’.
37037
37038     If WARN is non-‘nil’, then this function issues a warning if an
37039     auto-save file exists and is more recent than the visited file.
37040
37041     If NOAUTO is non-‘nil’, that says not to enable or disable
37042     Auto-Save mode.  The mode remains enabled if it was enabled before.
37043
37044     If AFTER-FIND-FILE-FROM-REVERT-BUFFER is non-‘nil’, that means this
37045     call was from ‘revert-buffer’.  This has no direct effect, but some
37046     mode functions and hook functions check the value of this variable.
37047
37048     If NOMODES is non-‘nil’, that means don’t alter the buffer’s major
37049     mode, don’t process local variables specifications in the file, and
37050     don’t run ‘find-file-hook’.  This feature is used by
37051     ‘revert-buffer’ in some cases.
37052
37053     The last thing ‘after-find-file’ does is call all the functions in
37054     the list ‘find-file-hook’.
37055
37056
37057File: elisp.info,  Node: Saving Buffers,  Next: Reading from Files,  Prev: Visiting Files,  Up: Files
37058
3705925.2 Saving Buffers
37060===================
37061
37062When you edit a file in Emacs, you are actually working on a buffer that
37063is visiting that file—that is, the contents of the file are copied into
37064the buffer and the copy is what you edit.  Changes to the buffer do not
37065change the file until you “save” the buffer, which means copying the
37066contents of the buffer into the file.  Buffers which are not visiting a
37067file can still be “saved”, in a sense, using functions in the
37068buffer-local ‘write-contents-functions’ hook.
37069
37070 -- Command: save-buffer &optional backup-option
37071     This function saves the contents of the current buffer in its
37072     visited file if the buffer has been modified since it was last
37073     visited or saved.  Otherwise it does nothing.
37074
37075     ‘save-buffer’ is responsible for making backup files.  Normally,
37076     BACKUP-OPTION is ‘nil’, and ‘save-buffer’ makes a backup file only
37077     if this is the first save since visiting the file.  Other values
37078     for BACKUP-OPTION request the making of backup files in other
37079     circumstances:
37080
37081        • With an argument of 4 or 64, reflecting 1 or 3 ‘C-u’’s, the
37082          ‘save-buffer’ function marks this version of the file to be
37083          backed up when the buffer is next saved.
37084
37085        • With an argument of 16 or 64, reflecting 2 or 3 ‘C-u’’s, the
37086          ‘save-buffer’ function unconditionally backs up the previous
37087          version of the file before saving it.
37088
37089        • With an argument of 0, unconditionally do _not_ make any
37090          backup file.
37091
37092 -- Command: save-some-buffers &optional save-silently-p pred
37093     This command saves some modified file-visiting buffers.  Normally
37094     it asks the user about each buffer.  But if SAVE-SILENTLY-P is
37095     non-‘nil’, it saves all the file-visiting buffers without querying
37096     the user.
37097
37098     The optional PRED argument provides a predicate that controls which
37099     buffers to ask about (or to save silently if SAVE-SILENTLY-P is
37100     non-‘nil’).  If PRED is ‘nil’, that means to use the value of
37101     ‘save-some-buffers-default-predicate’ instead of PRED.  If the
37102     result is ‘nil’, it means ask only about file-visiting buffers.  If
37103     it is ‘t’, that means also offer to save certain other non-file
37104     buffers—those that have a non-‘nil’ buffer-local value of
37105     ‘buffer-offer-save’ (*note Killing Buffers::).  A user who says
37106     ‘yes’ to saving a non-file buffer is asked to specify the file name
37107     to use.  The ‘save-buffers-kill-emacs’ function passes the value
37108     ‘t’ for PRED.
37109
37110     If the predicate is neither ‘t’ nor ‘nil’, then it should be a
37111     function of no arguments.  It will be called in each buffer to
37112     decide whether to offer to save that buffer.  If it returns a
37113     non-‘nil’ value in a certain buffer, that means do offer to save
37114     that buffer.
37115
37116 -- Command: write-file filename &optional confirm
37117     This function writes the current buffer into file FILENAME, makes
37118     the buffer visit that file, and marks it not modified.  Then it
37119     renames the buffer based on FILENAME, appending a string like ‘<2>’
37120     if necessary to make a unique buffer name.  It does most of this
37121     work by calling ‘set-visited-file-name’ (*note Buffer File Name::)
37122     and ‘save-buffer’.
37123
37124     If CONFIRM is non-‘nil’, that means to ask for confirmation before
37125     overwriting an existing file.  Interactively, confirmation is
37126     required, unless the user supplies a prefix argument.
37127
37128     If FILENAME is a directory name (*note Directory Names::),
37129     ‘write-file’ uses the name of the visited file, in directory
37130     FILENAME.  If the buffer is not visiting a file, it uses the buffer
37131     name instead.
37132
37133   Saving a buffer runs several hooks.  It also performs format
37134conversion (*note Format Conversion::).  Note that these hooks,
37135described below, are only run by ‘save-buffer’, they are not run by
37136other primitives and functions that write buffer text to files, and in
37137particular auto-saving (*note Auto-Saving::) doesn’t run these hooks.
37138
37139 -- Variable: write-file-functions
37140     The value of this variable is a list of functions to be called
37141     before writing out a buffer to its visited file.  If one of them
37142     returns non-‘nil’, the file is considered already written and the
37143     rest of the functions are not called, nor is the usual code for
37144     writing the file executed.
37145
37146     If a function in ‘write-file-functions’ returns non-‘nil’, it is
37147     responsible for making a backup file (if that is appropriate).  To
37148     do so, execute the following code:
37149
37150          (or buffer-backed-up (backup-buffer))
37151
37152     You might wish to save the file modes value returned by
37153     ‘backup-buffer’ and use that (if non-‘nil’) to set the mode bits of
37154     the file that you write.  This is what ‘save-buffer’ normally does.
37155     *Note Making Backup Files: Making Backups.
37156
37157     The hook functions in ‘write-file-functions’ are also responsible
37158     for encoding the data (if desired): they must choose a suitable
37159     coding system and end-of-line conversion (*note Lisp and Coding
37160     Systems::), perform the encoding (*note Explicit Encoding::), and
37161     set ‘last-coding-system-used’ to the coding system that was used
37162     (*note Encoding and I/O::).
37163
37164     If you set this hook locally in a buffer, it is assumed to be
37165     associated with the file or the way the contents of the buffer were
37166     obtained.  Thus the variable is marked as a permanent local, so
37167     that changing the major mode does not alter a buffer-local value.
37168     On the other hand, calling ‘set-visited-file-name’ will reset it.
37169     If this is not what you want, you might like to use
37170     ‘write-contents-functions’ instead.
37171
37172     Even though this is not a normal hook, you can use ‘add-hook’ and
37173     ‘remove-hook’ to manipulate the list.  *Note Hooks::.
37174
37175 -- Variable: write-contents-functions
37176     This works just like ‘write-file-functions’, but it is intended for
37177     hooks that pertain to the buffer’s contents, not to the particular
37178     visited file or its location, and can be used to create arbitrary
37179     save processes for buffers that aren’t visiting files at all.  Such
37180     hooks are usually set up by major modes, as buffer-local bindings
37181     for this variable.  This variable automatically becomes
37182     buffer-local whenever it is set; switching to a new major mode
37183     always resets this variable, but calling ‘set-visited-file-name’
37184     does not.
37185
37186     If any of the functions in this hook returns non-‘nil’, the file is
37187     considered already written and the rest are not called and neither
37188     are the functions in ‘write-file-functions’.
37189
37190     When using this hook to save buffers that are not visiting files
37191     (for instance, special-mode buffers), keep in mind that, if the
37192     function fails to save correctly and returns a ‘nil’ value,
37193     ‘save-buffer’ will go on to prompt the user for a file to save the
37194     buffer in.  If this is undesirable, consider having the function
37195     fail by raising an error.
37196
37197 -- User Option: before-save-hook
37198     This normal hook runs before a buffer is saved in its visited file,
37199     regardless of whether that is done normally or by one of the hooks
37200     described above.  For instance, the ‘copyright.el’ program uses
37201     this hook to make sure the file you are saving has the current year
37202     in its copyright notice.
37203
37204 -- User Option: after-save-hook
37205     This normal hook runs after a buffer has been saved in its visited
37206     file.
37207
37208 -- User Option: file-precious-flag
37209     If this variable is non-‘nil’, then ‘save-buffer’ protects against
37210     I/O errors while saving by writing the new file to a temporary name
37211     instead of the name it is supposed to have, and then renaming it to
37212     the intended name after it is clear there are no errors.  This
37213     procedure prevents problems such as a lack of disk space from
37214     resulting in an invalid file.
37215
37216     As a side effect, backups are necessarily made by copying.  *Note
37217     Rename or Copy::.  Yet, at the same time, saving a precious file
37218     always breaks all hard links between the file you save and other
37219     file names.
37220
37221     Some modes give this variable a non-‘nil’ buffer-local value in
37222     particular buffers.
37223
37224 -- User Option: require-final-newline
37225     This variable determines whether files may be written out that do
37226     _not_ end with a newline.  If the value of the variable is ‘t’,
37227     then ‘save-buffer’ silently adds a newline at the end of the buffer
37228     whenever it does not already end in one.  If the value is ‘visit’,
37229     Emacs adds a missing newline just after it visits the file.  If the
37230     value is ‘visit-save’, Emacs adds a missing newline both on
37231     visiting and on saving.  For any other non-‘nil’ value,
37232     ‘save-buffer’ asks the user whether to add a newline each time the
37233     case arises.
37234
37235     If the value of the variable is ‘nil’, then ‘save-buffer’ doesn’t
37236     add newlines at all.  ‘nil’ is the default value, but a few major
37237     modes set it to ‘t’ in particular buffers.
37238
37239   See also the function ‘set-visited-file-name’ (*note Buffer File
37240Name::).
37241
37242
37243File: elisp.info,  Node: Reading from Files,  Next: Writing to Files,  Prev: Saving Buffers,  Up: Files
37244
3724525.3 Reading from Files
37246=======================
37247
37248To copy the contents of a file into a buffer, use the function
37249‘insert-file-contents’.  (Don’t use the command ‘insert-file’ in a Lisp
37250program, as that sets the mark.)
37251
37252 -- Function: insert-file-contents filename &optional visit beg end
37253          replace
37254     This function inserts the contents of file FILENAME into the
37255     current buffer after point.  It returns a list of the absolute file
37256     name and the length of the data inserted.  An error is signaled if
37257     FILENAME is not the name of a file that can be read.
37258
37259     This function checks the file contents against the defined file
37260     formats, and converts the file contents if appropriate and also
37261     calls the functions in the list ‘after-insert-file-functions’.
37262     *Note Format Conversion::.  Normally, one of the functions in the
37263     ‘after-insert-file-functions’ list determines the coding system
37264     (*note Coding Systems::) used for decoding the file’s contents,
37265     including end-of-line conversion.  However, if the file contains
37266     null bytes, it is by default visited without any code conversions.
37267     *Note inhibit-nul-byte-detection: Lisp and Coding Systems.
37268
37269     If VISIT is non-‘nil’, this function additionally marks the buffer
37270     as unmodified and sets up various fields in the buffer so that it
37271     is visiting the file FILENAME: these include the buffer’s visited
37272     file name and its last save file modtime.  This feature is used by
37273     ‘find-file-noselect’ and you probably should not use it yourself.
37274
37275     If BEG and END are non-‘nil’, they should be numbers that are byte
37276     offsets specifying the portion of the file to insert.  In this
37277     case, VISIT must be ‘nil’.  For example,
37278
37279          (insert-file-contents filename nil 0 500)
37280
37281     inserts the first 500 characters of a file.
37282
37283     If the argument REPLACE is non-‘nil’, it means to replace the
37284     contents of the buffer (actually, just the accessible portion) with
37285     the contents of the file.  This is better than simply deleting the
37286     buffer contents and inserting the whole file, because (1) it
37287     preserves some marker positions and (2) it puts less data in the
37288     undo list.
37289
37290     It is possible to read a special file (such as a FIFO or an I/O
37291     device) with ‘insert-file-contents’, as long as REPLACE and VISIT
37292     are ‘nil’.
37293
37294 -- Function: insert-file-contents-literally filename &optional visit
37295          beg end replace
37296     This function works like ‘insert-file-contents’ except that it does
37297     not run ‘after-insert-file-functions’, and does not do format
37298     decoding, character code conversion, automatic uncompression, and
37299     so on.
37300
37301   If you want to pass a file name to another process so that another
37302program can read the file, use the function ‘file-local-copy’; see *note
37303Magic File Names::.
37304
37305
37306File: elisp.info,  Node: Writing to Files,  Next: File Locks,  Prev: Reading from Files,  Up: Files
37307
3730825.4 Writing to Files
37309=====================
37310
37311You can write the contents of a buffer, or part of a buffer, directly to
37312a file on disk using the ‘append-to-file’ and ‘write-region’ functions.
37313Don’t use these functions to write to files that are being visited; that
37314could cause confusion in the mechanisms for visiting.
37315
37316 -- Command: append-to-file start end filename
37317     This function appends the contents of the region delimited by START
37318     and END in the current buffer to the end of file FILENAME.  If that
37319     file does not exist, it is created.  This function returns ‘nil’.
37320
37321     An error is signaled if you cannot write or create FILENAME.
37322
37323     When called from Lisp, this function is completely equivalent to:
37324
37325          (write-region start end filename t)
37326
37327 -- Command: write-region start end filename &optional append visit
37328          lockname mustbenew
37329     This function writes the region delimited by START and END in the
37330     current buffer into the file specified by FILENAME.
37331
37332     If START is ‘nil’, then the command writes the entire buffer
37333     contents (_not_ just the accessible portion) to the file and
37334     ignores END.
37335
37336     If START is a string, then ‘write-region’ writes or appends that
37337     string, rather than text from the buffer.  END is ignored in this
37338     case.
37339
37340     If APPEND is non-‘nil’, then the specified text is appended to the
37341     existing file contents (if any).  If APPEND is a number,
37342     ‘write-region’ seeks to that byte offset from the start of the file
37343     and writes the data from there.
37344
37345     If MUSTBENEW is non-‘nil’, then ‘write-region’ asks for
37346     confirmation if FILENAME names an existing file.  If MUSTBENEW is
37347     the symbol ‘excl’, then ‘write-region’ does not ask for
37348     confirmation, but instead it signals an error ‘file-already-exists’
37349     if the file already exists.  Although ‘write-region’ normally
37350     follows a symbolic link and creates the pointed-to file if the
37351     symbolic link is dangling, it does not follow symbolic links if
37352     MUSTBENEW is ‘excl’.
37353
37354     The test for an existing file, when MUSTBENEW is ‘excl’, uses a
37355     special system feature.  At least for files on a local disk, there
37356     is no chance that some other program could create a file of the
37357     same name before Emacs does, without Emacs’s noticing.
37358
37359     If VISIT is ‘t’, then Emacs establishes an association between the
37360     buffer and the file: the buffer is then visiting that file.  It
37361     also sets the last file modification time for the current buffer to
37362     FILENAME’s modtime, and marks the buffer as not modified.  This
37363     feature is used by ‘save-buffer’, but you probably should not use
37364     it yourself.
37365
37366     If VISIT is a string, it specifies the file name to visit.  This
37367     way, you can write the data to one file (FILENAME) while recording
37368     the buffer as visiting another file (VISIT).  The argument VISIT is
37369     used in the echo area message and also for file locking; VISIT is
37370     stored in ‘buffer-file-name’.  This feature is used to implement
37371     ‘file-precious-flag’; don’t use it yourself unless you really know
37372     what you’re doing.
37373
37374     The optional argument LOCKNAME, if non-‘nil’, specifies the file
37375     name to use for purposes of locking and unlocking, overriding
37376     FILENAME and VISIT for that purpose.
37377
37378     The function ‘write-region’ converts the data which it writes to
37379     the appropriate file formats specified by ‘buffer-file-format’ and
37380     also calls the functions in the list
37381     ‘write-region-annotate-functions’.  *Note Format Conversion::.
37382
37383     Normally, ‘write-region’ displays the message ‘Wrote FILENAME’ in
37384     the echo area.  This message is inhibited if VISIT is neither ‘t’
37385     nor ‘nil’ nor a string, or if Emacs is operating in batch mode
37386     (*note Batch Mode::).  This feature is useful for programs that use
37387     files for internal purposes, files that the user does not need to
37388     know about.
37389
37390 -- Variable: write-region-inhibit-fsync
37391     If this variable’s value is ‘nil’, ‘write-region’ uses the ‘fsync’
37392     system call after writing a file.  Although this slows Emacs down,
37393     it lessens the risk of data loss after power failure.  If the value
37394     is ‘t’, Emacs does not use ‘fsync’.  The default value is ‘nil’
37395     when Emacs is interactive, and ‘t’ when Emacs runs in batch mode.
37396     *Note Files and Storage::.
37397
37398 -- Macro: with-temp-file file body...
37399     The ‘with-temp-file’ macro evaluates the BODY forms with a
37400     temporary buffer as the current buffer; then, at the end, it writes
37401     the buffer contents into file FILE.  It kills the temporary buffer
37402     when finished, restoring the buffer that was current before the
37403     ‘with-temp-file’ form.  Then it returns the value of the last form
37404     in BODY.
37405
37406     The current buffer is restored even in case of an abnormal exit via
37407     ‘throw’ or error (*note Nonlocal Exits::).
37408
37409     See also ‘with-temp-buffer’ in *note The Current Buffer: Definition
37410     of with-temp-buffer.
37411
37412
37413File: elisp.info,  Node: File Locks,  Next: Information about Files,  Prev: Writing to Files,  Up: Files
37414
3741525.5 File Locks
37416===============
37417
37418When two users edit the same file at the same time, they are likely to
37419interfere with each other.  Emacs tries to prevent this situation from
37420arising by recording a “file lock” when a file is being modified.  Emacs
37421can then detect the first attempt to modify a buffer visiting a file
37422that is locked by another Emacs job, and ask the user what to do.  The
37423file lock is really a file, a symbolic link with a special name, stored
37424in the same directory as the file you are editing.  The name is
37425constructed by prepending ‘.#’ to the filename of the buffer.  The
37426target of the symbolic link will be of the form ‘USER@HOST.PID:BOOT’,
37427where USER is replaced with the current username (from
37428‘user-login-name’), HOST with the name of the host where Emacs is
37429running (from ‘system-name’), PID with Emacs’s process id, and BOOT with
37430the time since the last reboot.  ‘:BOOT’ is omitted if the boot time is
37431unavailable.  (On file systems that do not support symbolic links, a
37432regular file is used instead, with contents of the form
37433‘USER@HOST.PID:BOOT’.)
37434
37435   When you access files using NFS, there may be a small probability
37436that you and another user will both lock the same file simultaneously.
37437If this happens, it is possible for the two users to make changes
37438simultaneously, but Emacs will still warn the user who saves second.
37439Also, the detection of modification of a buffer visiting a file changed
37440on disk catches some cases of simultaneous editing; see *note
37441Modification Time::.
37442
37443 -- Function: file-locked-p filename
37444     This function returns ‘nil’ if the file FILENAME is not locked.  It
37445     returns ‘t’ if it is locked by this Emacs process, and it returns
37446     the name of the user who has locked it if it is locked by some
37447     other job.
37448
37449          (file-locked-p "foo")
37450               ⇒ nil
37451
37452 -- Function: lock-buffer &optional filename
37453     This function locks the file FILENAME, if the current buffer is
37454     modified.  The argument FILENAME defaults to the current buffer’s
37455     visited file.  Nothing is done if the current buffer is not
37456     visiting a file, or is not modified, or if the option
37457     ‘create-lockfiles’ is ‘nil’.
37458
37459 -- Function: unlock-buffer
37460     This function unlocks the file being visited in the current buffer,
37461     if the buffer is modified.  If the buffer is not modified, then the
37462     file should not be locked, so this function does nothing.  It also
37463     does nothing if the current buffer is not visiting a file, or is
37464     not locked.
37465
37466 -- User Option: create-lockfiles
37467     If this variable is ‘nil’, Emacs does not lock files.
37468
37469 -- Function: ask-user-about-lock file other-user
37470     This function is called when the user tries to modify FILE, but it
37471     is locked by another user named OTHER-USER.  The default definition
37472     of this function asks the user to say what to do.  The value this
37473     function returns determines what Emacs does next:
37474
37475        • A value of ‘t’ says to grab the lock on the file.  Then this
37476          user may edit the file and OTHER-USER loses the lock.
37477
37478        • A value of ‘nil’ says to ignore the lock and let this user
37479          edit the file anyway.
37480
37481        • This function may instead signal a ‘file-locked’ error, in
37482          which case the change that the user was about to make does not
37483          take place.
37484
37485          The error message for this error looks like this:
37486
37487               error→ File is locked: FILE OTHER-USER
37488
37489          where ‘file’ is the name of the file and OTHER-USER is the
37490          name of the user who has locked the file.
37491
37492     If you wish, you can replace the ‘ask-user-about-lock’ function
37493     with your own version that makes the decision in another way.
37494
37495
37496File: elisp.info,  Node: Information about Files,  Next: Changing Files,  Prev: File Locks,  Up: Files
37497
3749825.6 Information about Files
37499============================
37500
37501This section describes the functions for retrieving various types of
37502information about files (or directories or symbolic links), such as
37503whether a file is readable or writable, and its size.  These functions
37504all take arguments which are file names.  Except where noted, these
37505arguments need to specify existing files, or an error is signaled.
37506
37507   Be careful with file names that end in spaces.  On some filesystems
37508(notably, MS-Windows), trailing whitespace characters in file names are
37509silently and automatically ignored.
37510
37511* Menu:
37512
37513* Testing Accessibility::   Is a given file readable?  Writable?
37514* Kinds of Files::          Is it a directory?  A symbolic link?
37515* Truenames::               Eliminating symbolic links from a file name.
37516* File Attributes::         File sizes, modification times, etc.
37517* Extended Attributes::     Extended file attributes for access control.
37518* Locating Files::          How to find a file in standard places.
37519
37520
37521File: elisp.info,  Node: Testing Accessibility,  Next: Kinds of Files,  Up: Information about Files
37522
3752325.6.1 Testing Accessibility
37524----------------------------
37525
37526These functions test for permission to access a file for reading,
37527writing, or execution.  Unless explicitly stated otherwise, they follow
37528symbolic links.  *Note Kinds of Files::.
37529
37530   On some operating systems, more complex sets of access permissions
37531can be specified, via mechanisms such as Access Control Lists (ACLs).
37532*Note Extended Attributes::, for how to query and set those permissions.
37533
37534 -- Function: file-exists-p filename
37535     This function returns ‘t’ if a file named FILENAME appears to
37536     exist.  This does not mean you can necessarily read the file, only
37537     that you can probably find out its attributes.  (On GNU and other
37538     POSIX-like systems, this is true if the file exists and you have
37539     execute permission on the containing directories, regardless of the
37540     permissions of the file itself.)
37541
37542     If the file does not exist, or if there was trouble determining
37543     whether the file exists, this function returns ‘nil’.
37544
37545     Directories are files, so ‘file-exists-p’ can return ‘t’ when given
37546     a directory.  However, because ‘file-exists-p’ follows symbolic
37547     links, it returns ‘t’ for a symbolic link name only if the target
37548     file exists.
37549
37550 -- Function: file-readable-p filename
37551     This function returns ‘t’ if a file named FILENAME exists and you
37552     can read it.  It returns ‘nil’ otherwise.
37553
37554 -- Function: file-executable-p filename
37555     This function returns ‘t’ if a file named FILENAME exists and you
37556     can execute it.  It returns ‘nil’ otherwise.  On GNU and other
37557     POSIX-like systems, if the file is a directory, execute permission
37558     means you can check the existence and attributes of files inside
37559     the directory, and open those files if their modes permit.
37560
37561 -- Function: file-writable-p filename
37562     This function returns ‘t’ if the file FILENAME can be written or
37563     created by you, and ‘nil’ otherwise.  A file is writable if the
37564     file exists and you can write it.  It is creatable if it does not
37565     exist, but its parent directory does exist and you can write in
37566     that directory.
37567
37568     In the example below, ‘foo’ is not writable because the parent
37569     directory does not exist, even though the user could create such a
37570     directory.
37571
37572          (file-writable-p "~/no-such-dir/foo")
37573               ⇒ nil
37574
37575 -- Function: file-accessible-directory-p dirname
37576     This function returns ‘t’ if you have permission to open existing
37577     files in the directory whose name as a file is DIRNAME; otherwise
37578     (e.g., if there is no such directory), it returns ‘nil’.  The value
37579     of DIRNAME may be either a directory name (such as ‘/foo/’) or the
37580     file name of a file which is a directory (such as ‘/foo’, without
37581     the final slash).
37582
37583     For example, from the following we deduce that any attempt to read
37584     a file in ‘/foo/’ will give an error:
37585
37586          (file-accessible-directory-p "/foo")
37587               ⇒ nil
37588
37589 -- Function: access-file filename string
37590     If you can read FILENAME this function returns ‘nil’; otherwise it
37591     signals an error using STRING as the error message text.
37592
37593 -- Function: file-ownership-preserved-p filename &optional group
37594     This function returns ‘t’ if deleting the file FILENAME and then
37595     creating it anew would keep the file’s owner unchanged.  It also
37596     returns ‘t’ for nonexistent files.
37597
37598     If the optional argument GROUP is non-‘nil’, this function also
37599     checks that the file’s group would be unchanged.
37600
37601     This function does not follow symbolic links.
37602
37603 -- Function: file-modes filename
37604     This function returns the “mode bits” of FILENAME—an integer
37605     summarizing its read, write, and execution permissions.  This
37606     function follows symbolic links.  If the file does not exist, the
37607     return value is ‘nil’.
37608
37609     *Note (coreutils)File permissions::, for a description of mode
37610     bits.  For example, if the low-order bit is 1, the file is
37611     executable by all users; if the second-lowest-order bit is 1, the
37612     file is writable by all users; etc.  The highest possible value is
37613     4095 (7777 octal), meaning that everyone has read, write, and
37614     execute permission, the SUID bit is set for both others and group,
37615     and the sticky bit is set.
37616
37617     *Note Changing Files::, for the ‘set-file-modes’ function, which
37618     can be used to set these permissions.
37619
37620          (file-modes "~/junk/diffs")
37621               ⇒ 492               ; Decimal integer.
37622          (format "%o" 492)
37623               ⇒ "754"             ; Convert to octal.
37624
37625          (set-file-modes "~/junk/diffs" #o666)
37626               ⇒ nil
37627
37628          $ ls -l diffs
37629          -rw-rw-rw- 1 lewis lewis 3063 Oct 30 16:00 diffs
37630
37631     *MS-DOS note:* On MS-DOS, there is no such thing as an executable
37632     file mode bit.  So ‘file-modes’ considers a file executable if its
37633     name ends in one of the standard executable extensions, such as
37634     ‘.com’, ‘.bat’, ‘.exe’, and some others.  Files that begin with the
37635     POSIX-standard ‘#!’ signature, such as shell and Perl scripts, are
37636     also considered executable.  Directories are also reported as
37637     executable, for compatibility with POSIX.  These conventions are
37638     also followed by ‘file-attributes’ (*note File Attributes::).
37639
37640
37641File: elisp.info,  Node: Kinds of Files,  Next: Truenames,  Prev: Testing Accessibility,  Up: Information about Files
37642
3764325.6.2 Distinguishing Kinds of Files
37644------------------------------------
37645
37646This section describes how to distinguish various kinds of files, such
37647as directories, symbolic links, and ordinary files.
37648
37649   Symbolic links are ordinarily followed wherever they appear.  For
37650example, to interpret the file name ‘a/b/c’, any of ‘a’, ‘a/b’, and
37651‘a/b/c’ can be symbolic links that are followed, possibly recursively if
37652the link targets are themselves symbolic links.  However, a few
37653functions do not follow symbolic links at the end of a file name
37654(‘a/b/c’ in this example).  Such a function is said to “not follow
37655symbolic links”.
37656
37657 -- Function: file-symlink-p filename
37658     If the file FILENAME is a symbolic link, this function does not
37659     follow it and instead returns its link target as a string.  (The
37660     link target string is not necessarily the full absolute file name
37661     of the target; determining the full file name that the link points
37662     to is nontrivial, see below.)
37663
37664     If the file FILENAME is not a symbolic link, or does not exist, or
37665     if there is trouble determining whether it is a symbolic link,
37666     ‘file-symlink-p’ returns ‘nil’.
37667
37668     Here are a few examples of using this function:
37669
37670          (file-symlink-p "not-a-symlink")
37671               ⇒ nil
37672          (file-symlink-p "sym-link")
37673               ⇒ "not-a-symlink"
37674          (file-symlink-p "sym-link2")
37675               ⇒ "sym-link"
37676          (file-symlink-p "/bin")
37677               ⇒ "/pub/bin"
37678
37679     Note that in the third example, the function returned ‘sym-link’,
37680     but did not proceed to resolve it, although that file is itself a
37681     symbolic link.  That is because this function does not follow
37682     symbolic links—the process of following the symbolic links does not
37683     apply to the last component of the file name.
37684
37685     The string that this function returns is what is recorded in the
37686     symbolic link; it may or may not include any leading directories.
37687     This function does _not_ expand the link target to produce a
37688     fully-qualified file name, and in particular does not use the
37689     leading directories, if any, of the FILENAME argument if the link
37690     target is not an absolute file name.  Here’s an example:
37691
37692          (file-symlink-p "/foo/bar/baz")
37693               ⇒ "some-file"
37694
37695     Here, although ‘/foo/bar/baz’ was given as a fully-qualified file
37696     name, the result is not, and in fact does not have any leading
37697     directories at all.  And since ‘some-file’ might itself be a
37698     symbolic link, you cannot simply prepend leading directories to it,
37699     nor even naively use ‘expand-file-name’ (*note File Name
37700     Expansion::) to produce its absolute file name.
37701
37702     For this reason, this function is seldom useful if you need to
37703     determine more than just the fact that a file is or isn’t a
37704     symbolic link.  If you actually need the file name of the link
37705     target, use ‘file-chase-links’ or ‘file-truename’, described in
37706     *note Truenames::.
37707
37708 -- Function: file-directory-p filename
37709     This function returns ‘t’ if FILENAME is the name of an existing
37710     directory.  It returns ‘nil’ if FILENAME does not name a directory,
37711     or if there is trouble determining whether it is a directory.  This
37712     function follows symbolic links.
37713
37714          (file-directory-p "~rms")
37715               ⇒ t
37716          (file-directory-p "~rms/lewis/files.texi")
37717               ⇒ nil
37718          (file-directory-p "~rms/lewis/no-such-file")
37719               ⇒ nil
37720          (file-directory-p "$HOME")
37721               ⇒ nil
37722          (file-directory-p
37723           (substitute-in-file-name "$HOME"))
37724               ⇒ t
37725
37726 -- Function: file-regular-p filename
37727     This function returns ‘t’ if the file FILENAME exists and is a
37728     regular file (not a directory, named pipe, terminal, or other I/O
37729     device).  It returns ‘nil’ if FILENAME does not exist or is not a
37730     regular file, or if there is trouble determining whether it is a
37731     regular file.  This function follows symbolic links.
37732
37733
37734File: elisp.info,  Node: Truenames,  Next: File Attributes,  Prev: Kinds of Files,  Up: Information about Files
37735
3773625.6.3 Truenames
37737----------------
37738
37739The “truename” of a file is the name that you get by following symbolic
37740links at all levels until none remain, then simplifying away ‘.’ and
37741‘..’ appearing as name components.  This results in a sort of canonical
37742name for the file.  A file does not always have a unique truename; the
37743number of distinct truenames a file has is equal to the number of hard
37744links to the file.  However, truenames are useful because they eliminate
37745symbolic links as a cause of name variation.
37746
37747 -- Function: file-truename filename
37748     This function returns the truename of the file FILENAME.  If the
37749     argument is not an absolute file name, this function first expands
37750     it against ‘default-directory’.
37751
37752     This function does not expand environment variables.  Only
37753     ‘substitute-in-file-name’ does that.  *Note Definition of
37754     substitute-in-file-name::.
37755
37756     If you may need to follow symbolic links preceding ‘..’ appearing
37757     as a name component, call ‘file-truename’ without prior direct or
37758     indirect calls to ‘expand-file-name’.  Otherwise, the file name
37759     component immediately preceding ‘..’ will be simplified away before
37760     ‘file-truename’ is called.  To eliminate the need for a call to
37761     ‘expand-file-name’, ‘file-truename’ handles ‘~’ in the same way
37762     that ‘expand-file-name’ does.
37763
37764     If the target of a symbolic links has remote file name syntax,
37765     ‘file-truename’ returns it quoted.  *Note Functions that Expand
37766     Filenames: File Name Expansion.
37767
37768 -- Function: file-chase-links filename &optional limit
37769     This function follows symbolic links, starting with FILENAME, until
37770     it finds a file name which is not the name of a symbolic link.
37771     Then it returns that file name.  This function does _not_ follow
37772     symbolic links at the level of parent directories.
37773
37774     If you specify a number for LIMIT, then after chasing through that
37775     many links, the function just returns what it has even if that is
37776     still a symbolic link.
37777
37778   To illustrate the difference between ‘file-chase-links’ and
37779‘file-truename’, suppose that ‘/usr/foo’ is a symbolic link to the
37780directory ‘/home/foo’, and ‘/home/foo/hello’ is an ordinary file (or at
37781least, not a symbolic link) or nonexistent.  Then we would have:
37782
37783     (file-chase-links "/usr/foo/hello")
37784          ;; This does not follow the links in the parent directories.
37785          ⇒ "/usr/foo/hello"
37786     (file-truename "/usr/foo/hello")
37787          ;; Assuming that ‘/home’ is not a symbolic link.
37788          ⇒ "/home/foo/hello"
37789
37790 -- Function: file-equal-p file1 file2
37791     This function returns ‘t’ if the files FILE1 and FILE2 name the
37792     same file.  This is similar to comparing their truenames, except
37793     that remote file names are also handled in an appropriate manner.
37794     If FILE1 or FILE2 does not exist, the return value is unspecified.
37795
37796 -- Function: file-name-case-insensitive-p filename
37797     Sometimes file names or their parts need to be compared as strings,
37798     in which case it’s important to know whether the underlying
37799     filesystem is case-insensitive.  This function returns ‘t’ if file
37800     FILENAME is on a case-insensitive filesystem.  It always returns
37801     ‘t’ on MS-DOS and MS-Windows.  On Cygwin and macOS, filesystems may
37802     or may not be case-insensitive, and the function tries to determine
37803     case-sensitivity by a runtime test.  If the test is inconclusive,
37804     the function returns ‘t’ on Cygwin and ‘nil’ on macOS.
37805
37806     Currently this function always returns ‘nil’ on platforms other
37807     than MS-DOS, MS-Windows, Cygwin, and macOS.  It does not detect
37808     case-insensitivity of mounted filesystems, such as Samba shares or
37809     NFS-mounted Windows volumes.  On remote hosts, it assumes ‘t’ for
37810     the ‘smb’ method.  For all other connection methods, runtime tests
37811     are performed.
37812
37813 -- Function: file-in-directory-p file dir
37814     This function returns ‘t’ if FILE is a file in directory DIR, or in
37815     a subdirectory of DIR.  It also returns ‘t’ if FILE and DIR are the
37816     same directory.  It compares the truenames of the two directories.
37817     If DIR does not name an existing directory, the return value is
37818     ‘nil’.
37819
37820 -- Function: vc-responsible-backend file
37821     This function determines the responsible VC backend of the given
37822     FILE.  For example, if ‘emacs.c’ is a file tracked by Git,
37823     ‘(vc-responsible-backend "emacs.c")’ returns ‘Git’.  Note that if
37824     FILE is a symbolic link, ‘vc-responsible-backend’ will not resolve
37825     it—the backend of the symbolic link file itself is reported.  To
37826     get the backend VC of the file to which FILE refers, wrap FILE with
37827     a symbolic link resolving function such as ‘file-chase-links’:
37828
37829          (vc-responsible-backend (file-chase-links "emacs.c"))
37830
37831
37832File: elisp.info,  Node: File Attributes,  Next: Extended Attributes,  Prev: Truenames,  Up: Information about Files
37833
3783425.6.4 File Attributes
37835----------------------
37836
37837This section describes the functions for getting detailed information
37838about a file, including the owner and group numbers, the number of
37839names, the inode number, the size, and the times of access and
37840modification.
37841
37842 -- Function: file-newer-than-file-p filename1 filename2
37843     This function returns ‘t’ if the file FILENAME1 is newer than file
37844     FILENAME2.  If FILENAME1 does not exist, it returns ‘nil’.  If
37845     FILENAME1 does exist, but FILENAME2 does not, it returns ‘t’.
37846
37847     In the following example, assume that the file ‘aug-19’ was written
37848     on the 19th, ‘aug-20’ was written on the 20th, and the file
37849     ‘no-file’ doesn’t exist at all.
37850
37851          (file-newer-than-file-p "aug-19" "aug-20")
37852               ⇒ nil
37853          (file-newer-than-file-p "aug-20" "aug-19")
37854               ⇒ t
37855          (file-newer-than-file-p "aug-19" "no-file")
37856               ⇒ t
37857          (file-newer-than-file-p "no-file" "aug-19")
37858               ⇒ nil
37859
37860 -- Function: file-attributes filename &optional id-format
37861     This function returns a list of attributes of file FILENAME.  If
37862     the specified file does not exist, it returns ‘nil’.  This function
37863     does not follow symbolic links.  The optional parameter ID-FORMAT
37864     specifies the preferred format of attributes UID and GID (see
37865     below)—the valid values are ‘'string’ and ‘'integer’.  The latter
37866     is the default, but we plan to change that, so you should specify a
37867     non-‘nil’ value for ID-FORMAT if you use the returned UID or GID.
37868
37869     On GNU platforms when operating on a local file, this function is
37870     atomic: if the filesystem is simultaneously being changed by some
37871     other process, this function returns the file’s attributes either
37872     before or after the change.  Otherwise this function is not atomic,
37873     and might return ‘nil’ if it detects the race condition, or might
37874     return a hodgepodge of the previous and current file attributes.
37875
37876     Accessor functions are provided to access the elements in this
37877     list.  The accessors are mentioned along with the descriptions of
37878     the elements below.
37879
37880     The elements of the list, in order, are:
37881
37882       0. ‘t’ for a directory, a string for a symbolic link (the name
37883          linked to), or ‘nil’ for a text file (‘file-attribute-type’).
37884
37885       1. The number of names the file has
37886          (‘file-attribute-link-number’).  Alternate names, also known
37887          as hard links, can be created by using the ‘add-name-to-file’
37888          function (*note Changing Files::).
37889
37890       2. The file’s UID, normally as a string
37891          (‘file-attribute-user-id’).  However, if it does not
37892          correspond to a named user, the value is an integer.
37893
37894       3. The file’s GID, likewise (‘file-attribute-group-id’).
37895
37896       4. The time of last access as a Lisp timestamp
37897          (‘file-attribute-access-time’).  The timestamp is in the style
37898          of ‘current-time’ (*note Time of Day::) and is truncated to
37899          that of the filesystem’s timestamp resolution; for example, on
37900          some FAT-based filesystems, only the date of last access is
37901          recorded, so this time will always hold the midnight of the
37902          day of the last access.
37903
37904       5. The time of last modification as a Lisp timestamp
37905          (‘file-attribute-modification-time’).  This is the last time
37906          when the file’s contents were modified.
37907
37908       6. The time of last status change as a Lisp timestamp
37909          (‘file-attribute-status-change-time’).  This is the time of
37910          the last change to the file’s access mode bits, its owner and
37911          group, and other information recorded in the filesystem for
37912          the file, beyond the file’s contents.
37913
37914       7. The size of the file in bytes (‘file-attribute-size’).
37915
37916       8. The file’s modes, as a string of ten letters or dashes, as in
37917          ‘ls -l’ (‘file-attribute-modes’).
37918
37919       9. An unspecified value, present for backward compatibility.
37920
37921       10. The file’s inode number (‘file-attribute-inode-number’), a
37922          nonnegative integer.
37923
37924       11. The filesystem number of the device that the file is on
37925          ‘file-attribute-device-number’), an integer.  This element and
37926          the file’s inode number together give enough information to
37927          distinguish any two files on the system—no two files can have
37928          the same values for both of these numbers.
37929
37930     For example, here are the file attributes for ‘files.texi’:
37931
37932          (file-attributes "files.texi" 'string)
37933               ⇒  (nil 1 "lh" "users"
37934                    (20614 64019 50040 152000)
37935                    (20000 23 0 0)
37936                    (20614 64555 902289 872000)
37937                    122295 "-rw-rw-rw-"
37938                    t 6473924464520138
37939                    1014478468)
37940
37941     and here is how the result is interpreted:
37942
37943     ‘nil’
37944          is neither a directory nor a symbolic link.
37945
37946     ‘1’
37947          has only one name (the name ‘files.texi’ in the current
37948          default directory).
37949
37950     ‘"lh"’
37951          is owned by the user with name ‘lh’.
37952
37953     ‘"users"’
37954          is in the group with name ‘users’.
37955
37956     ‘(20614 64019 50040 152000)’
37957          was last accessed on October 23, 2012, at 20:12:03.050040152
37958          UTC.
37959
37960     ‘(20000 23 0 0)’
37961          was last modified on July 15, 2001, at 08:53:43 UTC.
37962
37963     ‘(20614 64555 902289 872000)’
37964          last had its status changed on October 23, 2012, at
37965          20:20:59.902289872 UTC.
37966
37967     ‘122295’
37968          is 122295 bytes long.  (It may not contain 122295 characters,
37969          though, if some of the bytes belong to multibyte sequences,
37970          and also if the end-of-line format is CR-LF.)
37971
37972     ‘"-rw-rw-rw-"’
37973          has a mode of read and write access for the owner, group, and
37974          world.
37975
37976     ‘t’
37977          is merely a placeholder; it carries no information.
37978
37979     ‘6473924464520138’
37980          has an inode number of 6473924464520138.
37981
37982     ‘1014478468’
37983          is on the file-system device whose number is 1014478468.
37984
37985 -- Function: file-nlinks filename
37986     This function returns the number of names (i.e., hard links) that
37987     file FILENAME has.  If the file does not exist, this function
37988     returns ‘nil’.  Note that symbolic links have no effect on this
37989     function, because they are not considered to be names of the files
37990     they link to.  This function does not follow symbolic links.
37991
37992          $ ls -l foo*
37993          -rw-rw-rw- 2 rms rms 4 Aug 19 01:27 foo
37994          -rw-rw-rw- 2 rms rms 4 Aug 19 01:27 foo1
37995
37996          (file-nlinks "foo")
37997               ⇒ 2
37998          (file-nlinks "doesnt-exist")
37999               ⇒ nil
38000
38001
38002File: elisp.info,  Node: Extended Attributes,  Next: Locating Files,  Prev: File Attributes,  Up: Information about Files
38003
3800425.6.5 Extended File Attributes
38005-------------------------------
38006
38007On some operating systems, each file can be associated with arbitrary
38008“extended file attributes”.  At present, Emacs supports querying and
38009setting two specific sets of extended file attributes: Access Control
38010Lists (ACLs) and SELinux contexts.  These extended file attributes are
38011used, on some systems, to impose more sophisticated file access controls
38012than the basic Unix-style permissions discussed in the previous
38013sections.
38014
38015   A detailed explanation of ACLs and SELinux is beyond the scope of
38016this manual.  For our purposes, each file can be associated with an
38017“ACL”, which specifies its properties under an ACL-based file control
38018system, and/or an “SELinux context”, which specifies its properties
38019under the SELinux system.
38020
38021 -- Function: file-acl filename
38022     This function returns the ACL for the file FILENAME.  The exact
38023     Lisp representation of the ACL is unspecified (and may change in
38024     future Emacs versions), but it is the same as what ‘set-file-acl’
38025     takes for its ACL argument (*note Changing Files::).
38026
38027     The underlying ACL implementation is platform-specific; on
38028     GNU/Linux and BSD, Emacs uses the POSIX ACL interface, while on
38029     MS-Windows Emacs emulates the POSIX ACL interface with native file
38030     security APIs.
38031
38032     If ACLs are not supported or the file does not exist, then the
38033     return value is ‘nil’.
38034
38035 -- Function: file-selinux-context filename
38036     This function returns the SELinux context of the file FILENAME, as
38037     a list of the form ‘(USER ROLE TYPE RANGE)’.  The list elements are
38038     the context’s user, role, type, and range respectively, as Lisp
38039     strings; see the SELinux documentation for details about what these
38040     actually mean.  The return value has the same form as what
38041     ‘set-file-selinux-context’ takes for its CONTEXT argument (*note
38042     Changing Files::).
38043
38044     If SELinux is not supported or the file does not exist, then the
38045     return value is ‘(nil nil nil nil)’.
38046
38047 -- Function: file-extended-attributes filename
38048     This function returns an alist of the Emacs-recognized extended
38049     attributes of file FILENAME.  Currently, it serves as a convenient
38050     way to retrieve both the ACL and SELinux context; you can then call
38051     the function ‘set-file-extended-attributes’, with the returned
38052     alist as its second argument, to apply the same file access
38053     attributes to another file (*note Changing Files::).
38054
38055     One of the elements is ‘(acl . ACL)’, where ACL has the same form
38056     returned by ‘file-acl’.
38057
38058     Another element is ‘(selinux-context . CONTEXT)’, where CONTEXT is
38059     the SELinux context, in the same form returned by
38060     ‘file-selinux-context’.
38061
38062
38063File: elisp.info,  Node: Locating Files,  Prev: Extended Attributes,  Up: Information about Files
38064
3806525.6.6 Locating Files in Standard Places
38066----------------------------------------
38067
38068This section explains how to search for a file in a list of directories
38069(a “path”), or for an executable file in the standard list of executable
38070file directories.
38071
38072   To search for a user-specific configuration file, *Note Standard File
38073Names::, for the ‘locate-user-emacs-file’ function.
38074
38075 -- Function: locate-file filename path &optional suffixes predicate
38076     This function searches for a file whose name is FILENAME in a list
38077     of directories given by PATH, trying the suffixes in SUFFIXES.  If
38078     it finds such a file, it returns the file’s absolute file name
38079     (*note Relative File Names::); otherwise it returns ‘nil’.
38080
38081     The optional argument SUFFIXES gives the list of file-name suffixes
38082     to append to FILENAME when searching.  ‘locate-file’ tries each
38083     possible directory with each of these suffixes.  If SUFFIXES is
38084     ‘nil’, or ‘("")’, then there are no suffixes, and FILENAME is used
38085     only as-is.  Typical values of SUFFIXES are ‘exec-suffixes’ (*note
38086     Subprocess Creation::), ‘load-suffixes’, ‘load-file-rep-suffixes’
38087     and the return value of the function ‘get-load-suffixes’ (*note
38088     Load Suffixes::).
38089
38090     Typical values for PATH are ‘exec-path’ (*note Subprocess
38091     Creation::) when looking for executable programs, or ‘load-path’
38092     (*note Library Search::) when looking for Lisp files.  If FILENAME
38093     is absolute, PATH has no effect, but the suffixes in SUFFIXES are
38094     still tried.
38095
38096     The optional argument PREDICATE, if non-‘nil’, specifies a
38097     predicate function for testing whether a candidate file is
38098     suitable.  The predicate is passed the candidate file name as its
38099     single argument.  If PREDICATE is ‘nil’ or omitted, ‘locate-file’
38100     uses ‘file-readable-p’ as the predicate.  *Note Kinds of Files::,
38101     for other useful predicates, e.g., ‘file-executable-p’ and
38102     ‘file-directory-p’.
38103
38104     This function will normally skip directories, so if you want it to
38105     find directories, make sure the PREDICATE function returns ‘dir-ok’
38106     for them.  For example:
38107
38108          (locate-file "html" '("/var/www" "/srv") nil
38109                       (lambda (f) (if (file-directory-p f) 'dir-ok)))
38110
38111     For compatibility, PREDICATE can also be one of the symbols
38112     ‘executable’, ‘readable’, ‘writable’, ‘exists’, or a list of one or
38113     more of these symbols.
38114
38115 -- Function: executable-find program &optional remote
38116     This function searches for the executable file of the named PROGRAM
38117     and returns the absolute file name of the executable, including its
38118     file-name extensions, if any.  It returns ‘nil’ if the file is not
38119     found.  The function searches in all the directories in
38120     ‘exec-path’, and tries all the file-name extensions in
38121     ‘exec-suffixes’ (*note Subprocess Creation::).
38122
38123     If REMOTE is non-‘nil’, and ‘default-directory’ is a remote
38124     directory, PROGRAM is searched on the respective remote host.
38125
38126
38127File: elisp.info,  Node: Changing Files,  Next: Files and Storage,  Prev: Information about Files,  Up: Files
38128
3812925.7 Changing File Names and Attributes
38130=======================================
38131
38132The functions in this section rename, copy, delete, link, and set the
38133modes (permissions) of files.  Typically, they signal a ‘file-error’
38134error if they fail to perform their function, reporting the
38135system-dependent error message that describes the reason for the
38136failure.  If they fail because a file is missing, they signal a
38137‘file-missing’ error instead.
38138
38139   For performance, the operating system may cache or alias changes made
38140by these functions instead of writing them immediately to secondary
38141storage.  *Note Files and Storage::.
38142
38143   In the functions that have an argument NEWNAME, if this argument is a
38144directory name it is treated as if the nondirectory part of the source
38145name were appended.  Typically, a directory name is one that ends in ‘/’
38146(*note Directory Names::).  For example, if the old name is ‘a/b/c’, the
38147NEWNAME ‘d/e/f/’ is treated as if it were ‘d/e/f/c’.  This special
38148treatment does not apply if NEWNAME is not a directory name but names a
38149file that is a directory; for example, the NEWNAME ‘d/e/f’ is left as-is
38150even if ‘d/e/f’ happens to be a directory.
38151
38152   In the functions that have an argument NEWNAME, if a file by the name
38153of NEWNAME already exists, the actions taken depend on the value of the
38154argument OK-IF-ALREADY-EXISTS:
38155
38156   • Signal a ‘file-already-exists’ error if OK-IF-ALREADY-EXISTS is
38157     ‘nil’.
38158
38159   • Request confirmation if OK-IF-ALREADY-EXISTS is a number.
38160
38161   • Replace the old file without confirmation if OK-IF-ALREADY-EXISTS
38162     is any other value.
38163
38164 -- Command: add-name-to-file oldname newname &optional
38165          ok-if-already-exists
38166     This function gives the file named OLDNAME the additional name
38167     NEWNAME.  This means that NEWNAME becomes a new hard link to
38168     OLDNAME.
38169
38170     If NEWNAME is a symbolic link, its directory entry is replaced, not
38171     the directory entry it points to.  If OLDNAME is a symbolic link,
38172     this function might or might not follow the link; it does not
38173     follow the link on GNU platforms.  If OLDNAME is a directory, this
38174     function typically fails, although for the superuser on a few
38175     old-fashioned non-GNU platforms it can succeed and create a
38176     filesystem that is not tree-structured.
38177
38178     In the first part of the following example, we list two files,
38179     ‘foo’ and ‘foo3’.
38180
38181          $ ls -li fo*
38182          81908 -rw-rw-rw- 1 rms rms 29 Aug 18 20:32 foo
38183          84302 -rw-rw-rw- 1 rms rms 24 Aug 18 20:31 foo3
38184
38185     Now we create a hard link, by calling ‘add-name-to-file’, then list
38186     the files again.  This shows two names for one file, ‘foo’ and
38187     ‘foo2’.
38188
38189          (add-name-to-file "foo" "foo2")
38190               ⇒ nil
38191
38192          $ ls -li fo*
38193          81908 -rw-rw-rw- 2 rms rms 29 Aug 18 20:32 foo
38194          81908 -rw-rw-rw- 2 rms rms 29 Aug 18 20:32 foo2
38195          84302 -rw-rw-rw- 1 rms rms 24 Aug 18 20:31 foo3
38196
38197     Finally, we evaluate the following:
38198
38199          (add-name-to-file "foo" "foo3" t)
38200
38201     and list the files again.  Now there are three names for one file:
38202     ‘foo’, ‘foo2’, and ‘foo3’.  The old contents of ‘foo3’ are lost.
38203
38204          (add-name-to-file "foo1" "foo3")
38205               ⇒ nil
38206
38207          $ ls -li fo*
38208          81908 -rw-rw-rw- 3 rms rms 29 Aug 18 20:32 foo
38209          81908 -rw-rw-rw- 3 rms rms 29 Aug 18 20:32 foo2
38210          81908 -rw-rw-rw- 3 rms rms 29 Aug 18 20:32 foo3
38211
38212     This function is meaningless on operating systems where multiple
38213     names for one file are not allowed.  Some systems implement
38214     multiple names by copying the file instead.
38215
38216     See also ‘file-nlinks’ in *note File Attributes::.
38217
38218 -- Command: rename-file filename newname &optional ok-if-already-exists
38219     This command renames the file FILENAME as NEWNAME.
38220
38221     If FILENAME has additional names aside from FILENAME, it continues
38222     to have those names.  In fact, adding the name NEWNAME with
38223     ‘add-name-to-file’ and then deleting FILENAME has the same effect
38224     as renaming, aside from momentary intermediate states and treatment
38225     of errors, directories and symbolic links.
38226
38227     This command does not follow symbolic links.  If FILENAME is a
38228     symbolic link, this command renames the symbolic link, not the file
38229     it points to.  If NEWNAME is a symbolic link, its directory entry
38230     is replaced, not the directory entry it points to.
38231
38232     This command does nothing if FILENAME and NEWNAME are the same
38233     directory entry, i.e., if they refer to the same parent directory
38234     and give the same name within that directory.  Otherwise, if
38235     FILENAME and NEWNAME name the same file, this command does nothing
38236     on POSIX-conforming systems, and removes FILENAME on some non-POSIX
38237     systems.
38238
38239     If NEWNAME exists, then it must be an empty directory if OLDNAME is
38240     a directory and a non-directory otherwise.
38241
38242 -- Command: copy-file oldname newname &optional ok-if-already-exists
38243          time preserve-uid-gid preserve-extended-attributes
38244     This command copies the file OLDNAME to NEWNAME.  An error is
38245     signaled if OLDNAME is not a regular file.  If NEWNAME names a
38246     directory, it copies OLDNAME into that directory, preserving its
38247     final name component.
38248
38249     This function follows symbolic links, except that it does not
38250     follow a dangling symbolic link to create NEWNAME.
38251
38252     If TIME is non-‘nil’, then this function gives the new file the
38253     same last-modified time that the old one has.  (This works on only
38254     some operating systems.)  If setting the time gets an error,
38255     ‘copy-file’ signals a ‘file-date-error’ error.  In an interactive
38256     call, a prefix argument specifies a non-‘nil’ value for TIME.
38257
38258     If argument PRESERVE-UID-GID is ‘nil’, we let the operating system
38259     decide the user and group ownership of the new file (this is
38260     usually set to the user running Emacs).  If PRESERVE-UID-GID is
38261     non-‘nil’, we attempt to copy the user and group ownership of the
38262     file.  This works only on some operating systems, and only if you
38263     have the correct permissions to do so.
38264
38265     If the optional argument PRESERVE-PERMISSIONS is non-‘nil’, this
38266     function copies the file modes (or “permissions”) of OLDNAME to
38267     NEWNAME, as well as the Access Control List and SELinux context (if
38268     any).  *Note Information about Files::.
38269
38270     Otherwise, the file modes of NEWNAME are left unchanged if it is an
38271     existing file, and set to those of OLDNAME, masked by the default
38272     file permissions (see ‘set-default-file-modes’ below), if NEWNAME
38273     is to be newly created.  The Access Control List or SELinux context
38274     are not copied over in either case.
38275
38276 -- Command: make-symbolic-link target linkname &optional
38277          ok-if-already-exists
38278     This command makes a symbolic link to TARGET, named LINKNAME.  This
38279     is like the shell command ‘ln -s TARGET LINKNAME’.  The TARGET
38280     argument is treated only as a string; it need not name an existing
38281     file.  If OK-IF-ALREADY-EXISTS is an integer, indicating
38282     interactive use, then leading ‘~’ is expanded and leading ‘/:’ is
38283     stripped in the TARGET string.
38284
38285     If TARGET is a relative file name, the resulting symbolic link is
38286     interpreted relative to the directory containing the symbolic link.
38287     *Note Relative File Names::.
38288
38289     If both TARGET and LINKNAME have remote file name syntax, and if
38290     both remote identifications are equal, the symbolic link points to
38291     the local file name part of TARGET.
38292
38293     This function is not available on systems that don’t support
38294     symbolic links.
38295
38296 -- Command: delete-file filename &optional trash
38297     This command deletes the file FILENAME.  If the file has multiple
38298     names, it continues to exist under the other names.  If FILENAME is
38299     a symbolic link, ‘delete-file’ deletes only the symbolic link and
38300     not its target.
38301
38302     A suitable kind of ‘file-error’ error is signaled if the file does
38303     not exist, or is not deletable.  (On GNU and other POSIX-like
38304     systems, a file is deletable if its directory is writable.)
38305
38306     If the optional argument TRASH is non-‘nil’ and the variable
38307     ‘delete-by-moving-to-trash’ is non-‘nil’, this command moves the
38308     file into the system Trash instead of deleting it.  *Note
38309     Miscellaneous File Operations: (emacs)Misc File Ops.  When called
38310     interactively, TRASH is ‘t’ if no prefix argument is given, and
38311     ‘nil’ otherwise.
38312
38313     See also ‘delete-directory’ in *note Create/Delete Dirs::.
38314
38315 -- Command: set-file-modes filename mode
38316     This function sets the “file mode” (or “permissions”) of FILENAME
38317     to MODE.  This function follows symbolic links.
38318
38319     If called non-interactively, MODE must be an integer.  Only the
38320     lowest 12 bits of the integer are used; on most systems, only the
38321     lowest 9 bits are meaningful.  You can use the Lisp construct for
38322     octal numbers to enter MODE.  For example,
38323
38324          (set-file-modes #o644)
38325
38326     specifies that the file should be readable and writable for its
38327     owner, readable for group members, and readable for all other
38328     users.  *Note (coreutils)File permissions::, for a description of
38329     mode bit specifications.
38330
38331     Interactively, MODE is read from the minibuffer using
38332     ‘read-file-modes’ (see below), which lets the user type in either
38333     an integer or a string representing the permissions symbolically.
38334
38335     *Note File Attributes::, for the function ‘file-modes’, which
38336     returns the permissions of a file.
38337
38338 -- Function: set-default-file-modes mode
38339     This function sets the default permissions for new files created by
38340     Emacs and its subprocesses.  Every file created with Emacs
38341     initially has these permissions, or a subset of them
38342     (‘write-region’ will not grant execute permissions even if the
38343     default file permissions allow execution).  On GNU and other
38344     POSIX-like systems, the default permissions are given by the
38345     bitwise complement of the ‘umask’ value, i.e. each bit that is set
38346     in the argument MODE will be _reset_ in the default permissions
38347     with which Emacs creates files.
38348
38349     The argument MODE should be an integer which specifies the
38350     permissions, similar to ‘set-file-modes’ above.  Only the lowest 9
38351     bits are meaningful.
38352
38353     The default file permissions have no effect when you save a
38354     modified version of an existing file; saving a file preserves its
38355     existing permissions.
38356
38357 -- Macro: with-file-modes mode body...
38358     This macro evaluates the BODY forms with the default permissions
38359     for new files temporarily set to MODES (whose value is as for
38360     ‘set-file-modes’ above).  When finished, it restores the original
38361     default file permissions, and returns the value of the last form in
38362     BODY.
38363
38364     This is useful for creating private files, for example.
38365
38366 -- Function: default-file-modes
38367     This function returns the default file permissions, as an integer.
38368
38369 -- Function: read-file-modes &optional prompt base-file
38370     This function reads a set of file mode bits from the minibuffer.
38371     The first optional argument PROMPT specifies a non-default prompt.
38372     Second second optional argument BASE-FILE is the name of a file on
38373     whose permissions to base the mode bits that this function returns,
38374     if what the user types specifies mode bits relative to permissions
38375     of an existing file.
38376
38377     If user input represents an octal number, this function returns
38378     that number.  If it is a complete symbolic specification of mode
38379     bits, as in ‘"u=rwx"’, the function converts it to the equivalent
38380     numeric value using ‘file-modes-symbolic-to-number’ and returns the
38381     result.  If the specification is relative, as in ‘"o+g"’, then the
38382     permissions on which the specification is based are taken from the
38383     mode bits of BASE-FILE.  If BASE-FILE is omitted or ‘nil’, the
38384     function uses ‘0’ as the base mode bits.  The complete and relative
38385     specifications can be combined, as in ‘"u+r,g+rx,o+r,g-w"’.  *Note
38386     (coreutils)File permissions::, for a description of file mode
38387     specifications.
38388
38389 -- Function: file-modes-symbolic-to-number modes &optional base-modes
38390     This function converts a symbolic file mode specification in MODES
38391     into the equivalent integer.  If the symbolic specification is
38392     based on an existing file, that file’s mode bits are taken from the
38393     optional argument BASE-MODES; if that argument is omitted or ‘nil’,
38394     it defaults to 0, i.e., no access rights at all.
38395
38396 -- Function: set-file-times filename &optional time
38397     This function sets the access and modification times of FILENAME to
38398     TIME.  The return value is ‘t’ if the times are successfully set,
38399     otherwise it is ‘nil’.  TIME defaults to the current time and must
38400     be a time value (*note Time of Day::).
38401
38402 -- Function: set-file-extended-attributes filename attribute-alist
38403     This function sets the Emacs-recognized extended file attributes
38404     for ‘filename’.  The second argument ATTRIBUTE-ALIST should be an
38405     alist of the same form returned by ‘file-extended-attributes’.  The
38406     return value is ‘t’ if the attributes are successfully set,
38407     otherwise it is ‘nil’.  *Note Extended Attributes::.
38408
38409 -- Function: set-file-selinux-context filename context
38410     This function sets the SELinux security context for FILENAME to
38411     CONTEXT.  The CONTEXT argument should be a list ‘(USER ROLE TYPE
38412     RANGE)’, where each element is a string.  *Note Extended
38413     Attributes::.
38414
38415     The function returns ‘t’ if it succeeds in setting the SELinux
38416     context of FILENAME.  It returns ‘nil’ if the context was not set
38417     (e.g., if SELinux is disabled, or if Emacs was compiled without
38418     SELinux support).
38419
38420 -- Function: set-file-acl filename acl
38421     This function sets the Access Control List for FILENAME to ACL.
38422     The ACL argument should have the same form returned by the function
38423     ‘file-acl’.  *Note Extended Attributes::.
38424
38425     The function returns ‘t’ if it successfully sets the ACL of
38426     FILENAME, ‘nil’ otherwise.
38427
38428
38429File: elisp.info,  Node: Files and Storage,  Next: File Names,  Prev: Changing Files,  Up: Files
38430
3843125.8 Files and Secondary Storage
38432================================
38433
38434After Emacs changes a file, there are two reasons the changes might not
38435survive later failures of power or media, both having to do with
38436efficiency.  First, the operating system might alias written data with
38437data already stored elsewhere on secondary storage until one file or the
38438other is later modified; this will lose both files if the only copy on
38439secondary storage is lost due to media failure.  Second, the operating
38440system might not write data to secondary storage immediately, which will
38441lose the data if power is lost.
38442
38443   Although both sorts of failures can largely be avoided by a suitably
38444configured file system, such systems are typically more expensive or
38445less efficient.  In more-typical systems, to survive media failure you
38446can copy the file to a different device, and to survive a power failure
38447you can use the ‘write-region’ function with the
38448‘write-region-inhibit-fsync’ variable set to ‘nil’.  *Note Writing to
38449Files::.
38450
38451
38452File: elisp.info,  Node: File Names,  Next: Contents of Directories,  Prev: Files and Storage,  Up: Files
38453
3845425.9 File Names
38455===============
38456
38457Files are generally referred to by their names, in Emacs as elsewhere.
38458File names in Emacs are represented as strings.  The functions that
38459operate on a file all expect a file name argument.
38460
38461   In addition to operating on files themselves, Emacs Lisp programs
38462often need to operate on file names; i.e., to take them apart and to use
38463part of a name to construct related file names.  This section describes
38464how to manipulate file names.
38465
38466   The functions in this section do not actually access files, so they
38467can operate on file names that do not refer to an existing file or
38468directory.
38469
38470   On MS-DOS and MS-Windows, these functions (like the function that
38471actually operate on files) accept MS-DOS or MS-Windows file-name syntax,
38472where backslashes separate the components, as well as POSIX syntax; but
38473they always return POSIX syntax.  This enables Lisp programs to specify
38474file names in POSIX syntax and work properly on all systems without
38475change.(1)
38476
38477* Menu:
38478
38479* File Name Components::  The directory part of a file name, and the rest.
38480* Relative File Names::   Some file names are relative to a current directory.
38481* Directory Names::       A directory’s name as a directory
38482                            is different from its name as a file.
38483* File Name Expansion::   Converting relative file names to absolute ones.
38484* Unique File Names::     Generating names for temporary files.
38485* File Name Completion::  Finding the completions for a given file name.
38486* Standard File Names::   If your package uses a fixed file name,
38487                            how to handle various operating systems simply.
38488
38489   ---------- Footnotes ----------
38490
38491   (1) In MS-Windows versions of Emacs compiled for the Cygwin
38492environment, you can use the functions
38493‘cygwin-convert-file-name-to-windows’ and
38494‘cygwin-convert-file-name-from-windows’ to convert between the two
38495file-name syntaxes.
38496
38497
38498File: elisp.info,  Node: File Name Components,  Next: Relative File Names,  Up: File Names
38499
3850025.9.1 File Name Components
38501---------------------------
38502
38503The operating system groups files into directories.  To specify a file,
38504you must specify the directory and the file’s name within that
38505directory.  Therefore, Emacs considers a file name as having two main
38506parts: the “directory name” part, and the “nondirectory” part (or “file
38507name within the directory”).  Either part may be empty.  Concatenating
38508these two parts reproduces the original file name.
38509
38510   On most systems, the directory part is everything up to and including
38511the last slash (backslash is also allowed in input on MS-DOS or
38512MS-Windows); the nondirectory part is the rest.
38513
38514   For some purposes, the nondirectory part is further subdivided into
38515the name proper and the “version number”.  On most systems, only backup
38516files have version numbers in their names.
38517
38518 -- Function: file-name-directory filename
38519     This function returns the directory part of FILENAME, as a
38520     directory name (*note Directory Names::), or ‘nil’ if FILENAME does
38521     not include a directory part.
38522
38523     On GNU and other POSIX-like systems, a string returned by this
38524     function always ends in a slash.  On MS-DOS it can also end in a
38525     colon.
38526
38527          (file-name-directory "lewis/foo")  ; GNU example
38528               ⇒ "lewis/"
38529          (file-name-directory "foo")        ; GNU example
38530               ⇒ nil
38531
38532 -- Function: file-name-nondirectory filename
38533     This function returns the nondirectory part of FILENAME.
38534
38535          (file-name-nondirectory "lewis/foo")
38536               ⇒ "foo"
38537          (file-name-nondirectory "foo")
38538               ⇒ "foo"
38539          (file-name-nondirectory "lewis/")
38540               ⇒ ""
38541
38542 -- Function: file-name-sans-versions filename &optional
38543          keep-backup-version
38544     This function returns FILENAME with any file version numbers,
38545     backup version numbers, or trailing tildes discarded.
38546
38547     If KEEP-BACKUP-VERSION is non-‘nil’, then true file version numbers
38548     understood as such by the file system are discarded from the return
38549     value, but backup version numbers are kept.
38550
38551          (file-name-sans-versions "~rms/foo.~1~")
38552               ⇒ "~rms/foo"
38553          (file-name-sans-versions "~rms/foo~")
38554               ⇒ "~rms/foo"
38555          (file-name-sans-versions "~rms/foo")
38556               ⇒ "~rms/foo"
38557
38558 -- Function: file-name-extension filename &optional period
38559     This function returns FILENAME’s final extension, if any, after
38560     applying ‘file-name-sans-versions’ to remove any version/backup
38561     part.  The extension, in a file name, is the part that follows the
38562     last ‘.’ in the last name component (minus any version/backup
38563     part).
38564
38565     This function returns ‘nil’ for extensionless file names such as
38566     ‘foo’.  It returns ‘""’ for null extensions, as in ‘foo.’.  If the
38567     last component of a file name begins with a ‘.’, that ‘.’ doesn’t
38568     count as the beginning of an extension.  Thus, ‘.emacs’’s extension
38569     is ‘nil’, not ‘.emacs’.
38570
38571     If PERIOD is non-‘nil’, then the returned value includes the period
38572     that delimits the extension, and if FILENAME has no extension, the
38573     value is ‘""’.
38574
38575 -- Function: file-name-sans-extension filename
38576     This function returns FILENAME minus its extension, if any.  The
38577     version/backup part, if present, is only removed if the file has an
38578     extension.  For example,
38579
38580          (file-name-sans-extension "foo.lose.c")
38581               ⇒ "foo.lose"
38582          (file-name-sans-extension "big.hack/foo")
38583               ⇒ "big.hack/foo"
38584          (file-name-sans-extension "/my/home/.emacs")
38585               ⇒ "/my/home/.emacs"
38586          (file-name-sans-extension "/my/home/.emacs.el")
38587               ⇒ "/my/home/.emacs"
38588          (file-name-sans-extension "~/foo.el.~3~")
38589               ⇒ "~/foo"
38590          (file-name-sans-extension "~/foo.~3~")
38591               ⇒ "~/foo.~3~"
38592
38593     Note that the ‘.~3~’ in the two last examples is the backup part,
38594     not an extension.
38595
38596 -- Function: file-name-base filename
38597     This function is the composition of ‘file-name-sans-extension’ and
38598     ‘file-name-nondirectory’.  For example,
38599
38600          (file-name-base "/my/home/foo.c")
38601              ⇒ "foo"
38602
38603
38604File: elisp.info,  Node: Relative File Names,  Next: Directory Names,  Prev: File Name Components,  Up: File Names
38605
3860625.9.2 Absolute and Relative File Names
38607---------------------------------------
38608
38609All the directories in the file system form a tree starting at the root
38610directory.  A file name can specify all the directory names starting
38611from the root of the tree; then it is called an “absolute” file name.
38612Or it can specify the position of the file in the tree relative to a
38613default directory; then it is called a “relative” file name.  On GNU and
38614other POSIX-like systems, after any leading ‘~’ has been expanded, an
38615absolute file name starts with a ‘/’ (*note abbreviate-file-name::), and
38616a relative one does not.  On MS-DOS and MS-Windows, an absolute file
38617name starts with a slash or a backslash, or with a drive specification
38618‘X:/’, where X is the “drive letter”.
38619
38620 -- Function: file-name-absolute-p filename
38621     This function returns ‘t’ if file FILENAME is an absolute file
38622     name, ‘nil’ otherwise.  A file name is considered to be absolute if
38623     its first component is ‘~’, or is ‘~USER’ where USER is a valid
38624     login name.  In the following examples, assume that there is a user
38625     named ‘rms’ but no user named ‘nosuchuser’.
38626
38627          (file-name-absolute-p "~rms/foo")
38628               ⇒ t
38629          (file-name-absolute-p "~nosuchuser/foo")
38630               ⇒ nil
38631          (file-name-absolute-p "rms/foo")
38632               ⇒ nil
38633          (file-name-absolute-p "/user/rms/foo")
38634               ⇒ t
38635
38636   Given a possibly relative file name, you can expand any leading ‘~’
38637and convert the result to an absolute name using ‘expand-file-name’
38638(*note File Name Expansion::).  This function converts absolute file
38639names to relative names:
38640
38641 -- Function: file-relative-name filename &optional directory
38642     This function tries to return a relative name that is equivalent to
38643     FILENAME, assuming the result will be interpreted relative to
38644     DIRECTORY (an absolute directory name or directory file name).  If
38645     DIRECTORY is omitted or ‘nil’, it defaults to the current buffer’s
38646     default directory.
38647
38648     On some operating systems, an absolute file name begins with a
38649     device name.  On such systems, FILENAME has no relative equivalent
38650     based on DIRECTORY if they start with two different device names.
38651     In this case, ‘file-relative-name’ returns FILENAME in absolute
38652     form.
38653
38654          (file-relative-name "/foo/bar" "/foo/")
38655               ⇒ "bar"
38656          (file-relative-name "/foo/bar" "/hack/")
38657               ⇒ "../foo/bar"
38658
38659
38660File: elisp.info,  Node: Directory Names,  Next: File Name Expansion,  Prev: Relative File Names,  Up: File Names
38661
3866225.9.3 Directory Names
38663----------------------
38664
38665A “directory name” is a string that must name a directory if it names
38666any file at all.  A directory is actually a kind of file, and it has a
38667file name (called the “directory file name”, which is related to the
38668directory name but is typically not identical.  (This is not quite the
38669same as the usual POSIX terminology.)  These two names for the same
38670entity are related by a syntactic transformation.  On GNU and other
38671POSIX-like systems, this is simple: to obtain a directory name, append a
38672‘/’ to a directory file name that does not already end in ‘/’.  On
38673MS-DOS the relationship is more complicated.
38674
38675   The difference between a directory name and a directory file name is
38676subtle but crucial.  When an Emacs variable or function argument is
38677described as being a directory name, a directory file name is not
38678acceptable.  When ‘file-name-directory’ returns a string, that is always
38679a directory name.
38680
38681   The following two functions convert between directory names and
38682directory file names.  They do nothing special with environment variable
38683substitutions such as ‘$HOME’, and the constructs ‘~’, ‘.’ and ‘..’.
38684
38685 -- Function: file-name-as-directory filename
38686     This function returns a string representing FILENAME in a form that
38687     the operating system will interpret as the name of a directory (a
38688     directory name).  On most systems, this means appending a slash to
38689     the string (if it does not already end in one).
38690
38691          (file-name-as-directory "~rms/lewis")
38692               ⇒ "~rms/lewis/"
38693
38694 -- Function: directory-name-p filename
38695     This function returns non-‘nil’ if FILENAME ends with a directory
38696     separator character.  This is the forward slash ‘/’ on GNU and
38697     other POSIX-like systems; MS-Windows and MS-DOS recognize both the
38698     forward slash and the backslash ‘\’ as directory separators.
38699
38700 -- Function: directory-file-name dirname
38701     This function returns a string representing DIRNAME in a form that
38702     the operating system will interpret as the name of a file (a
38703     directory file name).  On most systems, this means removing the
38704     final directory separators from the string, unless the string
38705     consists entirely of directory separators.
38706
38707          (directory-file-name "~lewis/")
38708               ⇒ "~lewis"
38709
38710   Given a directory name, you can combine it with a relative file name
38711using ‘concat’:
38712
38713     (concat DIRNAME RELFILE)
38714
38715Be sure to verify that the file name is relative before doing that.  If
38716you use an absolute file name, the results could be syntactically
38717invalid or refer to the wrong file.
38718
38719   If you want to use a directory file name in making such a
38720combination, you must first convert it to a directory name using
38721‘file-name-as-directory’:
38722
38723     (concat (file-name-as-directory DIRFILE) RELFILE)
38724
38725Don’t try concatenating a slash by hand, as in
38726
38727     ;;; Wrong!
38728     (concat DIRFILE "/" RELFILE)
38729
38730because this is not portable.  Always use ‘file-name-as-directory’.
38731
38732   To avoid the issues mentioned above, or if the DIRNAME value might be
38733‘nil’ (for example, from an element of ‘load-path’), use:
38734
38735     (expand-file-name RELFILE DIRNAME)
38736
38737   However, ‘expand-file-name’ expands leading ‘~’ in RELFILE, which may
38738not be what you want.  *Note File Name Expansion::.
38739
38740   To convert a directory name to its abbreviation, use this function:
38741
38742 -- Function: abbreviate-file-name filename
38743     This function returns an abbreviated form of FILENAME.  It applies
38744     the abbreviations specified in ‘directory-abbrev-alist’ (*note File
38745     Aliases: (emacs)File Aliases.), then substitutes ‘~’ for the user’s
38746     home directory if the argument names a file in the home directory
38747     or one of its subdirectories.  If the home directory is a root
38748     directory, it is not replaced with ‘~’, because this does not make
38749     the result shorter on many systems.
38750
38751     You can use this function for directory names and for file names,
38752     because it recognizes abbreviations even as part of the name.
38753
38754
38755File: elisp.info,  Node: File Name Expansion,  Next: Unique File Names,  Prev: Directory Names,  Up: File Names
38756
3875725.9.4 Functions that Expand Filenames
38758--------------------------------------
38759
38760“Expanding” a file name means converting a relative file name to an
38761absolute one.  Since this is done relative to a default directory, you
38762must specify the default directory as well as the file name to be
38763expanded.  It also involves expanding abbreviations like ‘~/’ (*note
38764abbreviate-file-name::), and eliminating redundancies like ‘./’ and
38765‘NAME/../’.
38766
38767 -- Function: expand-file-name filename &optional directory
38768     This function converts FILENAME to an absolute file name.  If
38769     DIRECTORY is supplied, it is the default directory to start with if
38770     FILENAME is relative and does not start with ‘~’.  (The value of
38771     DIRECTORY should itself be an absolute directory name or directory
38772     file name; it may start with ‘~’.)  Otherwise, the current buffer’s
38773     value of ‘default-directory’ is used.  For example:
38774
38775          (expand-file-name "foo")
38776               ⇒ "/xcssun/users/rms/lewis/foo"
38777          (expand-file-name "../foo")
38778               ⇒ "/xcssun/users/rms/foo"
38779          (expand-file-name "foo" "/usr/spool/")
38780               ⇒ "/usr/spool/foo"
38781
38782     If the part of FILENAME before the first slash is ‘~’, it expands
38783     to your home directory, which is typically specified by the value
38784     of the ‘HOME’ environment variable (*note (emacs)General
38785     Variables::).  If the part before the first slash is ‘~USER’ and if
38786     USER is a valid login name, it expands to USER’s home directory.
38787     If you do not want this expansion for a relative FILENAME that
38788     might begin with a literal ‘~’, you can use ‘(concat
38789     (file-name-as-directory directory) filename)’ instead of
38790     ‘(expand-file-name filename directory)’.
38791
38792     Filenames containing ‘.’ or ‘..’ are simplified to their canonical
38793     form:
38794
38795          (expand-file-name "bar/../foo")
38796               ⇒ "/xcssun/users/rms/lewis/foo"
38797
38798     In some cases, a leading ‘..’ component can remain in the output:
38799
38800          (expand-file-name "../home" "/")
38801               ⇒ "/../home"
38802
38803     This is for the sake of filesystems that have the concept of a
38804     superroot above the root directory ‘/’.  On other filesystems,
38805     ‘/../’ is interpreted exactly the same as ‘/’.
38806
38807     Expanding ‘.’ or the empty string returns the default directory:
38808
38809          (expand-file-name "." "/usr/spool/")
38810               ⇒ "/usr/spool"
38811          (expand-file-name "" "/usr/spool/")
38812               ⇒ "/usr/spool"
38813
38814     Note that ‘expand-file-name’ does _not_ expand environment
38815     variables; only ‘substitute-in-file-name’ does that:
38816
38817          (expand-file-name "$HOME/foo")
38818               ⇒ "/xcssun/users/rms/lewis/$HOME/foo"
38819
38820     Note also that ‘expand-file-name’ does not follow symbolic links at
38821     any level.  This results in a difference between the way
38822     ‘file-truename’ and ‘expand-file-name’ treat ‘..’.  Assuming that
38823/tmp/bar’ is a symbolic link to the directory ‘/tmp/foo/bar’ we
38824     get:
38825
38826          (file-truename "/tmp/bar/../myfile")
38827               ⇒ "/tmp/foo/myfile"
38828          (expand-file-name "/tmp/bar/../myfile")
38829               ⇒ "/tmp/myfile"
38830
38831     If you may need to follow symbolic links preceding ‘..’, you should
38832     make sure to call ‘file-truename’ without prior direct or indirect
38833     calls to ‘expand-file-name’.  *Note Truenames::.
38834
38835 -- Variable: default-directory
38836     The value of this buffer-local variable is the default directory
38837     for the current buffer.  It should be an absolute directory name;
38838     it may start with ‘~’.  This variable is buffer-local in every
38839     buffer.
38840
38841     ‘expand-file-name’ uses the default directory when its second
38842     argument is ‘nil’.
38843
38844     The value is always a string ending with a slash.
38845
38846          default-directory
38847               ⇒ "/user/lewis/manual/"
38848
38849 -- Function: substitute-in-file-name filename
38850     This function replaces environment variable references in FILENAME
38851     with the environment variable values.  Following standard Unix
38852     shell syntax, ‘$’ is the prefix to substitute an environment
38853     variable value.  If the input contains ‘$$’, that is converted to
38854     ‘$’; this gives the user a way to quote a ‘$’.
38855
38856     The environment variable name is the series of alphanumeric
38857     characters (including underscores) that follow the ‘$’.  If the
38858     character following the ‘$’ is a ‘{’, then the variable name is
38859     everything up to the matching ‘}’.
38860
38861     Calling ‘substitute-in-file-name’ on output produced by
38862     ‘substitute-in-file-name’ tends to give incorrect results.  For
38863     instance, use of ‘$$’ to quote a single ‘$’ won’t work properly,
38864     and ‘$’ in an environment variable’s value could lead to repeated
38865     substitution.  Therefore, programs that call this function and put
38866     the output where it will be passed to this function need to double
38867     all ‘$’ characters to prevent subsequent incorrect results.
38868
38869     Here we assume that the environment variable ‘HOME’, which holds
38870     the user’s home directory, has value ‘/xcssun/users/rms’.
38871
38872          (substitute-in-file-name "$HOME/foo")
38873               ⇒ "/xcssun/users/rms/foo"
38874
38875     After substitution, if a ‘~’ or a ‘/’ appears immediately after
38876     another ‘/’, the function discards everything before it (up through
38877     the immediately preceding ‘/’).
38878
38879          (substitute-in-file-name "bar/~/foo")
38880               ⇒ "~/foo"
38881          (substitute-in-file-name "/usr/local/$HOME/foo")
38882               ⇒ "/xcssun/users/rms/foo"
38883               ;; ‘/usr/local/’ has been discarded.
38884
38885   Sometimes, it is not desired to expand file names.  In such cases,
38886the file name can be quoted to suppress the expansion, and to handle the
38887file name literally.  Quoting happens by prefixing the file name with
38888‘/:’.
38889
38890 -- Macro: file-name-quote name
38891     This macro adds the quotation prefix ‘/:’ to the file NAME.  For a
38892     local file NAME, it prefixes NAME with ‘/:’.  If NAME is a remote
38893     file name, the local part of NAME (*note Magic File Names::) is
38894     quoted.  If NAME is already a quoted file name, NAME is returned
38895     unchanged.
38896
38897          (substitute-in-file-name (file-name-quote "bar/~/foo"))
38898               ⇒ "/:bar/~/foo"
38899
38900          (substitute-in-file-name (file-name-quote "/ssh:host:bar/~/foo"))
38901               ⇒ "/ssh:host:/:bar/~/foo"
38902
38903     The macro cannot be used to suppress file name handlers from magic
38904     file names (*note Magic File Names::).
38905
38906 -- Macro: file-name-unquote name
38907     This macro removes the quotation prefix ‘/:’ from the file NAME, if
38908     any.  If NAME is a remote file name, the local part of NAME is
38909     unquoted.
38910
38911 -- Macro: file-name-quoted-p name
38912     This macro returns non-‘nil’, when NAME is quoted with the prefix
38913     ‘/:’.  If NAME is a remote file name, the local part of NAME is
38914     checked.
38915
38916
38917File: elisp.info,  Node: Unique File Names,  Next: File Name Completion,  Prev: File Name Expansion,  Up: File Names
38918
3891925.9.5 Generating Unique File Names
38920-----------------------------------
38921
38922Some programs need to write temporary files.  Here is the usual way to
38923construct a name for such a file:
38924
38925     (make-temp-file NAME-OF-APPLICATION)
38926
38927The job of ‘make-temp-file’ is to prevent two different users or two
38928different jobs from trying to use the exact same file name.
38929
38930 -- Function: make-temp-file prefix &optional dir-flag suffix text
38931     This function creates a temporary file and returns its name.  Emacs
38932     creates the temporary file’s name by adding to PREFIX some random
38933     characters that are different in each Emacs job.  The result is
38934     guaranteed to be a newly created file, containing TEXT if that’s
38935     given as a string and empty otherwise.  On MS-DOS, this function
38936     can truncate PREFIX to fit into the 8+3 file-name limits.  If
38937     PREFIX is a relative file name, it is expanded against
38938     ‘temporary-file-directory’.
38939
38940          (make-temp-file "foo")
38941               ⇒ "/tmp/foo232J6v"
38942
38943     When ‘make-temp-file’ returns, the file has been created and is
38944     empty.  At that point, you should write the intended contents into
38945     the file.
38946
38947     If DIR-FLAG is non-‘nil’, ‘make-temp-file’ creates an empty
38948     directory instead of an empty file.  It returns the file name, not
38949     the directory name, of that directory.  *Note Directory Names::.
38950
38951     If SUFFIX is non-‘nil’, ‘make-temp-file’ adds it at the end of the
38952     file name.
38953
38954     If TEXT is a string, ‘make-temp-file’ inserts it in the file.
38955
38956     To prevent conflicts among different libraries running in the same
38957     Emacs, each Lisp program that uses ‘make-temp-file’ should have its
38958     own PREFIX.  The number added to the end of PREFIX distinguishes
38959     between the same application running in different Emacs jobs.
38960     Additional added characters permit a large number of distinct names
38961     even in one Emacs job.
38962
38963   The default directory for temporary files is controlled by the
38964variable ‘temporary-file-directory’.  This variable gives the user a
38965uniform way to specify the directory for all temporary files.  Some
38966programs use ‘small-temporary-file-directory’ instead, if that is
38967non-‘nil’.  To use it, you should expand the prefix against the proper
38968directory before calling ‘make-temp-file’.
38969
38970 -- User Option: temporary-file-directory
38971     This variable specifies the directory name for creating temporary
38972     files.  Its value should be a directory name (*note Directory
38973     Names::), but it is good for Lisp programs to cope if the value is
38974     a directory’s file name instead.  Using the value as the second
38975     argument to ‘expand-file-name’ is a good way to achieve that.
38976
38977     The default value is determined in a reasonable way for your
38978     operating system; it is based on the ‘TMPDIR’, ‘TMP’ and ‘TEMP’
38979     environment variables, with a fall-back to a system-dependent name
38980     if none of these variables is defined.
38981
38982     Even if you do not use ‘make-temp-file’ to create the temporary
38983     file, you should still use this variable to decide which directory
38984     to put the file in.  However, if you expect the file to be small,
38985     you should use ‘small-temporary-file-directory’ first if that is
38986     non-‘nil’.
38987
38988 -- User Option: small-temporary-file-directory
38989     This variable specifies the directory name for creating certain
38990     temporary files, which are likely to be small.
38991
38992     If you want to write a temporary file which is likely to be small,
38993     you should compute the directory like this:
38994
38995          (make-temp-file
38996            (expand-file-name PREFIX
38997                              (or small-temporary-file-directory
38998                                  temporary-file-directory)))
38999
39000 -- Function: make-temp-name base-name
39001     This function generates a string that might be a unique file name.
39002     The name starts with BASE-NAME, and has several random characters
39003     appended to it, which are different in each Emacs job.  It is like
39004     ‘make-temp-file’ except that (i) it just constructs a name and does
39005     not create a file, (ii) BASE-NAME should be an absolute file name
39006     that is not magic, and (iii) if the returned file name is magic, it
39007     might name an existing file.  *Note Magic File Names::.
39008
39009     *Warning:* In most cases, you should not use this function; use
39010     ‘make-temp-file’ instead!  This function is susceptible to a race
39011     condition, between the ‘make-temp-name’ call and the creation of
39012     the file, which in some cases may cause a security hole.
39013
39014   Sometimes, it is necessary to create a temporary file on a remote
39015host or a mounted directory.  The following two functions support this.
39016
39017 -- Function: make-nearby-temp-file prefix &optional dir-flag suffix
39018     This function is similar to ‘make-temp-file’, but it creates a
39019     temporary file as close as possible to ‘default-directory’.  If
39020     PREFIX is a relative file name, and ‘default-directory’ is a remote
39021     file name or located on a mounted file systems, the temporary file
39022     is created in the directory returned by the function
39023     ‘temporary-file-directory’.  Otherwise, the function
39024     ‘make-temp-file’ is used.  PREFIX, DIR-FLAG and SUFFIX have the
39025     same meaning as in ‘make-temp-file’.
39026
39027          (let ((default-directory "/ssh:remotehost:"))
39028            (make-nearby-temp-file "foo"))
39029               ⇒ "/ssh:remotehost:/tmp/foo232J6v"
39030
39031 -- Function: temporary-file-directory
39032     The directory for writing temporary files via
39033     ‘make-nearby-temp-file’.  In case of a remote ‘default-directory’,
39034     this is a directory for temporary files on that remote host.  If
39035     such a directory does not exist, or ‘default-directory’ ought to be
39036     located on a mounted file system (see ‘mounted-file-systems’), the
39037     function returns ‘default-directory’.  For a non-remote and
39038     non-mounted ‘default-directory’, the value of the variable
39039     ‘temporary-file-directory’ is returned.
39040
39041   In order to extract the local part of the file’s name of a temporary
39042file, use ‘file-local-name’ (*note Magic File Names::).
39043
39044
39045File: elisp.info,  Node: File Name Completion,  Next: Standard File Names,  Prev: Unique File Names,  Up: File Names
39046
3904725.9.6 File Name Completion
39048---------------------------
39049
39050This section describes low-level subroutines for completing a file name.
39051For higher level functions, see *note Reading File Names::.
39052
39053 -- Function: file-name-all-completions partial-filename directory
39054     This function returns a list of all possible completions for a file
39055     whose name starts with PARTIAL-FILENAME in directory DIRECTORY.
39056     The order of the completions is the order of the files in the
39057     directory, which is unpredictable and conveys no useful
39058     information.
39059
39060     The argument PARTIAL-FILENAME must be a file name containing no
39061     directory part and no slash (or backslash on some systems).  The
39062     current buffer’s default directory is prepended to DIRECTORY, if
39063     DIRECTORY is not absolute.
39064
39065     In the following example, suppose that ‘~rms/lewis’ is the current
39066     default directory, and has five files whose names begin with ‘f’:
39067     ‘foo’, ‘file~’, ‘file.c’, ‘file.c.~1~’, and ‘file.c.~2~’.
39068
39069          (file-name-all-completions "f" "")
39070               ⇒ ("foo" "file~" "file.c.~2~"
39071                          "file.c.~1~" "file.c")
39072
39073          (file-name-all-completions "fo" "")
39074               ⇒ ("foo")
39075
39076 -- Function: file-name-completion filename directory &optional
39077          predicate
39078     This function completes the file name FILENAME in directory
39079     DIRECTORY.  It returns the longest prefix common to all file names
39080     in directory DIRECTORY that start with FILENAME.  If PREDICATE is
39081     non-‘nil’ then it ignores possible completions that don’t satisfy
39082     PREDICATE, after calling that function with one argument, the
39083     expanded absolute file name.
39084
39085     If only one match exists and FILENAME matches it exactly, the
39086     function returns ‘t’.  The function returns ‘nil’ if directory
39087     DIRECTORY contains no name starting with FILENAME.
39088
39089     In the following example, suppose that the current default
39090     directory has five files whose names begin with ‘f’: ‘foo’,
39091     ‘file~’, ‘file.c’, ‘file.c.~1~’, and ‘file.c.~2~’.
39092
39093          (file-name-completion "fi" "")
39094               ⇒ "file"
39095
39096          (file-name-completion "file.c.~1" "")
39097               ⇒ "file.c.~1~"
39098
39099          (file-name-completion "file.c.~1~" "")
39100               ⇒ t
39101
39102          (file-name-completion "file.c.~3" "")
39103               ⇒ nil
39104
39105 -- User Option: completion-ignored-extensions
39106     ‘file-name-completion’ usually ignores file names that end in any
39107     string in this list.  It does not ignore them when all the possible
39108     completions end in one of these suffixes.  This variable has no
39109     effect on ‘file-name-all-completions’.
39110
39111     A typical value might look like this:
39112
39113          completion-ignored-extensions
39114               ⇒ (".o" ".elc" "~" ".dvi")
39115
39116     If an element of ‘completion-ignored-extensions’ ends in a slash
39117     ‘/’, it signals a directory.  The elements which do _not_ end in a
39118     slash will never match a directory; thus, the above value will not
39119     filter out a directory named ‘foo.elc’.
39120
39121
39122File: elisp.info,  Node: Standard File Names,  Prev: File Name Completion,  Up: File Names
39123
3912425.9.7 Standard File Names
39125--------------------------
39126
39127Sometimes, an Emacs Lisp program needs to specify a standard file name
39128for a particular use—typically, to hold configuration data specified by
39129the current user.  Usually, such files should be located in the
39130directory specified by ‘user-emacs-directory’, which is typically
39131‘~/.config/emacs/’ or ‘~/.emacs.d/’ by default (*note How Emacs Finds
39132Your Init File: (emacs)Find Init.).  For example, abbrev definitions are
39133stored by default in ‘~/.config/emacs/abbrev_defs’ or
39134‘~/.emacs.d/abbrev_defs’.  The easiest way to specify such a file name
39135is to use the function ‘locate-user-emacs-file’.
39136
39137 -- Function: locate-user-emacs-file base-name &optional old-name
39138     This function returns an absolute file name for an Emacs-specific
39139     configuration or data file.  The argument ‘base-name’ should be a
39140     relative file name.  The return value is the absolute name of a
39141     file in the directory specified by ‘user-emacs-directory’; if that
39142     directory does not exist, this function creates it.
39143
39144     If the optional argument OLD-NAME is non-‘nil’, it specifies a file
39145     in the user’s home directory, ‘~/OLD-NAME’.  If such a file exists,
39146     the return value is the absolute name of that file, instead of the
39147     file specified by BASE-NAME.  This argument is intended to be used
39148     by Emacs packages to provide backward compatibility.  For instance,
39149     prior to the introduction of ‘user-emacs-directory’, the abbrev
39150     file was located in ‘~/.abbrev_defs’.  Here is the definition of
39151     ‘abbrev-file-name’:
39152
39153          (defcustom abbrev-file-name
39154            (locate-user-emacs-file "abbrev_defs" ".abbrev_defs")
39155            "Default name of file from which to read abbrevs."
39156            ...
39157            :type 'file)
39158
39159   A lower-level function for standardizing file names, which
39160‘locate-user-emacs-file’ uses as a subroutine, is
39161‘convert-standard-filename’.
39162
39163 -- Function: convert-standard-filename filename
39164     This function returns a file name based on FILENAME, which fits the
39165     conventions of the current operating system.
39166
39167     On GNU and other POSIX-like systems, this simply returns FILENAME.
39168     On other operating systems, it may enforce system-specific file
39169     name conventions; for example, on MS-DOS this function performs a
39170     variety of changes to enforce MS-DOS file name limitations,
39171     including converting any leading ‘.’ to ‘_’ and truncating to three
39172     characters after the ‘.’.
39173
39174     The recommended way to use this function is to specify a name which
39175     fits the conventions of GNU and Unix systems, and pass it to
39176     ‘convert-standard-filename’.
39177
39178
39179File: elisp.info,  Node: Contents of Directories,  Next: Create/Delete Dirs,  Prev: File Names,  Up: Files
39180
3918125.10 Contents of Directories
39182=============================
39183
39184A directory is a kind of file that contains other files entered under
39185various names.  Directories are a feature of the file system.
39186
39187   Emacs can list the names of the files in a directory as a Lisp list,
39188or display the names in a buffer using the ‘ls’ shell command.  In the
39189latter case, it can optionally display information about each file,
39190depending on the options passed to the ‘ls’ command.
39191
39192 -- Function: directory-files directory &optional full-name match-regexp
39193          nosort
39194     This function returns a list of the names of the files in the
39195     directory DIRECTORY.  By default, the list is in alphabetical
39196     order.
39197
39198     If FULL-NAME is non-‘nil’, the function returns the files’ absolute
39199     file names.  Otherwise, it returns the names relative to the
39200     specified directory.
39201
39202     If MATCH-REGEXP is non-‘nil’, this function returns only those file
39203     names that contain a match for that regular expression—the other
39204     file names are excluded from the list.  On case-insensitive
39205     filesystems, the regular expression matching is case-insensitive.
39206
39207     If NOSORT is non-‘nil’, ‘directory-files’ does not sort the list,
39208     so you get the file names in no particular order.  Use this if you
39209     want the utmost possible speed and don’t care what order the files
39210     are processed in.  If the order of processing is visible to the
39211     user, then the user will probably be happier if you do sort the
39212     names.
39213
39214          (directory-files "~lewis")
39215               ⇒ ("#foo#" "#foo.el#" "." ".."
39216                   "dired-mods.el" "files.texi"
39217                   "files.texi.~1~")
39218
39219     An error is signaled if DIRECTORY is not the name of a directory
39220     that can be read.
39221
39222 -- Function: directory-files-recursively directory regexp &optional
39223          include-directories predicate follow-symlinks
39224     Return all files under DIRECTORY whose names match REGEXP.  This
39225     function searches the specified DIRECTORY and its sub-directories,
39226     recursively, for files whose basenames (i.e., without the leading
39227     directories) match the specified REGEXP, and returns a list of the
39228     absolute file names of the matching files (*note absolute file
39229     names: Relative File Names.).  The file names are returned in
39230     depth-first order, meaning that files in some sub-directory are
39231     returned before the files in its parent directory.  In addition,
39232     matching files found in each subdirectory are sorted alphabetically
39233     by their basenames.  By default, directories whose names match
39234     REGEXP are omitted from the list, but if the optional argument
39235     INCLUDE-DIRECTORIES is non-‘nil’, they are included.
39236
39237     By default, all subdirectories are descended into.  If PREDICATE is
39238     ‘t’, errors when trying to descend into a subdirectory (for
39239     instance, if it’s not readable by this user) are ignored.  If it’s
39240     neither ‘nil’ nor ‘t’, it should be a function that takes one
39241     parameter (the subdirectory name) and should return non-‘nil’ if
39242     the directory is to be descended into.
39243
39244     Symbolic links to subdirectories are not followed by default, but
39245     if FOLLOW-SYMLINKS is non-‘nil’, they are followed.
39246
39247 -- Function: locate-dominating-file file name
39248     Starting at FILE, go up the directory tree hierarchy looking for
39249     the first directory where NAME, a string, exists, and return that
39250     directory.  If FILE is a file, its directory will serve as the
39251     starting point for the search; otherwise FILE should be a directory
39252     from which to start.  The function looks in the starting directory,
39253     then in its parent, then in its parent’s parent, etc., until it
39254     either finds a directory with NAME or reaches the root directory of
39255     the filesystem without finding NAME – in the latter case the
39256     function returns ‘nil’.
39257
39258     The argument ‘name’ can also be a predicate function.  The
39259     predicate is called for every directory examined by the function,
39260     starting from FILE (even if FILE is not a directory).  It is called
39261     with one argument (the file or directory) and should return
39262     non-‘nil’ if that directory is the one it is looking for.
39263
39264 -- Function: directory-files-and-attributes directory &optional
39265          full-name match-regexp nosort id-format
39266     This is similar to ‘directory-files’ in deciding which files to
39267     report on and how to report their names.  However, instead of
39268     returning a list of file names, it returns for each file a list
39269     ‘(FILENAME . ATTRIBUTES)’, where ATTRIBUTES is what
39270     ‘file-attributes’ returns for that file.  The optional argument
39271     ID-FORMAT has the same meaning as the corresponding argument to
39272     ‘file-attributes’ (*note Definition of file-attributes::).
39273
39274 -- Function: file-expand-wildcards pattern &optional full
39275     This function expands the wildcard pattern PATTERN, returning a
39276     list of file names that match it.
39277
39278     If PATTERN is written as an absolute file name, the values are
39279     absolute also.
39280
39281     If PATTERN is written as a relative file name, it is interpreted
39282     relative to the current default directory.  The file names returned
39283     are normally also relative to the current default directory.
39284     However, if FULL is non-‘nil’, they are absolute.
39285
39286 -- Function: insert-directory file switches &optional wildcard
39287          full-directory-p
39288     This function inserts (in the current buffer) a directory listing
39289     for directory FILE, formatted with ‘ls’ according to SWITCHES.  It
39290     leaves point after the inserted text.  SWITCHES may be a string of
39291     options, or a list of strings representing individual options.
39292
39293     The argument FILE may be either a directory or a file specification
39294     including wildcard characters.  If WILDCARD is non-‘nil’, that
39295     means treat FILE as a file specification with wildcards.
39296
39297     If FULL-DIRECTORY-P is non-‘nil’, that means the directory listing
39298     is expected to show the full contents of a directory.  You should
39299     specify ‘t’ when FILE is a directory and switches do not contain
39300     ‘-d’.  (The ‘-d’ option to ‘ls’ says to describe a directory itself
39301     as a file, rather than showing its contents.)
39302
39303     On most systems, this function works by running a directory listing
39304     program whose name is in the variable ‘insert-directory-program’.
39305     If WILDCARD is non-‘nil’, it also runs the shell specified by
39306     ‘shell-file-name’, to expand the wildcards.
39307
39308     MS-DOS and MS-Windows systems usually lack the standard Unix
39309     program ‘ls’, so this function emulates the standard Unix program
39310     ‘ls’ with Lisp code.
39311
39312     As a technical detail, when SWITCHES contains the long ‘--dired’
39313     option, ‘insert-directory’ treats it specially, for the sake of
39314     dired.  However, the normally equivalent short ‘-D’ option is just
39315     passed on to ‘insert-directory-program’, as any other option.
39316
39317 -- Variable: insert-directory-program
39318     This variable’s value is the program to run to generate a directory
39319     listing for the function ‘insert-directory’.  It is ignored on
39320     systems which generate the listing with Lisp code.
39321
39322
39323File: elisp.info,  Node: Create/Delete Dirs,  Next: Magic File Names,  Prev: Contents of Directories,  Up: Files
39324
3932525.11 Creating, Copying and Deleting Directories
39326================================================
39327
39328Most Emacs Lisp file-manipulation functions get errors when used on
39329files that are directories.  For example, you cannot delete a directory
39330with ‘delete-file’.  These special functions exist to create and delete
39331directories.
39332
39333 -- Command: make-directory dirname &optional parents
39334     This command creates a directory named DIRNAME.  If PARENTS is
39335     non-‘nil’, as is always the case in an interactive call, that means
39336     to create the parent directories first, if they don’t already
39337     exist.  ‘mkdir’ is an alias for this.
39338
39339 -- Command: make-empty-file filename &optional parents
39340     This command creates an empty file named FILENAME.  As
39341     ‘make-directory’, this command creates parent directories if
39342     PARENTS is non-‘nil’.  If FILENAME already exists, this command
39343     signals an error.
39344
39345 -- Command: copy-directory dirname newname &optional keep-time parents
39346          copy-contents
39347     This command copies the directory named DIRNAME to NEWNAME.  If
39348     NEWNAME is a directory name, DIRNAME will be copied to a
39349     subdirectory there.  *Note Directory Names::.
39350
39351     It always sets the file modes of the copied files to match the
39352     corresponding original file.
39353
39354     The third argument KEEP-TIME non-‘nil’ means to preserve the
39355     modification time of the copied files.  A prefix arg makes
39356     KEEP-TIME non-‘nil’.
39357
39358     The fourth argument PARENTS says whether to create parent
39359     directories if they don’t exist.  Interactively, this happens by
39360     default.
39361
39362     The fifth argument COPY-CONTENTS, if non-‘nil’, means to copy the
39363     contents of DIRNAME directly into NEWNAME if the latter is a
39364     directory name, instead of copying DIRNAME into it as a
39365     subdirectory.
39366
39367 -- Command: delete-directory dirname &optional recursive trash
39368     This command deletes the directory named DIRNAME.  The function
39369     ‘delete-file’ does not work for files that are directories; you
39370     must use ‘delete-directory’ for them.  If RECURSIVE is ‘nil’, and
39371     the directory contains any files, ‘delete-directory’ signals an
39372     error.  If recursive is non-‘nil’, there is no error merely because
39373     the directory or its files are deleted by some other process before
39374     ‘delete-directory’ gets to them.
39375
39376     ‘delete-directory’ only follows symbolic links at the level of
39377     parent directories.
39378
39379     If the optional argument TRASH is non-‘nil’ and the variable
39380     ‘delete-by-moving-to-trash’ is non-‘nil’, this command moves the
39381     file into the system Trash instead of deleting it.  *Note
39382     Miscellaneous File Operations: (emacs)Misc File Ops.  When called
39383     interactively, TRASH is ‘t’ if no prefix argument is given, and
39384     ‘nil’ otherwise.
39385
39386
39387File: elisp.info,  Node: Magic File Names,  Next: Format Conversion,  Prev: Create/Delete Dirs,  Up: Files
39388
3938925.12 Making Certain File Names “Magic”
39390=======================================
39391
39392You can implement special handling for certain file names.  This is
39393called making those names “magic”.  The principal use for this feature
39394is in implementing access to remote files (*note Remote Files:
39395(emacs)Remote Files.).
39396
39397   To define a kind of magic file name, you must supply a regular
39398expression to define the class of names (all those that match the
39399regular expression), plus a handler that implements all the primitive
39400Emacs file operations for file names that match.
39401
39402   The variable ‘file-name-handler-alist’ holds a list of handlers,
39403together with regular expressions that determine when to apply each
39404handler.  Each element has this form:
39405
39406     (REGEXP . HANDLER)
39407
39408All the Emacs primitives for file access and file name transformation
39409check the given file name against ‘file-name-handler-alist’.  If the
39410file name matches REGEXP, the primitives handle that file by calling
39411HANDLER.
39412
39413   The first argument given to HANDLER is the name of the primitive, as
39414a symbol; the remaining arguments are the arguments that were passed to
39415that primitive.  (The first of these arguments is most often the file
39416name itself.)  For example, if you do this:
39417
39418     (file-exists-p FILENAME)
39419
39420and FILENAME has handler HANDLER, then HANDLER is called like this:
39421
39422     (funcall HANDLER 'file-exists-p FILENAME)
39423
39424   When a function takes two or more arguments that must be file names,
39425it checks each of those names for a handler.  For example, if you do
39426this:
39427
39428     (expand-file-name FILENAME DIRNAME)
39429
39430then it checks for a handler for FILENAME and then for a handler for
39431DIRNAME.  In either case, the HANDLER is called like this:
39432
39433     (funcall HANDLER 'expand-file-name FILENAME DIRNAME)
39434
39435The HANDLER then needs to figure out whether to handle FILENAME or
39436DIRNAME.
39437
39438   If the specified file name matches more than one handler, the one
39439whose match starts last in the file name gets precedence.  This rule is
39440chosen so that handlers for jobs such as uncompression are handled
39441first, before handlers for jobs such as remote file access.
39442
39443   Here are the operations that a magic file name handler gets to
39444handle:
39445
39446‘access-file’, ‘add-name-to-file’, ‘byte-compiler-base-file-name’,
39447‘copy-directory’, ‘copy-file’, ‘delete-directory’, ‘delete-file’,
39448‘diff-latest-backup-file’, ‘directory-file-name’, ‘directory-files’,
39449‘directory-files-and-attributes’, ‘dired-compress-file’,
39450‘dired-uncache’, ‘exec-path’, ‘expand-file-name’,
39451‘file-accessible-directory-p’, ‘file-acl’, ‘file-attributes’,
39452‘file-directory-p’, ‘file-equal-p’, ‘file-executable-p’,
39453‘file-exists-p’, ‘file-in-directory-p’, ‘file-local-copy’, ‘file-modes’,
39454‘file-name-all-completions’, ‘file-name-as-directory’,
39455‘file-name-case-insensitive-p’, ‘file-name-completion’,
39456‘file-name-directory’, ‘file-name-nondirectory’,
39457‘file-name-sans-versions’, ‘file-newer-than-file-p’,
39458‘file-notify-add-watch’, ‘file-notify-rm-watch’, ‘file-notify-valid-p’,
39459‘file-ownership-preserved-p’, ‘file-readable-p’, ‘file-regular-p’,
39460‘file-remote-p’, ‘file-selinux-context’, ‘file-symlink-p’,
39461‘file-system-info’, ‘file-truename’, ‘file-writable-p’,
39462‘find-backup-file-name’,
39463‘get-file-buffer’, ‘insert-directory’, ‘insert-file-contents’,
39464‘load’, ‘make-auto-save-file-name’, ‘make-directory’,
39465‘make-directory-internal’, ‘make-nearby-temp-file’, ‘make-process’,
39466‘make-symbolic-link’,
39467‘process-file’, ‘rename-file’, ‘set-file-acl’, ‘set-file-modes’,
39468‘set-file-selinux-context’, ‘set-file-times’,
39469‘set-visited-file-modtime’, ‘shell-command’, ‘start-file-process’,
39470‘substitute-in-file-name’,
39471‘temporary-file-directory’, ‘unhandled-file-name-directory’,
39472‘vc-registered’, ‘verify-visited-file-modtime’,
39473‘write-region’.
39474
39475   Handlers for ‘insert-file-contents’ typically need to clear the
39476buffer’s modified flag, with ‘(set-buffer-modified-p nil)’, if the VISIT
39477argument is non-‘nil’.  This also has the effect of unlocking the buffer
39478if it is locked.
39479
39480   The handler function must handle all of the above operations, and
39481possibly others to be added in the future.  It need not implement all
39482these operations itself—when it has nothing special to do for a certain
39483operation, it can reinvoke the primitive, to handle the operation in the
39484usual way.  It should always reinvoke the primitive for an operation it
39485does not recognize.  Here’s one way to do this:
39486
39487     (defun my-file-handler (operation &rest args)
39488       ;; First check for the specific operations
39489       ;; that we have special handling for.
39490       (cond ((eq operation 'insert-file-contents) ...)
39491             ((eq operation 'write-region) ...)
39492             ...
39493             ;; Handle any operation we don’t know about.
39494             (t (let ((inhibit-file-name-handlers
39495                       (cons 'my-file-handler
39496                             (and (eq inhibit-file-name-operation operation)
39497                                  inhibit-file-name-handlers)))
39498                      (inhibit-file-name-operation operation))
39499                  (apply operation args)))))
39500
39501   When a handler function decides to call the ordinary Emacs primitive
39502for the operation at hand, it needs to prevent the primitive from
39503calling the same handler once again, thus leading to an infinite
39504recursion.  The example above shows how to do this, with the variables
39505‘inhibit-file-name-handlers’ and ‘inhibit-file-name-operation’.  Be
39506careful to use them exactly as shown above; the details are crucial for
39507proper behavior in the case of multiple handlers, and for operations
39508that have two file names that may each have handlers.
39509
39510   Handlers that don’t really do anything special for actual access to
39511the file—such as the ones that implement completion of host names for
39512remote file names—should have a non-‘nil’ ‘safe-magic’ property.  For
39513instance, Emacs normally protects directory names it finds in ‘PATH’
39514from becoming magic, if they look like magic file names, by prefixing
39515them with ‘/:’.  But if the handler that would be used for them has a
39516non-‘nil’ ‘safe-magic’ property, the ‘/:’ is not added.
39517
39518   A file name handler can have an ‘operations’ property to declare
39519which operations it handles in a nontrivial way.  If this property has a
39520non-‘nil’ value, it should be a list of operations; then only those
39521operations will call the handler.  This avoids inefficiency, but its
39522main purpose is for autoloaded handler functions, so that they won’t be
39523loaded except when they have real work to do.
39524
39525   Simply deferring all operations to the usual primitives does not
39526work.  For instance, if the file name handler applies to
39527‘file-exists-p’, then it must handle ‘load’ itself, because the usual
39528‘load’ code won’t work properly in that case.  However, if the handler
39529uses the ‘operations’ property to say it doesn’t handle ‘file-exists-p’,
39530then it need not handle ‘load’ nontrivially.
39531
39532 -- Variable: inhibit-file-name-handlers
39533     This variable holds a list of handlers whose use is presently
39534     inhibited for a certain operation.
39535
39536 -- Variable: inhibit-file-name-operation
39537     The operation for which certain handlers are presently inhibited.
39538
39539 -- Function: find-file-name-handler file operation
39540     This function returns the handler function for file name FILE, or
39541     ‘nil’ if there is none.  The argument OPERATION should be the
39542     operation to be performed on the file—the value you will pass to
39543     the handler as its first argument when you call it.  If OPERATION
39544     equals ‘inhibit-file-name-operation’, or if it is not found in the
39545     ‘operations’ property of the handler, this function returns ‘nil’.
39546
39547 -- Function: file-local-copy filename
39548     This function copies file FILENAME to an ordinary non-magic file on
39549     the local machine, if it isn’t on the local machine already.  Magic
39550     file names should handle the ‘file-local-copy’ operation if they
39551     refer to files on other machines.  A magic file name that is used
39552     for other purposes than remote file access should not handle
39553     ‘file-local-copy’; then this function will treat the file as local.
39554
39555     If FILENAME is local, whether magic or not, this function does
39556     nothing and returns ‘nil’.  Otherwise it returns the file name of
39557     the local copy file.
39558
39559 -- Function: file-remote-p filename &optional identification connected
39560     This function tests whether FILENAME is a remote file.  If FILENAME
39561     is local (not remote), the return value is ‘nil’.  If FILENAME is
39562     indeed remote, the return value is a string that identifies the
39563     remote system.
39564
39565     This identifier string can include a host name and a user name, as
39566     well as characters designating the method used to access the remote
39567     system.  For example, the remote identifier string for the filename
39568     ‘/sudo::/some/file’ is ‘/sudo:root@localhost:’.
39569
39570     If ‘file-remote-p’ returns the same identifier for two different
39571     filenames, that means they are stored on the same file system and
39572     can be accessed locally with respect to each other.  This means,
39573     for example, that it is possible to start a remote process
39574     accessing both files at the same time.  Implementers of file name
39575     handlers need to ensure this principle is valid.
39576
39577     IDENTIFICATION specifies which part of the identifier shall be
39578     returned as string.  IDENTIFICATION can be the symbol ‘method’,
39579     ‘user’ or ‘host’; any other value is handled like ‘nil’ and means
39580     to return the complete identifier string.  In the example above,
39581     the remote ‘user’ identifier string would be ‘root’.
39582
39583     If CONNECTED is non-‘nil’, this function returns ‘nil’ even if
39584     FILENAME is remote, if Emacs has no network connection to its host.
39585     This is useful when you want to avoid the delay of making
39586     connections when they don’t exist.
39587
39588 -- Function: unhandled-file-name-directory filename
39589     This function returns the name of a directory that is not magic.
39590     For a non-magic FILENAME it returns the corresponding directory
39591     name (*note Directory Names::).  For a magic FILENAME, it invokes
39592     the file name handler, which therefore decides what value to
39593     return.  If FILENAME is not accessible from a local process, then
39594     the file name handler should indicate that by returning ‘nil’.
39595
39596     This is useful for running a subprocess; every subprocess must have
39597     a non-magic directory to serve as its current directory, and this
39598     function is a good way to come up with one.
39599
39600 -- Function: file-local-name filename
39601     This function returns the “local part” of FILENAME.  This is the
39602     part of the file’s name that identifies it on the remote host, and
39603     is typically obtained by removing from the remote file name the
39604     parts that specify the remote host and the method of accessing it.
39605     For example:
39606
39607          (file-local-name "/ssh:USER@HOST:/foo/bar")
39608               ⇒ "/foo/bar"
39609
39610     For a remote FILENAME, this function returns a file name which
39611     could be used directly as an argument of a remote process (*note
39612     Asynchronous Processes::, and *note Synchronous Processes::), and
39613     as the program to run on the remote host.  If FILENAME is local,
39614     this function returns it unchanged.
39615
39616 -- User Option: remote-file-name-inhibit-cache
39617     The attributes of remote files can be cached for better
39618     performance.  If they are changed outside of Emacs’s control, the
39619     cached values become invalid, and must be reread.
39620
39621     When this variable is set to ‘nil’, cached values are never
39622     expired.  Use this setting with caution, only if you are sure
39623     nothing other than Emacs ever changes the remote files.  If it is
39624     set to ‘t’, cached values are never used.  This is the safest
39625     value, but could result in performance degradation.
39626
39627     A compromise is to set it to a positive number.  This means that
39628     cached values are used for that amount of seconds since they were
39629     cached.  If a remote file is checked regularly, it might be a good
39630     idea to let-bind this variable to a value less than the time period
39631     between consecutive checks.  For example:
39632
39633          (defun display-time-file-nonempty-p (file)
39634            (let ((remote-file-name-inhibit-cache
39635                   (- display-time-interval 5)))
39636              (and (file-exists-p file)
39637                   (< 0 (file-attribute-size
39638                         (file-attributes
39639                          (file-chase-links file)))))))
39640
39641
39642File: elisp.info,  Node: Format Conversion,  Prev: Magic File Names,  Up: Files
39643
3964425.13 File Format Conversion
39645============================
39646
39647Emacs performs several steps to convert the data in a buffer (text, text
39648properties, and possibly other information) to and from a representation
39649suitable for storing into a file.  This section describes the
39650fundamental functions that perform this “format conversion”, namely
39651‘insert-file-contents’ for reading a file into a buffer, and
39652‘write-region’ for writing a buffer into a file.
39653
39654* Menu:
39655
39656* Overview: Format Conversion Overview.     ‘insert-file-contents’ and ‘write-region’.
39657* Round-Trip: Format Conversion Round-Trip. Using ‘format-alist’.
39658* Piecemeal: Format Conversion Piecemeal.   Specifying non-paired conversion.
39659
39660
39661File: elisp.info,  Node: Format Conversion Overview,  Next: Format Conversion Round-Trip,  Up: Format Conversion
39662
3966325.13.1 Overview
39664----------------
39665
39666The function ‘insert-file-contents’:
39667
39668   • initially, inserts bytes from the file into the buffer;
39669   • decodes bytes to characters as appropriate;
39670   • processes formats as defined by entries in ‘format-alist’; and
39671   • calls functions in ‘after-insert-file-functions’.
39672
39673The function ‘write-region’:
39674
39675   • initially, calls functions in ‘write-region-annotate-functions’;
39676   • processes formats as defined by entries in ‘format-alist’;
39677   • encodes characters to bytes as appropriate; and
39678   • modifies the file with the bytes.
39679
39680   This shows the symmetry of the lowest-level operations; reading and
39681writing handle things in opposite order.  The rest of this section
39682describes the two facilities surrounding the three variables named
39683above, as well as some related functions.  *note Coding Systems::, for
39684details on character encoding and decoding.
39685
39686
39687File: elisp.info,  Node: Format Conversion Round-Trip,  Next: Format Conversion Piecemeal,  Prev: Format Conversion Overview,  Up: Format Conversion
39688
3968925.13.2 Round-Trip Specification
39690--------------------------------
39691
39692The most general of the two facilities is controlled by the variable
39693‘format-alist’, a list of “file format” specifications, which describe
39694textual representations used in files for the data in an Emacs buffer.
39695The descriptions for reading and writing are paired, which is why we
39696call this “round-trip” specification (*note Format Conversion
39697Piecemeal::, for non-paired specification).
39698
39699 -- Variable: format-alist
39700     This list contains one format definition for each defined file
39701     format.  Each format definition is a list of this form:
39702
39703          (NAME DOC-STRING REGEXP FROM-FN TO-FN MODIFY MODE-FN PRESERVE)
39704
39705Here is what the elements in a format definition mean:
39706
39707NAME
39708     The name of this format.
39709
39710DOC-STRING
39711     A documentation string for the format.
39712
39713REGEXP
39714     A regular expression which is used to recognize files represented
39715     in this format.  If ‘nil’, the format is never applied
39716     automatically.
39717
39718FROM-FN
39719     A shell command or function to decode data in this format (to
39720     convert file data into the usual Emacs data representation).
39721
39722     A shell command is represented as a string; Emacs runs the command
39723     as a filter to perform the conversion.
39724
39725     If FROM-FN is a function, it is called with two arguments, BEGIN
39726     and END, which specify the part of the buffer it should convert.
39727     It should convert the text by editing it in place.  Since this can
39728     change the length of the text, FROM-FN should return the modified
39729     end position.
39730
39731     One responsibility of FROM-FN is to make sure that the beginning of
39732     the file no longer matches REGEXP.  Otherwise it is likely to get
39733     called again.  Also, FROM-FN must not involve buffers or files
39734     other than the one being decoded, otherwise the internal buffer
39735     used for formatting might be overwritten.
39736
39737TO-FN
39738     A shell command or function to encode data in this format—that is,
39739     to convert the usual Emacs data representation into this format.
39740
39741     If TO-FN is a string, it is a shell command; Emacs runs the command
39742     as a filter to perform the conversion.
39743
39744     If TO-FN is a function, it is called with three arguments: BEGIN
39745     and END, which specify the part of the buffer it should convert,
39746     and BUFFER, which specifies which buffer.  There are two ways it
39747     can do the conversion:
39748
39749        • By editing the buffer in place.  In this case, TO-FN should
39750          return the end-position of the range of text, as modified.
39751
39752        • By returning a list of annotations.  This is a list of
39753          elements of the form ‘(POSITION . STRING)’, where POSITION is
39754          an integer specifying the relative position in the text to be
39755          written, and STRING is the annotation to add there.  The list
39756          must be sorted in order of position when TO-FN returns it.
39757
39758          When ‘write-region’ actually writes the text from the buffer
39759          to the file, it intermixes the specified annotations at the
39760          corresponding positions.  All this takes place without
39761          modifying the buffer.
39762
39763     TO-FN must not involve buffers or files other than the one being
39764     encoded, otherwise the internal buffer used for formatting might be
39765     overwritten.
39766
39767MODIFY
39768     A flag, ‘t’ if the encoding function modifies the buffer, and ‘nil’
39769     if it works by returning a list of annotations.
39770
39771MODE-FN
39772     A minor-mode function to call after visiting a file converted from
39773     this format.  The function is called with one argument, the integer
39774     1; that tells a minor-mode function to enable the mode.
39775
39776PRESERVE
39777     A flag, ‘t’ if ‘format-write-file’ should not remove this format
39778     from ‘buffer-file-format’.
39779
39780   The function ‘insert-file-contents’ automatically recognizes file
39781formats when it reads the specified file.  It checks the text of the
39782beginning of the file against the regular expressions of the format
39783definitions, and if it finds a match, it calls the decoding function for
39784that format.  Then it checks all the known formats over again.  It keeps
39785checking them until none of them is applicable.
39786
39787   Visiting a file, with ‘find-file-noselect’ or the commands that use
39788it, performs conversion likewise (because it calls
39789‘insert-file-contents’); it also calls the mode function for each format
39790that it decodes.  It stores a list of the format names in the
39791buffer-local variable ‘buffer-file-format’.
39792
39793 -- Variable: buffer-file-format
39794     This variable states the format of the visited file.  More
39795     precisely, this is a list of the file format names that were
39796     decoded in the course of visiting the current buffer’s file.  It is
39797     always buffer-local in all buffers.
39798
39799   When ‘write-region’ writes data into a file, it first calls the
39800encoding functions for the formats listed in ‘buffer-file-format’, in
39801the order of appearance in the list.
39802
39803 -- Command: format-write-file file format &optional confirm
39804     This command writes the current buffer contents into the file FILE
39805     in a format based on FORMAT, which is a list of format names.  It
39806     constructs the actual format starting from FORMAT, then appending
39807     any elements from the value of ‘buffer-file-format’ with a
39808     non-‘nil’ PRESERVE flag (see above), if they are not already
39809     present in FORMAT.  It then updates ‘buffer-file-format’ with this
39810     format, making it the default for future saves.  Except for the
39811     FORMAT argument, this command is similar to ‘write-file’.  In
39812     particular, CONFIRM has the same meaning and interactive treatment
39813     as the corresponding argument to ‘write-file’.  *Note Definition of
39814     write-file::.
39815
39816 -- Command: format-find-file file format
39817     This command finds the file FILE, converting it according to format
39818     FORMAT.  It also makes FORMAT the default if the buffer is saved
39819     later.
39820
39821     The argument FORMAT is a list of format names.  If FORMAT is ‘nil’,
39822     no conversion takes place.  Interactively, typing just <RET> for
39823     FORMAT specifies ‘nil’.
39824
39825 -- Command: format-insert-file file format &optional beg end
39826     This command inserts the contents of file FILE, converting it
39827     according to format FORMAT.  If BEG and END are non-‘nil’, they
39828     specify which part of the file to read, as in
39829     ‘insert-file-contents’ (*note Reading from Files::).
39830
39831     The return value is like what ‘insert-file-contents’ returns: a
39832     list of the absolute file name and the length of the data inserted
39833     (after conversion).
39834
39835     The argument FORMAT is a list of format names.  If FORMAT is ‘nil’,
39836     no conversion takes place.  Interactively, typing just <RET> for
39837     FORMAT specifies ‘nil’.
39838
39839 -- Variable: buffer-auto-save-file-format
39840     This variable specifies the format to use for auto-saving.  Its
39841     value is a list of format names, just like the value of
39842     ‘buffer-file-format’; however, it is used instead of
39843     ‘buffer-file-format’ for writing auto-save files.  If the value is
39844     ‘t’, the default, auto-saving uses the same format as a regular
39845     save in the same buffer.  This variable is always buffer-local in
39846     all buffers.
39847
39848
39849File: elisp.info,  Node: Format Conversion Piecemeal,  Prev: Format Conversion Round-Trip,  Up: Format Conversion
39850
3985125.13.3 Piecemeal Specification
39852-------------------------------
39853
39854In contrast to the round-trip specification described in the previous
39855subsection (*note Format Conversion Round-Trip::), you can use the
39856variables ‘after-insert-file-functions’ and
39857‘write-region-annotate-functions’ to separately control the respective
39858reading and writing conversions.
39859
39860   Conversion starts with one representation and produces another
39861representation.  When there is only one conversion to do, there is no
39862conflict about what to start with.  However, when there are multiple
39863conversions involved, conflict may arise when two conversions need to
39864start with the same data.
39865
39866   This situation is best understood in the context of converting text
39867properties during ‘write-region’.  For example, the character at
39868position 42 in a buffer is ‘X’ with a text property ‘foo’.  If the
39869conversion for ‘foo’ is done by inserting into the buffer, say, ‘FOO:’,
39870then that changes the character at position 42 from ‘X’ to ‘F’.  The
39871next conversion will start with the wrong data straight away.
39872
39873   To avoid conflict, cooperative conversions do not modify the buffer,
39874but instead specify “annotations”, a list of elements of the form
39875‘(POSITION . STRING)’, sorted in order of increasing POSITION.
39876
39877   If there is more than one conversion, ‘write-region’ merges their
39878annotations destructively into one sorted list.  Later, when the text
39879from the buffer is actually written to the file, it intermixes the
39880specified annotations at the corresponding positions.  All this takes
39881place without modifying the buffer.
39882
39883   In contrast, when reading, the annotations intermixed with the text
39884are handled immediately.  ‘insert-file-contents’ sets point to the
39885beginning of some text to be converted, then calls the conversion
39886functions with the length of that text.  These functions should always
39887return with point at the beginning of the inserted text.  This approach
39888makes sense for reading because annotations removed by the first
39889converter can’t be mistakenly processed by a later converter.  Each
39890conversion function should scan for the annotations it recognizes,
39891remove the annotation, modify the buffer text (to set a text property,
39892for example), and return the updated length of the text, as it stands
39893after those changes.  The value returned by one function becomes the
39894argument to the next function.
39895
39896 -- Variable: write-region-annotate-functions
39897     A list of functions for ‘write-region’ to call.  Each function in
39898     the list is called with two arguments: the start and end of the
39899     region to be written.  These functions should not alter the
39900     contents of the buffer.  Instead, they should return annotations.
39901
39902     As a special case, a function may return with a different buffer
39903     current.  Emacs takes this to mean that the current buffer contains
39904     altered text to be output.  It therefore changes the START and END
39905     arguments of the ‘write-region’ call, giving them the values of
39906     ‘point-min’ and ‘point-max’ in the new buffer, respectively.  It
39907     also discards all previous annotations, because they should have
39908     been dealt with by this function.
39909
39910 -- Variable: write-region-post-annotation-function
39911     The value of this variable, if non-‘nil’, should be a function.
39912     This function is called, with no arguments, after ‘write-region’
39913     has completed.
39914
39915     If any function in ‘write-region-annotate-functions’ returns with a
39916     different buffer current, Emacs calls
39917     ‘write-region-post-annotation-function’ more than once.  Emacs
39918     calls it with the last buffer that was current, and again with the
39919     buffer before that, and so on back to the original buffer.
39920
39921     Thus, a function in ‘write-region-annotate-functions’ can create a
39922     buffer, give this variable the local value of ‘kill-buffer’ in that
39923     buffer, set up the buffer with altered text, and make the buffer
39924     current.  The buffer will be killed after ‘write-region’ is done.
39925
39926 -- Variable: after-insert-file-functions
39927     Each function in this list is called by ‘insert-file-contents’ with
39928     one argument, the number of characters inserted, and with point at
39929     the beginning of the inserted text.  Each function should leave
39930     point unchanged, and return the new character count describing the
39931     inserted text as modified by the function.
39932
39933   We invite users to write Lisp programs to store and retrieve text
39934properties in files, using these hooks, and thus to experiment with
39935various data formats and find good ones.  Eventually we hope users will
39936produce good, general extensions we can install in Emacs.
39937
39938   We suggest not trying to handle arbitrary Lisp objects as text
39939property names or values—because a program that general is probably
39940difficult to write, and slow.  Instead, choose a set of possible data
39941types that are reasonably flexible, and not too hard to encode.
39942
39943
39944File: elisp.info,  Node: Backups and Auto-Saving,  Next: Buffers,  Prev: Files,  Up: Top
39945
3994626 Backups and Auto-Saving
39947**************************
39948
39949Backup files and auto-save files are two methods by which Emacs tries to
39950protect the user from the consequences of crashes or of the user’s own
39951errors.  Auto-saving preserves the text from earlier in the current
39952editing session; backup files preserve file contents prior to the
39953current session.
39954
39955* Menu:
39956
39957* Backup Files::   How backup files are made; how their names are chosen.
39958* Auto-Saving::    How auto-save files are made; how their names are chosen.
39959* Reverting::      ‘revert-buffer’, and how to customize what it does.
39960
39961
39962File: elisp.info,  Node: Backup Files,  Next: Auto-Saving,  Up: Backups and Auto-Saving
39963
3996426.1 Backup Files
39965=================
39966
39967A “backup file” is a copy of the old contents of a file you are editing.
39968Emacs makes a backup file the first time you save a buffer into its
39969visited file.  Thus, normally, the backup file contains the contents of
39970the file as it was before the current editing session.  The contents of
39971the backup file normally remain unchanged once it exists.
39972
39973   Backups are usually made by renaming the visited file to a new name.
39974Optionally, you can specify that backup files should be made by copying
39975the visited file.  This choice makes a difference for files with
39976multiple names; it also can affect whether the edited file remains owned
39977by the original owner or becomes owned by the user editing it.
39978
39979   By default, Emacs makes a single backup file for each file edited.
39980You can alternatively request numbered backups; then each new backup
39981file gets a new name.  You can delete old numbered backups when you
39982don’t want them any more, or Emacs can delete them automatically.
39983
39984   For performance, the operating system may not write the backup file’s
39985contents to secondary storage immediately, or may alias the backup data
39986with the original until one or the other is later modified.  *Note Files
39987and Storage::.
39988
39989* Menu:
39990
39991* Making Backups::     How Emacs makes backup files, and when.
39992* Rename or Copy::     Two alternatives: renaming the old file or copying it.
39993* Numbered Backups::   Keeping multiple backups for each source file.
39994* Backup Names::       How backup file names are computed; customization.
39995
39996
39997File: elisp.info,  Node: Making Backups,  Next: Rename or Copy,  Up: Backup Files
39998
3999926.1.1 Making Backup Files
40000--------------------------
40001
40002 -- Function: backup-buffer
40003     This function makes a backup of the file visited by the current
40004     buffer, if appropriate.  It is called by ‘save-buffer’ before
40005     saving the buffer the first time.
40006
40007     If a backup was made by renaming, the return value is a cons cell
40008     of the form (MODES EXTRA-ALIST BACKUPNAME), where MODES are the
40009     mode bits of the original file, as returned by ‘file-modes’ (*note
40010     Testing Accessibility::), EXTRA-ALIST is an alist describing the
40011     original file’s extended attributes, as returned by
40012     ‘file-extended-attributes’ (*note Extended Attributes::), and
40013     BACKUPNAME is the name of the backup.
40014
40015     In all other cases (i.e., if a backup was made by copying or if no
40016     backup was made), this function returns ‘nil’.
40017
40018 -- Variable: buffer-backed-up
40019     This buffer-local variable says whether this buffer’s file has been
40020     backed up on account of this buffer.  If it is non-‘nil’, the
40021     backup file has been written.  Otherwise, the file should be backed
40022     up when it is next saved (if backups are enabled).  This is a
40023     permanent local; ‘kill-all-local-variables’ does not alter it.
40024
40025 -- User Option: make-backup-files
40026     This variable determines whether or not to make backup files.  If
40027     it is non-‘nil’, then Emacs creates a backup of each file when it
40028     is saved for the first time—provided that ‘backup-inhibited’ is
40029     ‘nil’ (see below).
40030
40031     The following example shows how to change the ‘make-backup-files’
40032     variable only in the Rmail buffers and not elsewhere.  Setting it
40033     ‘nil’ stops Emacs from making backups of these files, which may
40034     save disk space.  (You would put this code in your init file.)
40035
40036          (add-hook 'rmail-mode-hook
40037                    (lambda () (setq-local make-backup-files nil)))
40038
40039 -- Variable: backup-enable-predicate
40040     This variable’s value is a function to be called on certain
40041     occasions to decide whether a file should have backup files.  The
40042     function receives one argument, an absolute file name to consider.
40043     If the function returns ‘nil’, backups are disabled for that file.
40044     Otherwise, the other variables in this section say whether and how
40045     to make backups.
40046
40047     The default value is ‘normal-backup-enable-predicate’, which checks
40048     for files in ‘temporary-file-directory’ and
40049     ‘small-temporary-file-directory’.
40050
40051 -- Variable: backup-inhibited
40052     If this variable is non-‘nil’, backups are inhibited.  It records
40053     the result of testing ‘backup-enable-predicate’ on the visited file
40054     name.  It can also coherently be used by other mechanisms that
40055     inhibit backups based on which file is visited.  For example, VC
40056     sets this variable non-‘nil’ to prevent making backups for files
40057     managed with a version control system.
40058
40059     This is a permanent local, so that changing the major mode does not
40060     lose its value.  Major modes should not set this variable—they
40061     should set ‘make-backup-files’ instead.
40062
40063 -- User Option: backup-directory-alist
40064     This variable’s value is an alist of filename patterns and backup
40065     directories.  Each element looks like
40066          (REGEXP . DIRECTORY)
40067
40068     Backups of files with names matching REGEXP will be made in
40069     DIRECTORY.  DIRECTORY may be relative or absolute.  If it is
40070     absolute, so that all matching files are backed up into the same
40071     directory, the file names in this directory will be the full name
40072     of the file backed up with all directory separators changed to ‘!’
40073     to prevent clashes.  This will not work correctly if your
40074     filesystem truncates the resulting name.
40075
40076     For the common case of all backups going into one directory, the
40077     alist should contain a single element pairing ‘"."’ with the
40078     appropriate directory.
40079
40080     If this variable is ‘nil’ (the default), or it fails to match a
40081     filename, the backup is made in the original file’s directory.
40082
40083     On MS-DOS filesystems without long names this variable is always
40084     ignored.
40085
40086 -- User Option: make-backup-file-name-function
40087     This variable’s value is a function to use for making backup file
40088     names.  The function ‘make-backup-file-name’ calls it.  *Note
40089     Naming Backup Files: Backup Names.
40090
40091     This could be buffer-local to do something special for specific
40092     files.  If you change it, you may need to change
40093     ‘backup-file-name-p’ and ‘file-name-sans-versions’ too.
40094
40095
40096File: elisp.info,  Node: Rename or Copy,  Next: Numbered Backups,  Prev: Making Backups,  Up: Backup Files
40097
4009826.1.2 Backup by Renaming or by Copying?
40099----------------------------------------
40100
40101There are two ways that Emacs can make a backup file:
40102
40103   • Emacs can rename the original file so that it becomes a backup
40104     file, and then write the buffer being saved into a new file.  After
40105     this procedure, any other names (i.e., hard links) of the original
40106     file now refer to the backup file.  The new file is owned by the
40107     user doing the editing, and its group is the default for new files
40108     written by the user in that directory.
40109
40110   • Emacs can copy the original file into a backup file, and then
40111     overwrite the original file with new contents.  After this
40112     procedure, any other names (i.e., hard links) of the original file
40113     continue to refer to the current (updated) version of the file.
40114     The file’s owner and group will be unchanged.
40115
40116   The first method, renaming, is the default.
40117
40118   The variable ‘backup-by-copying’, if non-‘nil’, says to use the
40119second method, which is to copy the original file and overwrite it with
40120the new buffer contents.  The variable ‘file-precious-flag’, if
40121non-‘nil’, also has this effect (as a sideline of its main
40122significance).  *Note Saving Buffers::.
40123
40124 -- User Option: backup-by-copying
40125     If this variable is non-‘nil’, Emacs always makes backup files by
40126     copying.  The default is ‘nil’.
40127
40128   The following three variables, when non-‘nil’, cause the second
40129method to be used in certain special cases.  They have no effect on the
40130treatment of files that don’t fall into the special cases.
40131
40132 -- User Option: backup-by-copying-when-linked
40133     If this variable is non-‘nil’, Emacs makes backups by copying for
40134     files with multiple names (hard links).  The default is ‘nil’.
40135
40136     This variable is significant only if ‘backup-by-copying’ is ‘nil’,
40137     since copying is always used when that variable is non-‘nil’.
40138
40139 -- User Option: backup-by-copying-when-mismatch
40140     If this variable is non-‘nil’ (the default), Emacs makes backups by
40141     copying in cases where renaming would change either the owner or
40142     the group of the file.
40143
40144     The value has no effect when renaming would not alter the owner or
40145     group of the file; that is, for files which are owned by the user
40146     and whose group matches the default for a new file created there by
40147     the user.
40148
40149     This variable is significant only if ‘backup-by-copying’ is ‘nil’,
40150     since copying is always used when that variable is non-‘nil’.
40151
40152 -- User Option: backup-by-copying-when-privileged-mismatch
40153     This variable, if non-‘nil’, specifies the same behavior as
40154     ‘backup-by-copying-when-mismatch’, but only for certain user-id and
40155     group-id values: namely, those less than or equal to a certain
40156     number.  You set this variable to that number.
40157
40158     Thus, if you set ‘backup-by-copying-when-privileged-mismatch’ to 0,
40159     backup by copying is done for the superuser and group 0 only, when
40160     necessary to prevent a change in the owner of the file.
40161
40162     The default is 200.
40163
40164
40165File: elisp.info,  Node: Numbered Backups,  Next: Backup Names,  Prev: Rename or Copy,  Up: Backup Files
40166
4016726.1.3 Making and Deleting Numbered Backup Files
40168------------------------------------------------
40169
40170If a file’s name is ‘foo’, the names of its numbered backup versions are
40171‘foo.~V~’, for various integers V, like this: ‘foo.~1~’, ‘foo.~2~’,
40172‘foo.~3~’, ..., ‘foo.~259~’, and so on.
40173
40174 -- User Option: version-control
40175     This variable controls whether to make a single non-numbered backup
40176     file or multiple numbered backups.
40177
40178     ‘nil’
40179          Make numbered backups if the visited file already has numbered
40180          backups; otherwise, do not.  This is the default.
40181
40182     ‘never’
40183          Do not make numbered backups.
40184
40185     ANYTHING ELSE
40186          Make numbered backups.
40187
40188   The use of numbered backups ultimately leads to a large number of
40189backup versions, which must then be deleted.  Emacs can do this
40190automatically or it can ask the user whether to delete them.
40191
40192 -- User Option: kept-new-versions
40193     The value of this variable is the number of newest versions to keep
40194     when a new numbered backup is made.  The newly made backup is
40195     included in the count.  The default value is 2.
40196
40197 -- User Option: kept-old-versions
40198     The value of this variable is the number of oldest versions to keep
40199     when a new numbered backup is made.  The default value is 2.
40200
40201   If there are backups numbered 1, 2, 3, 5, and 7, and both of these
40202variables have the value 2, then the backups numbered 1 and 2 are kept
40203as old versions and those numbered 5 and 7 are kept as new versions;
40204backup version 3 is excess.  The function ‘find-backup-file-name’ (*note
40205Backup Names::) is responsible for determining which backup versions to
40206delete, but does not delete them itself.
40207
40208 -- User Option: delete-old-versions
40209     If this variable is ‘t’, then saving a file deletes excess backup
40210     versions silently.  If it is ‘nil’, that means to ask for
40211     confirmation before deleting excess backups.  Otherwise, they are
40212     not deleted at all.
40213
40214 -- User Option: dired-kept-versions
40215     This variable specifies how many of the newest backup versions to
40216     keep in the Dired command ‘.’ (‘dired-clean-directory’).  That’s
40217     the same thing ‘kept-new-versions’ specifies when you make a new
40218     backup file.  The default is 2.
40219
40220
40221File: elisp.info,  Node: Backup Names,  Prev: Numbered Backups,  Up: Backup Files
40222
4022326.1.4 Naming Backup Files
40224--------------------------
40225
40226The functions in this section are documented mainly because you can
40227customize the naming conventions for backup files by redefining them.
40228If you change one, you probably need to change the rest.
40229
40230 -- Function: backup-file-name-p filename
40231     This function returns a non-‘nil’ value if FILENAME is a possible
40232     name for a backup file.  It just checks the name, not whether a
40233     file with the name FILENAME exists.
40234
40235          (backup-file-name-p "foo")
40236               ⇒ nil
40237          (backup-file-name-p "foo~")
40238               ⇒ 3
40239
40240     The standard definition of this function is as follows:
40241
40242          (defun backup-file-name-p (file)
40243            "Return non-nil if FILE is a backup file \
40244          name (numeric or not)..."
40245            (string-match "~\\'" file))
40246
40247     Thus, the function returns a non-‘nil’ value if the file name ends
40248     with a ‘~’.  (We use a backslash to split the documentation
40249     string’s first line into two lines in the text, but produce just
40250     one line in the string itself.)
40251
40252     This simple expression is placed in a separate function to make it
40253     easy to redefine for customization.
40254
40255 -- Function: make-backup-file-name filename
40256     This function returns a string that is the name to use for a
40257     non-numbered backup file for file FILENAME.  On Unix, this is just
40258     FILENAME with a tilde appended.
40259
40260     The standard definition of this function, on most operating
40261     systems, is as follows:
40262
40263          (defun make-backup-file-name (file)
40264            "Create the non-numeric backup file name for FILE..."
40265            (concat file "~"))
40266
40267     You can change the backup-file naming convention by redefining this
40268     function.  The following example redefines ‘make-backup-file-name’
40269     to prepend a ‘.’ in addition to appending a tilde:
40270
40271          (defun make-backup-file-name (filename)
40272            (expand-file-name
40273              (concat "." (file-name-nondirectory filename) "~")
40274              (file-name-directory filename)))
40275
40276          (make-backup-file-name "backups.texi")
40277               ⇒ ".backups.texi~"
40278
40279     Some parts of Emacs, including some Dired commands, assume that
40280     backup file names end with ‘~’.  If you do not follow that
40281     convention, it will not cause serious problems, but these commands
40282     may give less-than-desirable results.
40283
40284 -- Function: find-backup-file-name filename
40285     This function computes the file name for a new backup file for
40286     FILENAME.  It may also propose certain existing backup files for
40287     deletion.  ‘find-backup-file-name’ returns a list whose CAR is the
40288     name for the new backup file and whose CDR is a list of backup
40289     files whose deletion is proposed.  The value can also be ‘nil’,
40290     which means not to make a backup.
40291
40292     Two variables, ‘kept-old-versions’ and ‘kept-new-versions’,
40293     determine which backup versions should be kept.  This function
40294     keeps those versions by excluding them from the CDR of the value.
40295     *Note Numbered Backups::.
40296
40297     In this example, the value says that ‘~rms/foo.~5~’ is the name to
40298     use for the new backup file, and ‘~rms/foo.~3~’ is an excess
40299     version that the caller should consider deleting now.
40300
40301          (find-backup-file-name "~rms/foo")
40302               ⇒ ("~rms/foo.~5~" "~rms/foo.~3~")
40303
40304 -- Function: file-newest-backup filename
40305     This function returns the name of the most recent backup file for
40306     FILENAME, or ‘nil’ if that file has no backup files.
40307
40308     Some file comparison commands use this function so that they can
40309     automatically compare a file with its most recent backup.
40310
40311
40312File: elisp.info,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
40313
4031426.2 Auto-Saving
40315================
40316
40317Emacs periodically saves all files that you are visiting; this is called
40318“auto-saving”.  Auto-saving prevents you from losing more than a limited
40319amount of work if the system crashes.  By default, auto-saves happen
40320every 300 keystrokes, or after around 30 seconds of idle time.  *Note
40321Auto Save: (emacs)Auto Save, for information on auto-save for users.
40322Here we describe the functions used to implement auto-saving and the
40323variables that control them.
40324
40325 -- Variable: buffer-auto-save-file-name
40326     This buffer-local variable is the name of the file used for
40327     auto-saving the current buffer.  It is ‘nil’ if the buffer should
40328     not be auto-saved.
40329
40330          buffer-auto-save-file-name
40331               ⇒ "/xcssun/users/rms/lewis/#backups.texi#"
40332
40333 -- Command: auto-save-mode arg
40334     This is the mode command for Auto Save mode, a buffer-local minor
40335     mode.  When Auto Save mode is enabled, auto-saving is enabled in
40336     the buffer.  The calling convention is the same as for other minor
40337     mode commands (*note Minor Mode Conventions::).
40338
40339     Unlike most minor modes, there is no ‘auto-save-mode’ variable.
40340     Auto Save mode is enabled if ‘buffer-auto-save-file-name’ is
40341     non-‘nil’ and ‘buffer-saved-size’ (see below) is non-zero.
40342
40343 -- Function: auto-save-file-name-p filename
40344     This function returns a non-‘nil’ value if FILENAME is a string
40345     that could be the name of an auto-save file.  It assumes the usual
40346     naming convention for auto-save files: a name that begins and ends
40347     with hash marks (‘#’) is a possible auto-save file name.  The
40348     argument FILENAME should not contain a directory part.
40349
40350          (make-auto-save-file-name)
40351               ⇒ "/xcssun/users/rms/lewis/#backups.texi#"
40352          (auto-save-file-name-p "#backups.texi#")
40353               ⇒ 0
40354          (auto-save-file-name-p "backups.texi")
40355               ⇒ nil
40356
40357     The standard definition of this function is as follows:
40358
40359          (defun auto-save-file-name-p (filename)
40360            "Return non-nil if FILENAME can be yielded by..."
40361            (string-match "^#.*#$" filename))
40362
40363     This function exists so that you can customize it if you wish to
40364     change the naming convention for auto-save files.  If you redefine
40365     it, be sure to redefine the function ‘make-auto-save-file-name’
40366     correspondingly.
40367
40368 -- Function: make-auto-save-file-name
40369     This function returns the file name to use for auto-saving the
40370     current buffer.  This is just the file name with hash marks (‘#’)
40371     prepended and appended to it.  This function does not look at the
40372     variable ‘auto-save-visited-file-name’ (described below); callers
40373     of this function should check that variable first.
40374
40375          (make-auto-save-file-name)
40376               ⇒ "/xcssun/users/rms/lewis/#backups.texi#"
40377
40378     Here is a simplified version of the standard definition of this
40379     function:
40380
40381          (defun make-auto-save-file-name ()
40382            "Return file name to use for auto-saves \
40383          of current buffer.."
40384            (if buffer-file-name
40385                (concat
40386                 (file-name-directory buffer-file-name)
40387                 "#"
40388                 (file-name-nondirectory buffer-file-name)
40389                 "#")
40390              (expand-file-name
40391               (concat "#%" (buffer-name) "#"))))
40392
40393     This exists as a separate function so that you can redefine it to
40394     customize the naming convention for auto-save files.  Be sure to
40395     change ‘auto-save-file-name-p’ in a corresponding way.
40396
40397 -- User Option: auto-save-visited-file-name
40398     If this variable is non-‘nil’, Emacs auto-saves buffers in the
40399     files they are visiting.  That is, the auto-save is done in the
40400     same file that you are editing.  Normally, this variable is ‘nil’,
40401     so auto-save files have distinct names that are created by
40402     ‘make-auto-save-file-name’.
40403
40404     When you change the value of this variable, the new value does not
40405     take effect in an existing buffer until the next time auto-save
40406     mode is reenabled in it.  If auto-save mode is already enabled,
40407     auto-saves continue to go in the same file name until
40408     ‘auto-save-mode’ is called again.
40409
40410     Note that setting this variable to a non-‘nil’ value does not
40411     change the fact that auto-saving is different from saving the
40412     buffer; e.g., the hooks described in *note Saving Buffers:: are
40413     _not_ run when a buffer is auto-saved.
40414
40415 -- Function: recent-auto-save-p
40416     This function returns ‘t’ if the current buffer has been auto-saved
40417     since the last time it was read in or saved.
40418
40419 -- Function: set-buffer-auto-saved
40420     This function marks the current buffer as auto-saved.  The buffer
40421     will not be auto-saved again until the buffer text is changed
40422     again.  The function returns ‘nil’.
40423
40424 -- User Option: auto-save-interval
40425     The value of this variable specifies how often to do auto-saving,
40426     in terms of number of input events.  Each time this many additional
40427     input events are read, Emacs does auto-saving for all buffers in
40428     which that is enabled.  Setting this to zero disables autosaving
40429     based on the number of characters typed.
40430
40431 -- User Option: auto-save-timeout
40432     The value of this variable is the number of seconds of idle time
40433     that should cause auto-saving.  Each time the user pauses for this
40434     long, Emacs does auto-saving for all buffers in which that is
40435     enabled.  (If the current buffer is large, the specified timeout is
40436     multiplied by a factor that increases as the size increases; for a
40437     million-byte buffer, the factor is almost 4.)
40438
40439     If the value is zero or ‘nil’, then auto-saving is not done as a
40440     result of idleness, only after a certain number of input events as
40441     specified by ‘auto-save-interval’.
40442
40443 -- Variable: auto-save-hook
40444     This normal hook is run whenever an auto-save is about to happen.
40445
40446 -- User Option: auto-save-default
40447     If this variable is non-‘nil’, buffers that are visiting files have
40448     auto-saving enabled by default.  Otherwise, they do not.
40449
40450 -- Command: do-auto-save &optional no-message current-only
40451     This function auto-saves all buffers that need to be auto-saved.
40452     It saves all buffers for which auto-saving is enabled and that have
40453     been changed since the previous auto-save.
40454
40455     If any buffers are auto-saved, ‘do-auto-save’ normally displays a
40456     message saying ‘Auto-saving...’ in the echo area while auto-saving
40457     is going on.  However, if NO-MESSAGE is non-‘nil’, the message is
40458     inhibited.
40459
40460     If CURRENT-ONLY is non-‘nil’, only the current buffer is
40461     auto-saved.
40462
40463 -- Function: delete-auto-save-file-if-necessary &optional force
40464     This function deletes the current buffer’s auto-save file if
40465     ‘delete-auto-save-files’ is non-‘nil’.  It is called every time a
40466     buffer is saved.
40467
40468     Unless FORCE is non-‘nil’, this function only deletes the file if
40469     it was written by the current Emacs session since the last true
40470     save.
40471
40472 -- User Option: delete-auto-save-files
40473     This variable is used by the function
40474     ‘delete-auto-save-file-if-necessary’.  If it is non-‘nil’, Emacs
40475     deletes auto-save files when a true save is done (in the visited
40476     file).  This saves disk space and unclutters your directory.
40477
40478 -- Function: rename-auto-save-file
40479     This function adjusts the current buffer’s auto-save file name if
40480     the visited file name has changed.  It also renames an existing
40481     auto-save file, if it was made in the current Emacs session.  If
40482     the visited file name has not changed, this function does nothing.
40483
40484 -- Variable: buffer-saved-size
40485     The value of this buffer-local variable is the length of the
40486     current buffer, when it was last read in, saved, or auto-saved.
40487     This is used to detect a substantial decrease in size, and turn off
40488     auto-saving in response.
40489
40490     If it is −1, that means auto-saving is temporarily shut off in this
40491     buffer due to a substantial decrease in size.  Explicitly saving
40492     the buffer stores a positive value in this variable, thus
40493     reenabling auto-saving.  Turning auto-save mode off or on also
40494     updates this variable, so that the substantial decrease in size is
40495     forgotten.
40496
40497     If it is −2, that means this buffer should disregard changes in
40498     buffer size; in particular, it should not shut off auto-saving
40499     temporarily due to changes in buffer size.
40500
40501 -- Variable: auto-save-list-file-name
40502     This variable (if non-‘nil’) specifies a file for recording the
40503     names of all the auto-save files.  Each time Emacs does
40504     auto-saving, it writes two lines into this file for each buffer
40505     that has auto-saving enabled.  The first line gives the name of the
40506     visited file (it’s empty if the buffer has none), and the second
40507     gives the name of the auto-save file.
40508
40509     When Emacs exits normally, it deletes this file; if Emacs crashes,
40510     you can look in the file to find all the auto-save files that might
40511     contain work that was otherwise lost.  The ‘recover-session’
40512     command uses this file to find them.
40513
40514     The default name for this file specifies your home directory and
40515     starts with ‘.saves-’.  It also contains the Emacs process ID and
40516     the host name.
40517
40518 -- User Option: auto-save-list-file-prefix
40519     After Emacs reads your init file, it initializes
40520     ‘auto-save-list-file-name’ (if you have not already set it
40521     non-‘nil’) based on this prefix, adding the host name and process
40522     ID.  If you set this to ‘nil’ in your init file, then Emacs does
40523     not initialize ‘auto-save-list-file-name’.
40524
40525
40526File: elisp.info,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
40527
4052826.3 Reverting
40529==============
40530
40531If you have made extensive changes to a file and then change your mind
40532about them, you can get rid of them by reading in the previous version
40533of the file with the ‘revert-buffer’ command.  *Note Reverting a Buffer:
40534(emacs)Reverting.
40535
40536 -- Command: revert-buffer &optional ignore-auto noconfirm
40537          preserve-modes
40538     This command replaces the buffer text with the text of the visited
40539     file on disk.  This action undoes all changes since the file was
40540     visited or saved.
40541
40542     By default, if the latest auto-save file is more recent than the
40543     visited file, and the argument IGNORE-AUTO is ‘nil’,
40544     ‘revert-buffer’ asks the user whether to use that auto-save
40545     instead.  When you invoke this command interactively, IGNORE-AUTO
40546     is ‘t’ if there is no numeric prefix argument; thus, the
40547     interactive default is not to check the auto-save file.
40548
40549     Normally, ‘revert-buffer’ asks for confirmation before it changes
40550     the buffer; but if the argument NOCONFIRM is non-‘nil’,
40551     ‘revert-buffer’ does not ask for confirmation.
40552
40553     Normally, this command reinitializes the buffer’s major and minor
40554     modes using ‘normal-mode’.  But if PRESERVE-MODES is non-‘nil’, the
40555     modes remain unchanged.
40556
40557     Reverting tries to preserve marker positions in the buffer by using
40558     the replacement feature of ‘insert-file-contents’.  If the buffer
40559     contents and the file contents are identical before the revert
40560     operation, reverting preserves all the markers.  If they are not
40561     identical, reverting does change the buffer; in that case, it
40562     preserves the markers in the unchanged text (if any) at the
40563     beginning and end of the buffer.  Preserving any additional markers
40564     would be problematical.
40565
40566 -- Variable: revert-buffer-in-progress-p
40567     ‘revert-buffer’ binds this variable to a non-‘nil’ value while it
40568     is working.
40569
40570   You can customize how ‘revert-buffer’ does its work by setting the
40571variables described in the rest of this section.
40572
40573 -- User Option: revert-without-query
40574     This variable holds a list of files that should be reverted without
40575     query.  The value is a list of regular expressions.  If the visited
40576     file name matches one of these regular expressions, and the file
40577     has changed on disk but the buffer is not modified, then
40578     ‘revert-buffer’ reverts the file without asking the user for
40579     confirmation.
40580
40581   Some major modes customize ‘revert-buffer’ by making buffer-local
40582bindings for these variables:
40583
40584 -- Variable: revert-buffer-function
40585     The value of this variable is the function to use to revert this
40586     buffer.  It should be a function with two optional arguments to do
40587     the work of reverting.  The two optional arguments, IGNORE-AUTO and
40588     NOCONFIRM, are the arguments that ‘revert-buffer’ received.
40589
40590     Modes such as Dired mode, in which the text being edited does not
40591     consist of a file’s contents but can be regenerated in some other
40592     fashion, can give this variable a buffer-local value that is a
40593     special function to regenerate the contents.
40594
40595 -- Variable: revert-buffer-insert-file-contents-function
40596     The value of this variable specifies the function to use to insert
40597     the updated contents when reverting this buffer.  The function
40598     receives two arguments: first the file name to use; second, ‘t’ if
40599     the user has asked to read the auto-save file.
40600
40601     The reason for a mode to change this variable instead of
40602     ‘revert-buffer-function’ is to avoid duplicating or replacing the
40603     rest of what ‘revert-buffer’ does: asking for confirmation,
40604     clearing the undo list, deciding the proper major mode, and running
40605     the hooks listed below.
40606
40607 -- Variable: before-revert-hook
40608     This normal hook is run by the default ‘revert-buffer-function’
40609     before inserting the modified contents.  A custom
40610     ‘revert-buffer-function’ may or may not run this hook.
40611
40612 -- Variable: after-revert-hook
40613     This normal hook is run by the default ‘revert-buffer-function’
40614     after inserting the modified contents.  A custom
40615     ‘revert-buffer-function’ may or may not run this hook.
40616
40617   Emacs can revert buffers automatically.  It does that by default for
40618buffers visiting files.  The following describes how to add support for
40619auto-reverting new types of buffers.
40620
40621   First, such buffers must have a suitable ‘revert-buffer-function’ and
40622‘buffer-stale-function’ defined.
40623
40624 -- Variable: buffer-stale-function
40625     The value of this variable specifies a function to call to check
40626     whether a buffer needs reverting.  The default value only handles
40627     buffers that are visiting files, by checking their modification
40628     time.  Buffers that are not visiting files require a custom
40629     function of one optional argument NOCONFIRM.  The function should
40630     return non-‘nil’ if the buffer should be reverted.  The buffer is
40631     current when this function is called.
40632
40633     While this function is mainly intended for use in auto-reverting,
40634     it could be used for other purposes as well.  For instance, if
40635     auto-reverting is not enabled, it could be used to warn the user
40636     that the buffer needs reverting.  The idea behind the NOCONFIRM
40637     argument is that it should be ‘t’ if the buffer is going to be
40638     reverted without asking the user and ‘nil’ if the function is just
40639     going to be used to warn the user that the buffer is out of date.
40640     In particular, for use in auto-reverting, NOCONFIRM is ‘t’.  If the
40641     function is only going to be used for auto-reverting, you can
40642     ignore the NOCONFIRM argument.
40643
40644     If you just want to automatically auto-revert every
40645     ‘auto-revert-interval’ seconds (like the Buffer Menu), use:
40646
40647          (setq-local buffer-stale-function
40648               (lambda (&optional noconfirm) 'fast))
40649
40650     in the buffer’s mode function.
40651
40652     The special return value ‘fast’ tells the caller that the need for
40653     reverting was not checked, but that reverting the buffer is fast.
40654     It also tells Auto Revert not to print any revert messages, even if
40655     ‘auto-revert-verbose’ is non-‘nil’.  This is important, as getting
40656     revert messages every ‘auto-revert-interval’ seconds can be very
40657     annoying.  The information provided by this return value could also
40658     be useful if the function is consulted for purposes other than
40659     auto-reverting.
40660
40661   Once the buffer has a suitable ‘revert-buffer-function’ and
40662‘buffer-stale-function’, several problems usually remain.
40663
40664   The buffer will only auto-revert if it is marked unmodified.  Hence,
40665you will have to make sure that various functions mark the buffer
40666modified if and only if either the buffer contains information that
40667might be lost by reverting, or there is reason to believe that the user
40668might be inconvenienced by auto-reverting, because he is actively
40669working on the buffer.  The user can always override this by manually
40670adjusting the modified status of the buffer.  To support this, calling
40671the ‘revert-buffer-function’ on a buffer that is marked unmodified
40672should always keep the buffer marked unmodified.
40673
40674   It is important to assure that point does not continuously jump
40675around as a consequence of auto-reverting.  Of course, moving point
40676might be inevitable if the buffer radically changes.
40677
40678   You should make sure that the ‘revert-buffer-function’ does not print
40679messages that unnecessarily duplicate Auto Revert’s own messages,
40680displayed if ‘auto-revert-verbose’ is ‘t’, and effectively override a
40681‘nil’ value for ‘auto-revert-verbose’.  Hence, adapting a mode for
40682auto-reverting often involves getting rid of such messages.  This is
40683especially important for buffers that automatically revert every
40684‘auto-revert-interval’ seconds.
40685
40686   If the new auto-reverting is part of Emacs, you should mention it in
40687the documentation string of ‘global-auto-revert-non-file-buffers’.
40688
40689   Similarly, you should document the additions in the Emacs manual.
40690
40691
40692File: elisp.info,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
40693
4069427 Buffers
40695**********
40696
40697A “buffer” is a Lisp object containing text to be edited.  Buffers are
40698used to hold the contents of files that are being visited; there may
40699also be buffers that are not visiting files.  While several buffers may
40700exist at one time, only one buffer is designated the “current buffer” at
40701any time.  Most editing commands act on the contents of the current
40702buffer.  Each buffer, including the current buffer, may or may not be
40703displayed in any windows.
40704
40705* Menu:
40706
40707* Buffer Basics::       What is a buffer?
40708* Current Buffer::      Designating a buffer as current
40709                          so that primitives will access its contents.
40710* Buffer Names::        Accessing and changing buffer names.
40711* Buffer File Name::    The buffer file name indicates which file is visited.
40712* Buffer Modification:: A buffer is “modified” if it needs to be saved.
40713* Modification Time::   Determining whether the visited file was changed
40714                         behind Emacs’s back.
40715* Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
40716* Buffer List::         How to look at all the existing buffers.
40717* Creating Buffers::    Functions that create buffers.
40718* Killing Buffers::     Buffers exist until explicitly killed.
40719* Indirect Buffers::    An indirect buffer shares text with some other buffer.
40720* Swapping Text::       Swapping text between two buffers.
40721* Buffer Gap::          The gap in the buffer.
40722
40723
40724File: elisp.info,  Node: Buffer Basics,  Next: Current Buffer,  Up: Buffers
40725
4072627.1 Buffer Basics
40727==================
40728
40729A “buffer” is a Lisp object containing text to be edited.  Buffers are
40730used to hold the contents of files that are being visited; there may
40731also be buffers that are not visiting files.  Although several buffers
40732normally exist, only one buffer is designated the “current buffer” at
40733any time.  Most editing commands act on the contents of the current
40734buffer.  Each buffer, including the current buffer, may or may not be
40735displayed in any windows.
40736
40737   Buffers in Emacs editing are objects that have distinct names and
40738hold text that can be edited.  Buffers appear to Lisp programs as a
40739special data type.  You can think of the contents of a buffer as a
40740string that you can extend; insertions and deletions may occur in any
40741part of the buffer.  *Note Text::.
40742
40743   A Lisp buffer object contains numerous pieces of information.  Some
40744of this information is directly accessible to the programmer through
40745variables, while other information is accessible only through
40746special-purpose functions.  For example, the visited file name is
40747directly accessible through a variable, while the value of point is
40748accessible only through a primitive function.
40749
40750   Buffer-specific information that is directly accessible is stored in
40751“buffer-local” variable bindings, which are variable values that are
40752effective only in a particular buffer.  This feature allows each buffer
40753to override the values of certain variables.  Most major modes override
40754variables such as ‘fill-column’ or ‘comment-column’ in this way.  For
40755more information about buffer-local variables and functions related to
40756them, see *note Buffer-Local Variables::.
40757
40758   For functions and variables related to visiting files in buffers, see
40759*note Visiting Files:: and *note Saving Buffers::.  For functions and
40760variables related to the display of buffers in windows, see *note
40761Buffers and Windows::.
40762
40763 -- Function: bufferp object
40764     This function returns ‘t’ if OBJECT is a buffer, ‘nil’ otherwise.
40765
40766
40767File: elisp.info,  Node: Current Buffer,  Next: Buffer Names,  Prev: Buffer Basics,  Up: Buffers
40768
4076927.2 The Current Buffer
40770=======================
40771
40772There are, in general, many buffers in an Emacs session.  At any time,
40773one of them is designated the “current buffer”—the buffer in which most
40774editing takes place.  Most of the primitives for examining or changing
40775text operate implicitly on the current buffer (*note Text::).
40776
40777   Normally, the buffer displayed in the selected window is the current
40778buffer, but this is not always so: a Lisp program can temporarily
40779designate any buffer as current in order to operate on its contents,
40780without changing what is displayed on the screen.  The most basic
40781function for designating a current buffer is ‘set-buffer’.
40782
40783 -- Function: current-buffer
40784     This function returns the current buffer.
40785
40786          (current-buffer)
40787               ⇒ #<buffer buffers.texi>
40788
40789 -- Function: set-buffer buffer-or-name
40790     This function makes BUFFER-OR-NAME the current buffer.
40791     BUFFER-OR-NAME must be an existing buffer or the name of an
40792     existing buffer.  The return value is the buffer made current.
40793
40794     This function does not display the buffer in any window, so the
40795     user cannot necessarily see the buffer.  But Lisp programs will now
40796     operate on it.
40797
40798   When an editing command returns to the editor command loop, Emacs
40799automatically calls ‘set-buffer’ on the buffer shown in the selected
40800window.  This is to prevent confusion: it ensures that the buffer that
40801the cursor is in, when Emacs reads a command, is the buffer to which
40802that command applies (*note Command Loop::).  Thus, you should not use
40803‘set-buffer’ to switch visibly to a different buffer; for that, use the
40804functions described in *note Switching Buffers::.
40805
40806   When writing a Lisp function, do _not_ rely on this behavior of the
40807command loop to restore the current buffer after an operation.  Editing
40808commands can also be called as Lisp functions by other programs, not
40809just from the command loop; it is convenient for the caller if the
40810subroutine does not change which buffer is current (unless, of course,
40811that is the subroutine’s purpose).
40812
40813   To operate temporarily on another buffer, put the ‘set-buffer’ within
40814a ‘save-current-buffer’ form.  Here, as an example, is a simplified
40815version of the command ‘append-to-buffer’:
40816
40817     (defun append-to-buffer (buffer start end)
40818       "Append the text of the region to BUFFER."
40819       (interactive "BAppend to buffer: \nr")
40820       (let ((oldbuf (current-buffer)))
40821         (save-current-buffer
40822           (set-buffer (get-buffer-create buffer))
40823           (insert-buffer-substring oldbuf start end))))
40824
40825Here, we bind a local variable to record the current buffer, and then
40826‘save-current-buffer’ arranges to make it current again later.  Next,
40827‘set-buffer’ makes the specified buffer current, and
40828‘insert-buffer-substring’ copies the string from the original buffer to
40829the specified (and now current) buffer.
40830
40831   Alternatively, we can use the ‘with-current-buffer’ macro:
40832
40833     (defun append-to-buffer (buffer start end)
40834       "Append the text of the region to BUFFER."
40835       (interactive "BAppend to buffer: \nr")
40836       (let ((oldbuf (current-buffer)))
40837         (with-current-buffer (get-buffer-create buffer)
40838           (insert-buffer-substring oldbuf start end))))
40839
40840   In either case, if the buffer appended to happens to be displayed in
40841some window, the next redisplay will show how its text has changed.  If
40842it is not displayed in any window, you will not see the change
40843immediately on the screen.  The command causes the buffer to become
40844current temporarily, but does not cause it to be displayed.
40845
40846   If you make local bindings (with ‘let’ or function arguments) for a
40847variable that may also have buffer-local bindings, make sure that the
40848same buffer is current at the beginning and at the end of the local
40849binding’s scope.  Otherwise you might bind it in one buffer and unbind
40850it in another!
40851
40852   Do not rely on using ‘set-buffer’ to change the current buffer back,
40853because that won’t do the job if a quit happens while the wrong buffer
40854is current.  For instance, in the previous example, it would have been
40855wrong to do this:
40856
40857       (let ((oldbuf (current-buffer)))
40858         (set-buffer (get-buffer-create buffer))
40859         (insert-buffer-substring oldbuf start end)
40860         (set-buffer oldbuf))
40861
40862Using ‘save-current-buffer’ or ‘with-current-buffer’, as we did,
40863correctly handles quitting, errors, and ‘throw’, as well as ordinary
40864evaluation.
40865
40866 -- Special Form: save-current-buffer body...
40867     The ‘save-current-buffer’ special form saves the identity of the
40868     current buffer, evaluates the BODY forms, and finally restores that
40869     buffer as current.  The return value is the value of the last form
40870     in BODY.  The current buffer is restored even in case of an
40871     abnormal exit via ‘throw’ or error (*note Nonlocal Exits::).
40872
40873     If the buffer that used to be current has been killed by the time
40874     of exit from ‘save-current-buffer’, then it is not made current
40875     again, of course.  Instead, whichever buffer was current just
40876     before exit remains current.
40877
40878 -- Macro: with-current-buffer buffer-or-name body...
40879     The ‘with-current-buffer’ macro saves the identity of the current
40880     buffer, makes BUFFER-OR-NAME current, evaluates the BODY forms, and
40881     finally restores the current buffer.  BUFFER-OR-NAME must specify
40882     an existing buffer or the name of an existing buffer.
40883
40884     The return value is the value of the last form in BODY.  The
40885     current buffer is restored even in case of an abnormal exit via
40886     ‘throw’ or error (*note Nonlocal Exits::).
40887
40888 -- Macro: with-temp-buffer body...
40889     The ‘with-temp-buffer’ macro evaluates the BODY forms with a
40890     temporary buffer as the current buffer.  It saves the identity of
40891     the current buffer, creates a temporary buffer and makes it
40892     current, evaluates the BODY forms, and finally restores the
40893     previous current buffer while killing the temporary buffer.  By
40894     default, undo information (*note Undo::) is not recorded in the
40895     buffer created by this macro (but BODY can enable that, if needed).
40896
40897     The return value is the value of the last form in BODY.  You can
40898     return the contents of the temporary buffer by using
40899     ‘(buffer-string)’ as the last form.
40900
40901     The current buffer is restored even in case of an abnormal exit via
40902     ‘throw’ or error (*note Nonlocal Exits::).
40903
40904     See also ‘with-temp-file’ in *note Writing to Files: Definition of
40905     with-temp-file.
40906
40907
40908File: elisp.info,  Node: Buffer Names,  Next: Buffer File Name,  Prev: Current Buffer,  Up: Buffers
40909
4091027.3 Buffer Names
40911=================
40912
40913Each buffer has a unique name, which is a string.  Many of the functions
40914that work on buffers accept either a buffer or a buffer name as an
40915argument.  Any argument called BUFFER-OR-NAME is of this sort, and an
40916error is signaled if it is neither a string nor a buffer.  Any argument
40917called BUFFER must be an actual buffer object, not a name.
40918
40919   Buffers that are ephemeral and generally uninteresting to the user
40920have names starting with a space, so that the ‘list-buffers’ and
40921‘buffer-menu’ commands don’t mention them (but if such a buffer visits a
40922file, it *is* mentioned).  A name starting with space also initially
40923disables recording undo information; see *note Undo::.
40924
40925 -- Function: buffer-name &optional buffer
40926     This function returns the name of BUFFER as a string.  BUFFER
40927     defaults to the current buffer.
40928
40929     If ‘buffer-name’ returns ‘nil’, it means that BUFFER has been
40930     killed.  *Note Killing Buffers::.
40931
40932          (buffer-name)
40933               ⇒ "buffers.texi"
40934
40935          (setq foo (get-buffer "temp"))
40936               ⇒ #<buffer temp>
40937          (kill-buffer foo)
40938               ⇒ nil
40939          (buffer-name foo)
40940               ⇒ nil
40941          foo
40942               ⇒ #<killed buffer>
40943
40944 -- Command: rename-buffer newname &optional unique
40945     This function renames the current buffer to NEWNAME.  An error is
40946     signaled if NEWNAME is not a string.
40947
40948     Ordinarily, ‘rename-buffer’ signals an error if NEWNAME is already
40949     in use.  However, if UNIQUE is non-‘nil’, it modifies NEWNAME to
40950     make a name that is not in use.  Interactively, you can make UNIQUE
40951     non-‘nil’ with a numeric prefix argument.  (This is how the command
40952     ‘rename-uniquely’ is implemented.)
40953
40954     This function returns the name actually given to the buffer.
40955
40956 -- Function: get-buffer buffer-or-name
40957     This function returns the buffer specified by BUFFER-OR-NAME.  If
40958     BUFFER-OR-NAME is a string and there is no buffer with that name,
40959     the value is ‘nil’.  If BUFFER-OR-NAME is a buffer, it is returned
40960     as given; that is not very useful, so the argument is usually a
40961     name.  For example:
40962
40963          (setq b (get-buffer "lewis"))
40964               ⇒ #<buffer lewis>
40965          (get-buffer b)
40966               ⇒ #<buffer lewis>
40967          (get-buffer "Frazzle-nots")
40968               ⇒ nil
40969
40970     See also the function ‘get-buffer-create’ in *note Creating
40971     Buffers::.
40972
40973 -- Function: generate-new-buffer-name starting-name &optional ignore
40974     This function returns a name that would be unique for a new
40975     buffer—but does not create the buffer.  It starts with
40976     STARTING-NAME, and produces a name not currently in use for any
40977     buffer by appending a number inside of ‘<...>’.  It starts at 2 and
40978     keeps incrementing the number until it is not the name of an
40979     existing buffer.
40980
40981     If the optional second argument IGNORE is non-‘nil’, it should be a
40982     string, a potential buffer name.  It means to consider that
40983     potential buffer acceptable, if it is tried, even it is the name of
40984     an existing buffer (which would normally be rejected).  Thus, if
40985     buffers named ‘foo’, ‘foo<2>’, ‘foo<3>’ and ‘foo<4>’ exist,
40986
40987          (generate-new-buffer-name "foo")
40988               ⇒ "foo<5>"
40989          (generate-new-buffer-name "foo" "foo<3>")
40990               ⇒ "foo<3>"
40991          (generate-new-buffer-name "foo" "foo<6>")
40992               ⇒ "foo<5>"
40993
40994     See the related function ‘generate-new-buffer’ in *note Creating
40995     Buffers::.
40996
40997
40998File: elisp.info,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
40999
4100027.4 Buffer File Name
41001=====================
41002
41003The “buffer file name” is the name of the file that is visited in that
41004buffer.  When a buffer is not visiting a file, its buffer file name is
41005‘nil’.  Most of the time, the buffer name is the same as the
41006nondirectory part of the buffer file name, but the buffer file name and
41007the buffer name are distinct and can be set independently.  *Note
41008Visiting Files::.
41009
41010 -- Function: buffer-file-name &optional buffer
41011     This function returns the absolute file name of the file that
41012     BUFFER is visiting.  If BUFFER is not visiting any file,
41013     ‘buffer-file-name’ returns ‘nil’.  If BUFFER is not supplied, it
41014     defaults to the current buffer.
41015
41016          (buffer-file-name (other-buffer))
41017               ⇒ "/usr/user/lewis/manual/files.texi"
41018
41019 -- Variable: buffer-file-name
41020     This buffer-local variable contains the name of the file being
41021     visited in the current buffer, or ‘nil’ if it is not visiting a
41022     file.  It is a permanent local variable, unaffected by
41023     ‘kill-all-local-variables’.
41024
41025          buffer-file-name
41026               ⇒ "/usr/user/lewis/manual/buffers.texi"
41027
41028     It is risky to change this variable’s value without doing various
41029     other things.  Normally it is better to use ‘set-visited-file-name’
41030     (see below); some of the things done there, such as changing the
41031     buffer name, are not strictly necessary, but others are essential
41032     to avoid confusing Emacs.
41033
41034 -- Variable: buffer-file-truename
41035     This buffer-local variable holds the abbreviated truename of the
41036     file visited in the current buffer, or ‘nil’ if no file is visited.
41037     It is a permanent local, unaffected by ‘kill-all-local-variables’.
41038     *Note Truenames::, and *note abbreviate-file-name::.
41039
41040 -- Variable: buffer-file-number
41041     This buffer-local variable holds the file number and directory
41042     device number of the file visited in the current buffer, or ‘nil’
41043     if no file or a nonexistent file is visited.  It is a permanent
41044     local, unaffected by ‘kill-all-local-variables’.
41045
41046     The value is normally a list of the form ‘(FILENUM DEVNUM)’.  This
41047     pair of numbers uniquely identifies the file among all files
41048     accessible on the system.  See the function ‘file-attributes’, in
41049     *note File Attributes::, for more information about them.
41050
41051     If ‘buffer-file-name’ is the name of a symbolic link, then both
41052     numbers refer to the recursive target.
41053
41054 -- Function: get-file-buffer filename
41055     This function returns the buffer visiting file FILENAME.  If there
41056     is no such buffer, it returns ‘nil’.  The argument FILENAME, which
41057     must be a string, is expanded (*note File Name Expansion::), then
41058     compared against the visited file names of all live buffers.  Note
41059     that the buffer’s ‘buffer-file-name’ must match the expansion of
41060     FILENAME exactly.  This function will not recognize other names for
41061     the same file.
41062
41063          (get-file-buffer "buffers.texi")
41064              ⇒ #<buffer buffers.texi>
41065
41066     In unusual circumstances, there can be more than one buffer
41067     visiting the same file name.  In such cases, this function returns
41068     the first such buffer in the buffer list.
41069
41070 -- Function: find-buffer-visiting filename &optional predicate
41071     This is like ‘get-file-buffer’, except that it can return any
41072     buffer visiting the file _possibly under a different name_.  That
41073     is, the buffer’s ‘buffer-file-name’ does not need to match the
41074     expansion of FILENAME exactly, it only needs to refer to the same
41075     file.  If PREDICATE is non-‘nil’, it should be a function of one
41076     argument, a buffer visiting FILENAME.  The buffer is only
41077     considered a suitable return value if PREDICATE returns non-‘nil’.
41078     If it can not find a suitable buffer to return,
41079     ‘find-buffer-visiting’ returns ‘nil’.
41080
41081 -- Command: set-visited-file-name filename &optional no-query
41082          along-with-file
41083     If FILENAME is a non-empty string, this function changes the name
41084     of the file visited in the current buffer to FILENAME.  (If the
41085     buffer had no visited file, this gives it one.)  The _next time_
41086     the buffer is saved it will go in the newly-specified file.
41087
41088     This command marks the buffer as modified, since it does not (as
41089     far as Emacs knows) match the contents of FILENAME, even if it
41090     matched the former visited file.  It also renames the buffer to
41091     correspond to the new file name, unless the new name is already in
41092     use.
41093
41094     If FILENAME is ‘nil’ or the empty string, that stands for “no
41095     visited file”.  In this case, ‘set-visited-file-name’ marks the
41096     buffer as having no visited file, without changing the buffer’s
41097     modified flag.
41098
41099     Normally, this function asks the user for confirmation if there
41100     already is a buffer visiting FILENAME.  If NO-QUERY is non-‘nil’,
41101     that prevents asking this question.  If there already is a buffer
41102     visiting FILENAME, and the user confirms or NO-QUERY is non-‘nil’,
41103     this function makes the new buffer name unique by appending a
41104     number inside of ‘<...>’ to FILENAME.
41105
41106     If ALONG-WITH-FILE is non-‘nil’, that means to assume that the
41107     former visited file has been renamed to FILENAME.  In this case,
41108     the command does not change the buffer’s modified flag, nor the
41109     buffer’s recorded last file modification time as reported by
41110     ‘visited-file-modtime’ (*note Modification Time::).  If
41111     ALONG-WITH-FILE is ‘nil’, this function clears the recorded last
41112     file modification time, after which ‘visited-file-modtime’ returns
41113     zero.
41114
41115     When the function ‘set-visited-file-name’ is called interactively,
41116     it prompts for FILENAME in the minibuffer.
41117
41118 -- Variable: list-buffers-directory
41119     This buffer-local variable specifies a string to display in a
41120     buffer listing where the visited file name would go, for buffers
41121     that don’t have a visited file name.  Dired buffers use this
41122     variable.
41123
41124
41125File: elisp.info,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
41126
4112727.5 Buffer Modification
41128========================
41129
41130Emacs keeps a flag called the “modified flag” for each buffer, to record
41131whether you have changed the text of the buffer.  This flag is set to
41132‘t’ whenever you alter the contents of the buffer, and cleared to ‘nil’
41133when you save it.  Thus, the flag shows whether there are unsaved
41134changes.  The flag value is normally shown in the mode line (*note Mode
41135Line Variables::), and controls saving (*note Saving Buffers::) and
41136auto-saving (*note Auto-Saving::).
41137
41138   Some Lisp programs set the flag explicitly.  For example, the
41139function ‘set-visited-file-name’ sets the flag to ‘t’, because the text
41140does not match the newly-visited file, even if it is unchanged from the
41141file formerly visited.
41142
41143   The functions that modify the contents of buffers are described in
41144*note Text::.
41145
41146 -- Function: buffer-modified-p &optional buffer
41147     This function returns ‘t’ if the buffer BUFFER has been modified
41148     since it was last read in from a file or saved, or ‘nil’ otherwise.
41149     If BUFFER is not supplied, the current buffer is tested.
41150
41151 -- Function: set-buffer-modified-p flag
41152     This function marks the current buffer as modified if FLAG is
41153     non-‘nil’, or as unmodified if the flag is ‘nil’.
41154
41155     Another effect of calling this function is to cause unconditional
41156     redisplay of the mode line for the current buffer.  In fact, the
41157     function ‘force-mode-line-update’ works by doing this:
41158
41159          (set-buffer-modified-p (buffer-modified-p))
41160
41161 -- Function: restore-buffer-modified-p flag
41162     Like ‘set-buffer-modified-p’, but does not force redisplay of mode
41163     lines.
41164
41165 -- Command: not-modified &optional arg
41166     This command marks the current buffer as unmodified, and not
41167     needing to be saved.  If ARG is non-‘nil’, it marks the buffer as
41168     modified, so that it will be saved at the next suitable occasion.
41169     Interactively, ARG is the prefix argument.
41170
41171     Don’t use this function in programs, since it prints a message in
41172     the echo area; use ‘set-buffer-modified-p’ (above) instead.
41173
41174 -- Function: buffer-modified-tick &optional buffer
41175     This function returns BUFFER’s modification-count.  This is a
41176     counter that increments every time the buffer is modified.  If
41177     BUFFER is ‘nil’ (or omitted), the current buffer is used.
41178
41179 -- Function: buffer-chars-modified-tick &optional buffer
41180     This function returns BUFFER’s character-change modification-count.
41181     Changes to text properties leave this counter unchanged; however,
41182     each time text is inserted or removed from the buffer, the counter
41183     is reset to the value that would be returned by
41184     ‘buffer-modified-tick’.  By comparing the values returned by two
41185     ‘buffer-chars-modified-tick’ calls, you can tell whether a
41186     character change occurred in that buffer in between the calls.  If
41187     BUFFER is ‘nil’ (or omitted), the current buffer is used.
41188
41189   Sometimes there’s a need for modifying buffer in a way that doesn’t
41190really change its text, like if only its text properties are changed.
41191If your program needs to modify a buffer without triggering any hooks
41192and features that react to buffer modifications, use the
41193‘with-silent-modifications’ macro.
41194
41195 -- Macro: with-silent-modifications body...
41196     Execute BODY pretending it does not modify the buffer.  This
41197     includes checking whether the buffer’s file is locked (*note File
41198     Locks::), running buffer modification hooks (*note Change Hooks::),
41199     etc.  Note that if BODY actually modifies the buffer text (as
41200     opposed to its text properties), its undo data may become
41201     corrupted.
41202
41203
41204File: elisp.info,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
41205
4120627.6 Buffer Modification Time
41207=============================
41208
41209Suppose that you visit a file and make changes in its buffer, and
41210meanwhile the file itself is changed on disk.  At this point, saving the
41211buffer would overwrite the changes in the file.  Occasionally this may
41212be what you want, but usually it would lose valuable information.  Emacs
41213therefore checks the file’s modification time using the functions
41214described below before saving the file.  (*Note File Attributes::, for
41215how to examine a file’s modification time.)
41216
41217 -- Function: verify-visited-file-modtime &optional buffer
41218     This function compares what BUFFER (by default, the current-buffer)
41219     has recorded for the modification time of its visited file against
41220     the actual modification time of the file as recorded by the
41221     operating system.  The two should be the same unless some other
41222     process has written the file since Emacs visited or saved it.
41223
41224     The function returns ‘t’ if the last actual modification time and
41225     Emacs’s recorded modification time are the same, ‘nil’ otherwise.
41226     It also returns ‘t’ if the buffer has no recorded last modification
41227     time, that is if ‘visited-file-modtime’ would return zero.
41228
41229     It always returns ‘t’ for buffers that are not visiting a file,
41230     even if ‘visited-file-modtime’ returns a non-zero value.  For
41231     instance, it always returns ‘t’ for dired buffers.  It returns ‘t’
41232     for buffers that are visiting a file that does not exist and never
41233     existed, but ‘nil’ for file-visiting buffers whose file has been
41234     deleted.
41235
41236 -- Function: clear-visited-file-modtime
41237     This function clears out the record of the last modification time
41238     of the file being visited by the current buffer.  As a result, the
41239     next attempt to save this buffer will not complain of a discrepancy
41240     in file modification times.
41241
41242     This function is called in ‘set-visited-file-name’ and other
41243     exceptional places where the usual test to avoid overwriting a
41244     changed file should not be done.
41245
41246 -- Function: visited-file-modtime
41247     This function returns the current buffer’s recorded last file
41248     modification time, as a Lisp timestamp (*note Time of Day::).
41249
41250     If the buffer has no recorded last modification time, this function
41251     returns zero.  This case occurs, for instance, if the buffer is not
41252     visiting a file or if the time has been explicitly cleared by
41253     ‘clear-visited-file-modtime’.  Note, however, that
41254     ‘visited-file-modtime’ returns a timestamp for some non-file
41255     buffers too.  For instance, in a Dired buffer listing a directory,
41256     it returns the last modification time of that directory, as
41257     recorded by Dired.
41258
41259     If the buffer is visiting a file that doesn’t exist, this function
41260     returns −1.
41261
41262 -- Function: set-visited-file-modtime &optional time
41263     This function updates the buffer’s record of the last modification
41264     time of the visited file, to the value specified by TIME if TIME is
41265     not ‘nil’, and otherwise to the last modification time of the
41266     visited file.
41267
41268     If TIME is neither ‘nil’ nor an integer flag returned by
41269     ‘visited-file-modtime’, it should be a Lisp time value (*note Time
41270     of Day::).
41271
41272     This function is useful if the buffer was not read from the file
41273     normally, or if the file itself has been changed for some known
41274     benign reason.
41275
41276 -- Function: ask-user-about-supersession-threat filename
41277     This function is used to ask a user how to proceed after an attempt
41278     to modify a buffer visiting file FILENAME when the file is newer
41279     than the buffer text.  Emacs detects this because the modification
41280     time of the file on disk is newer than the last save-time and its
41281     contents have changed.  This means some other program has probably
41282     altered the file.
41283
41284     Depending on the user’s answer, the function may return normally,
41285     in which case the modification of the buffer proceeds, or it may
41286     signal a ‘file-supersession’ error with data ‘(FILENAME)’, in which
41287     case the proposed buffer modification is not allowed.
41288
41289     This function is called automatically by Emacs on the proper
41290     occasions.  It exists so you can customize Emacs by redefining it.
41291     See the file ‘userlock.el’ for the standard definition.
41292
41293     See also the file locking mechanism in *note File Locks::.
41294
41295
41296File: elisp.info,  Node: Read Only Buffers,  Next: Buffer List,  Prev: Modification Time,  Up: Buffers
41297
4129827.7 Read-Only Buffers
41299======================
41300
41301If a buffer is “read-only”, then you cannot change its contents,
41302although you may change your view of the contents by scrolling and
41303narrowing.
41304
41305   Read-only buffers are used in two kinds of situations:
41306
41307   • A buffer visiting a write-protected file is normally read-only.
41308
41309     Here, the purpose is to inform the user that editing the buffer
41310     with the aim of saving it in the file may be futile or undesirable.
41311     The user who wants to change the buffer text despite this can do so
41312     after clearing the read-only flag with ‘C-x C-q’.
41313
41314   • Modes such as Dired and Rmail make buffers read-only when altering
41315     the contents with the usual editing commands would probably be a
41316     mistake.
41317
41318     The special commands of these modes bind ‘buffer-read-only’ to
41319     ‘nil’ (with ‘let’) or bind ‘inhibit-read-only’ to ‘t’ around the
41320     places where they themselves change the text.
41321
41322 -- Variable: buffer-read-only
41323     This buffer-local variable specifies whether the buffer is
41324     read-only.  The buffer is read-only if this variable is non-‘nil’.
41325     However, characters that have the ‘inhibit-read-only’ text property
41326     can still be modified.  *Note inhibit-read-only: Special
41327     Properties.
41328
41329 -- Variable: inhibit-read-only
41330     If this variable is non-‘nil’, then read-only buffers and,
41331     depending on the actual value, some or all read-only characters may
41332     be modified.  Read-only characters in a buffer are those that have
41333     a non-‘nil’ ‘read-only’ text property.  *Note Special Properties::,
41334     for more information about text properties.
41335
41336     If ‘inhibit-read-only’ is ‘t’, all ‘read-only’ character properties
41337     have no effect.  If ‘inhibit-read-only’ is a list, then ‘read-only’
41338     character properties have no effect if they are members of the list
41339     (comparison is done with ‘eq’).
41340
41341 -- Command: read-only-mode &optional arg
41342     This is the mode command for Read Only minor mode, a buffer-local
41343     minor mode.  When the mode is enabled, ‘buffer-read-only’ is
41344     non-‘nil’ in the buffer; when disabled, ‘buffer-read-only’ is ‘nil’
41345     in the buffer.  The calling convention is the same as for other
41346     minor mode commands (*note Minor Mode Conventions::).
41347
41348     This minor mode mainly serves as a wrapper for ‘buffer-read-only’;
41349     unlike most minor modes, there is no separate ‘read-only-mode’
41350     variable.  Even when Read Only mode is disabled, characters with
41351     non-‘nil’ ‘read-only’ text properties remain read-only.  To
41352     temporarily ignore all read-only states, bind ‘inhibit-read-only’,
41353     as described above.
41354
41355     When enabling Read Only mode, this mode command also enables View
41356     mode if the option ‘view-read-only’ is non-‘nil’.  *Note
41357     Miscellaneous Buffer Operations: (emacs)Misc Buffer.  When
41358     disabling Read Only mode, it disables View mode if View mode was
41359     enabled.
41360
41361 -- Function: barf-if-buffer-read-only &optional position
41362     This function signals a ‘buffer-read-only’ error if the current
41363     buffer is read-only.  If the text at POSITION (which defaults to
41364     point) has the ‘inhibit-read-only’ text property set, the error
41365     will not be raised.
41366
41367     *Note Using Interactive::, for another way to signal an error if
41368     the current buffer is read-only.
41369
41370
41371File: elisp.info,  Node: Buffer List,  Next: Creating Buffers,  Prev: Read Only Buffers,  Up: Buffers
41372
4137327.8 The Buffer List
41374====================
41375
41376The “buffer list” is a list of all live buffers.  The order of the
41377buffers in this list is based primarily on how recently each buffer has
41378been displayed in a window.  Several functions, notably ‘other-buffer’,
41379use this ordering.  A buffer list displayed for the user also follows
41380this order.
41381
41382   Creating a buffer adds it to the end of the buffer list, and killing
41383a buffer removes it from that list.  A buffer moves to the front of this
41384list whenever it is chosen for display in a window (*note Switching
41385Buffers::) or a window displaying it is selected (*note Selecting
41386Windows::).  A buffer moves to the end of the list when it is buried
41387(see ‘bury-buffer’, below).  There are no functions available to the
41388Lisp programmer which directly manipulate the buffer list.
41389
41390   In addition to the fundamental buffer list just described, Emacs
41391maintains a local buffer list for each frame, in which the buffers that
41392have been displayed (or had their windows selected) in that frame come
41393first.  (This order is recorded in the frame’s ‘buffer-list’ frame
41394parameter; see *note Buffer Parameters::.)  Buffers never displayed in
41395that frame come afterward, ordered according to the fundamental buffer
41396list.
41397
41398 -- Function: buffer-list &optional frame
41399     This function returns the buffer list, including all buffers, even
41400     those whose names begin with a space.  The elements are actual
41401     buffers, not their names.
41402
41403     If FRAME is a frame, this returns FRAME’s local buffer list.  If
41404     FRAME is ‘nil’ or omitted, the fundamental buffer list is used: the
41405     buffers appear in order of most recent display or selection,
41406     regardless of which frames they were displayed on.
41407
41408          (buffer-list)
41409               ⇒ (#<buffer buffers.texi>
41410                   #<buffer  *Minibuf-1*> #<buffer buffer.c>
41411                   #<buffer *Help*> #<buffer TAGS>)
41412
41413          ;; Note that the name of the minibuffer
41414          ;;   begins with a space!
41415          (mapcar #'buffer-name (buffer-list))
41416              ⇒ ("buffers.texi" " *Minibuf-1*"
41417                  "buffer.c" "*Help*" "TAGS")
41418
41419   The list returned by ‘buffer-list’ is constructed specifically; it is
41420not an internal Emacs data structure, and modifying it has no effect on
41421the order of buffers.  If you want to change the order of buffers in the
41422fundamental buffer list, here is an easy way:
41423
41424     (defun reorder-buffer-list (new-list)
41425       (while new-list
41426         (bury-buffer (car new-list))
41427         (setq new-list (cdr new-list))))
41428
41429   With this method, you can specify any order for the list, but there
41430is no danger of losing a buffer or adding something that is not a valid
41431live buffer.
41432
41433   To change the order or value of a specific frame’s buffer list, set
41434that frame’s ‘buffer-list’ parameter with ‘modify-frame-parameters’
41435(*note Parameter Access::).
41436
41437 -- Function: other-buffer &optional buffer visible-ok frame
41438     This function returns the first buffer in the buffer list other
41439     than BUFFER.  Usually, this is the buffer appearing in the most
41440     recently selected window (in frame FRAME or else the selected
41441     frame, *note Input Focus::), aside from BUFFER.  Buffers whose
41442     names start with a space are not considered at all.
41443
41444     If BUFFER is not supplied (or if it is not a live buffer), then
41445     ‘other-buffer’ returns the first buffer in the selected frame’s
41446     local buffer list.  (If FRAME is non-‘nil’, it returns the first
41447     buffer in FRAME’s local buffer list instead.)
41448
41449     If FRAME has a non-‘nil’ ‘buffer-predicate’ parameter, then
41450     ‘other-buffer’ uses that predicate to decide which buffers to
41451     consider.  It calls the predicate once for each buffer, and if the
41452     value is ‘nil’, that buffer is ignored.  *Note Buffer Parameters::.
41453
41454     If VISIBLE-OK is ‘nil’, ‘other-buffer’ avoids returning a buffer
41455     visible in any window on any visible frame, except as a last
41456     resort.  If VISIBLE-OK is non-‘nil’, then it does not matter
41457     whether a buffer is displayed somewhere or not.
41458
41459     If no suitable buffer exists, the buffer ‘*scratch*’ is returned
41460     (and created, if necessary).
41461
41462 -- Function: last-buffer &optional buffer visible-ok frame
41463     This function returns the last buffer in FRAME’s buffer list other
41464     than BUFFER.  If FRAME is omitted or ‘nil’, it uses the selected
41465     frame’s buffer list.
41466
41467     The argument VISIBLE-OK is handled as with ‘other-buffer’, see
41468     above.  If no suitable buffer can be found, the buffer ‘*scratch*’
41469     is returned.
41470
41471 -- Command: bury-buffer &optional buffer-or-name
41472     This command puts BUFFER-OR-NAME at the end of the buffer list,
41473     without changing the order of any of the other buffers on the list.
41474     This buffer therefore becomes the least desirable candidate for
41475     ‘other-buffer’ to return.  The argument can be either a buffer
41476     itself or the name of one.
41477
41478     This function operates on each frame’s ‘buffer-list’ parameter as
41479     well as the fundamental buffer list; therefore, the buffer that you
41480     bury will come last in the value of ‘(buffer-list FRAME)’ and in
41481     the value of ‘(buffer-list)’.  In addition, it also puts the buffer
41482     at the end of the list of buffers of the selected window (*note
41483     Window History::) provided it is shown in that window.
41484
41485     If BUFFER-OR-NAME is ‘nil’ or omitted, this means to bury the
41486     current buffer.  In addition, if the current buffer is displayed in
41487     the selected window, this makes sure that the window is either
41488     deleted or another buffer is shown in it.  More precisely, if the
41489     selected window is dedicated (*note Dedicated Windows::) and there
41490     are other windows on its frame, the window is deleted.  If it is
41491     the only window on its frame and that frame is not the only frame
41492     on its terminal, the frame is dismissed by calling the function
41493     specified by ‘frame-auto-hide-function’ (*note Quitting Windows::).
41494     Otherwise, it calls ‘switch-to-prev-buffer’ (*note Window
41495     History::) to show another buffer in that window.  If
41496     BUFFER-OR-NAME is displayed in some other window, it remains
41497     displayed there.
41498
41499     To replace a buffer in all the windows that display it, use
41500     ‘replace-buffer-in-windows’, *Note Buffers and Windows::.
41501
41502 -- Command: unbury-buffer
41503     This command switches to the last buffer in the local buffer list
41504     of the selected frame.  More precisely, it calls the function
41505     ‘switch-to-buffer’ (*note Switching Buffers::), to display the
41506     buffer returned by ‘last-buffer’ (see above), in the selected
41507     window.
41508
41509 -- Variable: buffer-list-update-hook
41510     This is a normal hook run whenever the buffer list changes.
41511     Functions (implicitly) running this hook are ‘get-buffer-create’
41512     (*note Creating Buffers::), ‘rename-buffer’ (*note Buffer Names::),
41513     ‘kill-buffer’ (*note Killing Buffers::), ‘bury-buffer’ (see above)
41514     and ‘select-window’ (*note Selecting Windows::).
41515
41516     Functions run by this hook should avoid calling ‘select-window’
41517     with a nil NORECORD argument or ‘with-temp-buffer’ since either may
41518     lead to infinite recursion.
41519
41520
41521File: elisp.info,  Node: Creating Buffers,  Next: Killing Buffers,  Prev: Buffer List,  Up: Buffers
41522
4152327.9 Creating Buffers
41524=====================
41525
41526This section describes the two primitives for creating buffers.
41527‘get-buffer-create’ creates a buffer if it finds no existing buffer with
41528the specified name; ‘generate-new-buffer’ always creates a new buffer
41529and gives it a unique name.
41530
41531   Other functions you can use to create buffers include
41532‘with-output-to-temp-buffer’ (*note Temporary Displays::) and
41533‘create-file-buffer’ (*note Visiting Files::).  Starting a subprocess
41534can also create a buffer (*note Processes::).
41535
41536 -- Function: get-buffer-create buffer-or-name
41537     This function returns a buffer named BUFFER-OR-NAME.  The buffer
41538     returned does not become the current buffer—this function does not
41539     change which buffer is current.
41540
41541     BUFFER-OR-NAME must be either a string or an existing buffer.  If
41542     it is a string and a live buffer with that name already exists,
41543     ‘get-buffer-create’ returns that buffer.  If no such buffer exists,
41544     it creates a new buffer.  If BUFFER-OR-NAME is a buffer instead of
41545     a string, it is returned as given, even if it is dead.
41546
41547          (get-buffer-create "foo")
41548               ⇒ #<buffer foo>
41549
41550     The major mode for a newly created buffer is set to Fundamental
41551     mode.  (The default value of the variable ‘major-mode’ is handled
41552     at a higher level; see *note Auto Major Mode::.)  If the name
41553     begins with a space, the buffer initially disables undo information
41554     recording (*note Undo::).
41555
41556 -- Function: generate-new-buffer name
41557     This function returns a newly created, empty buffer, but does not
41558     make it current.  The name of the buffer is generated by passing
41559     NAME to the function ‘generate-new-buffer-name’ (*note Buffer
41560     Names::).  Thus, if there is no buffer named NAME, then that is the
41561     name of the new buffer; if that name is in use, a suffix of the
41562     form ‘<N>’, where N is an integer, is appended to NAME.
41563
41564     An error is signaled if NAME is not a string.
41565
41566          (generate-new-buffer "bar")
41567               ⇒ #<buffer bar>
41568          (generate-new-buffer "bar")
41569               ⇒ #<buffer bar<2>>
41570          (generate-new-buffer "bar")
41571               ⇒ #<buffer bar<3>>
41572
41573     The major mode for the new buffer is set to Fundamental mode.  The
41574     default value of the variable ‘major-mode’ is handled at a higher
41575     level.  *Note Auto Major Mode::.
41576
41577
41578File: elisp.info,  Node: Killing Buffers,  Next: Indirect Buffers,  Prev: Creating Buffers,  Up: Buffers
41579
4158027.10 Killing Buffers
41581=====================
41582
41583“Killing a buffer” makes its name unknown to Emacs and makes the memory
41584space it occupied available for other use.
41585
41586   The buffer object for the buffer that has been killed remains in
41587existence as long as anything refers to it, but it is specially marked
41588so that you cannot make it current or display it.  Killed buffers retain
41589their identity, however; if you kill two distinct buffers, they remain
41590distinct according to ‘eq’ although both are dead.
41591
41592   If you kill a buffer that is current or displayed in a window, Emacs
41593automatically selects or displays some other buffer instead.  This means
41594that killing a buffer can change the current buffer.  Therefore, when
41595you kill a buffer, you should also take the precautions associated with
41596changing the current buffer (unless you happen to know that the buffer
41597being killed isn’t current).  *Note Current Buffer::.
41598
41599   If you kill a buffer that is the base buffer of one or more indirect
41600buffers (*note Indirect Buffers::), the indirect buffers are
41601automatically killed as well.
41602
41603   The ‘buffer-name’ of a buffer is ‘nil’ if, and only if, the buffer is
41604killed.  A buffer that has not been killed is called a “live” buffer.
41605To test whether a buffer is live or killed, use the function
41606‘buffer-live-p’ (see below).
41607
41608 -- Command: kill-buffer &optional buffer-or-name
41609     This function kills the buffer BUFFER-OR-NAME, freeing all its
41610     memory for other uses or to be returned to the operating system.
41611     If BUFFER-OR-NAME is ‘nil’ or omitted, it kills the current buffer.
41612
41613     Any processes that have this buffer as the ‘process-buffer’ are
41614     sent the ‘SIGHUP’ (hangup) signal, which normally causes them to
41615     terminate.  *Note Signals to Processes::.
41616
41617     If the buffer is visiting a file and contains unsaved changes,
41618     ‘kill-buffer’ asks the user to confirm before the buffer is killed.
41619     It does this even if not called interactively.  To prevent the
41620     request for confirmation, clear the modified flag before calling
41621     ‘kill-buffer’.  *Note Buffer Modification::.
41622
41623     This function calls ‘replace-buffer-in-windows’ for cleaning up all
41624     windows currently displaying the buffer to be killed.
41625
41626     Killing a buffer that is already dead has no effect.
41627
41628     This function returns ‘t’ if it actually killed the buffer.  It
41629     returns ‘nil’ if the user refuses to confirm or if BUFFER-OR-NAME
41630     was already dead.
41631
41632          (kill-buffer "foo.unchanged")
41633               ⇒ t
41634          (kill-buffer "foo.changed")
41635
41636          ---------- Buffer: Minibuffer ----------
41637          Buffer foo.changed modified; kill anyway? (yes or no) yes
41638          ---------- Buffer: Minibuffer ----------
41639
41640               ⇒ t
41641
41642 -- Variable: kill-buffer-query-functions
41643     Before confirming unsaved changes, ‘kill-buffer’ calls the
41644     functions in the list ‘kill-buffer-query-functions’, in order of
41645     appearance, with no arguments.  The buffer being killed is the
41646     current buffer when they are called.  The idea of this feature is
41647     that these functions will ask for confirmation from the user.  If
41648     any of them returns ‘nil’, ‘kill-buffer’ spares the buffer’s life.
41649
41650 -- Variable: kill-buffer-hook
41651     This is a normal hook run by ‘kill-buffer’ after asking all the
41652     questions it is going to ask, just before actually killing the
41653     buffer.  The buffer to be killed is current when the hook functions
41654     run.  *Note Hooks::.  This variable is a permanent local, so its
41655     local binding is not cleared by changing major modes.
41656
41657 -- User Option: buffer-offer-save
41658     This variable, if non-‘nil’ in a particular buffer, tells
41659     ‘save-buffers-kill-emacs’ to offer to save that buffer, just as it
41660     offers to save file-visiting buffers.  If ‘save-some-buffers’ is
41661     called with the second optional argument set to ‘t’, it will also
41662     offer to save the buffer.  Lastly, if this variable is set to the
41663     symbol ‘always’, both ‘save-buffers-kill-emacs’ and
41664     ‘save-some-buffers’ will always offer to save.  *Note Definition of
41665     save-some-buffers::.  The variable ‘buffer-offer-save’
41666     automatically becomes buffer-local when set for any reason.  *Note
41667     Buffer-Local Variables::.
41668
41669 -- Variable: buffer-save-without-query
41670     This variable, if non-‘nil’ in a particular buffer, tells
41671     ‘save-buffers-kill-emacs’ and ‘save-some-buffers’ to save this
41672     buffer (if it’s modified) without asking the user.  The variable
41673     automatically becomes buffer-local when set for any reason.
41674
41675 -- Function: buffer-live-p object
41676     This function returns ‘t’ if OBJECT is a live buffer (a buffer
41677     which has not been killed), ‘nil’ otherwise.
41678
41679
41680File: elisp.info,  Node: Indirect Buffers,  Next: Swapping Text,  Prev: Killing Buffers,  Up: Buffers
41681
4168227.11 Indirect Buffers
41683======================
41684
41685An “indirect buffer” shares the text of some other buffer, which is
41686called the “base buffer” of the indirect buffer.  In some ways it is the
41687analogue, for buffers, of a symbolic link among files.  The base buffer
41688may not itself be an indirect buffer.
41689
41690   The text of the indirect buffer is always identical to the text of
41691its base buffer; changes made by editing either one are visible
41692immediately in the other.  This includes the text properties as well as
41693the characters themselves.
41694
41695   In all other respects, the indirect buffer and its base buffer are
41696completely separate.  They have different names, independent values of
41697point, independent narrowing, independent markers and overlays (though
41698inserting or deleting text in either buffer relocates the markers and
41699overlays for both), independent major modes, and independent
41700buffer-local variable bindings.
41701
41702   An indirect buffer cannot visit a file, but its base buffer can.  If
41703you try to save the indirect buffer, that actually saves the base
41704buffer.
41705
41706   Killing an indirect buffer has no effect on its base buffer.  Killing
41707the base buffer effectively kills the indirect buffer in that it cannot
41708ever again be the current buffer.
41709
41710 -- Command: make-indirect-buffer base-buffer name &optional clone
41711     This creates and returns an indirect buffer named NAME whose base
41712     buffer is BASE-BUFFER.  The argument BASE-BUFFER may be a live
41713     buffer or the name (a string) of an existing buffer.  If NAME is
41714     the name of an existing buffer, an error is signaled.
41715
41716     If CLONE is non-‘nil’, then the indirect buffer originally shares
41717     the state of BASE-BUFFER such as major mode, minor modes, buffer
41718     local variables and so on.  If CLONE is omitted or ‘nil’ the
41719     indirect buffer’s state is set to the default state for new
41720     buffers.
41721
41722     If BASE-BUFFER is an indirect buffer, its base buffer is used as
41723     the base for the new buffer.  If, in addition, CLONE is non-‘nil’,
41724     the initial state is copied from the actual base buffer, not from
41725     BASE-BUFFER.
41726
41727 -- Command: clone-indirect-buffer newname display-flag &optional
41728          norecord
41729     This function creates and returns a new indirect buffer that shares
41730     the current buffer’s base buffer and copies the rest of the current
41731     buffer’s attributes.  (If the current buffer is not indirect, it is
41732     used as the base buffer.)
41733
41734     If DISPLAY-FLAG is non-‘nil’, as it always is in interactive calls,
41735     that means to display the new buffer by calling ‘pop-to-buffer’.
41736     If NORECORD is non-‘nil’, that means not to put the new buffer to
41737     the front of the buffer list.
41738
41739 -- Function: buffer-base-buffer &optional buffer
41740     This function returns the base buffer of BUFFER, which defaults to
41741     the current buffer.  If BUFFER is not indirect, the value is ‘nil’.
41742     Otherwise, the value is another buffer, which is never an indirect
41743     buffer.
41744
41745
41746File: elisp.info,  Node: Swapping Text,  Next: Buffer Gap,  Prev: Indirect Buffers,  Up: Buffers
41747
4174827.12 Swapping Text Between Two Buffers
41749=======================================
41750
41751Specialized modes sometimes need to let the user access from the same
41752buffer several vastly different types of text.  For example, you may
41753need to display a summary of the buffer text, in addition to letting the
41754user access the text itself.
41755
41756   This could be implemented with multiple buffers (kept in sync when
41757the user edits the text), or with narrowing (*note Narrowing::).  But
41758these alternatives might sometimes become tedious or prohibitively
41759expensive, especially if each type of text requires expensive
41760buffer-global operations in order to provide correct display and editing
41761commands.
41762
41763   Emacs provides another facility for such modes: you can quickly swap
41764buffer text between two buffers with ‘buffer-swap-text’.  This function
41765is very fast because it doesn’t move any text, it only changes the
41766internal data structures of the buffer object to point to a different
41767chunk of text.  Using it, you can pretend that a group of two or more
41768buffers are actually a single virtual buffer that holds the contents of
41769all the individual buffers together.
41770
41771 -- Function: buffer-swap-text buffer
41772     This function swaps the text of the current buffer and that of its
41773     argument BUFFER.  It signals an error if one of the two buffers is
41774     an indirect buffer (*note Indirect Buffers::) or is a base buffer
41775     of an indirect buffer.
41776
41777     All the buffer properties that are related to the buffer text are
41778     swapped as well: the positions of point and mark, all the markers,
41779     the overlays, the text properties, the undo list, the value of the
41780     ‘enable-multibyte-characters’ flag (*note
41781     enable-multibyte-characters: Text Representations.), etc.
41782
41783     *Warning:* If this function is called from within a
41784     ‘save-excursion’ form, the current buffer will be set to BUFFER
41785     upon leaving the form, since the marker used by ‘save-excursion’ to
41786     save the position and buffer will be swapped as well.
41787
41788   If you use ‘buffer-swap-text’ on a file-visiting buffer, you should
41789set up a hook to save the buffer’s original text rather than what it was
41790swapped with.  ‘write-region-annotate-functions’ works for this purpose.
41791You should probably set ‘buffer-saved-size’ to −2 in the buffer, so that
41792changes in the text it is swapped with will not interfere with
41793auto-saving.
41794
41795
41796File: elisp.info,  Node: Buffer Gap,  Prev: Swapping Text,  Up: Buffers
41797
4179827.13 The Buffer Gap
41799====================
41800
41801Emacs buffers are implemented using an invisible “gap” to make insertion
41802and deletion faster.  Insertion works by filling in part of the gap, and
41803deletion adds to the gap.  Of course, this means that the gap must first
41804be moved to the locus of the insertion or deletion.  Emacs moves the gap
41805only when you try to insert or delete.  This is why your first editing
41806command in one part of a large buffer, after previously editing in
41807another far-away part, sometimes involves a noticeable delay.
41808
41809   This mechanism works invisibly, and Lisp code should never be
41810affected by the gap’s current location, but these functions are
41811available for getting information about the gap status.
41812
41813 -- Function: gap-position
41814     This function returns the current gap position in the current
41815     buffer.
41816
41817 -- Function: gap-size
41818     This function returns the current gap size of the current buffer.
41819
41820
41821File: elisp.info,  Node: Windows,  Next: Frames,  Prev: Buffers,  Up: Top
41822
4182328 Windows
41824**********
41825
41826This chapter describes the functions and variables related to Emacs
41827windows.  *Note Frames::, for how windows are assigned an area of screen
41828available for Emacs to use.  *Note Display::, for information on how
41829text is displayed in windows.
41830
41831* Menu:
41832
41833* Basic Windows::           Basic information on using windows.
41834* Windows and Frames::      Relating windows to the frame they appear on.
41835* Window Sizes::            Accessing a window’s size.
41836* Resizing Windows::        Changing the sizes of windows.
41837* Preserving Window Sizes:: Preserving the size of windows.
41838* Splitting Windows::       Creating a new window.
41839* Deleting Windows::        Removing a window from its frame.
41840* Recombining Windows::     Preserving the frame layout when splitting and
41841                              deleting windows.
41842* Selecting Windows::       The selected window is the one that you edit in.
41843* Cyclic Window Ordering::  Moving around the existing windows.
41844* Buffers and Windows::     Each window displays the contents of a buffer.
41845* Switching Buffers::       Higher-level functions for switching to a buffer.
41846* Displaying Buffers::      Displaying a buffer in a suitable window.
41847* Window History::          Each window remembers the buffers displayed in it.
41848* Dedicated Windows::       How to avoid displaying another buffer in
41849                              a specific window.
41850* Quitting Windows::        How to restore the state prior to displaying a
41851                              buffer.
41852* Side Windows::            Special windows on a frame’s sides.
41853* Atomic Windows::          Preserving parts of the window layout.
41854* Window Point::            Each window has its own location of point.
41855* Window Start and End::    Buffer positions indicating which text is
41856                              on-screen in a window.
41857* Textual Scrolling::       Moving text up and down through the window.
41858* Vertical Scrolling::      Moving the contents up and down on the window.
41859* Horizontal Scrolling::    Moving the contents sideways on the window.
41860* Coordinates and Windows:: Converting coordinates to windows.
41861* Mouse Window Auto-selection:: Automatically selecting windows with the mouse.
41862* Window Configurations::   Saving and restoring the state of the screen.
41863* Window Parameters::       Associating additional information with windows.
41864* Window Hooks::            Hooks for scrolling, window size changes,
41865                              redisplay going past a certain point,
41866                              or window configuration changes.
41867
41868
41869File: elisp.info,  Node: Basic Windows,  Next: Windows and Frames,  Up: Windows
41870
4187128.1 Basic Concepts of Emacs Windows
41872====================================
41873
41874A “window” is an area of the screen that is used to display a buffer
41875(*note Buffers::).  In Emacs Lisp, windows are represented by a special
41876Lisp object type.
41877
41878   Windows are grouped into frames (*note Frames::).  Each frame
41879contains at least one window; the user can subdivide it into multiple,
41880non-overlapping windows to view several buffers at once.  Lisp programs
41881can use multiple windows for a variety of purposes.  In Rmail, for
41882example, you can view a summary of message titles in one window, and the
41883contents of the selected message in another window.
41884
41885   Emacs uses the word “window” with a different meaning than in
41886graphical desktop environments and window systems, such as the X Window
41887System.  When Emacs is run on X, each of its graphical X windows is an
41888Emacs frame (containing one or more Emacs windows).  When Emacs is run
41889on a text terminal, the frame fills the entire terminal screen.
41890
41891   Unlike X windows, Emacs windows are “tiled”; they never overlap
41892within the area of the frame.  When a window is created, resized, or
41893deleted, the change in window space is taken from or given to the
41894adjacent windows, so that the total area of the frame is unchanged.
41895
41896 -- Function: windowp object
41897     This function returns ‘t’ if OBJECT is a window (whether or not it
41898     displays a buffer).  Otherwise, it returns ‘nil’.
41899
41900   A “live window” is one that is actually displaying a buffer in a
41901frame.
41902
41903 -- Function: window-live-p object
41904     This function returns ‘t’ if OBJECT is a live window and ‘nil’
41905     otherwise.  A live window is one that displays a buffer.
41906
41907   The windows in each frame are organized into a “window tree”.  *Note
41908Windows and Frames::.  The leaf nodes of each window tree are live
41909windows—the ones actually displaying buffers.  The internal nodes of the
41910window tree are “internal windows”, which are not live.
41911
41912   A “valid window” is one that is either live or internal.  A valid
41913window can be “deleted”, i.e., removed from its frame (*note Deleting
41914Windows::); then it is no longer valid, but the Lisp object representing
41915it might be still referenced from other Lisp objects.  A deleted window
41916may be made valid again by restoring a saved window configuration (*note
41917Window Configurations::).
41918
41919   You can distinguish valid windows from deleted windows with
41920‘window-valid-p’.
41921
41922 -- Function: window-valid-p object
41923     This function returns ‘t’ if OBJECT is a live window, or an
41924     internal window in a window tree.  Otherwise, it returns ‘nil’,
41925     including for the case where OBJECT is a deleted window.
41926
41927   In each frame, at any time, exactly one Emacs window is designated as
41928“selected within the frame”.  For the selected frame, that window is
41929called the “selected window”—the one in which most editing takes place,
41930and in which the cursor for selected windows appears (*note Cursor
41931Parameters::).  Keyboard input that inserts or deletes text is also
41932normally directed to this window.  The selected window’s buffer is
41933usually also the current buffer, except when ‘set-buffer’ has been used
41934(*note Current Buffer::).  As for non-selected frames, the window
41935selected within the frame becomes the selected window if the frame is
41936ever selected.  *Note Selecting Windows::.
41937
41938 -- Function: selected-window
41939     This function returns the selected window (which is always a live
41940     window).
41941
41942   Sometimes several windows collectively and cooperatively display a
41943buffer, for example, under the management of Follow Mode (*note
41944(emacs)Follow Mode::), where the windows together display a bigger
41945portion of the buffer than one window could alone.  It is often useful
41946to consider such a “window group” as a single entity.  Several functions
41947such as ‘window-group-start’ (*note Window Start and End::) allow you to
41948do this by supplying, as an argument, one of the windows as a stand in
41949for the whole group.
41950
41951 -- Function: selected-window-group
41952     When the selected window is a member of a group of windows, this
41953     function returns a list of the windows in the group, ordered such
41954     that the first window in the list is displaying the earliest part
41955     of the buffer, and so on.  Otherwise the function returns a list
41956     containing just the selected window.
41957
41958     The selected window is considered part of a group when the buffer
41959     local variable ‘selected-window-group-function’ is set to a
41960     function.  In this case, ‘selected-window-group’ calls it with no
41961     arguments and returns its result (which should be the list of
41962     windows in the group).
41963
41964
41965File: elisp.info,  Node: Windows and Frames,  Next: Window Sizes,  Prev: Basic Windows,  Up: Windows
41966
4196728.2 Windows and Frames
41968=======================
41969
41970Each window belongs to exactly one frame (*note Frames::).
41971
41972 -- Function: window-frame &optional window
41973     This function returns the frame that the window WINDOW belongs to.
41974     If WINDOW is ‘nil’, it defaults to the selected window.
41975
41976 -- Function: window-list &optional frame minibuffer window
41977     This function returns a list of live windows belonging to the frame
41978     FRAME.  If FRAME is omitted or ‘nil’, it defaults to the selected
41979     frame.
41980
41981     The optional argument MINIBUFFER specifies whether to include the
41982     minibuffer window in the returned list.  If MINIBUFFER is ‘t’, the
41983     minibuffer window is included.  If MINIBUFFER is ‘nil’ or omitted,
41984     the minibuffer window is included only if it is active.  If
41985     MINIBUFFER is neither ‘nil’ nor ‘t’, the minibuffer window is never
41986     included.
41987
41988     The optional argument WINDOW, if non-‘nil’, should be a live window
41989     on the specified frame; then WINDOW will be the first element in
41990     the returned list.  If WINDOW is omitted or ‘nil’, the window
41991     selected within the frame is the first element.
41992
41993   Windows in the same frame are organized into a “window tree”, whose
41994leaf nodes are the live windows.  The internal nodes of a window tree
41995are not live; they exist for the purpose of organizing the relationships
41996between live windows.  The root node of a window tree is called the
41997“root window”.  It can be either a live window (if the frame has just
41998one window), or an internal window.
41999
42000   A minibuffer window (*note Minibuffer Windows::) that is not alone on
42001its frame does not have a parent window, so it strictly speaking is not
42002part of its frame’s window tree.  Nonetheless, it is a sibling window of
42003the frame’s root window, and thus can be reached via
42004‘window-next-sibling’.  Also, the function ‘window-tree’ described at
42005the end of this section lists the minibuffer window alongside the actual
42006window tree.
42007
42008 -- Function: frame-root-window &optional frame-or-window
42009     This function returns the root window for FRAME-OR-WINDOW.  The
42010     argument FRAME-OR-WINDOW should be either a window or a frame; if
42011     omitted or ‘nil’, it defaults to the selected frame.  If
42012     FRAME-OR-WINDOW is a window, the return value is the root window of
42013     that window’s frame.
42014
42015   When a window is split, there are two live windows where previously
42016there was one.  One of these is represented by the same Lisp window
42017object as the original window, and the other is represented by a
42018newly-created Lisp window object.  Both of these live windows become
42019leaf nodes of the window tree, as “child windows” of a single internal
42020window.  If necessary, Emacs automatically creates this internal window,
42021which is also called the “parent window”, and assigns it to the
42022appropriate position in the window tree.  A set of windows that share
42023the same parent are called “siblings”.
42024
42025 -- Function: window-parent &optional window
42026     This function returns the parent window of WINDOW.  If WINDOW is
42027     omitted or ‘nil’, it defaults to the selected window.  The return
42028     value is ‘nil’ if WINDOW has no parent (i.e., it is a minibuffer
42029     window or the root window of its frame).
42030
42031   Each internal window always has at least two child windows.  If this
42032number falls to one as a result of window deletion, Emacs automatically
42033deletes the internal window, and its sole remaining child window takes
42034its place in the window tree.
42035
42036   Each child window can be either a live window, or an internal window
42037(which in turn would have its own child windows).  Therefore, each
42038internal window can be thought of as occupying a certain rectangular
42039“screen area”—the union of the areas occupied by the live windows that
42040are ultimately descended from it.
42041
42042   For each internal window, the screen areas of the immediate children
42043are arranged either vertically or horizontally (never both).  If the
42044child windows are arranged one above the other, they are said to form a
42045“vertical combination”; if they are arranged side by side, they are said
42046to form a “horizontal combination”.  Consider the following example:
42047
42048          ______________________________________
42049         | ______  ____________________________ |
42050         ||      || __________________________ ||
42051         ||      |||                          |||
42052         ||      |||                          |||
42053         ||      |||                          |||
42054         ||      |||____________W4____________|||
42055         ||      || __________________________ ||
42056         ||      |||                          |||
42057         ||      |||                          |||
42058         ||      |||____________W5____________|||
42059         ||__W2__||_____________W3_____________ |
42060         |__________________W1__________________|
42061
42062
42063The root window of this frame is an internal window, W1.  Its child
42064windows form a horizontal combination, consisting of the live window W2
42065and the internal window W3.  The child windows of W3 form a vertical
42066combination, consisting of the live windows W4 and W5.  Hence, the live
42067windows in this window tree are W2, W4, and W5.
42068
42069   The following functions can be used to retrieve a child window of an
42070internal window, and the siblings of a child window.
42071
42072 -- Function: window-top-child &optional window
42073     This function returns the topmost child window of WINDOW, if WINDOW
42074     is an internal window whose children form a vertical combination.
42075     For any other type of window, the return value is ‘nil’.
42076
42077 -- Function: window-left-child &optional window
42078     This function returns the leftmost child window of WINDOW, if
42079     WINDOW is an internal window whose children form a horizontal
42080     combination.  For any other type of window, the return value is
42081     ‘nil’.
42082
42083 -- Function: window-child window
42084     This function returns the first child window of the internal window
42085     WINDOW—the topmost child window for a vertical combination, or the
42086     leftmost child window for a horizontal combination.  If WINDOW is a
42087     live window, the return value is ‘nil’.
42088
42089 -- Function: window-combined-p &optional window horizontal
42090     This function returns a non-‘nil’ value if and only if WINDOW is
42091     part of a vertical combination.  If WINDOW is omitted or ‘nil’, it
42092     defaults to the selected one.
42093
42094     If the optional argument HORIZONTAL is non-‘nil’, this means to
42095     return non-‘nil’ if and only if WINDOW is part of a horizontal
42096     combination.
42097
42098 -- Function: window-next-sibling &optional window
42099     This function returns the next sibling of the window WINDOW.  If
42100     omitted or ‘nil’, WINDOW defaults to the selected window.  The
42101     return value is ‘nil’ if WINDOW is the last child of its parent.
42102
42103 -- Function: window-prev-sibling &optional window
42104     This function returns the previous sibling of the window WINDOW.
42105     If omitted or ‘nil’, WINDOW defaults to the selected window.  The
42106     return value is ‘nil’ if WINDOW is the first child of its parent.
42107
42108   The functions ‘window-next-sibling’ and ‘window-prev-sibling’ should
42109not be confused with the functions ‘next-window’ and ‘previous-window’,
42110which return the next and previous window, respectively, in the cyclic
42111ordering of windows (*note Cyclic Window Ordering::).
42112
42113   The following functions can be useful to locate a window within its
42114frame.
42115
42116 -- Function: frame-first-window &optional frame-or-window
42117     This function returns the live window at the upper left corner of
42118     the frame specified by FRAME-OR-WINDOW.  The argument
42119     FRAME-OR-WINDOW must denote a window or a live frame and defaults
42120     to the selected frame.  If FRAME-OR-WINDOW specifies a window, this
42121     function returns the first window on that window’s frame.  Under
42122     the assumption that the frame from our canonical example is
42123     selected ‘(frame-first-window)’ returns W2.
42124
42125 -- Function: window-at-side-p &optional window side
42126     This function returns ‘t’ if WINDOW is located at SIDE of its
42127     containing frame.  The argument WINDOW must be a valid window and
42128     defaults to the selected one.  The argument SIDE can be any of the
42129     symbols ‘left’, ‘top’, ‘right’ or ‘bottom’.  The default value
42130     ‘nil’ is handled like ‘bottom’.
42131
42132     Note that this function disregards the minibuffer window (*note
42133     Minibuffer Windows::).  Hence, with SIDE equal to ‘bottom’ it may
42134     return ‘t’ also when the minibuffer window appears right below
42135     WINDOW.
42136
42137 -- Function: window-in-direction direction &optional window ignore sign
42138          wrap mini
42139     This function returns the nearest live window in direction
42140     DIRECTION as seen from the position of ‘window-point’ in window
42141     WINDOW.  The argument DIRECTION must be one of ‘above’, ‘below’,
42142     ‘left’ or ‘right’.  The optional argument WINDOW must denote a live
42143     window and defaults to the selected one.
42144
42145     This function does not return a window whose ‘no-other-window’
42146     parameter is non-‘nil’ (*note Window Parameters::).  If the nearest
42147     window’s ‘no-other-window’ parameter is non-‘nil’, this function
42148     tries to find another window in the indicated direction whose
42149     ‘no-other-window’ parameter is ‘nil’.  If the optional argument
42150     IGNORE is non-‘nil’, a window may be returned even if its
42151     ‘no-other-window’ parameter is non-‘nil’.
42152
42153     If the optional argument SIGN is a negative number, it means to use
42154     the right or bottom edge of WINDOW as reference position instead of
42155     ‘window-point’.  If SIGN is a positive number, it means to use the
42156     left or top edge of WINDOW as reference position.
42157
42158     If the optional argument WRAP is non-‘nil’, this means to wrap
42159     DIRECTION around frame borders.  For example, if WINDOW is at the
42160     top of the frame and DIRECTION is ‘above’, then this function
42161     usually returns the frame’s minibuffer window if it’s active and a
42162     window at the bottom of the frame otherwise.
42163
42164     If the optional argument MINI is ‘nil’, this means to return the
42165     minibuffer window if and only if it is currently active.  If MINI
42166     is non-‘nil’, this function may return the minibuffer window even
42167     when it’s not active.  However, if WRAP is non-‘nil’, it always
42168     acts as if MINI were ‘nil’.
42169
42170     If it doesn’t find a suitable window, this function returns ‘nil’.
42171
42172     Don’t use this function to check whether there is _no_ window in
42173     DIRECTION.  Calling ‘window-at-side-p’ described above is a much
42174     more efficient way to do that.
42175
42176   The following function allows the entire window tree of a frame to be
42177retrieved:
42178
42179 -- Function: window-tree &optional frame
42180     This function returns a list representing the window tree for frame
42181     FRAME.  If FRAME is omitted or ‘nil’, it defaults to the selected
42182     frame.
42183
42184     The return value is a list of the form ‘(ROOT MINI)’, where ROOT
42185     represents the window tree of the frame’s root window, and MINI is
42186     the frame’s minibuffer window.
42187
42188     If the root window is live, ROOT is that window itself.  Otherwise,
42189     ROOT is a list ‘(DIR EDGES W1 W2 ...)’ where DIR is ‘nil’ for a
42190     horizontal combination and ‘t’ for a vertical combination, EDGES
42191     gives the size and position of the combination, and the remaining
42192     elements are the child windows.  Each child window may again be a
42193     window object (for a live window) or a list with the same format as
42194     above (for an internal window).  The EDGES element is a list ‘(LEFT
42195     TOP RIGHT BOTTOM)’, similar to the value returned by ‘window-edges’
42196     (*note Coordinates and Windows::).
42197
42198
42199File: elisp.info,  Node: Window Sizes,  Next: Resizing Windows,  Prev: Windows and Frames,  Up: Windows
42200
4220128.3 Window Sizes
42202=================
42203
42204The following schematic shows the structure of a live window:
42205
42206             ____________________________________________
42207            |______________ Header Line ______________|RD| ^
42208          ^ |LS|LM|LF|                       |RF|RM|RS|  | |
42209          | |  |  |  |                       |  |  |  |  | |
42210     Window |  |  |  |       Text Area       |  |  |  |  | Window
42211     Body | |  |  |  |     (Window Body)     |  |  |  |  | Total
42212     Height |  |  |  |                       |  |  |  |  | Height
42213          | |  |  |  |<- Window Body Width ->|  |  |  |  | |
42214          v |__|__|__|_______________________|__|__|__|  | |
42215            |_________ Horizontal Scroll Bar _________|  | |
42216            |_______________ Mode Line _______________|__| |
42217            |_____________ Bottom Divider _______________| v
42218             <---------- Window Total Width ------------>
42219
42220
42221   At the center of the window is the “text area”, or “body”, where the
42222buffer text is displayed.  The text area can be surrounded by a series
42223of optional areas.  On the left and right, from innermost to outermost,
42224these are the left and right fringes, denoted by LF and RF (*note
42225Fringes::); the left and right margins, denoted by LM and RM in the
42226schematic (*note Display Margins::); the left or right vertical scroll
42227bar, only one of which is present at any time, denoted by LS and RS
42228(*note Scroll Bars::); and the right divider, denoted by RD (*note
42229Window Dividers::).  At the top of the window is the header line (*note
42230Header Lines::).  At the bottom of the window are the horizontal scroll
42231bar (*note Scroll Bars::); the mode line (*note Mode Line Format::); and
42232the bottom divider (*note Window Dividers::).
42233
42234   Emacs provides miscellaneous functions for finding the height and
42235width of a window.  The return value of many of these functions can be
42236specified either in units of pixels or in units of lines and columns.
42237On a graphical display, the latter actually correspond to the height and
42238width of a default character specified by the frame’s default font as
42239returned by ‘frame-char-height’ and ‘frame-char-width’ (*note Frame
42240Font::).  Thus, if a window is displaying text with a different font or
42241size, the reported line height and column width for that window may
42242differ from the actual number of text lines or columns displayed within
42243it.
42244
42245   The “total height” of a window is the number of lines comprising the
42246window’s body, the header line, the horizontal scroll bar, the mode line
42247and the bottom divider (if any).
42248
42249 -- Function: window-total-height &optional window round
42250     This function returns the total height, in lines, of the window
42251     WINDOW.  If WINDOW is omitted or ‘nil’, it defaults to the selected
42252     window.  If WINDOW is an internal window, the return value is the
42253     total height occupied by its descendant windows.
42254
42255     If a window’s pixel height is not an integral multiple of its
42256     frame’s default character height, the number of lines occupied by
42257     the window is rounded internally.  This is done in a way such that,
42258     if the window is a parent window, the sum of the total heights of
42259     all its child windows internally equals the total height of their
42260     parent.  This means that although two windows have the same pixel
42261     height, their internal total heights may differ by one line.  This
42262     means also, that if window is vertically combined and has a next
42263     sibling, the topmost row of that sibling can be calculated as the
42264     sum of this window’s topmost row and total height (*note
42265     Coordinates and Windows::)
42266
42267     If the optional argument ROUND is ‘ceiling’, this function returns
42268     the smallest integer larger than WINDOW’s pixel height divided by
42269     the character height of its frame; if it is ‘floor’, it returns the
42270     largest integer smaller than said value; with any other ROUND it
42271     returns the internal value of WINDOWS’s total height.
42272
42273   The “total width” of a window is the number of lines comprising the
42274window’s body, its margins, fringes, scroll bars and a right divider (if
42275any).
42276
42277 -- Function: window-total-width &optional window round
42278     This function returns the total width, in columns, of the window
42279     WINDOW.  If WINDOW is omitted or ‘nil’, it defaults to the selected
42280     window.  If WINDOW is internal, the return value is the total width
42281     occupied by its descendant windows.
42282
42283     If a window’s pixel width is not an integral multiple of its
42284     frame’s character width, the number of lines occupied by the window
42285     is rounded internally.  This is done in a way such that, if the
42286     window is a parent window, the sum of the total widths of all its
42287     children internally equals the total width of their parent.  This
42288     means that although two windows have the same pixel width, their
42289     internal total widths may differ by one column.  This means also,
42290     that if this window is horizontally combined and has a next
42291     sibling, the leftmost column of that sibling can be calculated as
42292     the sum of this window’s leftmost column and total width (*note
42293     Coordinates and Windows::).  The optional argument ROUND behaves as
42294     it does for ‘window-total-height’.
42295
42296 -- Function: window-total-size &optional window horizontal round
42297     This function returns either the total height in lines or the total
42298     width in columns of the window WINDOW.  If HORIZONTAL is omitted or
42299     ‘nil’, this is equivalent to calling ‘window-total-height’ for
42300     WINDOW; otherwise it is equivalent to calling ‘window-total-width’
42301     for WINDOW.  The optional argument ROUND behaves as it does for
42302     ‘window-total-height’.
42303
42304   The following two functions can be used to return the total size of a
42305window in units of pixels.
42306
42307 -- Function: window-pixel-height &optional window
42308     This function returns the total height of window WINDOW in pixels.
42309     WINDOW must be a valid window and defaults to the selected one.
42310
42311     The return value includes mode and header line, a horizontal scroll
42312     bar and a bottom divider, if any.  If WINDOW is an internal window,
42313     its pixel height is the pixel height of the screen areas spanned by
42314     its children.
42315
42316 -- Function: window-pixel-width &optional window
42317     This function returns the width of window WINDOW in pixels.  WINDOW
42318     must be a valid window and defaults to the selected one.
42319
42320     The return value includes the fringes and margins of WINDOW as well
42321     as any vertical dividers or scroll bars belonging to WINDOW.  If
42322     WINDOW is an internal window, its pixel width is the width of the
42323     screen areas spanned by its children.
42324
42325   The following functions can be used to determine whether a given
42326window has any adjacent windows.
42327
42328 -- Function: window-full-height-p &optional window
42329     This function returns non-‘nil’ if WINDOW has no other window above
42330     or below it in its frame.  More precisely, this means that the
42331     total height of WINDOW equals the total height of the root window
42332     on that frame.  The minibuffer window does not count in this
42333     regard.  If WINDOW is omitted or ‘nil’, it defaults to the selected
42334     window.
42335
42336 -- Function: window-full-width-p &optional window
42337     This function returns non-‘nil’ if WINDOW has no other window to
42338     the left or right in its frame, i.e., its total width equals that
42339     of the root window on that frame.  If WINDOW is omitted or ‘nil’,
42340     it defaults to the selected window.
42341
42342   The “body height” of a window is the height of its text area, which
42343does not include a mode or header line, a horizontal scroll bar, or a
42344bottom divider.
42345
42346 -- Function: window-body-height &optional window pixelwise
42347     This function returns the height, in lines, of the body of window
42348     WINDOW.  If WINDOW is omitted or ‘nil’, it defaults to the selected
42349     window; otherwise it must be a live window.
42350
42351     If the optional argument PIXELWISE is non-‘nil’, this function
42352     returns the body height of WINDOW counted in pixels.
42353
42354     If PIXELWISE is ‘nil’, the return value is rounded down to the
42355     nearest integer, if necessary.  This means that if a line at the
42356     bottom of the text area is only partially visible, that line is not
42357     counted.  It also means that the height of a window’s body can
42358     never exceed its total height as returned by ‘window-total-height’.
42359
42360   The “body width” of a window is the width of its text area, which
42361does not include the scroll bar, fringes, margins or a right divider.
42362Note that when one or both fringes are removed (by setting their width
42363to zero), the display engine reserves two character cells, one on each
42364side of the window, for displaying the continuation and truncation
42365glyphs, which leaves 2 columns less for text display.  (The function
42366‘window-max-chars-per-line’, described below, takes this peculiarity
42367into account.)
42368
42369 -- Function: window-body-width &optional window pixelwise
42370     This function returns the width, in columns, of the body of window
42371     WINDOW.  If WINDOW is omitted or ‘nil’, it defaults to the selected
42372     window; otherwise it must be a live window.
42373
42374     If the optional argument PIXELWISE is non-‘nil’, this function
42375     returns the body width of WINDOW in units of pixels.
42376
42377     If PIXELWISE is ‘nil’, the return value is rounded down to the
42378     nearest integer, if necessary.  This means that if a column on the
42379     right of the text area is only partially visible, that column is
42380     not counted.  It also means that the width of a window’s body can
42381     never exceed its total width as returned by ‘window-total-width’.
42382
42383 -- Function: window-body-size &optional window horizontal pixelwise
42384     This function returns the body height or body width of WINDOW.  If
42385     HORIZONTAL is omitted or ‘nil’, it is equivalent to calling
42386     ‘window-body-height’ for WINDOW; otherwise it is equivalent to
42387     calling ‘window-body-width’.  In either case, the optional argument
42388     PIXELWISE is passed to the function called.
42389
42390   For compatibility with previous versions of Emacs, ‘window-height’ is
42391an alias for ‘window-total-height’, and ‘window-width’ is an alias for
42392‘window-body-width’.  These aliases are considered obsolete and will be
42393removed in the future.
42394
42395   The pixel heights of a window’s mode and header line can be retrieved
42396with the functions given below.  Their return value is usually accurate
42397unless the window has not been displayed before: In that case, the
42398return value is based on an estimate of the font used for the window’s
42399frame.
42400
42401 -- Function: window-mode-line-height &optional window
42402     This function returns the height in pixels of WINDOW’s mode line.
42403     WINDOW must be a live window and defaults to the selected one.  If
42404     WINDOW has no mode line, the return value is zero.
42405
42406 -- Function: window-header-line-height &optional window
42407     This function returns the height in pixels of WINDOW’s header line.
42408     WINDOW must be a live window and defaults to the selected one.  If
42409     WINDOW has no header line, the return value is zero.
42410
42411   Functions for retrieving the height and/or width of window dividers
42412(*note Window Dividers::), fringes (*note Fringes::), scroll bars (*note
42413Scroll Bars::), and display margins (*note Display Margins::) are
42414described in the corresponding sections.
42415
42416   If your Lisp program needs to make layout decisions, you will find
42417the following function useful:
42418
42419 -- Function: window-max-chars-per-line &optional window face
42420     This function returns the number of characters displayed in the
42421     specified face FACE in the specified window WINDOW (which must be a
42422     live window).  If FACE was remapped (*note Face Remapping::), the
42423     information is returned for the remapped face.  If omitted or
42424     ‘nil’, FACE defaults to the default face, and WINDOW defaults to
42425     the selected window.
42426
42427     Unlike ‘window-body-width’, this function accounts for the actual
42428     size of FACE’s font, instead of working in units of the canonical
42429     character width of WINDOW’s frame (*note Frame Font::).  It also
42430     accounts for space used by the continuation glyph, if WINDOW lacks
42431     one or both of its fringes.
42432
42433   Commands that change the size of windows (*note Resizing Windows::),
42434or split them (*note Splitting Windows::), obey the variables
42435‘window-min-height’ and ‘window-min-width’, which specify the smallest
42436allowable window height and width.  They also obey the variable
42437‘window-size-fixed’, with which a window can be “fixed” in size (*note
42438Preserving Window Sizes::).
42439
42440 -- User Option: window-min-height
42441     This option specifies the minimum total height, in lines, of any
42442     window.  Its value has to accommodate at least one text line as
42443     well as a mode and header line, a horizontal scroll bar and a
42444     bottom divider, if present.
42445
42446 -- User Option: window-min-width
42447     This option specifies the minimum total width, in columns, of any
42448     window.  Its value has to accommodate two text columns as well as
42449     margins, fringes, a scroll bar and a right divider, if present.
42450
42451   The following function tells how small a specific window can get
42452taking into account the sizes of its areas and the values of
42453‘window-min-height’, ‘window-min-width’ and ‘window-size-fixed’ (*note
42454Preserving Window Sizes::).
42455
42456 -- Function: window-min-size &optional window horizontal ignore
42457          pixelwise
42458     This function returns the minimum size of WINDOW.  WINDOW must be a
42459     valid window and defaults to the selected one.  The optional
42460     argument HORIZONTAL non-‘nil’ means to return the minimum number of
42461     columns of WINDOW; otherwise return the minimum number of WINDOW’s
42462     lines.
42463
42464     The return value makes sure that all components of WINDOW remain
42465     fully visible if WINDOW’s size were actually set to it.  With
42466     HORIZONTAL ‘nil’ it includes the mode and header line, the
42467     horizontal scroll bar and the bottom divider, if present.  With
42468     HORIZONTAL non-‘nil’ it includes the margins and fringes, the
42469     vertical scroll bar and the right divider, if present.
42470
42471     The optional argument IGNORE, if non-‘nil’, means ignore
42472     restrictions imposed by fixed size windows, ‘window-min-height’ or
42473     ‘window-min-width’ settings.  If IGNORE equals ‘safe’, live windows
42474     may get as small as ‘window-safe-min-height’ lines and
42475     ‘window-safe-min-width’ columns.  If IGNORE is a window, ignore
42476     restrictions for that window only.  Any other non-‘nil’ value means
42477     ignore all of the above restrictions for all windows.
42478
42479     The optional argument PIXELWISE non-‘nil’ means to return the
42480     minimum size of WINDOW counted in pixels.
42481
42482
42483File: elisp.info,  Node: Resizing Windows,  Next: Preserving Window Sizes,  Prev: Window Sizes,  Up: Windows
42484
4248528.4 Resizing Windows
42486=====================
42487
42488This section describes functions for resizing a window without changing
42489the size of its frame.  Because live windows do not overlap, these
42490functions are meaningful only on frames that contain two or more
42491windows: resizing a window also changes the size of a neighboring
42492window.  If there is just one window on a frame, its size cannot be
42493changed except by resizing the frame (*note Frame Size::).
42494
42495   Except where noted, these functions also accept internal windows as
42496arguments.  Resizing an internal window causes its child windows to be
42497resized to fit the same space.
42498
42499 -- Function: window-resizable window delta &optional horizontal ignore
42500          pixelwise
42501     This function returns DELTA if the size of WINDOW can be changed
42502     vertically by DELTA lines.  If the optional argument HORIZONTAL is
42503     non-‘nil’, it instead returns DELTA if WINDOW can be resized
42504     horizontally by DELTA columns.  It does not actually change the
42505     window size.
42506
42507     If WINDOW is ‘nil’, it defaults to the selected window.
42508
42509     A positive value of DELTA means to check whether the window can be
42510     enlarged by that number of lines or columns; a negative value of
42511     DELTA means to check whether the window can be shrunk by that many
42512     lines or columns.  If DELTA is non-zero, a return value of 0 means
42513     that the window cannot be resized.
42514
42515     Normally, the variables ‘window-min-height’ and ‘window-min-width’
42516     specify the smallest allowable window size (*note Window Sizes::).
42517     However, if the optional argument IGNORE is non-‘nil’, this
42518     function ignores ‘window-min-height’ and ‘window-min-width’, as
42519     well as ‘window-size-fixed’.  Instead, it considers the
42520     minimum-height window to be one consisting of a header and a mode
42521     line, a horizontal scrollbar and a bottom divider (if any), plus a
42522     text area one line tall; and a minimum-width window as one
42523     consisting of fringes, margins, a scroll bar and a right divider
42524     (if any), plus a text area two columns wide.
42525
42526     If the optional argument PIXELWISE is non-‘nil’, DELTA is
42527     interpreted as pixels.
42528
42529 -- Function: window-resize window delta &optional horizontal ignore
42530          pixelwise
42531     This function resizes WINDOW by DELTA increments.  If HORIZONTAL is
42532     ‘nil’, it changes the height by DELTA lines; otherwise, it changes
42533     the width by DELTA columns.  A positive DELTA means to enlarge the
42534     window, and a negative DELTA means to shrink it.
42535
42536     If WINDOW is ‘nil’, it defaults to the selected window.  If the
42537     window cannot be resized as demanded, an error is signaled.
42538
42539     The optional argument IGNORE has the same meaning as for the
42540     function ‘window-resizable’ above.
42541
42542     If the optional argument PIXELWISE is non-‘nil’, DELTA will be
42543     interpreted as pixels.
42544
42545     The choice of which window edges this function alters depends on
42546     the values of the option ‘window-combination-resize’ and the
42547     combination limits of the involved windows; in some cases, it may
42548     alter both edges.  *Note Recombining Windows::.  To resize by
42549     moving only the bottom or right edge of a window, use the function
42550     ‘adjust-window-trailing-edge’.
42551
42552 -- Function: adjust-window-trailing-edge window delta &optional
42553          horizontal pixelwise
42554     This function moves WINDOW’s bottom edge by DELTA lines.  If
42555     optional argument HORIZONTAL is non-‘nil’, it instead moves the
42556     right edge by DELTA columns.  If WINDOW is ‘nil’, it defaults to
42557     the selected window.
42558
42559     If the optional argument PIXELWISE is non-‘nil’, DELTA is
42560     interpreted as pixels.
42561
42562     A positive DELTA moves the edge downwards or to the right; a
42563     negative DELTA moves it upwards or to the left.  If the edge cannot
42564     be moved as far as specified by DELTA, this function moves it as
42565     far as possible but does not signal an error.
42566
42567     This function tries to resize windows adjacent to the edge that is
42568     moved.  If this is not possible for some reason (e.g., if that
42569     adjacent window is fixed-size), it may resize other windows.
42570
42571 -- User Option: window-resize-pixelwise
42572     If the value of this option is non-‘nil’, Emacs resizes windows in
42573     units of pixels.  This currently affects functions like
42574     ‘split-window’ (*note Splitting Windows::), ‘maximize-window’,
42575     ‘minimize-window’, ‘fit-window-to-buffer’, ‘fit-frame-to-buffer’
42576     and ‘shrink-window-if-larger-than-buffer’ (all listed below).
42577
42578     Note that when a frame’s pixel size is not a multiple of its
42579     character size, at least one window may get resized pixelwise even
42580     if this option is ‘nil’.  The default value is ‘nil’.
42581
42582   The following commands resize windows in more specific ways.  When
42583called interactively, they act on the selected window.
42584
42585 -- Command: fit-window-to-buffer &optional window max-height min-height
42586          max-width min-width preserve-size
42587     This command adjusts the height or width of WINDOW to fit the text
42588     in it.  It returns non-‘nil’ if it was able to resize WINDOW, and
42589     ‘nil’ otherwise.  If WINDOW is omitted or ‘nil’, it defaults to the
42590     selected window.  Otherwise, it should be a live window.
42591
42592     If WINDOW is part of a vertical combination, this function adjusts
42593     WINDOW’s height.  The new height is calculated from the actual
42594     height of the accessible portion of its buffer.  The optional
42595     argument MAX-HEIGHT, if non-‘nil’, specifies the maximum total
42596     height that this function can give WINDOW.  The optional argument
42597     MIN-HEIGHT, if non-‘nil’, specifies the minimum total height that
42598     it can give, which overrides the variable ‘window-min-height’.
42599     Both MAX-HEIGHT and MIN-HEIGHT are specified in lines and include
42600     mode and header line and a bottom divider, if any.
42601
42602     If WINDOW is part of a horizontal combination and the value of the
42603     option ‘fit-window-to-buffer-horizontally’ (see below) is
42604     non-‘nil’, this function adjusts WINDOW’s width.  The new width of
42605     WINDOW is calculated from the maximum length of its buffer’s lines
42606     that follow the current start position of WINDOW.  The optional
42607     argument MAX-WIDTH specifies a maximum width and defaults to the
42608     width of WINDOW’s frame.  The optional argument MIN-WIDTH specifies
42609     a minimum width and defaults to ‘window-min-width’.  Both MAX-WIDTH
42610     and MIN-WIDTH are specified in columns and include fringes, margins
42611     and scrollbars, if any.
42612
42613     The optional argument PRESERVE-SIZE, if non-‘nil’, will install a
42614     parameter to preserve the size of WINDOW during future resize
42615     operations (*note Preserving Window Sizes::).
42616
42617     If the option ‘fit-frame-to-buffer’ (see below) is non-‘nil’, this
42618     function will try to resize the frame of WINDOW to fit its contents
42619     by calling ‘fit-frame-to-buffer’ (see below).
42620
42621 -- User Option: fit-window-to-buffer-horizontally
42622     If this is non-‘nil’, ‘fit-window-to-buffer’ can resize windows
42623     horizontally.  If this is ‘nil’ (the default)
42624     ‘fit-window-to-buffer’ never resizes windows horizontally.  If this
42625     is ‘only’, it can resize windows horizontally only.  Any other
42626     value means ‘fit-window-to-buffer’ can resize windows in both
42627     dimensions.
42628
42629 -- User Option: fit-frame-to-buffer
42630     If this option is non-‘nil’, ‘fit-window-to-buffer’ can fit a frame
42631     to its buffer.  A frame is fit if and only if its root window is a
42632     live window and this option is non-‘nil’.  If this is
42633     ‘horizontally’, frames are fit horizontally only.  If this is
42634     ‘vertically’, frames are fit vertically only.  Any other non-‘nil’
42635     value means frames can be resized in both dimensions.
42636
42637   If you have a frame that displays only one window, you can fit that
42638frame to its buffer using the command ‘fit-frame-to-buffer’.
42639
42640 -- Command: fit-frame-to-buffer &optional frame max-height min-height
42641          max-width min-width only
42642     This command adjusts the size of FRAME to display the contents of
42643     its buffer exactly.  FRAME can be any live frame and defaults to
42644     the selected one.  Fitting is done only if FRAME’s root window is
42645     live.  The arguments MAX-HEIGHT, MIN-HEIGHT, MAX-WIDTH and
42646     MIN-WIDTH specify bounds on the new total size of FRAME’s root
42647     window.  MIN-HEIGHT and MIN-WIDTH default to the values of
42648     ‘window-min-height’ and ‘window-min-width’ respectively.
42649
42650     If the optional argument ONLY is ‘vertically’, this function may
42651     resize the frame vertically only.  If ONLY is ‘horizontally’, it
42652     may resize the frame horizontally only.
42653
42654   The behavior of ‘fit-frame-to-buffer’ can be controlled with the help
42655of the two options listed next.
42656
42657 -- User Option: fit-frame-to-buffer-margins
42658     This option can be used to specify margins around frames to be fit
42659     by ‘fit-frame-to-buffer’.  Such margins can be useful to avoid, for
42660     example, that the resized frame overlaps the taskbar or parts of
42661     its parent frame.
42662
42663     It specifies the numbers of pixels to be left free on the left,
42664     above, the right, and below a frame that shall be fit.  The default
42665     specifies ‘nil’ for each which means to use no margins.  The value
42666     specified here can be overridden for a specific frame by that
42667     frame’s ‘fit-frame-to-buffer-margins’ parameter, if present.
42668
42669 -- User Option: fit-frame-to-buffer-sizes
42670     This option specifies size boundaries for ‘fit-frame-to-buffer’.
42671     It specifies the total maximum and minimum lines and maximum and
42672     minimum columns of the root window of any frame that shall be fit
42673     to its buffer.  If any of these values is non-‘nil’, it overrides
42674     the corresponding argument of ‘fit-frame-to-buffer’.
42675
42676 -- Command: shrink-window-if-larger-than-buffer &optional window
42677     This command attempts to reduce WINDOW’s height as much as possible
42678     while still showing its full buffer, but no less than
42679     ‘window-min-height’ lines.  The return value is non-‘nil’ if the
42680     window was resized, and ‘nil’ otherwise.  If WINDOW is omitted or
42681     ‘nil’, it defaults to the selected window.  Otherwise, it should be
42682     a live window.
42683
42684     This command does nothing if the window is already too short to
42685     display all of its buffer, or if any of the buffer is scrolled
42686     off-screen, or if the window is the only live window in its frame.
42687
42688     This command calls ‘fit-window-to-buffer’ (see above) to do its
42689     work.
42690
42691 -- Command: balance-windows &optional window-or-frame
42692     This function balances windows in a way that gives more space to
42693     full-width and/or full-height windows.  If WINDOW-OR-FRAME
42694     specifies a frame, it balances all windows on that frame.  If
42695     WINDOW-OR-FRAME specifies a window, it balances only that window
42696     and its siblings (*note Windows and Frames::).
42697
42698 -- Command: balance-windows-area
42699     This function attempts to give all windows on the selected frame
42700     approximately the same share of the screen area.  Full-width or
42701     full-height windows are not given more space than other windows.
42702
42703 -- Command: maximize-window &optional window
42704     This function attempts to make WINDOW as large as possible, in both
42705     dimensions, without resizing its frame or deleting other windows.
42706     If WINDOW is omitted or ‘nil’, it defaults to the selected window.
42707
42708 -- Command: minimize-window &optional window
42709     This function attempts to make WINDOW as small as possible, in both
42710     dimensions, without deleting it or resizing its frame.  If WINDOW
42711     is omitted or ‘nil’, it defaults to the selected window.
42712
42713
42714File: elisp.info,  Node: Preserving Window Sizes,  Next: Splitting Windows,  Prev: Resizing Windows,  Up: Windows
42715
4271628.5 Preserving Window Sizes
42717============================
42718
42719A window can get resized explicitly by using one of the functions from
42720the preceding section or implicitly, for example, when resizing an
42721adjacent window, when splitting or deleting a window (*note Splitting
42722Windows::, *note Deleting Windows::) or when resizing the window’s frame
42723(*note Frame Size::).
42724
42725   It is possible to avoid implicit resizing of a specific window when
42726there are one or more other resizable windows on the same frame.  For
42727this purpose, Emacs must be advised to “preserve” the size of that
42728window.  There are two basic ways to do that.
42729
42730 -- Variable: window-size-fixed
42731     If this buffer-local variable is non-‘nil’, the size of any window
42732     displaying the buffer cannot normally be changed.  Deleting a
42733     window or changing the frame’s size may still change the window’s
42734     size, if there is no choice.
42735
42736     If the value is ‘height’, then only the window’s height is fixed;
42737     if the value is ‘width’, then only the window’s width is fixed.
42738     Any other non-‘nil’ value fixes both the width and the height.
42739
42740     If this variable is ‘nil’, this does not necessarily mean that any
42741     window showing the buffer can be resized in the desired direction.
42742     To determine that, use the function ‘window-resizable’.  *Note
42743     Resizing Windows::.
42744
42745   Often ‘window-size-fixed’ is overly aggressive because it inhibits
42746any attempt to explicitly resize or split an affected window as well.
42747This may even happen after the window has been resized implicitly, for
42748example, when deleting an adjacent window or resizing the window’s
42749frame.  The following function tries hard to never disallow resizing
42750such a window explicitly:
42751
42752 -- Function: window-preserve-size &optional window horizontal preserve
42753     This function (un-)marks the height of window WINDOW as preserved
42754     for future resize operations.  WINDOW must be a live window and
42755     defaults to the selected one.  If the optional argument HORIZONTAL
42756     is non-‘nil’, it (un-)marks the width of WINDOW as preserved.
42757
42758     If the optional argument PRESERVE is ‘t’, this means to preserve
42759     the current height/width of WINDOW’s body.  The height/width of
42760     WINDOW will change only if Emacs has no better choice.  Resizing a
42761     window whose height/width is preserved by this function never
42762     throws an error.
42763
42764     If PRESERVE is ‘nil’, this means to stop preserving the
42765     height/width of WINDOW, lifting any respective restraint induced by
42766     a previous call of this function for WINDOW.  Calling
42767     ‘enlarge-window’, ‘shrink-window’ or ‘fit-window-to-buffer’ with
42768     WINDOW as argument may also remove the respective restraint.
42769
42770   ‘window-preserve-size’ is currently invoked by the following
42771functions:
42772
42773‘fit-window-to-buffer’
42774     If the optional argument PRESERVE-SIZE of that function (*note
42775     Resizing Windows::) is non-‘nil’, the size established by that
42776     function is preserved.
42777
42778‘display-buffer’
42779     If the ALIST argument of that function (*note Choosing Window::)
42780     contains a ‘preserve-size’ entry, the size of the window produced
42781     by that function is preserved.
42782
42783   ‘window-preserve-size’ installs a window parameter (*note Window
42784Parameters::) called ‘window-preserved-size’ which is consulted by the
42785window resizing functions.  This parameter will not prevent resizing the
42786window when the window shows another buffer than the one when
42787‘window-preserve-size’ was invoked or if its size has changed since
42788then.
42789
42790   The following function can be used to check whether the height of a
42791particular window is preserved:
42792
42793 -- Function: window-preserved-size &optional window horizontal
42794     This function returns the preserved height of window WINDOW in
42795     pixels.  WINDOW must be a live window and defaults to the selected
42796     one.  If the optional argument HORIZONTAL is non-‘nil’, it returns
42797     the preserved width of WINDOW.  It returns ‘nil’ if the size of
42798     WINDOW is not preserved.
42799
42800
42801File: elisp.info,  Node: Splitting Windows,  Next: Deleting Windows,  Prev: Preserving Window Sizes,  Up: Windows
42802
4280328.6 Splitting Windows
42804======================
42805
42806This section describes functions for creating a new window by
42807“splitting” an existing one.  Note that some windows are special in the
42808sense that these functions may fail to split them as described here.
42809Examples of such windows are side windows (*note Side Windows::) and
42810atomic windows (*note Atomic Windows::).
42811
42812 -- Function: split-window &optional window size side pixelwise
42813     This function creates a new live window next to the window WINDOW.
42814     If WINDOW is omitted or ‘nil’, it defaults to the selected window.
42815     That window is split, and reduced in size.  The space is taken up
42816     by the new window, which is returned.
42817
42818     The optional second argument SIZE determines the sizes of WINDOW
42819     and/or the new window.  If it is omitted or ‘nil’, both windows are
42820     given equal sizes; if there is an odd line, it is allocated to the
42821     new window.  If SIZE is a positive number, WINDOW is given SIZE
42822     lines (or columns, depending on the value of SIDE).  If SIZE is a
42823     negative number, the new window is given −SIZE lines (or columns).
42824
42825     If SIZE is ‘nil’, this function obeys the variables
42826     ‘window-min-height’ and ‘window-min-width’ (*note Window Sizes::).
42827     Thus, it signals an error if splitting would result in making a
42828     window smaller than those variables specify.  However, a non-‘nil’
42829     value for SIZE causes those variables to be ignored; in that case,
42830     the smallest allowable window is considered to be one that has
42831     space for a text area one line tall and/or two columns wide.
42832
42833     Hence, if SIZE is specified, it’s the caller’s responsibility to
42834     check whether the emanating windows are large enough to encompass
42835     all areas like a mode line or a scroll bar.  The function
42836     ‘window-min-size’ (*note Window Sizes::) can be used to determine
42837     the minimum requirements of WINDOW in this regard.  Since the new
42838     window usually inherits areas like the mode line or the scroll bar
42839     from WINDOW, that function is also a good guess for the minimum
42840     size of the new window.  The caller should specify a smaller size
42841     only if it correspondingly removes an inherited area before the
42842     next redisplay.
42843
42844     The optional third argument SIDE determines the position of the new
42845     window relative to WINDOW.  If it is ‘nil’ or ‘below’, the new
42846     window is placed below WINDOW.  If it is ‘above’, the new window is
42847     placed above WINDOW.  In both these cases, SIZE specifies a total
42848     window height, in lines.
42849
42850     If SIDE is ‘t’ or ‘right’, the new window is placed on the right of
42851     WINDOW.  If SIDE is ‘left’, the new window is placed on the left of
42852     WINDOW.  In both these cases, SIZE specifies a total window width,
42853     in columns.
42854
42855     The optional fourth argument PIXELWISE, if non-‘nil’, means to
42856     interpret SIZE in units of pixels, instead of lines and columns.
42857
42858     If WINDOW is a live window, the new window inherits various
42859     properties from it, including margins and scroll bars.  If WINDOW
42860     is an internal window, the new window inherits the properties of
42861     the window selected within WINDOW’s frame.
42862
42863     The behavior of this function may be altered by the window
42864     parameters of WINDOW, so long as the variable
42865     ‘ignore-window-parameters’ is ‘nil’.  If the value of the
42866     ‘split-window’ window parameter is ‘t’, this function ignores all
42867     other window parameters.  Otherwise, if the value of the
42868     ‘split-window’ window parameter is a function, that function is
42869     called with the arguments WINDOW, SIZE, and SIDE, in lieu of the
42870     usual action of ‘split-window’.  Otherwise, this function obeys the
42871     ‘window-atom’ or ‘window-side’ window parameter, if any.  *Note
42872     Window Parameters::.
42873
42874   As an example, here is a sequence of ‘split-window’ calls that yields
42875the window configuration discussed in *note Windows and Frames::.  This
42876example demonstrates splitting a live window as well as splitting an
42877internal window.  We begin with a frame containing a single window (a
42878live root window), which we denote by W4.  Calling ‘(split-window W4)’
42879yields this window configuration:
42880
42881          ______________________________________
42882         | ____________________________________ |
42883         ||                                    ||
42884         ||                                    ||
42885         ||                                    ||
42886         ||_________________W4_________________||
42887         | ____________________________________ |
42888         ||                                    ||
42889         ||                                    ||
42890         ||                                    ||
42891         ||_________________W5_________________||
42892         |__________________W3__________________|
42893
42894
42895The ‘split-window’ call has created a new live window, denoted by W5.
42896It has also created a new internal window, denoted by W3, which becomes
42897the root window and the parent of both W4 and W5.
42898
42899   Next, we call ‘(split-window W3 nil 'left)’, passing the internal
42900window W3 as the argument.  The result:
42901
42902          ______________________________________
42903         | ______  ____________________________ |
42904         ||      || __________________________ ||
42905         ||      |||                          |||
42906         ||      |||                          |||
42907         ||      |||                          |||
42908         ||      |||____________W4____________|||
42909         ||      || __________________________ ||
42910         ||      |||                          |||
42911         ||      |||                          |||
42912         ||      |||____________W5____________|||
42913         ||__W2__||_____________W3_____________ |
42914         |__________________W1__________________|
42915
42916A new live window W2 is created, to the left of the internal window W3.
42917A new internal window W1 is created, becoming the new root window.
42918
42919   For interactive use, Emacs provides two commands which always split
42920the selected window.  These call ‘split-window’ internally.
42921
42922 -- Command: split-window-right &optional size
42923     This function splits the selected window into two side-by-side
42924     windows, putting the selected window on the left.  If SIZE is
42925     positive, the left window gets SIZE columns; if SIZE is negative,
42926     the right window gets −SIZE columns.
42927
42928 -- Command: split-window-below &optional size
42929     This function splits the selected window into two windows, one
42930     above the other, leaving the upper window selected.  If SIZE is
42931     positive, the upper window gets SIZE lines; if SIZE is negative,
42932     the lower window gets −SIZE lines.
42933
42934 -- User Option: split-window-keep-point
42935     If the value of this variable is non-‘nil’ (the default),
42936     ‘split-window-below’ behaves as described above.
42937
42938     If it is ‘nil’, ‘split-window-below’ adjusts point in each of the
42939     two windows to minimize redisplay.  (This is useful on slow
42940     terminals.)  It selects whichever window contains the screen line
42941     that point was previously on.  Note that this only affects
42942     ‘split-window-below’, not the lower-level ‘split-window’ function.
42943
42944
42945File: elisp.info,  Node: Deleting Windows,  Next: Recombining Windows,  Prev: Splitting Windows,  Up: Windows
42946
4294728.7 Deleting Windows
42948=====================
42949
42950“Deleting” a window removes it from the frame’s window tree.  If the
42951window is a live window, it disappears from the screen.  If the window
42952is an internal window, its child windows are deleted too.
42953
42954   Even after a window is deleted, it continues to exist as a Lisp
42955object, until there are no more references to it.  Window deletion can
42956be reversed, by restoring a saved window configuration (*note Window
42957Configurations::).
42958
42959 -- Command: delete-window &optional window
42960     This function removes WINDOW from display and returns ‘nil’.  If
42961     WINDOW is omitted or ‘nil’, it defaults to the selected window.
42962
42963     If deleting the window would leave no more windows in the window
42964     tree (e.g., if it is the only live window in the frame) or all
42965     remaining windows on WINDOW’s frame are side windows (*note Side
42966     Windows::), an error is signaled.  If WINDOW is part of an atomic
42967     window (*note Atomic Windows::), this function tries to delete the
42968     root of that atomic window instead.
42969
42970     By default, the space taken up by WINDOW is given to one of its
42971     adjacent sibling windows, if any.  However, if the variable
42972     ‘window-combination-resize’ is non-‘nil’, the space is
42973     proportionally distributed among any remaining windows in the same
42974     window combination.  *Note Recombining Windows::.
42975
42976     The behavior of this function may be altered by the window
42977     parameters of WINDOW, so long as the variable
42978     ‘ignore-window-parameters’ is ‘nil’.  If the value of the
42979     ‘delete-window’ window parameter is ‘t’, this function ignores all
42980     other window parameters.  Otherwise, if the value of the
42981     ‘delete-window’ window parameter is a function, that function is
42982     called with the argument WINDOW, in lieu of the usual action of
42983     ‘delete-window’.  *Note Window Parameters::.
42984
42985 -- Command: delete-other-windows &optional window
42986     This function makes WINDOW fill its frame, deleting other windows
42987     as necessary.  If WINDOW is omitted or ‘nil’, it defaults to the
42988     selected window.  An error is signaled if WINDOW is a side window
42989     (*note Side Windows::).  If WINDOW is part of an atomic window
42990     (*note Atomic Windows::), this function tries to make the root of
42991     that atomic window fill its frame.  The return value is ‘nil’.
42992
42993     The behavior of this function may be altered by the window
42994     parameters of WINDOW, so long as the variable
42995     ‘ignore-window-parameters’ is ‘nil’.  If the value of the
42996     ‘delete-other-windows’ window parameter is ‘t’, this function
42997     ignores all other window parameters.  Otherwise, if the value of
42998     the ‘delete-other-windows’ window parameter is a function, that
42999     function is called with the argument WINDOW, in lieu of the usual
43000     action of ‘delete-other-windows’.  *Note Window Parameters::.
43001
43002     Also, if ‘ignore-window-parameters’ is ‘nil’, this function does
43003     not delete any window whose ‘no-delete-other-windows’ parameter is
43004     non-‘nil’.
43005
43006 -- Command: delete-windows-on &optional buffer-or-name frame
43007     This function deletes all windows showing BUFFER-OR-NAME, by
43008     calling ‘delete-window’ on those windows.  BUFFER-OR-NAME should be
43009     a buffer, or the name of a buffer; if omitted or ‘nil’, it defaults
43010     to the current buffer.  If there are no windows showing the
43011     specified buffer, this function does nothing.  If the specified
43012     buffer is a minibuffer, an error is signaled.
43013
43014     If there is a dedicated window showing the buffer, and that window
43015     is the only one on its frame, this function also deletes that frame
43016     if it is not the only frame on the terminal.
43017
43018     The optional argument FRAME specifies which frames to operate on:
43019
43020        • ‘nil’ means operate on all frames.
43021        • ‘t’ means operate on the selected frame.
43022        • ‘visible’ means operate on all visible frames.
43023        • ‘0’ means operate on all visible or iconified frames.
43024        • A frame means operate on that frame.
43025
43026     Note that this argument does not have the same meaning as in other
43027     functions which scan all live windows (*note Cyclic Window
43028     Ordering::).  Specifically, the meanings of ‘t’ and ‘nil’ here are
43029     the opposite of what they are in those other functions.
43030
43031
43032File: elisp.info,  Node: Recombining Windows,  Next: Selecting Windows,  Prev: Deleting Windows,  Up: Windows
43033
4303428.8 Recombining Windows
43035========================
43036
43037When deleting the last sibling of a window W, its parent window is
43038deleted too, with W replacing it in the window tree.  This means that W
43039must be recombined with its parent’s siblings to form a new window
43040combination (*note Windows and Frames::).  In some occasions, deleting a
43041live window may even entail the deletion of two internal windows.
43042
43043          ______________________________________
43044         | ______  ____________________________ |
43045         ||      || __________________________ ||
43046         ||      ||| ___________  ___________ |||
43047         ||      ||||           ||           ||||
43048         ||      ||||____W6_____||_____W7____||||
43049         ||      |||____________W4____________|||
43050         ||      || __________________________ ||
43051         ||      |||                          |||
43052         ||      |||                          |||
43053         ||      |||____________W5____________|||
43054         ||__W2__||_____________W3_____________ |
43055         |__________________W1__________________|
43056
43057
43058Deleting W5 in this configuration normally causes the deletion of W3 and
43059W4.  The remaining live windows W2, W6 and W7 are recombined to form a
43060new horizontal combination with parent W1.
43061
43062   Sometimes, however, it makes sense to not delete a parent window like
43063W4.  In particular, a parent window should not be removed when it was
43064used to preserve a combination embedded in a combination of the same
43065type.  Such embeddings make sense to assure that when you split a window
43066and subsequently delete the new window, Emacs reestablishes the layout
43067of the associated frame as it existed before the splitting.
43068
43069   Consider a scenario starting with two live windows W2 and W3 and
43070their parent W1.
43071
43072          ______________________________________
43073         | ____________________________________ |
43074         ||                                    ||
43075         ||                                    ||
43076         ||                                    ||
43077         ||                                    ||
43078         ||                                    ||
43079         ||                                    ||
43080         ||_________________W2_________________||
43081         | ____________________________________ |
43082         ||                                    ||
43083         ||                                    ||
43084         ||_________________W3_________________||
43085         |__________________W1__________________|
43086
43087
43088Split W2 to make a new window W4 as follows.
43089
43090          ______________________________________
43091         | ____________________________________ |
43092         ||                                    ||
43093         ||                                    ||
43094         ||_________________W2_________________||
43095         | ____________________________________ |
43096         ||                                    ||
43097         ||                                    ||
43098         ||_________________W4_________________||
43099         | ____________________________________ |
43100         ||                                    ||
43101         ||                                    ||
43102         ||_________________W3_________________||
43103         |__________________W1__________________|
43104
43105
43106Now, when enlarging a window vertically, Emacs tries to obtain the
43107corresponding space from its lower sibling, provided such a window
43108exists.  In our scenario, enlarging W4 will steal space from W3.
43109
43110          ______________________________________
43111         | ____________________________________ |
43112         ||                                    ||
43113         ||                                    ||
43114         ||_________________W2_________________||
43115         | ____________________________________ |
43116         ||                                    ||
43117         ||                                    ||
43118         ||                                    ||
43119         ||                                    ||
43120         ||_________________W4_________________||
43121         | ____________________________________ |
43122         ||_________________W3_________________||
43123         |__________________W1__________________|
43124
43125
43126Deleting W4 will now give its entire space to W2, including the space
43127earlier stolen from W3.
43128
43129          ______________________________________
43130         | ____________________________________ |
43131         ||                                    ||
43132         ||                                    ||
43133         ||                                    ||
43134         ||                                    ||
43135         ||                                    ||
43136         ||                                    ||
43137         ||                                    ||
43138         ||                                    ||
43139         ||_________________W2_________________||
43140         | ____________________________________ |
43141         ||_________________W3_________________||
43142         |__________________W1__________________|
43143
43144
43145This can be counterintuitive, in particular if W4 were used for
43146displaying a buffer only temporarily (*note Temporary Displays::), and
43147you want to continue working with the initial layout.
43148
43149   The behavior can be fixed by making a new parent window when
43150splitting W2.  The variable described next allows that to be done.
43151
43152 -- User Option: window-combination-limit
43153     This variable controls whether splitting a window shall make a new
43154     parent window.  The following values are recognized:
43155
43156     ‘nil’
43157          This means that the new live window is allowed to share the
43158          existing parent window, if one exists, provided the split
43159          occurs in the same direction as the existing window
43160          combination (otherwise, a new internal window is created
43161          anyway).
43162
43163     ‘window-size’
43164          This means that ‘display-buffer’ makes a new parent window
43165          when it splits a window and is passed a ‘window-height’ or
43166          ‘window-width’ entry in the ALIST argument (*note Buffer
43167          Display Action Functions::).  Otherwise, window splitting
43168          behaves as for a value of ‘nil’.
43169
43170     ‘temp-buffer-resize’
43171          In this case ‘with-temp-buffer-window’ makes a new parent
43172          window when it splits a window and ‘temp-buffer-resize-mode’
43173          is enabled (*note Temporary Displays::).  Otherwise, window
43174          splitting behaves as for ‘nil’.
43175
43176     ‘temp-buffer’
43177          In this case ‘with-temp-buffer-window’ always makes a new
43178          parent window when it splits an existing window (*note
43179          Temporary Displays::).  Otherwise, window splitting behaves as
43180          for ‘nil’.
43181
43182     ‘display-buffer’
43183          This means that when ‘display-buffer’ (*note Choosing
43184          Window::) splits a window it always makes a new parent window.
43185          Otherwise, window splitting behaves as for ‘nil’.
43186
43187     ‘t’
43188          This means that splitting a window always creates a new parent
43189          window.  Thus, if the value of this variable is at all times
43190          ‘t’, then at all times every window tree is a binary tree (a
43191          tree where each window except the root window has exactly one
43192          sibling).
43193
43194     The default is ‘window-size’.  Other values are reserved for future
43195     use.
43196
43197     If, as a consequence of this variable’s setting, ‘split-window’
43198     makes a new parent window, it also calls
43199     ‘set-window-combination-limit’ (see below) on the newly-created
43200     internal window.  This affects how the window tree is rearranged
43201     when the child windows are deleted (see below).
43202
43203   If ‘window-combination-limit’ is ‘t’, splitting W2 in the initial
43204configuration of our scenario would have produced this:
43205
43206          ______________________________________
43207         | ____________________________________ |
43208         || __________________________________ ||
43209         |||                                  |||
43210         |||________________W2________________|||
43211         || __________________________________ ||
43212         |||                                  |||
43213         |||________________W4________________|||
43214         ||_________________W5_________________||
43215         | ____________________________________ |
43216         ||                                    ||
43217         ||                                    ||
43218         ||_________________W3_________________||
43219         |__________________W1__________________|
43220
43221
43222A new internal window W5 has been created; its children are W2 and the
43223new live window W4.  Now, W2 is the only sibling of W4, so enlarging W4
43224will try to shrink W2, leaving W3 unaffected.  Observe that W5
43225represents a vertical combination of two windows embedded in the
43226vertical combination W1.
43227
43228 -- Function: set-window-combination-limit window limit
43229     This function sets the “combination limit” of the window WINDOW to
43230     LIMIT.  This value can be retrieved via the function
43231     ‘window-combination-limit’.  See below for its effects; note that
43232     it is only meaningful for internal windows.  The ‘split-window’
43233     function automatically calls this function, passing it ‘t’ as
43234     LIMIT, provided the value of the variable
43235     ‘window-combination-limit’ is ‘t’ when it is called.
43236
43237 -- Function: window-combination-limit window
43238     This function returns the combination limit for WINDOW.
43239
43240     The combination limit is meaningful only for an internal window.
43241     If it is ‘nil’, then Emacs is allowed to automatically delete
43242     WINDOW, in response to a window deletion, in order to group the
43243     child windows of WINDOW with its sibling windows to form a new
43244     window combination.  If the combination limit is ‘t’, the child
43245     windows of WINDOW are never automatically recombined with its
43246     siblings.
43247
43248     If, in the configuration shown at the beginning of this section,
43249     the combination limit of W4 (the parent window of W6 and W7) is
43250     ‘t’, deleting W5 will not implicitly delete W4 too.
43251
43252   Alternatively, the problems sketched above can be avoided by always
43253resizing all windows in the same combination whenever one of its windows
43254is split or deleted.  This also permits splitting windows that would be
43255otherwise too small for such an operation.
43256
43257 -- User Option: window-combination-resize
43258     If this variable is ‘nil’, ‘split-window’ can only split a window
43259     (denoted by WINDOW) if WINDOW’s screen area is large enough to
43260     accommodate both itself and the new window.
43261
43262     If this variable is ‘t’, ‘split-window’ tries to resize all windows
43263     that are part of the same combination as WINDOW, in order to
43264     accommodate the new window.  In particular, this may allow
43265     ‘split-window’ to succeed even if WINDOW is a fixed-size window or
43266     too small to ordinarily split.  Furthermore, subsequently resizing
43267     or deleting WINDOW may resize all other windows in its combination.
43268
43269     The default is ‘nil’.  Other values are reserved for future use.  A
43270     specific split operation may ignore the value of this variable if
43271     it is affected by a non-‘nil’ value of ‘window-combination-limit’.
43272
43273   To illustrate the effect of ‘window-combination-resize’, consider the
43274following frame layout.
43275
43276          ______________________________________
43277         | ____________________________________ |
43278         ||                                    ||
43279         ||                                    ||
43280         ||                                    ||
43281         ||                                    ||
43282         ||_________________W2_________________||
43283         | ____________________________________ |
43284         ||                                    ||
43285         ||                                    ||
43286         ||                                    ||
43287         ||                                    ||
43288         ||_________________W3_________________||
43289         |__________________W1__________________|
43290
43291
43292If ‘window-combination-resize’ is ‘nil’, splitting window W3 leaves the
43293size of W2 unchanged:
43294
43295          ______________________________________
43296         | ____________________________________ |
43297         ||                                    ||
43298         ||                                    ||
43299         ||                                    ||
43300         ||                                    ||
43301         ||_________________W2_________________||
43302         | ____________________________________ |
43303         ||                                    ||
43304         ||_________________W3_________________||
43305         | ____________________________________ |
43306         ||                                    ||
43307         ||_________________W4_________________||
43308         |__________________W1__________________|
43309
43310
43311If ‘window-combination-resize’ is ‘t’, splitting W3 instead leaves all
43312three live windows with approximately the same height:
43313
43314          ______________________________________
43315         | ____________________________________ |
43316         ||                                    ||
43317         ||                                    ||
43318         ||_________________W2_________________||
43319         | ____________________________________ |
43320         ||                                    ||
43321         ||                                    ||
43322         ||_________________W3_________________||
43323         | ____________________________________ |
43324         ||                                    ||
43325         ||                                    ||
43326         ||_________________W4_________________||
43327         |__________________W1__________________|
43328
43329
43330Deleting any of the live windows W2, W3 or W4 will distribute its space
43331proportionally among the two remaining live windows.
43332
43333
43334File: elisp.info,  Node: Selecting Windows,  Next: Cyclic Window Ordering,  Prev: Recombining Windows,  Up: Windows
43335
4333628.9 Selecting Windows
43337======================
43338
43339 -- Function: select-window window &optional norecord
43340     This function makes WINDOW the selected window and the window
43341     selected within its frame (*note Basic Windows::), and selects that
43342     frame.  It also makes WINDOW’s buffer (*note Buffers and Windows::)
43343     current and sets that buffer’s value of ‘point’ to the value of
43344     ‘window-point’ (*note Window Point::) in WINDOW.  WINDOW must be a
43345     live window.  The return value is WINDOW.
43346
43347     By default, this function also moves WINDOW’s buffer to the front
43348     of the buffer list (*note Buffer List::) and makes WINDOW the most
43349     recently selected window.  If the optional argument NORECORD is
43350     non-‘nil’, these additional actions are omitted.
43351
43352     In addition, this function by default also tells the display engine
43353     to update the display of WINDOW when its frame gets redisplayed the
43354     next time.  If NORECORD is non-‘nil’, such updates are usually not
43355     performed.  If, however, NORECORD equals the special symbol
43356     ‘mark-for-redisplay’, the additional actions mentioned above are
43357     omitted but WINDOW will be nevertheless updated.
43358
43359     Note that sometimes selecting a window is not enough to show it, or
43360     make its frame the top-most frame on display: you may also need to
43361     raise the frame or make sure input focus is directed to that frame.
43362     *Note Input Focus::.
43363
43364   For historical reasons, Emacs does not run a separate hook whenever a
43365window gets selected.  Applications and internal routines often
43366temporarily select a window to perform a few actions on it.  They do
43367that either to simplify coding—because many functions by default operate
43368on the selected window when no WINDOW argument is specified—or because
43369some functions did not (and still do not) take a window as argument and
43370always operate(d) on the selected window instead.  Running a hook every
43371time a window gets selected for a short time and once more when the
43372previously selected window gets restored is not useful.
43373
43374   However, when its NORECORD argument is ‘nil’, ‘select-window’ updates
43375the buffer list and thus indirectly runs the normal hook
43376‘buffer-list-update-hook’ (*note Buffer List::).  Consequently, that
43377hook provides one way to run a function whenever a window gets selected
43378more “permanently”.
43379
43380   Since ‘buffer-list-update-hook’ is also run by functions that are not
43381related to window management, it will usually make sense to save the
43382value of the selected window somewhere and compare it with the value of
43383‘selected-window’ while running that hook.  Also, to avoid false
43384positives when using ‘buffer-list-update-hook’, it is good practice that
43385every ‘select-window’ call supposed to select a window only temporarily
43386passes a non-‘nil’ NORECORD argument.  If possible, the macro
43387‘with-selected-window’ (see below) should be used in such cases.
43388
43389   Emacs also runs the hook ‘window-selection-change-functions’ whenever
43390the redisplay routine detects that another window has been selected
43391since last redisplay.  *Note Window Hooks::, for a detailed explanation.
43392‘window-state-change-functions’ (described in the same section) is
43393another abnormal hook run after a different window has been selected but
43394is triggered by other window changes as well.
43395
43396   The sequence of calls to ‘select-window’ with a non-‘nil’ NORECORD
43397argument determines an ordering of windows by their selection time.  The
43398function ‘get-lru-window’ can be used to retrieve the least recently
43399selected live window (*note Cyclic Window Ordering::).
43400
43401 -- Macro: save-selected-window forms...
43402     This macro records the selected frame, as well as the selected
43403     window of each frame, executes FORMS in sequence, then restores the
43404     earlier selected frame and windows.  It also saves and restores the
43405     current buffer.  It returns the value of the last form in FORMS.
43406
43407     This macro does not save or restore anything about the sizes,
43408     arrangement or contents of windows; therefore, if FORMS change
43409     them, the change persists.  If the previously selected window of
43410     some frame is no longer live at the time of exit from FORMS, that
43411     frame’s selected window is left alone.  If the previously selected
43412     window is no longer live, then whatever window is selected at the
43413     end of FORMS remains selected.  The current buffer is restored if
43414     and only if it is still live when exiting FORMS.
43415
43416     This macro changes neither the ordering of recently selected
43417     windows nor the buffer list.
43418
43419 -- Macro: with-selected-window window forms...
43420     This macro selects WINDOW, executes FORMS in sequence, then
43421     restores the previously selected window and current buffer.  The
43422     ordering of recently selected windows and the buffer list remain
43423     unchanged unless you deliberately change them within FORMS; for
43424     example, by calling ‘select-window’ with argument NORECORD ‘nil’.
43425     Hence, this macro is the preferred way to temporarily work with
43426     WINDOW as the selected window without needlessly running
43427     ‘buffer-list-update-hook’.
43428
43429 -- Function: frame-selected-window &optional frame
43430     This function returns the window on FRAME that is selected within
43431     that frame.  FRAME should be a live frame; if omitted or ‘nil’, it
43432     defaults to the selected frame.
43433
43434 -- Function: set-frame-selected-window frame window &optional norecord
43435     This function makes WINDOW the window selected within the frame
43436     FRAME.  FRAME should be a live frame; if ‘nil’, it defaults to the
43437     selected frame.  WINDOW should be a live window; if ‘nil’, it
43438     defaults to the selected window.
43439
43440     If FRAME is the selected frame, this makes WINDOW the selected
43441     window.
43442
43443     If the optional argument NORECORD is non-‘nil’, this function does
43444     not alter the list of most recently selected windows, nor the
43445     buffer list.
43446
43447 -- Function: window-use-time &optional window
43448     This functions returns the use time of window WINDOW.  WINDOW must
43449     be a live window and defaults to the selected one.
43450
43451     The “use time” of a window is not really a time value, but an
43452     integer that does increase monotonically with each call of
43453     ‘select-window’ with a ‘nil’ NORECORD argument.  The window with
43454     the lowest use time is usually called the least recently used
43455     window while the window with the highest use time is called the
43456     most recently used one (*note Cyclic Window Ordering::).
43457
43458
43459File: elisp.info,  Node: Cyclic Window Ordering,  Next: Buffers and Windows,  Prev: Selecting Windows,  Up: Windows
43460
4346128.10 Cyclic Ordering of Windows
43462================================
43463
43464When you use the command ‘C-x o’ (‘other-window’) to select some other
43465window, it moves through live windows in a specific order.  For any
43466given configuration of windows, this order never varies.  It is called
43467the “cyclic ordering of windows”.
43468
43469   The ordering is determined by a depth-first traversal of each frame’s
43470window tree, retrieving the live windows which are the leaf nodes of the
43471tree (*note Windows and Frames::).  If the minibuffer is active, the
43472minibuffer window is included too.  The ordering is cyclic, so the last
43473window in the sequence is followed by the first one.
43474
43475 -- Function: next-window &optional window minibuf all-frames
43476     This function returns a live window, the one following WINDOW in
43477     the cyclic ordering of windows.  WINDOW should be a live window; if
43478     omitted or ‘nil’, it defaults to the selected window.
43479
43480     The optional argument MINIBUF specifies whether minibuffer windows
43481     should be included in the cyclic ordering.  Normally, when MINIBUF
43482     is ‘nil’, a minibuffer window is included only if it is currently
43483     active; this matches the behavior of ‘C-x o’.  (Note that a
43484     minibuffer window is active as long as its minibuffer is in use;
43485     see *note Minibuffers::).
43486
43487     If MINIBUF is ‘t’, the cyclic ordering includes all minibuffer
43488     windows.  If MINIBUF is neither ‘t’ nor ‘nil’, minibuffer windows
43489     are not included even if they are active.
43490
43491     The optional argument ALL-FRAMES specifies which frames to
43492     consider:
43493
43494        • ‘nil’ means to consider windows on WINDOW’s frame.  If the
43495          minibuffer window is considered (as specified by the MINIBUF
43496          argument), then frames that share the minibuffer window are
43497          considered too.
43498
43499        • ‘t’ means to consider windows on all existing frames.
43500
43501        • ‘visible’ means to consider windows on all visible frames.
43502
43503        • 0 means to consider windows on all visible or iconified
43504          frames.
43505
43506        • A frame means to consider windows on that specific frame.
43507
43508        • Anything else means to consider windows on WINDOW’s frame, and
43509          no others.
43510
43511     If more than one frame is considered, the cyclic ordering is
43512     obtained by appending the orderings for those frames, in the same
43513     order as the list of all live frames (*note Finding All Frames::).
43514
43515 -- Function: previous-window &optional window minibuf all-frames
43516     This function returns a live window, the one preceding WINDOW in
43517     the cyclic ordering of windows.  The other arguments are handled
43518     like in ‘next-window’.
43519
43520 -- Command: other-window count &optional all-frames
43521     This function selects a live window, one COUNT places from the
43522     selected window in the cyclic ordering of windows.  If COUNT is a
43523     positive number, it skips COUNT windows forwards; if COUNT is
43524     negative, it skips −COUNT windows backwards; if COUNT is zero, that
43525     simply re-selects the selected window.  When called interactively,
43526     COUNT is the numeric prefix argument.
43527
43528     The optional argument ALL-FRAMES has the same meaning as in
43529     ‘next-window’, like a ‘nil’ MINIBUF argument to ‘next-window’.
43530
43531     This function does not select a window that has a non-‘nil’
43532     ‘no-other-window’ window parameter (*note Window Parameters::),
43533     provided that ‘ignore-window-parameters’ is ‘nil’.
43534
43535     If the ‘other-window’ parameter of the selected window is a
43536     function, and ‘ignore-window-parameters’ is ‘nil’, that function
43537     will be called with the arguments COUNT and ALL-FRAMES instead of
43538     the normal operation of this function.
43539
43540 -- Function: walk-windows fun &optional minibuf all-frames
43541     This function calls the function FUN once for each live window,
43542     with the window as the argument.
43543
43544     It follows the cyclic ordering of windows.  The optional arguments
43545     MINIBUF and ALL-FRAMES specify the set of windows included; these
43546     have the same arguments as in ‘next-window’.  If ALL-FRAMES
43547     specifies a frame, the first window walked is the first window on
43548     that frame (the one returned by ‘frame-first-window’), not
43549     necessarily the selected window.
43550
43551     If FUN changes the window configuration by splitting or deleting
43552     windows, that does not alter the set of windows walked, which is
43553     determined prior to calling FUN for the first time.
43554
43555 -- Function: one-window-p &optional no-mini all-frames
43556     This function returns ‘t’ if the selected window is the only live
43557     window, and ‘nil’ otherwise.
43558
43559     If the minibuffer window is active, it is normally considered (so
43560     that this function returns ‘nil’).  However, if the optional
43561     argument NO-MINI is non-‘nil’, the minibuffer window is ignored
43562     even if active.  The optional argument ALL-FRAMES has the same
43563     meaning as for ‘next-window’.
43564
43565   The following functions return a window which satisfies some
43566criterion, without selecting it:
43567
43568 -- Function: get-lru-window &optional all-frames dedicated not-selected
43569     This function returns a live window which is heuristically the
43570     least recently used.  The optional argument ALL-FRAMES has the same
43571     meaning as in ‘next-window’.
43572
43573     If any full-width windows are present, only those windows are
43574     considered.  A minibuffer window is never a candidate.  A dedicated
43575     window (*note Dedicated Windows::) is never a candidate unless the
43576     optional argument DEDICATED is non-‘nil’.  The selected window is
43577     never returned, unless it is the only candidate.  However, if the
43578     optional argument NOT-SELECTED is non-‘nil’, this function returns
43579     ‘nil’ in that case.
43580
43581 -- Function: get-mru-window &optional all-frames dedicated not-selected
43582     This function is like ‘get-lru-window’, but it returns the most
43583     recently used window instead.  The meaning of the arguments is the
43584     same as described for ‘get-lru-window’.
43585
43586 -- Function: get-largest-window &optional all-frames dedicated
43587          not-selected
43588     This function returns the window with the largest area (height
43589     times width).  The optional argument ALL-FRAMES specifies the
43590     windows to search, and has the same meaning as in ‘next-window’.
43591
43592     A minibuffer window is never a candidate.  A dedicated window
43593     (*note Dedicated Windows::) is never a candidate unless the
43594     optional argument DEDICATED is non-‘nil’.  The selected window is
43595     not a candidate if the optional argument NOT-SELECTED is non-‘nil’.
43596     If the optional argument NOT-SELECTED is non-‘nil’ and the selected
43597     window is the only candidate, this function returns ‘nil’.
43598
43599     If there are two candidate windows of the same size, this function
43600     prefers the one that comes first in the cyclic ordering of windows,
43601     starting from the selected window.
43602
43603 -- Function: get-window-with-predicate predicate &optional minibuf
43604          all-frames default
43605     This function calls the function PREDICATE for each of the windows
43606     in the cyclic order of windows in turn, passing it the window as an
43607     argument.  If the predicate returns non-‘nil’ for any window, this
43608     function stops and returns that window.  If no such window is
43609     found, the return value is DEFAULT (which defaults to ‘nil’).
43610
43611     The optional arguments MINIBUF and ALL-FRAMES specify the windows
43612     to search, and have the same meanings as in ‘next-window’.
43613
43614
43615File: elisp.info,  Node: Buffers and Windows,  Next: Switching Buffers,  Prev: Cyclic Window Ordering,  Up: Windows
43616
4361728.11 Buffers and Windows
43618=========================
43619
43620This section describes low-level functions for examining and setting the
43621contents of windows.  *Note Switching Buffers::, for higher-level
43622functions for displaying a specific buffer in a window.
43623
43624 -- Function: window-buffer &optional window
43625     This function returns the buffer that WINDOW is displaying.  If
43626     WINDOW is omitted or ‘nil’ it defaults to the selected window.  If
43627     WINDOW is an internal window, this function returns ‘nil’.
43628
43629 -- Function: set-window-buffer window buffer-or-name &optional
43630          keep-margins
43631     This function makes WINDOW display BUFFER-OR-NAME.  WINDOW should
43632     be a live window; if ‘nil’, it defaults to the selected window.
43633     BUFFER-OR-NAME should be a buffer, or the name of an existing
43634     buffer.  This function does not change which window is selected,
43635     nor does it directly change which buffer is current (*note Current
43636     Buffer::).  Its return value is ‘nil’.
43637
43638     If WINDOW is “strongly dedicated” to a buffer and BUFFER-OR-NAME
43639     does not specify that buffer, this function signals an error.
43640     *Note Dedicated Windows::.
43641
43642     By default, this function resets WINDOW’s position, display
43643     margins, fringe widths, and scroll bar settings, based on the local
43644     variables in the specified buffer.  However, if the optional
43645     argument KEEP-MARGINS is non-‘nil’, it leaves WINDOW’s display
43646     margins, fringes and scroll bar settings alone.
43647
43648     When writing an application, you should normally use
43649     ‘display-buffer’ (*note Choosing Window::) or the higher-level
43650     functions described in *note Switching Buffers::, instead of
43651     calling ‘set-window-buffer’ directly.
43652
43653     This runs ‘window-scroll-functions’, followed by
43654     ‘window-configuration-change-hook’.  *Note Window Hooks::.
43655
43656 -- Variable: buffer-display-count
43657     This buffer-local variable records the number of times a buffer has
43658     been displayed in a window.  It is incremented each time
43659     ‘set-window-buffer’ is called for the buffer.
43660
43661 -- Variable: buffer-display-time
43662     This buffer-local variable records the time at which a buffer was
43663     last displayed in a window.  The value is ‘nil’ if the buffer has
43664     never been displayed.  It is updated each time ‘set-window-buffer’
43665     is called for the buffer, with the value returned by ‘current-time’
43666     (*note Time of Day::).
43667
43668 -- Function: get-buffer-window &optional buffer-or-name all-frames
43669     This function returns the first window displaying BUFFER-OR-NAME in
43670     the cyclic ordering of windows, starting from the selected window
43671     (*note Cyclic Window Ordering::).  If no such window exists, the
43672     return value is ‘nil’.
43673
43674     BUFFER-OR-NAME should be a buffer or the name of a buffer; if
43675     omitted or ‘nil’, it defaults to the current buffer.  The optional
43676     argument ALL-FRAMES specifies which windows to consider:
43677
43678        • ‘t’ means consider windows on all existing frames.
43679        • ‘visible’ means consider windows on all visible frames.
43680        • 0 means consider windows on all visible or iconified frames.
43681        • A frame means consider windows on that frame only.
43682        • Any other value means consider windows on the selected frame.
43683
43684     Note that these meanings differ slightly from those of the
43685     ALL-FRAMES argument to ‘next-window’ (*note Cyclic Window
43686     Ordering::).  This function may be changed in a future version of
43687     Emacs to eliminate this discrepancy.
43688
43689 -- Function: get-buffer-window-list &optional buffer-or-name minibuf
43690          all-frames
43691     This function returns a list of all windows currently displaying
43692     BUFFER-OR-NAME.  BUFFER-OR-NAME should be a buffer or the name of
43693     an existing buffer.  If omitted or ‘nil’, it defaults to the
43694     current buffer.  If the currently selected window displays
43695     BUFFER-OR-NAME, it will be the first in the list returned by this
43696     function.
43697
43698     The arguments MINIBUF and ALL-FRAMES have the same meanings as in
43699     the function ‘next-window’ (*note Cyclic Window Ordering::).  Note
43700     that the ALL-FRAMES argument does _not_ behave exactly like in
43701     ‘get-buffer-window’.
43702
43703 -- Command: replace-buffer-in-windows &optional buffer-or-name
43704     This command replaces BUFFER-OR-NAME with some other buffer, in all
43705     windows displaying it.  BUFFER-OR-NAME should be a buffer, or the
43706     name of an existing buffer; if omitted or ‘nil’, it defaults to the
43707     current buffer.
43708
43709     The replacement buffer in each window is chosen via
43710     ‘switch-to-prev-buffer’ (*note Window History::).  Any dedicated
43711     window displaying BUFFER-OR-NAME is deleted if possible (*note
43712     Dedicated Windows::).  If such a window is the only window on its
43713     frame and there are other frames on the same terminal, the frame is
43714     deleted as well.  If the dedicated window is the only window on the
43715     only frame on its terminal, the buffer is replaced anyway.
43716
43717
43718File: elisp.info,  Node: Switching Buffers,  Next: Displaying Buffers,  Prev: Buffers and Windows,  Up: Windows
43719
4372028.12 Switching to a Buffer in a Window
43721=======================================
43722
43723This section describes high-level functions for switching to a specified
43724buffer in some window.  In general, “switching to a buffer” means to (1)
43725show the buffer in some window, (2) make that window the selected window
43726(and its frame the selected frame), and (3) make the buffer the current
43727buffer.
43728
43729   Do _not_ use these functions to make a buffer temporarily current
43730just so a Lisp program can access or modify it.  They have side-effects,
43731such as changing window histories (*note Window History::), which will
43732surprise the user if used that way.  If you want to make a buffer
43733current to modify it in Lisp, use ‘with-current-buffer’,
43734‘save-current-buffer’, or ‘set-buffer’.  *Note Current Buffer::.
43735
43736 -- Command: switch-to-buffer buffer-or-name &optional norecord
43737          force-same-window
43738     This command attempts to display BUFFER-OR-NAME in the selected
43739     window and make it the current buffer.  It is often used
43740     interactively (as the binding of ‘C-x b’), as well as in Lisp
43741     programs.  The return value is the buffer switched to.
43742
43743     If BUFFER-OR-NAME is ‘nil’, it defaults to the buffer returned by
43744     ‘other-buffer’ (*note Buffer List::).  If BUFFER-OR-NAME is a
43745     string that is not the name of any existing buffer, this function
43746     creates a new buffer with that name; the new buffer’s major mode is
43747     determined by the variable ‘major-mode’ (*note Major Modes::).
43748
43749     Normally, the specified buffer is put at the front of the buffer
43750     list—both the global buffer list and the selected frame’s buffer
43751     list (*note Buffer List::).  However, this is not done if the
43752     optional argument NORECORD is non-‘nil’.
43753
43754     Sometimes, the selected window may not be suitable for displaying
43755     the buffer.  This happens if the selected window is a minibuffer
43756     window, or if the selected window is strongly dedicated to its
43757     buffer (*note Dedicated Windows::).  In such cases, the command
43758     normally tries to display the buffer in some other window, by
43759     invoking ‘pop-to-buffer’ (see below).
43760
43761     If the optional argument FORCE-SAME-WINDOW is non-‘nil’ and the
43762     selected window is not suitable for displaying the buffer, this
43763     function always signals an error when called non-interactively.  In
43764     interactive use, if the selected window is a minibuffer window,
43765     this function will try to use some other window instead.  If the
43766     selected window is strongly dedicated to its buffer, the option
43767     ‘switch-to-buffer-in-dedicated-window’ described next can be used
43768     to proceed.
43769
43770 -- User Option: switch-to-buffer-in-dedicated-window
43771     This option, if non-‘nil’, allows ‘switch-to-buffer’ to proceed
43772     when called interactively and the selected window is strongly
43773     dedicated to its buffer.
43774
43775     The following values are respected:
43776
43777     ‘nil’
43778          Disallows switching and signals an error as in non-interactive
43779          use.
43780
43781     ‘prompt’
43782          Prompts the user whether to allow switching.
43783
43784     ‘pop’
43785          Invokes ‘pop-to-buffer’ to proceed.
43786
43787     ‘t’
43788          Marks the selected window as non-dedicated and proceeds.
43789
43790     This option does not affect non-interactive calls of
43791     ‘switch-to-buffer’.
43792
43793   By default, ‘switch-to-buffer’ tries to preserve ‘window-point’.
43794This behavior can be tuned using the following option.
43795
43796 -- User Option: switch-to-buffer-preserve-window-point
43797     If this variable is ‘nil’, ‘switch-to-buffer’ displays the buffer
43798     specified by BUFFER-OR-NAME at the position of that buffer’s
43799     ‘point’.  If this variable is ‘already-displayed’, it tries to
43800     display the buffer at its previous position in the selected window,
43801     provided the buffer is currently displayed in some other window on
43802     any visible or iconified frame.  If this variable is ‘t’,
43803     ‘switch-to-buffer’ unconditionally tries to display the buffer at
43804     its previous position in the selected window.
43805
43806     This variable is ignored if the buffer is already displayed in the
43807     selected window or never appeared in it before, or if
43808     ‘switch-to-buffer’ calls ‘pop-to-buffer’ to display the buffer.
43809
43810 -- User Option: switch-to-buffer-obey-display-actions
43811     If this variable is non-‘nil’, ‘switch-to-buffer’ respects display
43812     actions specified by ‘display-buffer-overriding-action’,
43813     ‘display-buffer-alist’ and other display related variables.
43814
43815   The next two commands are similar to ‘switch-to-buffer’, except for
43816the described features.
43817
43818 -- Command: switch-to-buffer-other-window buffer-or-name &optional
43819          norecord
43820     This function displays the buffer specified by BUFFER-OR-NAME in
43821     some window other than the selected window.  It uses the function
43822     ‘pop-to-buffer’ internally (see below).
43823
43824     If the selected window already displays the specified buffer, it
43825     continues to do so, but another window is nonetheless found to
43826     display it as well.
43827
43828     The BUFFER-OR-NAME and NORECORD arguments have the same meanings as
43829     in ‘switch-to-buffer’.
43830
43831 -- Command: switch-to-buffer-other-frame buffer-or-name &optional
43832          norecord
43833     This function displays the buffer specified by BUFFER-OR-NAME in a
43834     new frame.  It uses the function ‘pop-to-buffer’ internally (see
43835     below).
43836
43837     If the specified buffer is already displayed in another window, in
43838     any frame on the current terminal, this switches to that window
43839     instead of creating a new frame.  However, the selected window is
43840     never used for this.
43841
43842     The BUFFER-OR-NAME and NORECORD arguments have the same meanings as
43843     in ‘switch-to-buffer’.
43844
43845   The above commands use the function ‘pop-to-buffer’, which flexibly
43846displays a buffer in some window and selects that window for editing.
43847In turn, ‘pop-to-buffer’ uses ‘display-buffer’ for displaying the
43848buffer.  Hence, all the variables affecting ‘display-buffer’ will affect
43849it as well.  *Note Choosing Window::, for the documentation of
43850‘display-buffer’.
43851
43852 -- Command: pop-to-buffer buffer-or-name &optional action norecord
43853     This function makes BUFFER-OR-NAME the current buffer and displays
43854     it in some window, preferably not the window currently selected.
43855     It then selects the displaying window.  If that window is on a
43856     different graphical frame, that frame is given input focus if
43857     possible (*note Input Focus::).
43858
43859     If BUFFER-OR-NAME is ‘nil’, it defaults to the buffer returned by
43860     ‘other-buffer’ (*note Buffer List::).  If BUFFER-OR-NAME is a
43861     string that is not the name of any existing buffer, this function
43862     creates a new buffer with that name; the new buffer’s major mode is
43863     determined by the variable ‘major-mode’ (*note Major Modes::).  In
43864     any case, that buffer is made current and returned, even when no
43865     suitable window was found to display it.
43866
43867     If ACTION is non-‘nil’, it should be a display action to pass to
43868     ‘display-buffer’ (*note Choosing Window::).  Alternatively, a
43869     non-‘nil’, non-list value means to pop to a window other than the
43870     selected one—even if the buffer is already displayed in the
43871     selected window.
43872
43873     Like ‘switch-to-buffer’, this function updates the buffer list
43874     unless NORECORD is non-‘nil’.
43875
43876
43877File: elisp.info,  Node: Displaying Buffers,  Next: Window History,  Prev: Switching Buffers,  Up: Windows
43878
4387928.13 Displaying a Buffer in a Suitable Window
43880==============================================
43881
43882This section describes lower-level functions Emacs uses to find or
43883create a window for displaying a specified buffer.  The common workhorse
43884of these functions is ‘display-buffer’ which eventually handles all
43885incoming requests for buffer display (*note Choosing Window::).
43886
43887   ‘display-buffer’ delegates the task of finding a suitable window to
43888so-called action functions (*note Buffer Display Action Functions::).
43889First, ‘display-buffer’ compiles a so-called action alist—a special
43890association list that action functions can use to fine-tune their
43891behavior.  Then it passes that alist on to each action function it calls
43892(*note Buffer Display Action Alists::).
43893
43894   The behavior of ‘display-buffer’ is highly customizable.  To
43895understand how customizations are used in practice, you may wish to
43896study examples illustrating the order of precedence which
43897‘display-buffer’ uses to call action functions (*note Precedence of
43898Action Functions::).  To avoid conflicts between Lisp programs calling
43899‘display-buffer’ and user customizations of its behavior, it may make
43900sense to follow a number of guidelines which are sketched in the final
43901part of this section (*note The Zen of Buffer Display::).
43902
43903* Menu:
43904
43905* Choosing Window::         How to choose a window for displaying a buffer.
43906* Buffer Display Action Functions:: Support functions for buffer display.
43907* Buffer Display Action Alists:: Alists for fine-tuning buffer display.
43908* Choosing Window Options:: Extra options affecting how buffers are displayed.
43909* Precedence of Action Functions:: Examples to explain the precedence of
43910                              action functions.
43911* The Zen of Buffer Display:: How to avoid that buffers get lost in between
43912                              windows.
43913
43914
43915File: elisp.info,  Node: Choosing Window,  Next: Buffer Display Action Functions,  Up: Displaying Buffers
43916
4391728.13.1 Choosing a Window for Displaying a Buffer
43918-------------------------------------------------
43919
43920The command ‘display-buffer’ flexibly chooses a window for display, and
43921displays a specified buffer in that window.  It can be called
43922interactively, via the key binding ‘C-x 4 C-o’.  It is also used as a
43923subroutine by many functions and commands, including ‘switch-to-buffer’
43924and ‘pop-to-buffer’ (*note Switching Buffers::).
43925
43926   This command performs several complex steps to find a window to
43927display in.  These steps are described by means of “display actions”,
43928which have the form ‘(FUNCTIONS . ALIST)’.  Here, FUNCTIONS is either a
43929single function or a list of functions, referred to as “action
43930functions” (*note Buffer Display Action Functions::); and ALIST is an
43931association list, referred to as “action alist” (*note Buffer Display
43932Action Alists::).  *Note The Zen of Buffer Display::, for samples of
43933display actions.
43934
43935   An action function accepts two arguments: the buffer to display and
43936an action alist.  It attempts to display the buffer in some window,
43937picking or creating a window according to its own criteria.  If
43938successful, it returns the window; otherwise, it returns ‘nil’.
43939
43940   ‘display-buffer’ works by combining display actions from several
43941sources, and calling the action functions in turn, until one of them
43942manages to display the buffer and returns a non-‘nil’ value.
43943
43944 -- Command: display-buffer buffer-or-name &optional action frame
43945     This command makes BUFFER-OR-NAME appear in some window, without
43946     selecting the window or making the buffer current.  The argument
43947     BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
43948     The return value is the window chosen to display the buffer, or
43949     ‘nil’ if no suitable window was found.
43950
43951     The optional argument ACTION, if non-‘nil’, should normally be a
43952     display action (described above).  ‘display-buffer’ builds a list
43953     of action functions and an action alist, by consolidating display
43954     actions from the following sources (in order of their precedence,
43955     from highest to lowest):
43956
43957        • The variable ‘display-buffer-overriding-action’.
43958
43959        • The user option ‘display-buffer-alist’.
43960
43961        • The ACTION argument.
43962
43963        • The user option ‘display-buffer-base-action’.
43964
43965        • The constant ‘display-buffer-fallback-action’.
43966
43967     In practice this means that ‘display-buffer’ builds a list of all
43968     action functions specified by these display actions.  The first
43969     element of this list is the first action function specified by
43970     ‘display-buffer-overriding-action’, if any.  Its last element is
43971     ‘display-buffer-pop-up-frame’—the last action function specified by
43972     ‘display-buffer-fallback-action’.  Duplicates are not removed from
43973     this list—hence one and the same action function may be called
43974     multiple times during one call of ‘display-buffer’.
43975
43976     ‘display-buffer’ calls the action functions specified by this list
43977     in turn, passing the buffer as the first argument and the combined
43978     action alist as the second argument, until one of the functions
43979     returns non-‘nil’.  *Note Precedence of Action Functions::, for
43980     examples how display actions specified by different sources are
43981     processed by ‘display-buffer’.
43982
43983     Note that the second argument is always the list of _all_ action
43984     alist entries specified by the sources named above.  Hence, the
43985     first element of that list is the first action alist entry
43986     specified by ‘display-buffer-overriding-action’, if any.  Its last
43987     element is the last alist entry of ‘display-buffer-base-action’, if
43988     any (the action alist of ‘display-buffer-fallback-action’ is
43989     empty).
43990
43991     Note also, that the combined action alist may contain duplicate
43992     entries and entries for the same key with different values.  As a
43993     rule, action functions always use the first association of a key
43994     they find.  Hence, the association an action function uses is not
43995     necessarily the association provided by the display action that
43996     specified that action function,
43997
43998     The argument ACTION can also have a non-‘nil’, non-list value.
43999     This has the special meaning that the buffer should be displayed in
44000     a window other than the selected one, even if the selected window
44001     is already displaying it.  If called interactively with a prefix
44002     argument, ACTION is ‘t’.  Lisp programs should always supply a list
44003     value.
44004
44005     The optional argument FRAME, if non-‘nil’, specifies which frames
44006     to check when deciding whether the buffer is already displayed.  It
44007     is equivalent to adding an element ‘(reusable-frames . FRAME)’ to
44008     the action alist of ACTION (*note Buffer Display Action Alists::).
44009     The FRAME argument is provided for compatibility reasons, Lisp
44010     programs should not use it.
44011
44012 -- Variable: display-buffer-overriding-action
44013     The value of this variable should be a display action, which is
44014     treated with the highest priority by ‘display-buffer’.  The default
44015     value is an empty display action, i.e., ‘(nil . nil)’.
44016
44017 -- User Option: display-buffer-alist
44018     The value of this option is an alist mapping conditions to display
44019     actions.  Each condition may be either a regular expression
44020     matching a buffer name or a function that takes two arguments: a
44021     buffer name and the ACTION argument passed to ‘display-buffer’.  If
44022     either the name of the buffer passed to ‘display-buffer’ matches a
44023     regular expression in this alist, or the function specified by a
44024     condition returns non-‘nil’, then ‘display-buffer’ uses the
44025     corresponding display action to display the buffer.
44026
44027 -- User Option: display-buffer-base-action
44028     The value of this option should be a display action.  This option
44029     can be used to define a standard display action for calls to
44030     ‘display-buffer’.
44031
44032 -- Constant: display-buffer-fallback-action
44033     This display action specifies the fallback behavior for
44034     ‘display-buffer’ if no other display actions are given.
44035
44036
44037File: elisp.info,  Node: Buffer Display Action Functions,  Next: Buffer Display Action Alists,  Prev: Choosing Window,  Up: Displaying Buffers
44038
4403928.13.2 Action Functions for Buffer Display
44040-------------------------------------------
44041
44042An “action function” is a function ‘display-buffer’ calls for choosing a
44043window to display a buffer.  Action functions take two arguments:
44044BUFFER, the buffer to display, and ALIST, an action alist (*note Buffer
44045Display Action Alists::).  They are supposed to return a window
44046displaying BUFFER if they succeed and ‘nil’ if they fail.
44047
44048   The following basic action functions are defined in Emacs.
44049
44050 -- Function: display-buffer-same-window buffer alist
44051     This function tries to display BUFFER in the selected window.  It
44052     fails if the selected window is a minibuffer window or is dedicated
44053     to another buffer (*note Dedicated Windows::).  It also fails if
44054     ALIST has a non-‘nil’ ‘inhibit-same-window’ entry.
44055
44056 -- Function: display-buffer-reuse-window buffer alist
44057     This function tries to display BUFFER by finding a window that is
44058     already displaying it.  Windows on the selected frame are preferred
44059     to windows on other frames.
44060
44061     If ALIST has a non-‘nil’ ‘inhibit-same-window’ entry, the selected
44062     window is not eligible for reuse.  The set of frames to search for
44063     a window already displaying BUFFER can be specified with the help
44064     of the ‘reusable-frames’ action alist entry.  If ALIST contains no
44065     ‘reusable-frames’ entry, this function searches just the selected
44066     frame.
44067
44068     If this function chooses a window on another frame, it makes that
44069     frame visible and, unless ALIST contains an ‘inhibit-switch-frame’
44070     entry, raises that frame if necessary.
44071
44072 -- Function: display-buffer-reuse-mode-window buffer alist
44073     This function tries to display BUFFER by finding a window that is
44074     displaying a buffer in a given mode.
44075
44076     If ALIST contains a ‘mode’ entry, its value specifes a major mode
44077     (a symbol) or a list of major modes.  If ALIST contains no ‘mode’
44078     entry, the current major mode of BUFFER is used instead.  A window
44079     is a candidate if it displays a buffer whose mode derives from one
44080     of the modes specified thusly.
44081
44082     The behavior is also controlled by ALIST entries for
44083     ‘inhibit-same-window’, ‘reusable-frames’ and
44084     ‘inhibit-switch-frame’, like ‘display-buffer-reuse-window’ does.
44085
44086 -- Function: display-buffer-pop-up-window buffer alist
44087     This function tries to display BUFFER by splitting the largest or
44088     least recently-used window (usually located on the selected frame).
44089     It actually performs the split by calling the function specified by
44090     ‘split-window-preferred-function’ (*note Choosing Window
44091     Options::).
44092
44093     The size of the new window can be adjusted by supplying
44094     ‘window-height’ and ‘window-width’ entries in ALIST.  If ALIST
44095     contains a ‘preserve-size’ entry, Emacs will also try to preserve
44096     the size of the new window during future resize operations (*note
44097     Preserving Window Sizes::).
44098
44099     This function fails if no window can be split.  More often than
44100     not, this happens because no window is large enough to allow
44101     splitting.  Setting ‘split-height-threshold’ or
44102     ‘split-width-threshold’ to lower values may help in this regard.
44103     Splitting also fails when the selected frame has an ‘unsplittable’
44104     frame parameter; *note Buffer Parameters::.
44105
44106 -- Function: display-buffer-in-previous-window buffer alist
44107     This function tries to display BUFFER in a window where it was
44108     displayed previously.
44109
44110     If ALIST contains a non-‘nil’ ‘inhibit-same-window’ entry, the
44111     selected window is not eligible for use.  A dedicated window is
44112     usable only if it already shows BUFFER.  If ALIST contains a
44113     ‘previous-window’ entry, the window specified by that entry is
44114     usable even if it never showed BUFFER before.
44115
44116     If ALIST contains a ‘reusable-frames’ entry (*note Buffer Display
44117     Action Alists::), its value determines which frames to search for a
44118     suitable window.  If ALIST contains no ‘reusable-frames’ entry,
44119     this function searches just the selected frame if
44120     ‘display-buffer-reuse-frames’ and ‘pop-up-frames’ are both ‘nil’;
44121     it searches all frames on the current terminal if either of those
44122     variables is non-‘nil’.
44123
44124     If more than one window qualifies as usable according to these
44125     rules, this function makes a choice in the following order of
44126     preference:
44127
44128        • The window specified by any ‘previous-window’ ALIST entry,
44129          provided it is not the selected window.
44130
44131        • A window that showed BUFFER before, provided it is not the
44132          selected window.
44133
44134        • The selected window if it is either specified by a
44135          ‘previous-window’ ALIST entry or showed BUFFER before.
44136
44137 -- Function: display-buffer-use-some-window buffer alist
44138     This function tries to display BUFFER by choosing an existing
44139     window and displaying the buffer in that window.  It can fail if
44140     all windows are dedicated to other buffers (*note Dedicated
44141     Windows::).
44142
44143 -- Function: display-buffer-in-direction buffer alist
44144     This function tries to display BUFFER at a location specified by
44145     ALIST.  For this purpose, ALIST should contain a ‘direction’ entry
44146     whose value is one of ‘left’, ‘above’ (or ‘up’), ‘right’ and
44147     ‘below’ (or ‘down’).  Other values are usually interpreted as
44148     ‘below’.
44149
44150     If ALIST also contains a ‘window’ entry, its value specifies a
44151     reference window.  That value can be a special symbol like ‘main’
44152     which stands for the selected frame’s main window (*note Side
44153     Window Options and Functions::) or ‘root’ standing for the selected
44154     frame’s root window (*note Windows and Frames::).  It can also
44155     specify an arbitrary valid window.  Any other value (or omitting
44156     the ‘window’ entry entirely) means to use the selected window as
44157     reference window.
44158
44159     This function first tries to reuse a window in the specified
44160     direction that already shows BUFFER.  If no such window exists, it
44161     tries to split the reference window in order to produce a new
44162     window in the specified direction.  If this fails as well, it will
44163     try to display BUFFER in an existing window in the specified
44164     direction.  In either case, the window chosen will appear on the
44165     side of the reference window specified by the ‘direction’ entry,
44166     sharing at least one edge with the reference window.
44167
44168     If the reference window is live, the edge the chosen window will
44169     share with it is always the opposite of the one specified by the
44170     ‘direction’ entry.  For example, if the value of the ‘direction’
44171     entry is ‘left’, the chosen window’s right edge coordinate (*note
44172     Coordinates and Windows::) will equal the reference window’s left
44173     edge coordinate.
44174
44175     If the reference window is internal, a reused window must share
44176     with it the edge specified by the ‘direction’ entry.  Hence if, for
44177     example, the reference window is the frame’s root window and the
44178     value of the ‘direction’ entry is ‘left’, a reused window must be
44179     on the left of the frame.  This means that the left edge coordinate
44180     of the chosen window and that of the reference window are the same.
44181
44182     A new window, however, will be created by splitting the reference
44183     window such that the chosen window will share the opposite edge
44184     with the reference window.  In our example, a new root window would
44185     be created with a new live window and the reference window as its
44186     children.  The chosen window’s right edge coordinate would then
44187     equal the left edge coordinate of the reference window.  Its left
44188     edge coordinate would equal the left edge coordinate of the frame’s
44189     new root window.
44190
44191     Four special values for ‘direction’ entries allow to implicitly
44192     specify the selected frame’s main window as the reference window:
44193     ‘leftmost’, ‘top’, ‘rightmost’ and ‘bottom’.  This means that
44194     instead of, for example, ‘(direction . left) (window . main)’ one
44195     can just specify ‘(direction . leftmost)’.  An existing ‘window’
44196     ALIST entry is ignored in such cases.
44197
44198 -- Function: display-buffer-below-selected buffer alist
44199     This function tries to display BUFFER in a window below the
44200     selected window.  If there is a window below the selected one and
44201     that window already displays BUFFER, it reuses that window.
44202
44203     If there is no such window, this function tries to create a new
44204     window by splitting the selected one, and displays BUFFER there.
44205     It will also try to adjust that window’s size provided ALIST
44206     contains a suitable ‘window-height’ or ‘window-width’ entry, see
44207     above.
44208
44209     If splitting the selected window fails and there is a non-dedicated
44210     window below the selected one showing some other buffer, this
44211     function tries to use that window for showing BUFFER.
44212
44213     If ALIST contains a ‘window-min-height’ entry, this function
44214     ensures that the window used is or can become at least as high as
44215     specified by that entry’s value.  Note that this is only a
44216     guarantee.  In order to actually resize the window used, ALIST must
44217     also provide an appropriate ‘window-height’ entry.
44218
44219 -- Function: display-buffer-at-bottom buffer alist
44220     This function tries to display BUFFER in a window at the bottom of
44221     the selected frame.
44222
44223     This either tries to split the window at the bottom of the frame or
44224     the frame’s root window, or to reuse an existing window at the
44225     bottom of the selected frame.
44226
44227 -- Function: display-buffer-pop-up-frame buffer alist
44228     This function creates a new frame, and displays the buffer in that
44229     frame’s window.  It actually performs the frame creation by calling
44230     the function specified in ‘pop-up-frame-function’ (*note Choosing
44231     Window Options::).  If ALIST contains a ‘pop-up-frame-parameters’
44232     entry, the associated value is added to the newly created frame’s
44233     parameters.
44234
44235 -- Function: display-buffer-in-child-frame buffer alist
44236     This function tries to display BUFFER in a child frame (*note Child
44237     Frames::) of the selected frame, either reusing an existing child
44238     frame or by making a new one.  If ALIST has a non-‘nil’
44239     ‘child-frame-parameters’ entry, the corresponding value is an alist
44240     of frame parameters to give the new frame.  A ‘parent-frame’
44241     parameter specifying the selected frame is provided by default.  If
44242     the child frame should become the child of another frame, a
44243     corresponding entry must be added to ALIST.
44244
44245     The appearance of child frames is largely dependent on the
44246     parameters provided via ALIST.  It is advisable to use at least
44247     ratios to specify the size (*note Size Parameters::) and the
44248     position (*note Position Parameters::) of the child frame, and to
44249     add a ‘keep-ratio’ parameter (*note Frame Interaction
44250     Parameters::), in order to make sure that the child frame remains
44251     visible.  For other parameters that should be considered see *note
44252     Child Frames::.
44253
44254 -- Function: display-buffer-use-some-frame buffer alist
44255     This function tries to display BUFFER by finding a frame that meets
44256     a predicate (by default any frame other than the selected frame).
44257
44258     If this function chooses a window on another frame, it makes that
44259     frame visible and, unless ALIST contains an ‘inhibit-switch-frame’
44260     entry, raises that frame if necessary.
44261
44262     If ALIST has a non-‘nil’ ‘frame-predicate’ entry, its value is a
44263     function taking one argument (a frame), returning non-‘nil’ if the
44264     frame is a candidate; this function replaces the default predicate.
44265
44266     If ALIST has a non-‘nil’ ‘inhibit-same-window’ entry, the selected
44267     window is not used; thus if the selected frame has a single window,
44268     it is not used.
44269
44270 -- Function: display-buffer-no-window buffer alist
44271     If ALIST has a non-‘nil’ ‘allow-no-window’ entry, then this
44272     function does not display BUFFER and returns the symbol ‘fail’.
44273     This constitutes the only exception to the convention that an
44274     action function returns either ‘nil’ or a window showing BUFFER.
44275     If ALIST has no such ‘allow-no-window’ entry, this function returns
44276     ‘nil’.
44277
44278     If this function returns ‘fail’, ‘display-buffer’ will skip the
44279     execution of any further display actions and return ‘nil’
44280     immediately.  If this function returns ‘nil’, ‘display-buffer’ will
44281     continue with the next display action, if any.
44282
44283     It is assumed that when a caller of ‘display-buffer’ specifies a
44284     non-‘nil’ ‘allow-no-window’ entry, it is also able to handle a
44285     ‘nil’ return value.
44286
44287   Two other action functions are described in their proper
44288sections—‘display-buffer-in-side-window’ (*note Displaying Buffers in
44289Side Windows::) and ‘display-buffer-in-atom-window’ (*note Atomic
44290Windows::).
44291
44292
44293File: elisp.info,  Node: Buffer Display Action Alists,  Next: Choosing Window Options,  Prev: Buffer Display Action Functions,  Up: Displaying Buffers
44294
4429528.13.3 Action Alists for Buffer Display
44296----------------------------------------
44297
44298An “action alist” is an association list mapping predefined symbols
44299recognized by action functions to values these functions are supposed to
44300interpret accordingly.  In each call, ‘display-buffer’ constructs a new,
44301possibly empty action alist and passes that entire list on to any action
44302function it calls.
44303
44304   By design, action functions are free in their interpretation of
44305action alist entries.  In fact, some entries like ‘allow-no-window’ or
44306‘previous-window’ have a meaning only for one or a few action functions,
44307and are ignored by the rest.  Other entries, like ‘inhibit-same-window’
44308or ‘window-parameters’, are supposed to be respected by most action
44309functions, including those provided by application programs and external
44310packages.
44311
44312   In the previous subsection we have described in detail how individual
44313action functions interpret the action alist entries they care about.
44314Here we give a reference list of all known action alist entries
44315according to their symbols, together with their values and action
44316functions (*note Buffer Display Action Functions::) that recognize them.
44317Throughout this list, the terms “buffer” will refer to the buffer
44318‘display-buffer’ is supposed to display, and “value” refers to the
44319entry’s value.
44320
44321‘inhibit-same-window’
44322     If the value is non-‘nil’, this signals that the selected window
44323     must not be used for displaying the buffer.  All action functions
44324     that (re-)use an existing window should respect this entry.
44325
44326‘previous-window’
44327     The value must specify a window that may have displayed the buffer
44328     previously.  ‘display-buffer-in-previous-window’ will give
44329     preference to such a window provided it is still live and not
44330     dedicated to another buffer.
44331
44332‘mode’
44333     The value is either a major mode or a list of major modes.
44334     ‘display-buffer-reuse-mode-window’ may reuse a window whenever the
44335     value specified by this entry matches the major mode of that
44336     window’s buffer.  Other action functions ignore such entries.
44337
44338‘frame-predicate’
44339     The value must be a function taking one argument (a frame),
44340     supposed to return non-‘nil’ if that frame is a candidate for
44341     displaying the buffer.  This entry is used by
44342     ‘display-buffer-use-some-frame’.
44343
44344‘reusable-frames’
44345     The value specifies the set of frames to search for a window that
44346     can be reused because it already displays the buffer.  It can be
44347     set as follows:
44348
44349        • ‘nil’ means consider only windows on the selected frame.
44350          (Actually, the last frame used that is not a minibuffer-only
44351          frame.)
44352        • ‘t’ means consider windows on all frames.
44353        • ‘visible’ means consider windows on all visible frames.
44354        • 0 means consider windows on all visible or iconified frames.
44355        • A frame means consider windows on that frame only.
44356
44357     Note that the meaning of ‘nil’ differs slightly from that of the
44358     ALL-FRAMES argument to ‘next-window’ (*note Cyclic Window
44359     Ordering::).
44360
44361     A major client of this is ‘display-buffer-reuse-window’, but all
44362     other action functions that try to reuse a window are affected as
44363     well.  ‘display-buffer-in-previous-window’ consults it when
44364     searching for a window that previously displayed the buffer on
44365     another frame.
44366
44367‘inhibit-switch-frame’
44368     A non-‘nil’ value prevents another frame from being raised or
44369     selected, if the window chosen by ‘display-buffer’ is displayed
44370     there.  Primarily affected by this are
44371     ‘display-buffer-use-some-frame’ and ‘display-buffer-reuse-window’.
44372     ‘display-buffer-pop-up-frame’ should be affected as well, but there
44373     is no guarantee that the window manager will comply.
44374
44375‘window-parameters’
44376     The value specifies an alist of window parameters to give the
44377     chosen window.  All action functions that choose a window should
44378     process this entry.
44379
44380‘window-min-height’
44381     The value specifies a minimum height of the window used, in lines.
44382     If a window is not or cannot be made as high as specified by this
44383     entry, the window is not considered for use.  The only client of
44384     this entry is presently ‘display-buffer-below-selected’.
44385
44386     Note that providing such an entry alone does not necessarily make
44387     the window as tall as specified by its value.  To actually resize
44388     an existing window or make a new window as tall as specified by
44389     that value, a ‘window-height’ entry specifying that value should be
44390     provided as well.  Such a ‘window-height’ entry can, however,
44391     specify a completely different value or ask the window height to be
44392     fit to that of its buffer in which case the ‘window-min-height’
44393     entry provides the guaranteed minimum height of the window used.
44394
44395‘window-height’
44396     The value specifies whether and how to adjust the height of the
44397     chosen window and can be one of the following:
44398
44399        • ‘nil’ means to leave the height of the chosen window alone.
44400
44401        • An integer number specifies the desired total height of the
44402          chosen window in lines.
44403
44404        • A floating-point number specifies the fraction of the chosen
44405          window’s desired total height with respect to the total height
44406          of its frame’s root window.
44407
44408        • If the value specifies a function, that function is called
44409          with one argument—the chosen window.  The function is supposed
44410          to adjust the height of the window; its return value is
44411          ignored.  Suitable functions are
44412          ‘shrink-window-if-larger-than-buffer’ and
44413          ‘fit-window-to-buffer’, see *note Resizing Windows::.
44414
44415     By convention, the height of the chosen window is adjusted only if
44416     the window is part of a vertical combination (*note Windows and
44417     Frames::) to avoid changing the height of other, unrelated windows.
44418     Also, this entry should be processed only under certain conditions
44419     which are specified right below this list.
44420
44421‘window-width’
44422     This entry is similar to the ‘window-height’ entry described
44423     before, but used to adjust the chosen window’s width instead.  The
44424     value can be one of the following:
44425
44426        • ‘nil’ means to leave the width of the chosen window alone.
44427
44428        • An integer specifies the desired total width of the chosen
44429          window in columns.
44430
44431        • A floating-point number specifies the fraction of the chosen
44432          window’s desired total width with respect to the total width
44433          of the frame’s root window.
44434
44435        • If the value specifies a function, that function is called
44436          with one argument—the chosen window.  The function is supposed
44437          to adjust the width of the window; its return value is
44438          ignored.
44439
44440     By convention, the width of the chosen window is adjusted only if
44441     the window is part of a horizontal combination (*note Windows and
44442     Frames::) to avoid changing the width of other, unrelated windows.
44443     Also, this entry should be processed under only certain conditions
44444     which are specified right below this list.
44445
44446‘dedicated’
44447     If non-‘nil’, such an entry tells ‘display-buffer’ to mark any
44448     window it creates as dedicated to its buffer (*note Dedicated
44449     Windows::).  It does that by calling ‘set-window-dedicated-p’ with
44450     the chosen window as first argument and the entry’s value as
44451     second.
44452
44453‘preserve-size’
44454     If non-‘nil’ such an entry tells Emacs to preserve the size of the
44455     window chosen (*note Preserving Window Sizes::).  The value should
44456     be either ‘(t . nil)’ to preserve the width of the window,
44457     ‘(nil . t)’ to preserve its height or ‘(t . t)’ to preserve both,
44458     its width and its height.  This entry should be processed only
44459     under certain conditions which are specified right after this list.
44460
44461‘pop-up-frame-parameters’
44462     The value specifies an alist of frame parameters to give a new
44463     frame, if one is created.  ‘display-buffer-pop-up-frame’ is its one
44464     and only addressee.
44465
44466‘parent-frame’
44467     The value specifies the parent frame to be used when the buffer is
44468     displayed on a child frame.  This entry is used only by
44469     ‘display-buffer-in-child-frame’.
44470
44471‘child-frame-parameters’
44472     The value specifies an alist of frame parameters to use when the
44473     buffer is displayed on a child frame.  This entry is used only by
44474     ‘display-buffer-in-child-frame’.
44475
44476‘side’
44477     The value denotes the side of the frame or window where a new
44478     window displaying the buffer shall be created.  This entry is used
44479     by ‘display-buffer-in-side-window’ to indicate the side of the
44480     frame where a new side window shall be placed (*note Displaying
44481     Buffers in Side Windows::).  It is also used by
44482     ‘display-buffer-in-atom-window’ to indicate the side of an existing
44483     window where the new window shall be located (*note Atomic
44484     Windows::).
44485
44486‘slot’
44487     If non-‘nil’, the value specifies the slot of the side window
44488     supposed to display the buffer.  This entry is used only by
44489     ‘display-buffer-in-side-window’.
44490
44491‘direction’
44492     The value specifies a direction which, together with a ‘window’
44493     entry, allows ‘display-buffer-in-direction’ to determine the
44494     location of the window to display the buffer.
44495
44496‘window’
44497     The value specifies a window that is in some way related to the
44498     window chosen by ‘display-buffer’.  This entry is currently used by
44499     ‘display-buffer-in-atom-window’ to indicate the window on whose
44500     side the new window shall be created.  It is also used by
44501     ‘display-buffer-in-direction’ to specify the reference window on
44502     whose side the resulting window shall appear.
44503
44504‘allow-no-window’
44505     If the value is non-‘nil’, ‘display-buffer’ does not necessarily
44506     have to display the buffer and the caller is prepared to accept
44507     that.  This entry is not intended for user customizations, since
44508     there is no guarantee that an arbitrary caller of ‘display-buffer’
44509     will be able to handle the case that no window will display the
44510     buffer.  ‘display-buffer-no-window’ is the only action function
44511     that cares about this entry.
44512
44513   By convention, the entries ‘window-height’, ‘window-width’ and
44514‘preserve-size’ are applied after the chosen window’s buffer has been
44515set up and if and only if that window never showed another buffer
44516before.  More precisely, the latter means that the window must have been
44517either created by the current ‘display-buffer’ call or the window was
44518created earlier by ‘display-buffer’ to show the buffer and never was
44519used to show another buffer until it was reused by the current
44520invocation of ‘display-buffer’.
44521
44522
44523File: elisp.info,  Node: Choosing Window Options,  Next: Precedence of Action Functions,  Prev: Buffer Display Action Alists,  Up: Displaying Buffers
44524
4452528.13.4 Additional Options for Displaying Buffers
44526-------------------------------------------------
44527
44528The behavior of buffer display actions (*note Choosing Window::) can be
44529further modified by the following user options.
44530
44531 -- User Option: pop-up-windows
44532     If the value of this variable is non-‘nil’, ‘display-buffer’ is
44533     allowed to split an existing window to make a new window for
44534     displaying in.  This is the default.
44535
44536     This variable is provided for backward compatibility only.  It is
44537     obeyed by ‘display-buffer’ via a special mechanism in
44538     ‘display-buffer-fallback-action’, which calls the action function
44539     ‘display-buffer-pop-up-window’ (*note Buffer Display Action
44540     Functions::) when the value of this option is non-‘nil’.  It is not
44541     consulted by ‘display-buffer-pop-up-window’ itself, which the user
44542     may specify directly in ‘display-buffer-alist’ etc.
44543
44544 -- User Option: split-window-preferred-function
44545     This variable specifies a function for splitting a window, in order
44546     to make a new window for displaying a buffer.  It is used by the
44547     ‘display-buffer-pop-up-window’ action function to actually split
44548     the window.
44549
44550     The value must be a function that takes one argument, a window, and
44551     returns either a new window (which will be used to display the
44552     desired buffer) or ‘nil’ (which means the splitting failed).  The
44553     default value is ‘split-window-sensibly’, which is documented next.
44554
44555 -- Function: split-window-sensibly &optional window
44556     This function tries to split WINDOW and return the newly created
44557     window.  If WINDOW cannot be split, it returns ‘nil’.  If WINDOW is
44558     omitted or ‘nil’, it defaults to the selected window.
44559
44560     This function obeys the usual rules that determine when a window
44561     may be split (*note Splitting Windows::).  It first tries to split
44562     by placing the new window below, subject to the restriction imposed
44563     by ‘split-height-threshold’ (see below), in addition to any other
44564     restrictions.  If that fails, it tries to split by placing the new
44565     window to the right, subject to ‘split-width-threshold’ (see
44566     below).  If that also fails, and the window is the only window on
44567     its frame, this function again tries to split and place the new
44568     window below, disregarding ‘split-height-threshold’.  If this fails
44569     as well, this function gives up and returns ‘nil’.
44570
44571 -- User Option: split-height-threshold
44572     This variable specifies whether ‘split-window-sensibly’ is allowed
44573     to split the window placing the new window below.  If it is an
44574     integer, that means to split only if the original window has at
44575     least that many lines.  If it is ‘nil’, that means not to split
44576     this way.
44577
44578 -- User Option: split-width-threshold
44579     This variable specifies whether ‘split-window-sensibly’ is allowed
44580     to split the window placing the new window to the right.  If the
44581     value is an integer, that means to split only if the original
44582     window has at least that many columns.  If the value is ‘nil’, that
44583     means not to split this way.
44584
44585 -- User Option: even-window-sizes
44586     This variable, if non-‘nil’, causes ‘display-buffer’ to even window
44587     sizes whenever it reuses an existing window, and that window is
44588     adjacent to the selected one.
44589
44590     If its value is ‘width-only’, sizes are evened only if the reused
44591     window is on the left or right of the selected one and the selected
44592     window is wider than the reused one.  If its value is ‘height-only’
44593     sizes are evened only if the reused window is above or beneath the
44594     selected window and the selected window is higher than the reused
44595     one.  Any other non-‘nil’ value means to even sizes in any of these
44596     cases provided the selected window is larger than the reused one in
44597     the sense of their combination.
44598
44599 -- User Option: pop-up-frames
44600     If the value of this variable is non-‘nil’, that means
44601     ‘display-buffer’ may display buffers by making new frames.  The
44602     default is ‘nil’.
44603
44604     A non-‘nil’ value also means that when ‘display-buffer’ is looking
44605     for a window already displaying BUFFER-OR-NAME, it can search any
44606     visible or iconified frame, not just the selected frame.
44607
44608     This variable is provided mainly for backward compatibility.  It is
44609     obeyed by ‘display-buffer’ via a special mechanism in
44610     ‘display-buffer-fallback-action’, which calls the action function
44611     ‘display-buffer-pop-up-frame’ (*note Buffer Display Action
44612     Functions::) if the value is non-‘nil’.  (This is done before
44613     attempting to split a window.)  This variable is not consulted by
44614     ‘display-buffer-pop-up-frame’ itself, which the user may specify
44615     directly in ‘display-buffer-alist’ etc.
44616
44617 -- User Option: pop-up-frame-function
44618     This variable specifies a function for creating a new frame, in
44619     order to make a new window for displaying a buffer.  It is used by
44620     the ‘display-buffer-pop-up-frame’ action function.
44621
44622     The value should be a function that takes no arguments and returns
44623     a frame, or ‘nil’ if no frame could be created.  The default value
44624     is a function that creates a frame using the parameters specified
44625     by ‘pop-up-frame-alist’ (see below).
44626
44627 -- User Option: pop-up-frame-alist
44628     This variable holds an alist of frame parameters (*note Frame
44629     Parameters::), which is used by the function specified by
44630     ‘pop-up-frame-function’ to make a new frame.  The default is ‘nil’.
44631
44632     This option is provided for backward compatibility only.  Note,
44633     that when ‘display-buffer-pop-up-frame’ calls the function
44634     specified by ‘pop-up-frame-function’, it prepends the value of all
44635     ‘pop-up-frame-parameters’ action alist entries to
44636     ‘pop-up-frame-alist’ so that the values specified by the action
44637     alist entry effectively override any corresponding values of
44638     ‘pop-up-frame-alist’.
44639
44640     Hence, users should set up a ‘pop-up-frame-parameters’ action alist
44641     entry in ‘display-buffer-alist’ instead of customizing
44642     ‘pop-up-frame-alist’.  Only this will guarantee that the value of a
44643     parameter specified by the user overrides the value of that
44644     parameter specified by the caller of ‘display-buffer’.
44645
44646   Many efforts in the design of ‘display-buffer’ have been given to
44647maintain compatibility with code that uses older options like
44648‘pop-up-windows’, ‘pop-up-frames’, ‘pop-up-frame-alist’,
44649‘same-window-buffer-names’ and ‘same-window-regexps’.  Lisp Programs and
44650users should refrain from using these options.  Above we already warned
44651against customizing ‘pop-up-frame-alist’.  Here we describe how to
44652convert the remaining options to use display actions instead.
44653
44654‘pop-up-windows’
44655     This variable is ‘t’ by default.  Instead of customizing it to
44656     ‘nil’ and thus telling ‘display-buffer’ what not to do, it’s much
44657     better to list in ‘display-buffer-base-action’ the action functions
44658     it should try instead as, for example:
44659
44660          (customize-set-variable
44661           'display-buffer-base-action
44662           '((display-buffer-reuse-window display-buffer-same-window
44663              display-buffer-in-previous-window
44664              display-buffer-use-some-window)))
44665
44666‘pop-up-frames’
44667     Instead of customizing this variable to ‘t’, customize
44668     ‘display-buffer-base-action’, for example, as follows:
44669
44670          (customize-set-variable
44671           'display-buffer-base-action
44672           '((display-buffer-reuse-window display-buffer-pop-up-frame)
44673             (reusable-frames . 0)))
44674
44675‘same-window-buffer-names’
44676‘same-window-regexps’
44677     Instead of adding a buffer name or a regular expression to one of
44678     these options use a ‘display-buffer-alist’ entry for that buffer
44679     specifying the action function ‘display-buffer-same-window’.
44680
44681          (customize-set-variable
44682           'display-buffer-alist
44683           (cons '("\\*foo\\*" (display-buffer-same-window))
44684                  display-buffer-alist))
44685
44686
44687File: elisp.info,  Node: Precedence of Action Functions,  Next: The Zen of Buffer Display,  Prev: Choosing Window Options,  Up: Displaying Buffers
44688
4468928.13.5 Precedence of Action Functions
44690--------------------------------------
44691
44692From the past subsections we already know that ‘display-buffer’ must be
44693supplied with a number of display actions (*note Choosing Window::) in
44694order to display a buffer.  In a completely uncustomized Emacs, these
44695actions are specified by ‘display-buffer-fallback-action’ in the
44696following order of precedence: Reuse a window, pop up a new window on
44697the same frame, use a window previously showing the buffer, use some
44698window and pop up a new frame.  (Note that the remaining actions named
44699by ‘display-buffer-fallback-action’ are void in an uncustomized Emacs).
44700
44701   Consider the following form:
44702
44703     (display-buffer (get-buffer-create "*foo*"))
44704
44705Evaluating this form in the buffer ‘*scratch*’ of an uncustomized Emacs
44706session will usually fail to reuse a window that shows ‘*foo*’ already,
44707but succeed in popping up a new window.  Evaluating the same form again
44708will now not cause any visible changes—‘display-buffer’ reused the
44709window already showing ‘*foo*’ because that action was applicable and
44710had the highest precedence among all applicable actions.
44711
44712   Popping up a new window will fail if there is not enough space on the
44713selected frame.  In an uncustomized Emacs it typically fails when there
44714are already two windows on a frame.  For example, if you now type
44715‘C-x 1’ followed by ‘C-x 2’ and evaluate the form once more, ‘*foo*’
44716should show up in the lower window—‘display-buffer’ just used “some”
44717window.  If, before typing ‘C-x 2’ you had typed ‘C-x o’, ‘*foo*’ would
44718have been shown in the upper window because “some” window stands for the
44719“least recently used” window and the selected window has been least
44720recently used if and only if it is alone on its frame.
44721
44722   Let’s assume you did not type ‘C-x o’ and ‘*foo*’ is shown in the
44723lower window.  Type ‘C-x o’ to get there followed by ‘C-x left’ and
44724evaluate the form again.  This should display ‘*foo*’ in the same, lower
44725window because that window had already shown ‘*foo*’ previously and was
44726therefore chosen instead of some other window.
44727
44728   So far we have only observed the default behavior in an uncustomized
44729Emacs session.  To see how this behavior can be customized, let’s
44730consider the option ‘display-buffer-base-action’.  It provides a very
44731coarse customization which conceptually affects the display of _any_
44732buffer.  It can be used to supplement the actions supplied by
44733‘display-buffer-fallback-action’ by reordering them or by adding actions
44734that are not present there but fit more closely the user’s editing
44735practice.  However, it can also be used to change the default behavior
44736in a more profound way.
44737
44738   Let’s consider a user who, as a rule, prefers to display buffers on
44739another frame.  Such a user might provide the following customization:
44740
44741     (customize-set-variable
44742      'display-buffer-base-action
44743      '((display-buffer-reuse-window display-buffer-pop-up-frame)
44744        (reusable-frames . 0)))
44745
44746This setting will cause ‘display-buffer’ to first try to find a window
44747showing the buffer on a visible or iconified frame and, if no such frame
44748exists, pop up a new frame.  You can observe this behavior on a
44749graphical system by typing ‘C-x 1’ in the window showing ‘*scratch*’ and
44750evaluating our canonical ‘display-buffer’ form.  This will usually
44751create (and give focus to) a new frame whose root window shows ‘*foo*’.
44752Iconify that frame and evaluate the canonical form again:
44753‘display-buffer’ will reuse the window on the new frame (usually raising
44754the frame and giving it focus too).
44755
44756   Only if creating a new frame fails, ‘display-buffer’ will apply the
44757actions supplied by ‘display-buffer-fallback-action’ which means to
44758again try reusing a window, popping up a new window and so on.  A
44759trivial way to make frame creation fail is supplied by the following
44760form:
44761
44762     (let ((pop-up-frame-function 'ignore))
44763       (display-buffer (get-buffer-create "*foo*")))
44764
44765We will forget about that form immediately after observing that it fails
44766to create a new frame and uses a fallback action instead.
44767
44768   Note that ‘display-buffer-reuse-window’ appears redundant in the
44769customization of ‘display-buffer-base-action’ because it is already part
44770of ‘display-buffer-fallback-action’ and should be tried there anyway.
44771However, that would fail because due to the precedence of
44772‘display-buffer-base-action’ over ‘display-buffer-fallback-action’, at
44773that time ‘display-buffer-pop-up-frame’ would have already won the race.
44774In fact, this:
44775
44776     (customize-set-variable
44777      'display-buffer-base-action
44778      '(display-buffer-pop-up-frame (reusable-frames . 0)))
44779
44780would cause ‘display-buffer’ to _always_ pop up a new frame which is
44781probably not what our user wants.
44782
44783   So far, we have only shown how _users_ can customize the default
44784behavior of ‘display-buffer’.  Let us now see how _applications_ can
44785change the course of ‘display-buffer’.  The canonical way to do that is
44786to use the ACTION argument of ‘display-buffer’ or a function that calls
44787it, like, for example, ‘pop-to-buffer’ (*note Switching Buffers::).
44788
44789   Suppose an application wants to display ‘*foo*’ preferably below the
44790selected window (to immediately attract the attention of the user to the
44791new window) or, if that fails, in a window at the bottom of the frame.
44792It could do that with a call like this:
44793
44794     (display-buffer
44795      (get-buffer-create "*foo*")
44796      '((display-buffer-below-selected display-buffer-at-bottom)))
44797
44798In order to see how this new, modified form works, delete any frame
44799showing ‘*foo*’, type ‘C-x 1’ followed by ‘C-x 2’ in the window showing
44800‘*scratch*’, and subsequently evaluate that form.  ‘display-buffer’
44801should split the upper window, and show ‘*foo*’ in the new window.
44802Alternatively, if after ‘C-x 2’ you had typed ‘C-x o’, ‘display-buffer’
44803would have split the window at the bottom instead.
44804
44805   Suppose now that, before evaluating the new form, you have made the
44806selected window as small as possible, for example, by evaluating the
44807form ‘(fit-window-to-buffer)’ in that window.  In that case,
44808‘display-buffer’ would have failed to split the selected window and
44809would have split the frame’s root window instead, effectively displaying
44810‘*foo*’ at the bottom of the frame.
44811
44812   In either case, evaluating the new form a second time should reuse
44813the window already showing ‘*foo*’ since both functions supplied by the
44814ACTION argument try to reuse such a window first.
44815
44816   By setting the ACTION argument, an application effectively overrules
44817any customization of ‘display-buffer-base-action’.  Our user can now
44818either accept the choice of the application, or redouble by customizing
44819the option ‘display-buffer-alist’ as follows:
44820
44821     (customize-set-variable
44822      'display-buffer-alist
44823      '(("\\*foo\\*"
44824         (display-buffer-reuse-window display-buffer-pop-up-frame))))
44825
44826Trying this with the new, modified form above in a configuration that
44827does not show ‘*foo*’ anywhere, will display ‘*foo*’ on a separate
44828frame, completely ignoring the ACTION argument of ‘display-buffer’.
44829
44830   Note that we didn’t care to specify a ‘reusable-frames’ action alist
44831entry in our specification of ‘display-buffer-alist’.  ‘display-buffer’
44832always takes the first one it finds—in our case the one specified by
44833‘display-buffer-base-action’.  If we wanted to use a different
44834specification, for example, to exclude iconified frames showing ‘*foo*’
44835from the list of reusable ones, we would have to specify that
44836separately, however:
44837
44838     (customize-set-variable
44839      'display-buffer-alist
44840      '(("\\*foo\\*"
44841         (display-buffer-reuse-window display-buffer-pop-up-frame)
44842         (reusable-frames . visible))))
44843
44844If you try this, you will notice that repeated attempts to display
44845‘*foo*’ will succeed to reuse a frame only if that frame is visible.
44846
44847   The above example would allow the conclusion that users customize
44848‘display-buffer-alist’ for the sole purpose to overrule the ACTION
44849argument chosen by applications.  Such a conclusion would be incorrect.
44850‘display-buffer-alist’ is the standard option for users to direct the
44851course of display of specific buffers in a preferred way regardless of
44852whether the display is also guided by an ACTION argument.
44853
44854   We can, however, reasonably conclude that customizing
44855‘display-buffer-alist’ differs from customizing
44856‘display-buffer-base-action’ in two major aspects: it is stronger
44857because it overrides the ACTION argument of ‘display-buffer’, and it
44858allows to explicitly specify the affected buffers.  In fact, displaying
44859other buffers is not affected in any way by a customization for ‘*foo*’.
44860For example,
44861
44862     (display-buffer (get-buffer-create "*bar*"))
44863
44864continues being governed by the settings of ‘display-buffer-base-action’
44865and ‘display-buffer-fallback-action’ only.
44866
44867   We could stop with our examples here but Lisp programs still have an
44868ace up their sleeves which they can use to overrule any customization of
44869‘display-buffer-alist’.  It’s the variable
44870‘display-buffer-overriding-action’ which they can bind around
44871‘display-buffer’ calls as follows:
44872
44873     (let ((display-buffer-overriding-action
44874            '((display-buffer-same-window))))
44875       (display-buffer
44876        (get-buffer-create "*foo*")
44877        '((display-buffer-below-selected display-buffer-at-bottom))))
44878
44879Evaluating this form will usually display ‘*foo*’ in the selected window
44880regardless of the ACTION argument and any user customizations.
44881(Usually, an application will not bother to also provide an ACTION
44882argument.  Here it just serves to illustrate the fact that it gets
44883overridden.)
44884
44885   It might be illustrative to look at the list of action functions
44886‘display-buffer’ would have tried to display ‘*foo*’ with the
44887customizations we provided here.  The list (including comments
44888explaining who added this and the subsequent elements) is:
44889
44890     (display-buffer-same-window  ;; `display-buffer-overriding-action'
44891      display-buffer-reuse-window ;; `display-buffer-alist'
44892      display-buffer-pop-up-frame
44893      display-buffer-below-selected ;; ACTION argument
44894      display-buffer-at-bottom
44895      display-buffer-reuse-window ;; `display-buffer-base-action'
44896      display-buffer-pop-up-frame
44897      display-buffer--maybe-same-window ;; `display-buffer-fallback-action'
44898      display-buffer-reuse-window
44899      display-buffer--maybe-pop-up-frame-or-window
44900      display-buffer-in-previous-window
44901      display-buffer-use-some-window
44902      display-buffer-pop-up-frame)
44903
44904Note that among the internal functions listed here,
44905‘display-buffer--maybe-same-window’ is effectively ignored while
44906‘display-buffer--maybe-pop-up-frame-or-window’ actually runs
44907‘display-buffer-pop-up-window’.
44908
44909   The action alist passed in each function call is:
44910
44911     ((reusable-frames . visible)
44912      (reusable-frames . 0))
44913
44914which shows that we have used the second specification of
44915‘display-buffer-alist’ above, overriding the specification supplied by
44916‘display-buffer-base-action’.  Suppose our user had written that as
44917
44918     (customize-set-variable
44919      'display-buffer-alist
44920      '(("\\*foo\\*"
44921         (display-buffer-reuse-window display-buffer-pop-up-frame)
44922         (inhibit-same-window . t)
44923         (reusable-frames . visible))))
44924
44925In this case the ‘inhibit-same-window’ alist entry will successfully
44926invalidate the ‘display-buffer-same-window’ specification from
44927‘display-buffer-overriding-action’ and ‘display-buffer’ will show
44928‘*foo*’ on another frame.  To make ‘display-buffer-overriding-action’
44929more robust in this regard, the application would have to specify an
44930appropriate ‘inhibit-same-window’ entry too, for example, as follows:
44931
44932     (let ((display-buffer-overriding-action
44933            '(display-buffer-same-window (inhibit-same-window . nil))))
44934       (display-buffer (get-buffer-create "*foo*")))
44935
44936This last example shows that while the precedence order of action
44937functions is fixed, as described in *note Choosing Window::, an action
44938alist entry specified by a display action ranked lower in that order can
44939affect the execution of a higher ranked display action.
44940
44941
44942File: elisp.info,  Node: The Zen of Buffer Display,  Prev: Precedence of Action Functions,  Up: Displaying Buffers
44943
4494428.13.6 The Zen of Buffer Display
44945---------------------------------
44946
44947In its most simplistic form, a frame accommodates always one single
44948window that can be used for displaying a buffer.  As a consequence, it
44949is always the latest call of ‘display-buffer’ that will have succeeded
44950in placing its buffer there.
44951
44952   Since working with such a frame is not very practical, Emacs by
44953default allows for more complex frame layouts controlled by the default
44954values of the frame size and the ‘split-height-threshold’ and
44955‘split-width-threshold’ options.  Displaying a buffer not yet shown on a
44956frame then either splits the single window on that frame or (re-)uses
44957one of its two windows.
44958
44959   The default behavior is abandoned as soon as the user customizes one
44960of these thresholds or manually changes the frame’s layout.  The default
44961behavior is also abandoned when calling ‘display-buffer’ with a
44962non-‘nil’ ACTION argument or the user customizes one of the options
44963mentioned in the previous subsections.  Mastering ‘display-buffer’ soon
44964may become a frustrating experience due to the plethora of applicable
44965display actions and the resulting frame layouts.
44966
44967   However, refraining from using buffer display functions and falling
44968back on a split & delete windows metaphor is not a good idea either.
44969Buffer display functions give Lisp programs and users a framework to
44970reconcile their different needs; no comparable framework exists for
44971splitting and deleting windows.  Buffer display functions also allow to
44972at least partially restore the layout of a frame when removing a buffer
44973from it later (*note Quitting Windows::).
44974
44975   Below we will give a number of guidelines to redeem the frustration
44976mentioned above and thus to avoid literally losing buffers in-between
44977the windows of a frame.
44978
44979Write display actions without stress
44980     Writing display actions can be a pain because one has to lump
44981     together action functions and action alists in one huge list.
44982     (Historical reasons prevented us from having ‘display-buffer’
44983     support separate arguments for these.)  It might help to memorize
44984     some basic forms like the ones listed below:
44985
44986          '(nil (inhibit-same-window . t))
44987
44988     specifies an action alist entry only and no action function.  Its
44989     sole purpose is to inhibit a ‘display-buffer-same-window’ function
44990     specified elsewhere from showing the buffer in the same window, see
44991     also the last example of the preceding subsection.
44992
44993          '(display-buffer-below-selected)
44994
44995     on the other hand, specifies one action function and an empty
44996     action alist.  To combine the effects of the above two
44997     specifications one would write the form
44998
44999          '(display-buffer-below-selected (inhibit-same-window . t))
45000
45001     to add another action function one would write
45002
45003          '((display-buffer-below-selected display-buffer-at-bottom)
45004            (inhibit-same-window . t))
45005
45006     and to add another alist entry one would write
45007
45008          '((display-buffer-below-selected display-buffer-at-bottom)
45009            (inhibit-same-window . t)
45010            (window-height . fit-window-to-buffer))
45011
45012     That last form can be used as ACTION argument of ‘display-buffer’
45013     in the following way:
45014
45015          (display-buffer
45016           (get-buffer-create "*foo*")
45017           '((display-buffer-below-selected display-buffer-at-bottom)
45018             (inhibit-same-window . t)
45019             (window-height . fit-window-to-buffer)))
45020
45021     In a customization of ‘display-buffer-alist’ it would be used as
45022     follows:
45023
45024          (customize-set-variable
45025           'display-buffer-alist
45026           '(("\\*foo\\*"
45027              (display-buffer-below-selected display-buffer-at-bottom)
45028              (inhibit-same-window . t)
45029              (window-height . fit-window-to-buffer))))
45030
45031     To add a customization for a second buffer one would then write:
45032
45033          (customize-set-variable
45034           'display-buffer-alist
45035           '(("\\*foo\\*"
45036              (display-buffer-below-selected display-buffer-at-bottom)
45037              (inhibit-same-window . t)
45038              (window-height . fit-window-to-buffer))
45039             ("\\*bar\\*"
45040              (display-buffer-reuse-window display-buffer-pop-up-frame)
45041              (reusable-frames . visible))))
45042
45043Treat each other with respect
45044     ‘display-buffer-alist’ and ‘display-buffer-base-action’ are user
45045     options—Lisp programs must never set or rebind them.
45046     ‘display-buffer-overriding-action’, on the other hand, is reserved
45047     for applications—who seldom use that option and if they use it,
45048     then with utmost care.
45049
45050     Older implementations of ‘display-buffer’ frequently caused users
45051     and applications to fight over the settings of user options like
45052     ‘pop-up-frames’ and ‘pop-up-windows’ (*note Choosing Window
45053     Options::).  This was one major reason for redesigning
45054     ‘display-buffer’—to provide a clear framework specifying what users
45055     and applications should be allowed to do.
45056
45057     Lisp programs must be prepared that user customizations may cause
45058     buffers to get displayed in an unexpected way.  They should never
45059     assume in their subsequent behavior, that the buffer has been shown
45060     precisely the way they asked for in the ACTION argument of
45061     ‘display-buffer’.
45062
45063     Users should not pose too many and too severe restrictions on how
45064     arbitrary buffers get displayed.  Otherwise, they will risk to lose
45065     the characteristics of showing a buffer for a certain purpose.
45066     Suppose a Lisp program has been written to compare different
45067     versions of a buffer in two windows side-by-side.  If the
45068     customization of ‘display-buffer-alist’ prescribes that any such
45069     buffer should be always shown in or below the selected window, the
45070     program will have a hard time to set up the desired window
45071     configuration via ‘display-buffer’.
45072
45073     To specify a preference for showing an arbitrary buffer, users
45074     should customize ‘display-buffer-base-action’.  An example of how
45075     users who prefer working with multiple frames would do that was
45076     given in the previous subsection.  ‘display-buffer-alist’ should be
45077     reserved for displaying specific buffers in a specific way.
45078
45079Consider reusing a window that already shows the buffer
45080     Generally, it’s always a good idea for users and Lisp programmers
45081     to be prepared for the case that a window already shows the buffer
45082     in question and to reuse that window.  In the preceding subsection
45083     we have shown that failing to do so properly may cause
45084     ‘display-buffer’ to continuously pop up a new frame although a
45085     frame showing that buffer existed already.  In a few cases only, it
45086     might be undesirable to reuse a window, for example, when a
45087     different portion of the buffer should be shown in that window.
45088
45089     Hence, ‘display-buffer-reuse-window’ is one action function that
45090     should be used as often as possible, both in ACTION arguments and
45091     customizations.  An ‘inhibit-same-window’ entry in the ACTION
45092     argument usually takes care of the most common case where reusing a
45093     window showing the buffer should be avoided—that where the window
45094     in question is the selected one.
45095
45096Attract focus to the window chosen
45097     This is a no-brainer for people working with multiple frames—the
45098     frame showing the buffer will automatically raise and get focus
45099     unless an ‘inhibit-switch-frame’ entry forbids it.  For single
45100     frame users this task can be considerably more difficult.  In
45101     particular, ‘display-buffer-pop-up-window’ and
45102     ‘display-buffer-use-some-window’ can become obtrusive in this
45103     regard.  They split or use a seemingly arbitrary (often the largest
45104     or least recently used) window, distracting the user’s attention.
45105
45106     Some Lisp programs therefore try to choose a window at the bottom
45107     of the frame, for example, in order to display the buffer in
45108     vicinity of the minibuffer window where the user is expected to
45109     answer a question related to the new window.  For non-input related
45110     actions ‘display-buffer-below-selected’ might be preferable because
45111     the selected window usually already has the user’s attention.
45112
45113Handle subsequent invocations of ‘display-buffer’
45114     ‘display-buffer’ is not overly well suited for displaying several
45115     buffers in sequence and making sure that all these buffers are
45116     shown orderly in the resulting window configuration.  Again, the
45117     standard action functions ‘display-buffer-pop-up-window’ and
45118     ‘display-buffer-use-some-window’ are not very suited for this
45119     purpose due to their somewhat chaotic nature in more complex
45120     configurations.
45121
45122     To produce a window configuration displaying multiple buffers (or
45123     different views of one and the same buffer) in one and the same
45124     display cycle, Lisp programmers will unavoidably have to write
45125     their own action functions.  A few tricks listed below might help
45126     in this regard.
45127
45128        • Making windows atomic (*note Atomic Windows::) avoids breaking
45129          an existing window composition when popping up a new window.
45130          The new window will pop up outside the composition instead.
45131
45132        • Temporarily dedicating windows to their buffers (*note
45133          Dedicated Windows::) avoids using a window for displaying a
45134          different buffer.  A non-dedicated window will be used
45135          instead.
45136
45137        • Calling ‘window-preserve-size’ (*note Preserving Window
45138          Sizes::) will try to keep the size of the argument window
45139          unchanged when popping up a new window.  You have to make sure
45140          that another window in the same combination can be shrunk
45141          instead, though.
45142
45143        • Side windows (*note Side Windows::) can be used for displaying
45144          specific buffers always in a window at the same position of a
45145          frame.  This permits grouping buffers that do not compete for
45146          being shown at the same time on a frame and showing any such
45147          buffer in the same window without disrupting the display of
45148          other buffers.
45149
45150        • Child frames (*note Child Frames::) can be used to display a
45151          buffer within the screen estate of the selected frame without
45152          disrupting that frame’s window configuration and without the
45153          overhead associated with full-fledged frames as inflicted by
45154          ‘display-buffer-pop-up-frame’.
45155
45156
45157File: elisp.info,  Node: Window History,  Next: Dedicated Windows,  Prev: Displaying Buffers,  Up: Windows
45158
4515928.14 Window History
45160====================
45161
45162Each window remembers in a list the buffers it has previously displayed,
45163and the order in which these buffers were removed from it.  This history
45164is used, for example, by ‘replace-buffer-in-windows’ (*note Buffers and
45165Windows::), and when quitting windows (*note Quitting Windows::).  The
45166list is automatically maintained by Emacs, but you can use the following
45167functions to explicitly inspect or alter it:
45168
45169 -- Function: window-prev-buffers &optional window
45170     This function returns a list specifying the previous contents of
45171     WINDOW.  The optional argument WINDOW should be a live window and
45172     defaults to the selected one.
45173
45174     Each list element has the form ‘(BUFFER WINDOW-START WINDOW-POS)’,
45175     where BUFFER is a buffer previously shown in the window,
45176     WINDOW-START is the window start position (*note Window Start and
45177     End::) when that buffer was last shown, and WINDOW-POS is the point
45178     position (*note Window Point::) when that buffer was last shown in
45179     WINDOW.
45180
45181     The list is ordered so that earlier elements correspond to more
45182     recently-shown buffers, and the first element usually corresponds
45183     to the buffer most recently removed from the window.
45184
45185 -- Function: set-window-prev-buffers window prev-buffers
45186     This function sets WINDOW’s previous buffers to the value of
45187     PREV-BUFFERS.  The argument WINDOW must be a live window and
45188     defaults to the selected one.  The argument PREV-BUFFERS should be
45189     a list of the same form as that returned by ‘window-prev-buffers’.
45190
45191   In addition, each window maintains a list of “next buffers”, which is
45192a list of buffers re-shown by ‘switch-to-prev-buffer’ (see below).  This
45193list is mainly used by ‘switch-to-prev-buffer’ and
45194‘switch-to-next-buffer’ for choosing buffers to switch to.
45195
45196 -- Function: window-next-buffers &optional window
45197     This function returns the list of buffers recently re-shown in
45198     WINDOW via ‘switch-to-prev-buffer’.  The WINDOW argument must
45199     denote a live window or ‘nil’ (meaning the selected window).
45200
45201 -- Function: set-window-next-buffers window next-buffers
45202     This function sets the next buffer list of WINDOW to NEXT-BUFFERS.
45203     The WINDOW argument should be a live window or ‘nil’ (meaning the
45204     selected window).  The argument NEXT-BUFFERS should be a list of
45205     buffers.
45206
45207   The following commands can be used to cycle through the global buffer
45208list, much like ‘bury-buffer’ and ‘unbury-buffer’.  However, they cycle
45209according to the specified window’s history list, rather than the global
45210buffer list.  In addition, they restore window-specific window start and
45211point positions, and may show a buffer even if it is already shown in
45212another window.  The ‘switch-to-prev-buffer’ command, in particular, is
45213used by ‘replace-buffer-in-windows’, ‘bury-buffer’ and ‘quit-window’ to
45214find a replacement buffer for a window.
45215
45216 -- Command: switch-to-prev-buffer &optional window bury-or-kill
45217     This command displays the previous buffer in WINDOW.  The argument
45218     WINDOW should be a live window or ‘nil’ (meaning the selected
45219     window).  If the optional argument BURY-OR-KILL is non-‘nil’, this
45220     means that the buffer currently shown in WINDOW is about to be
45221     buried or killed and consequently should not be switched to in
45222     future invocations of this command.
45223
45224     The previous buffer is usually the buffer shown before the buffer
45225     currently shown in WINDOW.  However, a buffer that has been buried
45226     or killed, or has been already shown by a recent invocation of
45227     ‘switch-to-prev-buffer’, does not qualify as previous buffer.
45228
45229     If repeated invocations of this command have already shown all
45230     buffers previously shown in WINDOW, further invocations will show
45231     buffers from the buffer list of the frame WINDOW appears on (*note
45232     Buffer List::).
45233
45234     The option ‘switch-to-prev-buffer-skip’ described below can be used
45235     to inhibit switching to certain buffers, for example, to those
45236     already shown in another window.  Also, if WINDOW’s frame has a
45237     ‘buffer-predicate’ parameter (*note Buffer Parameters::), that
45238     predicate may inhibit switching to certain buffers.
45239
45240 -- Command: switch-to-next-buffer &optional window
45241     This command switches to the next buffer in WINDOW, thus undoing
45242     the effect of the last ‘switch-to-prev-buffer’ command in WINDOW.
45243     The argument WINDOW must be a live window and defaults to the
45244     selected one.
45245
45246     If there is no recent invocation of ‘switch-to-prev-buffer’ that
45247     can be undone, this function tries to show a buffer from the buffer
45248     list of the frame WINDOW appears on (*note Buffer List::).
45249
45250     The option ‘switch-to-prev-buffer-skip’ and the ‘buffer-predicate’
45251     (*note Buffer Parameters::) of WINDOW’s frame affect this command
45252     as they do for ‘switch-to-prev-buffer’.
45253
45254   By default ‘switch-to-prev-buffer’ and ‘switch-to-next-buffer’ can
45255switch to a buffer that is already shown in another window.  The
45256following option can be used to override this behavior.
45257
45258 -- User Option: switch-to-prev-buffer-skip
45259     If this variable is ‘nil’, ‘switch-to-prev-buffer’ may switch to
45260     any buffer, including those already shown in other windows.
45261
45262     If this variable is non-‘nil’, ‘switch-to-prev-buffer’ will refrain
45263     from switching to certain buffers.  The following values can be
45264     used:
45265
45266        • ‘this’ means do not switch to a buffer shown on the frame that
45267          hosts the window ‘switch-to-prev-buffer’ is acting upon.
45268
45269        • ‘visible’ means do not switch to a buffer shown on any visible
45270          frame.
45271
45272        • 0 (the number zero) means do not switch to a buffer shown on
45273          any visible or iconified frame.
45274
45275        • ‘t’ means do not switch to a buffer shown on any live frame.
45276
45277        • A function that takes three arguments—the WINDOW argument of
45278          ‘switch-to-prev-buffer’, a buffer ‘switch-to-prev-buffer’
45279          intends to switch to and the BURY-OR-KILL argument of
45280          ‘switch-to-prev-buffer’.  If that function returns non-‘nil’,
45281          ‘switch-to-prev-buffer’ will refrain from switching to the
45282          buffer specified by the second argument.
45283
45284     The command ‘switch-to-next-buffer’ obeys this option in a similar
45285     way.  If this option specifies a function, ‘switch-to-next-buffer’
45286     will call that function with the third argument always ‘nil’.
45287
45288     Note that since ‘switch-to-prev-buffer’ is called by ‘bury-buffer’,
45289     ‘replace-buffer-in-windows’ and ‘quit-restore-window’ as well,
45290     customizing this option may also affect the behavior of Emacs when
45291     a window is quit or a buffer gets buried or killed.
45292
45293     Note also that under certain circumstances ‘switch-to-prev-buffer’
45294     and ‘switch-to-next-buffer’ may ignore this option, for example,
45295     when there is only one buffer left these functions can switch to.
45296
45297
45298File: elisp.info,  Node: Dedicated Windows,  Next: Quitting Windows,  Prev: Window History,  Up: Windows
45299
4530028.15 Dedicated Windows
45301=======================
45302
45303Functions for displaying a buffer can be told to not use specific
45304windows by marking these windows as “dedicated” to their buffers.
45305‘display-buffer’ (*note Choosing Window::) never uses a dedicated window
45306for displaying another buffer in it.  ‘get-lru-window’ and
45307‘get-largest-window’ (*note Cyclic Window Ordering::) do not consider
45308dedicated windows as candidates when their DEDICATED argument is
45309non-‘nil’.  The behavior of ‘set-window-buffer’ (*note Buffers and
45310Windows::) with respect to dedicated windows is slightly different, see
45311below.
45312
45313   Functions supposed to remove a buffer from a window or a window from
45314a frame can behave specially when a window they operate on is dedicated.
45315We will distinguish three basic cases, namely where (1) the window is
45316not the only window on its frame, (2) the window is the only window on
45317its frame but there are other frames on the same terminal left, and (3)
45318the window is the only window on the only frame on the same terminal.
45319
45320   In particular, ‘delete-windows-on’ (*note Deleting Windows::) handles
45321case (2) by deleting the associated frame and case (3) by showing
45322another buffer in that frame’s only window.  The function
45323‘replace-buffer-in-windows’ (*note Buffers and Windows::) which is
45324called when a buffer gets killed, deletes the window in case (1) and
45325behaves like ‘delete-windows-on’ otherwise.
45326
45327   When ‘bury-buffer’ (*note Buffer List::) operates on the selected
45328window (which shows the buffer that shall be buried), it handles case
45329(2) by calling ‘frame-auto-hide-function’ (*note Quitting Windows::) to
45330deal with the selected frame.  The other two cases are handled as with
45331‘replace-buffer-in-windows’.
45332
45333 -- Function: window-dedicated-p &optional window
45334     This function returns non-‘nil’ if WINDOW is dedicated to its
45335     buffer and ‘nil’ otherwise.  More precisely, the return value is
45336     the value assigned by the last call of ‘set-window-dedicated-p’ for
45337     WINDOW, or ‘nil’ if that function was never called with WINDOW as
45338     its argument.  The default for WINDOW is the selected window.
45339
45340 -- Function: set-window-dedicated-p window flag
45341     This function marks WINDOW as dedicated to its buffer if FLAG is
45342     non-‘nil’, and non-dedicated otherwise.
45343
45344     As a special case, if FLAG is ‘t’, WINDOW becomes “strongly”
45345     dedicated to its buffer.  ‘set-window-buffer’ signals an error when
45346     the window it acts upon is strongly dedicated to its buffer and
45347     does not already display the buffer it is asked to display.  Other
45348     functions do not treat ‘t’ differently from any non-‘nil’ value.
45349
45350   You can also tell ‘display-buffer’ to mark a window it creates as
45351dedicated to its buffer by providing a suitable ‘dedicated’ action alist
45352entry (*note Buffer Display Action Alists::).
45353
45354
45355File: elisp.info,  Node: Quitting Windows,  Next: Side Windows,  Prev: Dedicated Windows,  Up: Windows
45356
4535728.16 Quitting Windows
45358======================
45359
45360When you want to get rid of a window used for displaying a buffer, you
45361can call ‘delete-window’ or ‘delete-windows-on’ (*note Deleting
45362Windows::) to remove that window from its frame.  If the buffer is shown
45363on a separate frame, you might want to call ‘delete-frame’ (*note
45364Deleting Frames::) instead.  If, on the other hand, a window has been
45365reused for displaying the buffer, you might prefer showing the buffer
45366previously shown in that window, by calling the function
45367‘switch-to-prev-buffer’ (*note Window History::).  Finally, you might
45368want to either bury (*note Buffer List::) or kill (*note Killing
45369Buffers::) the window’s buffer.
45370
45371   The following command uses information on how the window for
45372displaying the buffer was obtained in the first place, thus attempting
45373to automate the above decisions for you.
45374
45375 -- Command: quit-window &optional kill window
45376     This command quits WINDOW and buries its buffer.  The argument
45377     WINDOW must be a live window and defaults to the selected one.
45378     With prefix argument KILL non-‘nil’, it kills the buffer instead of
45379     burying it.  It calls the function ‘quit-restore-window’ described
45380     next to deal with the window and its buffer.
45381
45382     The functions in ‘quit-window-hook’ are run before doing anything
45383     else.
45384
45385 -- Function: quit-restore-window &optional window bury-or-kill
45386     This function handles WINDOW and its buffer after quitting.  The
45387     optional argument WINDOW must be a live window and defaults to the
45388     selected one.  The function’s behavior is determined by the four
45389     elements of the list specified by WINDOW’s ‘quit-restore’ parameter
45390     (*note Window Parameters::).
45391
45392     The first element of the ‘quit-restore’ parameter is one of the
45393     symbols ‘window’, meaning that the window has been specially
45394     created by ‘display-buffer’; ‘frame’, a separate frame has been
45395     created; ‘same’, the window has only ever displayed this buffer; or
45396     ‘other’, the window showed another buffer before.  ‘frame’ and
45397     ‘window’ affect how the window is quit, while ‘same’ and ‘other’
45398     affect the redisplay of buffers previously shown in WINDOW.
45399
45400     The parameter’s second element is either one of the symbols
45401     ‘window’ or ‘frame’, or a list whose elements are the buffer shown
45402     in WINDOW before, that buffer’s window start and window point
45403     positions, and WINDOW’s height at that time.  If that buffer is
45404     still live when WINDOW is quit, then this function may reuse WINDOW
45405     to display it.
45406
45407     The third element is the window selected at the time the parameter
45408     was created.  If this function deletes WINDOW, it subsequently
45409     tries to reselect the window named by that element.
45410
45411     The fourth element is the buffer whose display caused the creation
45412     of this parameter.  This function may delete WINDOW if and only if
45413     it still shows that buffer.
45414
45415     This function will try to delete WINDOW if and only if (1) the
45416     first element of its ‘quit-restore’ parameter is either ‘window’ or
45417     ‘frame’, (2) the window has no history of previously-displayed
45418     buffers and (3) the fourth element of the ‘quit-restore’ parameter
45419     specifies the buffer currently displayed in WINDOW.  If WINDOW is
45420     part of an atomic window (*note Atomic Windows::), it will try to
45421     delete the root of that atomic window instead.  In either case, it
45422     tries to avoid signaling an error when WINDOW cannot be deleted.
45423
45424     If WINDOW shall be deleted, is the only window on its frame and
45425     there are other frames on that frame’s terminal, the value of the
45426     optional argument BURY-OR-KILL determines how to proceed with the
45427     window.  If BURY-OR-KILL equals ‘kill’, the frame is deleted
45428     unconditionally.  Otherwise, the fate of the frame is determined by
45429     calling ‘frame-auto-hide-function’ (see below) with that frame as
45430     sole argument.
45431
45432     If the third element of the ‘quit-restore’ parameter is a list of
45433     buffer, window start (*note Window Start and End::), and point
45434     (*note Window Point::), and that buffer is still live, the buffer
45435     will be displayed, and start and point set accordingly.  If, in
45436     addition, WINDOW’s buffer was temporarily resized, this function
45437     will also try to restore the original height of WINDOW.
45438
45439     Otherwise, if WINDOW was previously used for displaying other
45440     buffers (*note Window History::), the most recent buffer in that
45441     history will be displayed.  In either case, if WINDOW is not
45442     deleted, its ‘quit-restore’ parameter is reset to ‘nil’.
45443
45444     The optional argument BURY-OR-KILL specifies how to deal with
45445     WINDOW’s buffer.  The following values are handled:
45446
45447     ‘nil’
45448          This means to not deal with the buffer in any particular way.
45449          As a consequence, if WINDOW is not deleted, invoking
45450          ‘switch-to-prev-buffer’ will usually show the buffer again.
45451
45452     ‘append’
45453          This means that if WINDOW is not deleted, its buffer is moved
45454          to the end of WINDOW’s list of previous buffers, so it’s less
45455          likely that a future invocation of ‘switch-to-prev-buffer’
45456          will switch to it.  Also, it moves the buffer to the end of
45457          the frame’s buffer list.
45458
45459     ‘bury’
45460          This means that if WINDOW is not deleted, its buffer is
45461          removed from WINDOW’s list of previous buffers.  Also, it
45462          moves the buffer to the end of the frame’s buffer list.  This
45463          value provides the most reliable remedy to not have
45464          ‘switch-to-prev-buffer’ switch to this buffer again without
45465          killing the buffer.
45466
45467     ‘kill’
45468          This means to kill WINDOW’s buffer.
45469
45470     Typically, the display routines run by ‘display-buffer’ will set
45471     the ‘quit-restore’ window parameter correctly.  It’s also possible
45472     to set it manually, using the following code for displaying BUFFER
45473     in WINDOW:
45474
45475          (display-buffer-record-window type window buffer)
45476
45477          (set-window-buffer window buffer)
45478
45479          (set-window-prev-buffers window nil)
45480
45481     Setting the window history to ‘nil’ ensures that a future call to
45482     ‘quit-window’ can delete the window altogether.
45483
45484   The following option specifies how to deal with a frame containing
45485just one window that should be either quit, or whose buffer should be
45486buried.
45487
45488 -- User Option: frame-auto-hide-function
45489     The function specified by this option is called to automatically
45490     hide frames.  This function is called with one argument—a frame.
45491
45492     The function specified here is called by ‘bury-buffer’ (*note
45493     Buffer List::) when the selected window is dedicated and shows the
45494     buffer to bury.  It is also called by ‘quit-restore-window’ (see
45495     above) when the frame of the window to quit has been specially
45496     created for displaying that window’s buffer and the buffer is not
45497     killed.
45498
45499     The default is to call ‘iconify-frame’ (*note Visibility of
45500     Frames::).  Alternatively, you may specify either ‘delete-frame’
45501     (*note Deleting Frames::) to remove the frame from its display,
45502     ‘make-frame-invisible’ to make the frame invisible, ‘ignore’ to
45503     leave the frame unchanged, or any other function that can take a
45504     frame as its sole argument.
45505
45506     Note that the function specified by this option is called only if
45507     the specified frame contains just one live window and there is at
45508     least one other frame on the same terminal.
45509
45510     For a particular frame, the value specified here may be overridden
45511     by that frame’s ‘auto-hide-function’ frame parameter (*note Frame
45512     Interaction Parameters::).
45513
45514
45515File: elisp.info,  Node: Side Windows,  Next: Atomic Windows,  Prev: Quitting Windows,  Up: Windows
45516
4551728.17 Side Windows
45518==================
45519
45520Side windows are special windows positioned at any of the four sides of
45521a frame’s root window (*note Windows and Frames::).  In practice, this
45522means that the area of the frame’s root window is subdivided into a main
45523window and a number of side windows surrounding that main window.  The
45524main window is either a “normal” live window or specifies the area
45525containing all the normal windows.
45526
45527   In their most simple form of use, side windows allow to display
45528specific buffers always in the same area of a frame.  Hence they can be
45529regarded as a generalization of the concept provided by
45530‘display-buffer-at-bottom’ (*note Buffer Display Action Functions::) to
45531the remaining sides of a frame.  With suitable customizations, however,
45532side windows can be also used to provide frame layouts similar to those
45533found in so-called integrated development environments (IDEs).
45534
45535* Menu:
45536
45537* Displaying Buffers in Side Windows:: An action function for displaying
45538                              buffers in side windows.
45539* Side Window Options and Functions:: Further tuning of side windows.
45540* Frame Layouts with Side Windows:: Setting up frame layouts with side
45541                              windows.
45542
45543
45544File: elisp.info,  Node: Displaying Buffers in Side Windows,  Next: Side Window Options and Functions,  Up: Side Windows
45545
4554628.17.1 Displaying Buffers in Side Windows
45547------------------------------------------
45548
45549The following action function for ‘display-buffer’ (*note Buffer Display
45550Action Functions::) creates or reuses a side window for displaying the
45551specified buffer.
45552
45553 -- Function: display-buffer-in-side-window buffer alist
45554     This function displays BUFFER in a side window of the selected
45555     frame.  It returns the window used for displaying BUFFER, ‘nil’ if
45556     no such window can be found or created.
45557
45558     ALIST is an association list of symbols and values as for
45559     ‘display-buffer’.  The following symbols in ALIST are special for
45560     this function:
45561
45562     ‘side’
45563          Denotes the side of the frame where the window shall be
45564          located.  Valid values are ‘left’, ‘top’, ‘right’ and
45565          ‘bottom’.  If unspecified, the window is located at the bottom
45566          of the frame.
45567
45568     ‘slot’
45569          Denotes a slot at the specified side where to locate the
45570          window.  A value of zero means to preferably position the
45571          window in the middle of the specified side.  A negative value
45572          means to use a slot preceding (that is, above or on the left
45573          of) the middle slot.  A positive value means to use a slot
45574          following (that is, below or on the right of) the middle slot.
45575          Hence, all windows on a specific side are ordered by their
45576          ‘slot’ value.  If unspecified, the window is located in the
45577          middle of the specified side.
45578
45579     If you specify the same slot on the same side for two or more
45580     different buffers, the buffer displayed last is shown in the
45581     corresponding window.  Hence, slots can be used for sharing the
45582     same side window between buffers.
45583
45584     This function installs the ‘window-side’ and ‘window-slot’
45585     parameters (*note Window Parameters::) and makes them persistent.
45586     It does not install any other window parameters unless they have
45587     been explicitly provided via a ‘window-parameters’ entry in ALIST.
45588
45589   By default, side windows cannot be split via ‘split-window’ (*note
45590Splitting Windows::).  Also, a side window is not reused or split by any
45591buffer display action (*note Buffer Display Action Functions::) unless
45592it is explicitly specified as target of that action.  Note also that
45593‘delete-other-windows’ cannot make a side window the only window on its
45594frame (*note Deleting Windows::).
45595
45596   Once set up, side windows also change the behavior of the commands
45597‘switch-to-prev-buffer’ and ‘switch-to-next-buffer’ (*note Window
45598History::).  In particular, these commands will refrain from showing, in
45599a side window, buffers that have not been displayed in that window
45600before.  They will also refrain from having a normal, non-side window
45601show a buffer that has been already displayed in a side window.  A
45602notable exception to the latter rule occurs when an application, after
45603displaying a buffer, resets that buffer’s local variables.
45604
45605
45606File: elisp.info,  Node: Side Window Options and Functions,  Next: Frame Layouts with Side Windows,  Prev: Displaying Buffers in Side Windows,  Up: Side Windows
45607
4560828.17.2 Side Window Options and Functions
45609-----------------------------------------
45610
45611The following options provide additional control over the placement of
45612side windows.
45613
45614 -- User Option: window-sides-vertical
45615     If non-‘nil’, the side windows on the left and right of a frame
45616     occupy the frame’s full height.  Otherwise, the side windows on the
45617     top and bottom of the frame occupy the frame’s full width.
45618
45619 -- User Option: window-sides-slots
45620     This option specifies the maximum number of side windows on each
45621     side of a frame.  The value is a list of four elements specifying
45622     the number of side window slots on (in this order) the left, top,
45623     right and bottom of each frame.  If an element is a number, it
45624     means to display at most that many windows on the corresponding
45625     side.  If an element is ‘nil’, it means there’s no bound on the
45626     number of slots on that side.
45627
45628     If any of the specified values is zero, no window can be created on
45629     the corresponding side.  ‘display-buffer-in-side-window’ will not
45630     signal an error in that case, but will return ‘nil’.  If a
45631     specified value just forbids the creation of an additional side
45632     window, the most suitable window on that side is reused and may
45633     have its ‘window-slot’ parameter changed accordingly.
45634
45635 -- User Option: window-sides-reversed
45636     This option specifies whether top/bottom side windows should appear
45637     in reverse order.  When this is ‘nil’, side windows on the top and
45638     bottom of a frame are always drawn from left to right with
45639     increasing slot values.  When this is ‘t’, the drawing order is
45640     reversed and side windows on the top and bottom of a frame are
45641     drawn from right to left with increasing slot values.
45642
45643     When this is ‘bidi’, the drawing order is reversed if and only if
45644     the value of ‘bidi-paragraph-direction’ (*note Bidirectional
45645     Display::) is ‘right-to-left’ in the buffer displayed in the window
45646     most recently selected within the main window area of this frame.
45647     Sometimes that window may be hard to find, so heuristics are used
45648     to avoid that the drawing order changes inadvertently when another
45649     window gets selected.
45650
45651     The layout of side windows on the left or right of a frame is not
45652     affected by the value of this variable.
45653
45654   When a frame has side windows, the following function returns the
45655main window of that frame.
45656
45657 -- Function: window-main-window &optional frame
45658     This function returns the main window of the specified FRAME.  The
45659     optional argument FRAME must be a live frame and defaults to the
45660     selected one.
45661
45662     If FRAME has no side windows, it returns FRAME’s root window.
45663     Otherwise, it returns either an internal non-side window such that
45664     all other non-side windows on FRAME descend from it, or the single
45665     live non-side window of FRAME.  Note that the main window of a
45666     frame cannot be deleted via ‘delete-window’.
45667
45668   The following command is handy to toggle the appearance of all side
45669windows on a specified frame.
45670
45671 -- Command: window-toggle-side-windows &optional frame
45672     This command toggles side windows on the specified FRAME.  The
45673     optional argument FRAME must be a live frame and defaults to the
45674     selected one.
45675
45676     If FRAME has at least one side window, this command saves the state
45677     of FRAME’s root window in the FRAME’s ‘window-state’ frame
45678     parameter and deletes all side windows on FRAME afterwards.
45679
45680     If FRAME has no side windows, but does have a ‘window-state’
45681     parameter, this command uses that parameter’s value to restore the
45682     side windows on FRAME leaving FRAME’s main window alone.
45683
45684     An error is signaled if FRAME has no side windows and no saved
45685     state is found for it.
45686
45687
45688File: elisp.info,  Node: Frame Layouts with Side Windows,  Prev: Side Window Options and Functions,  Up: Side Windows
45689
4569028.17.3 Frame Layouts with Side Windows
45691---------------------------------------
45692
45693Side windows can be used to create more complex frame layouts like those
45694provided by integrated development environments (IDEs).  In such
45695layouts, the area of the main window is where the normal editing
45696activities take place.  Side windows are not conceived for editing in
45697the usual sense.  Rather, they are supposed to display information
45698complementary to the current editing activity, like lists of files, tags
45699or buffers, help information, search or grep results or shell output.
45700
45701   The layout of such a frame might appear as follows:
45702
45703          ___________________________________
45704         |          *Buffer List*            |
45705         |___________________________________|
45706         |     |                       |     |
45707         |  *  |                       |  *  |
45708         |  d  |                       |  T  |
45709         |  i  |                       |  a  |
45710         |  r  |   Main Window Area    |  g  |
45711         |  e  |                       |  s  |
45712         |  d  |                       |  *  |
45713         |  *  |                       |     |
45714         |_____|_______________________|_____|
45715         | *help*/*grep*/  |  *shell*/       |
45716         | *Completions*   |  *compilation*  |
45717         |_________________|_________________|
45718         |             Echo Area             |
45719         |___________________________________|
45720
45721
45722
45723   The following example illustrates how window parameters (*note Window
45724Parameters::) can be used with ‘display-buffer-in-side-window’ (*note
45725Displaying Buffers in Side Windows::) to set up code for producing the
45726frame layout sketched above.
45727
45728     (defvar parameters
45729       '(window-parameters . ((no-other-window . t)
45730                              (no-delete-other-windows . t))))
45731
45732     (setq fit-window-to-buffer-horizontally t)
45733     (setq window-resize-pixelwise t)
45734
45735     (setq
45736      display-buffer-alist
45737      `(("\\*Buffer List\\*" display-buffer-in-side-window
45738         (side . top) (slot . 0) (window-height . fit-window-to-buffer)
45739         (preserve-size . (nil . t)) ,parameters)
45740        ("\\*Tags List\\*" display-buffer-in-side-window
45741         (side . right) (slot . 0) (window-width . fit-window-to-buffer)
45742         (preserve-size . (t . nil)) ,parameters)
45743        ("\\*\\(?:help\\|grep\\|Completions\\)\\*"
45744         display-buffer-in-side-window
45745         (side . bottom) (slot . -1) (preserve-size . (nil . t))
45746         ,parameters)
45747        ("\\*\\(?:shell\\|compilation\\)\\*" display-buffer-in-side-window
45748         (side . bottom) (slot . 1) (preserve-size . (nil . t))
45749         ,parameters)))
45750
45751   This specifies ‘display-buffer-alist’ entries (*note Choosing
45752Window::) for buffers with fixed names.  In particular, it asks for
45753showing ‘*Buffer List*’ with adjustable height at the top of the frame
45754and ‘*Tags List*’ with adjustable width on the frame’s right.  It also
45755asks for having the ‘*help*’, ‘*grep*’ and ‘*Completions*’ buffers share
45756a window on the bottom left side of the frame and the ‘*shell*’ and
45757‘*compilation*’ buffers appear in a window on the bottom right side of
45758the frame.
45759
45760   Note that the option ‘fit-window-to-buffer-horizontally’ must have a
45761non-‘nil’ value in order to allow horizontal adjustment of windows.
45762Entries are also added that ask for preserving the height of side
45763windows at the top and bottom of the frame and the width of side windows
45764at the left or right of the frame.  To assure that side windows retain
45765their respective sizes when maximizing the frame, the variable
45766‘window-resize-pixelwise’ is set to a non-‘nil’ value.  *Note Resizing
45767Windows::.
45768
45769   The last form also makes sure that none of the created side windows
45770are accessible via ‘C-x o’ by installing the ‘no-other-window’ parameter
45771for each of these windows.  In addition, it makes sure that side windows
45772are not deleted via ‘C-x 1’ by installing the ‘no-delete-other-windows’
45773parameter for each of these windows.
45774
45775   Since ‘dired’ buffers have no fixed names, we use a special function
45776‘dired-default-directory-on-left’ in order to display a lean directory
45777buffer on the left side of the frame.
45778
45779     (defun dired-default-directory-on-left ()
45780       "Display `default-directory' in side window on left, hiding details."
45781       (interactive)
45782       (let ((buffer (dired-noselect default-directory)))
45783         (with-current-buffer buffer (dired-hide-details-mode t))
45784         (display-buffer-in-side-window
45785          buffer `((side . left) (slot . 0)
45786                   (window-width . fit-window-to-buffer)
45787                   (preserve-size . (t . nil)) ,parameters))))
45788
45789   Evaluating the preceding forms and typing, in any order,
45790‘M-x list-buffers’, ‘C-h f’, ‘M-x shell’, ‘M-x list-tags’, and ‘M-x
45791dired-default-directory-on-left’ should now reproduce the frame layout
45792sketched above.
45793
45794
45795File: elisp.info,  Node: Atomic Windows,  Next: Window Point,  Prev: Side Windows,  Up: Windows
45796
4579728.18 Atomic Windows
45798====================
45799
45800Atomic windows are rectangular compositions of at least two live
45801windows.  They have the following distinctive characteristics:
45802
45803   • The function ‘split-window’ (*note Splitting Windows::), when
45804     applied to a constituent of an atomic window, will try to create
45805     the new window outside of the atomic window.
45806
45807   • The function ‘delete-window’ (*note Deleting Windows::), when
45808     applied to a constituent of an atomic window, will try to delete
45809     the entire atomic window instead.
45810
45811   • The function ‘delete-other-windows’ (*note Deleting Windows::),
45812     when applied to a constituent of an atomic window, will try to make
45813     the atomic window fill its frame or main window (*note Side
45814     Windows::).
45815
45816   This means that the basic groups of functions that alter the window
45817structure treat an atomic window like a live one, thus preserving the
45818internal structure of the atomic window.
45819
45820   Atomic windows are useful to construct and preserve window layouts
45821that are meaningful only when all involved buffers are shown
45822simultaneously in a specific manner, such as when showing differences
45823between file revisions, or the same text in different languages or
45824markups.  They can also be used to permanently display information
45825pertinent to a specific window in bars on that window’s sides.
45826
45827   Atomic windows are implemented with the help of the reserved
45828‘window-atom’ window parameter (*note Window Parameters::) and an
45829internal window (*note Basic Windows::) called the root window of the
45830atomic window.  All windows that are part of the same atomic window have
45831this root window as their common ancestor and are assigned a non-‘nil’
45832‘window-atom’ parameter.
45833
45834   The following function returns the root of the atomic window a
45835specified window is part of:
45836
45837 -- Function: window-atom-root &optional window
45838     This functions returns the root of the atomic window WINDOW is a
45839     part of.  The specified WINDOW must be a valid window and defaults
45840     to the selected one.  It returns ‘nil’ if WINDOW is not part of an
45841     atomic window.
45842
45843   The most simple approach to make a new atomic window is to take an
45844existing internal window and apply the following function:
45845
45846 -- Function: window-make-atom window
45847     This function converts WINDOW into an atomic window.  The specified
45848     WINDOW must be an internal window.  All this function does is to
45849     set the ‘window-atom’ parameter of each descendant of WINDOW to
45850     ‘t’.
45851
45852   To create a new atomic window from an existing live window or to add
45853a new window to an existing atomic window, the following buffer display
45854action function (*note Buffer Display Action Functions::) can be used:
45855
45856 -- Function: display-buffer-in-atom-window buffer alist
45857     This function tries to display BUFFER in a new window that will be
45858     combined with an existing window to form an atomic window.  If the
45859     existing window is already part of an atomic window, it adds the
45860     new window to that atomic window.
45861
45862     The specified ALIST is an association list of symbols and values.
45863     The following symbols have a special meaning:
45864
45865     ‘window’
45866          The value of such an element specifies an existing window the
45867          new window shall be combined with.  If it specifies an
45868          internal window, all children of that window become part of
45869          the atomic window too.  If no window is specified, the new
45870          window becomes a sibling of the selected window.  The
45871          ‘window-atom’ parameter of the existing window is set to
45872          ‘main’ provided that window is live and its ‘window-atom’
45873          parameter was not already set.
45874
45875     ‘side’
45876          The value of such an element denotes the side of the existing
45877          window where the new window shall be located.  Valid values
45878          are ‘below’, ‘right’, ‘above’ and ‘left’.  The default is
45879          ‘below’.  The ‘window-atom’ parameter of the new window is set
45880          to this value.
45881
45882     The return value is the new window, ‘nil’ when creating that window
45883     failed.
45884
45885   Note that the value of the ‘window-atom’ parameter does not really
45886matter as long as it is non-‘nil’.  The values assigned by
45887‘display-buffer-in-atom-window’ just allow for easy retrieval of the
45888original and the new window after that function has been applied.  Note
45889also that the ‘window-atom’ parameter is the only window parameter
45890assigned by ‘display-buffer-in-atom-window’.  Further parameters have to
45891be set by the application explicitly via a ‘window-parameters’ entry in
45892ALIST.
45893
45894   Atomic windows automatically cease to exist when one of their
45895constituents gets deleted.  To dissolve an atomic window manually, reset
45896the ‘window-atom’ parameter of its constituents—the root of the atomic
45897window and all its descendants.
45898
45899   The following code snippet, when applied to a single-window frame,
45900first splits the selected window and makes the selected and the new
45901window constituents of an atomic window with their parent as root.  It
45902then displays the buffer ‘*Messages*’ in a new window at the frame’s
45903bottom and makes that new window part of the atomic window just created.
45904
45905     (let ((window (split-window-right)))
45906       (window-make-atom (window-parent window))
45907       (display-buffer-in-atom-window
45908        (get-buffer-create "*Messages*")
45909        `((window . ,(window-parent window)) (window-height . 5))))
45910
45911   At this moment typing ‘C-x 2’ in any window of that frame produces a
45912new window at the bottom of the frame.  Typing ‘C-x 3’ instead will put
45913the new window at the frame’s right.  In either case, typing now ‘C-x 1’
45914in any window of the atomic window will remove the new window only.
45915Typing ‘C-x 0’ in any window of the atomic window will make that new
45916window fill the frame.
45917
45918
45919File: elisp.info,  Node: Window Point,  Next: Window Start and End,  Prev: Atomic Windows,  Up: Windows
45920
4592128.19 Windows and Point
45922=======================
45923
45924Each window has its own value of point (*note Point::), independent of
45925the value of point in other windows displaying the same buffer.  This
45926makes it useful to have multiple windows showing one buffer.
45927
45928   • The window point is established when a window is first created; it
45929     is initialized from the buffer’s point, or from the window point of
45930     another window opened on the buffer if such a window exists.
45931
45932   • Selecting a window sets the value of point in its buffer from the
45933     window’s value of point.  Conversely, deselecting a window sets the
45934     window’s value of point from that of the buffer.  Thus, when you
45935     switch between windows that display a given buffer, the point value
45936     for the selected window is in effect in the buffer, while the point
45937     values for the other windows are stored in those windows.
45938
45939   • As long as the selected window displays the current buffer, the
45940     window’s point and the buffer’s point always move together; they
45941     remain equal.
45942
45943   Emacs displays the cursor, by default as a rectangular block, in each
45944window at the position of that window’s point.  When the user switches
45945to another buffer in a window, Emacs moves that window’s cursor to where
45946point is in that buffer.  If the exact position of point is hidden
45947behind some display element, such as a display string or an image, Emacs
45948displays the cursor immediately before or after that display element.
45949
45950 -- Function: window-point &optional window
45951     This function returns the current position of point in WINDOW.  For
45952     a nonselected window, this is the value point would have (in that
45953     window’s buffer) if that window were selected.  The default for
45954     WINDOW is the selected window.
45955
45956     When WINDOW is the selected window, the value returned is the value
45957     of point in that window’s buffer.  Strictly speaking, it would be
45958     more correct to return the top-level value of point, outside of any
45959     ‘save-excursion’ forms.  But that value is hard to find.
45960
45961 -- Function: set-window-point window position
45962     This function positions point in WINDOW at position POSITION in
45963     WINDOW’s buffer.  It returns POSITION.
45964
45965     If WINDOW is selected, this simply does ‘goto-char’ in WINDOW’s
45966     buffer.
45967
45968 -- Variable: window-point-insertion-type
45969     This variable specifies the marker insertion type (*note Marker
45970     Insertion Types::) of ‘window-point’.  The default is ‘nil’, so
45971     ‘window-point’ will stay behind text inserted there.
45972
45973
45974File: elisp.info,  Node: Window Start and End,  Next: Textual Scrolling,  Prev: Window Point,  Up: Windows
45975
4597628.20 The Window Start and End Positions
45977========================================
45978
45979Each window maintains a marker used to keep track of a buffer position
45980that specifies where in the buffer display should start.  This position
45981is called the “display-start” position of the window (or just the
45982“start”).  The character after this position is the one that appears at
45983the upper left corner of the window.  It is usually, but not inevitably,
45984at the beginning of a text line.
45985
45986   After switching windows or buffers, and in some other cases, if the
45987window start is in the middle of a line, Emacs adjusts the window start
45988to the start of a line.  This prevents certain operations from leaving
45989the window start at a meaningless point within a line.  This feature may
45990interfere with testing some Lisp code by executing it using the commands
45991of Lisp mode, because they trigger this readjustment.  To test such
45992code, put it into a command and bind the command to a key.
45993
45994 -- Function: window-start &optional window
45995     This function returns the display-start position of window WINDOW.
45996     If WINDOW is ‘nil’, the selected window is used.
45997
45998     When you create a window, or display a different buffer in it, the
45999     display-start position is set to a display-start position recently
46000     used for the same buffer, or to ‘point-min’ if the buffer doesn’t
46001     have any.
46002
46003     Redisplay updates the window-start position (if you have not
46004     specified it explicitly since the previous redisplay)—to make sure
46005     point appears on the screen.  Nothing except redisplay
46006     automatically changes the window-start position; if you move point,
46007     do not expect the window-start position to change in response until
46008     after the next redisplay.
46009
46010 -- Function: window-group-start &optional window
46011     This function is like ‘window-start’, except that when WINDOW is a
46012     part of a group of windows (*note Window Group::),
46013     ‘window-group-start’ returns the start position of the entire
46014     group.  This condition holds when the buffer local variable
46015     ‘window-group-start-function’ is set to a function.  In this case,
46016     ‘window-group-start’ calls the function with the single argument
46017     WINDOW, then returns its result.
46018
46019 -- Function: window-end &optional window update
46020     This function returns the position where display of its buffer ends
46021     in WINDOW.  The default for WINDOW is the selected window.
46022
46023     Simply changing the buffer text or moving point does not update the
46024     value that ‘window-end’ returns.  The value is updated only when
46025     Emacs redisplays and redisplay completes without being preempted.
46026
46027     If the last redisplay of WINDOW was preempted, and did not finish,
46028     Emacs does not know the position of the end of display in that
46029     window.  In that case, this function returns ‘nil’.
46030
46031     If UPDATE is non-‘nil’, ‘window-end’ always returns an up-to-date
46032     value for where display ends, based on the current ‘window-start’
46033     value.  If a previously saved value of that position is still
46034     valid, ‘window-end’ returns that value; otherwise it computes the
46035     correct value by scanning the buffer text.
46036
46037     Even if UPDATE is non-‘nil’, ‘window-end’ does not attempt to
46038     scroll the display if point has moved off the screen, the way real
46039     redisplay would do.  It does not alter the ‘window-start’ value.
46040     In effect, it reports where the displayed text will end if
46041     scrolling is not required.  Note that the position it returns might
46042     be only partially visible.
46043
46044 -- Function: window-group-end &optional window update
46045     This function is like ‘window-end’, except that when WINDOW is a
46046     part of a group of windows (*note Window Group::),
46047     ‘window-group-end’ returns the end position of the entire group.
46048     This condition holds when the buffer local variable
46049     ‘window-group-end-function’ is set to a function.  In this case,
46050     ‘window-group-end’ calls the function with the two arguments WINDOW
46051     and UPDATE, then returns its result.  The argument UPDATE has the
46052     same meaning as in ‘window-end’.
46053
46054 -- Function: set-window-start window position &optional noforce
46055     This function sets the display-start position of WINDOW to POSITION
46056     in WINDOW’s buffer.  It returns POSITION.
46057
46058     The display routines insist that the position of point be visible
46059     when a buffer is displayed.  Normally, they select the
46060     display-start position according to their internal logic (and
46061     scroll the window if necessary) to make point visible.  However, if
46062     you specify the start position with this function using ‘nil’ for
46063     NOFORCE, it means you want display to start at POSITION even if
46064     that would put the location of point off the screen.  If this does
46065     place point off screen, the display routines attempt to move point
46066     to the left margin on the middle line in the window.
46067
46068     For example, if point is 1 and you set the start of the window
46069     to 37, the start of the next line, point will be above the top of
46070     the window.  The display routines will automatically move point if
46071     it is still 1 when redisplay occurs.  Here is an example:
46072
46073          ;; Here is what ‘foo’ looks like before executing
46074          ;;   the ‘set-window-start’ expression.
46075
46076          ---------- Buffer: foo ----------
46077          ★This is the contents of buffer foo.
46078          2
46079          3
46080          4
46081          5
46082          6
46083          ---------- Buffer: foo ----------
46084
46085          (set-window-start
46086           (selected-window)
46087           (save-excursion
46088             (goto-char 1)
46089             (forward-line 1)
46090             (point)))
46091          ⇒ 37
46092
46093          ;; Here is what ‘foo’ looks like after executing
46094          ;;   the ‘set-window-start’ expression.
46095          ---------- Buffer: foo ----------
46096          2
46097          3
46098          ★4
46099          5
46100          6
46101          ---------- Buffer: foo ----------
46102
46103     If the attempt to make point visible (i.e., in a fully-visible
46104     screen line) fails, the display routines will disregard the
46105     requested window-start position and compute a new one anyway.
46106     Thus, for reliable results Lisp programs that call this function
46107     should always move point to be inside the window whose display
46108     starts at POSITION.
46109
46110     If NOFORCE is non-‘nil’, and POSITION would place point off screen
46111     at the next redisplay, then redisplay computes a new window-start
46112     position that works well with point, and thus POSITION is not used.
46113
46114 -- Function: set-window-group-start window position &optional noforce
46115     This function is like ‘set-window-start’, except that when WINDOW
46116     is a part of a group of windows (*note Window Group::),
46117     ‘set-window-group-start’ sets the start position of the entire
46118     group.  This condition holds when the buffer local variable
46119     ‘set-window-group-start-function’ is set to a function.  In this
46120     case, ‘set-window-group-start’ calls the function with the three
46121     arguments WINDOW, POSITION, and NOFORCE, then returns its result.
46122     The arguments POSITION and NOFORCE in this function have the same
46123     meaning as in ‘set-window-start’.
46124
46125 -- Function: pos-visible-in-window-p &optional position window
46126          partially
46127     This function returns non-‘nil’ if POSITION is within the range of
46128     text currently visible on the screen in WINDOW.  It returns ‘nil’
46129     if POSITION is scrolled vertically out of view.  Locations that are
46130     partially obscured are not considered visible unless PARTIALLY is
46131     non-‘nil’.  The argument POSITION defaults to the current position
46132     of point in WINDOW; WINDOW defaults to the selected window.  If
46133     POSITION is ‘t’, that means to check either the first visible
46134     position of the last screen line in WINDOW, or the end-of-buffer
46135     position, whichever comes first.
46136
46137     This function considers only vertical scrolling.  If POSITION is
46138     out of view only because WINDOW has been scrolled horizontally,
46139     ‘pos-visible-in-window-p’ returns non-‘nil’ anyway.  *Note
46140     Horizontal Scrolling::.
46141
46142     If POSITION is visible, ‘pos-visible-in-window-p’ returns ‘t’ if
46143     PARTIALLY is ‘nil’; if PARTIALLY is non-‘nil’, and the character
46144     following POSITION is fully visible, it returns a list of the form
46145     ‘(X Y)’, where X and Y are the pixel coordinates relative to the
46146     top left corner of the window; otherwise it returns an extended
46147     list of the form ‘(X Y RTOP RBOT ROWH VPOS)’, where RTOP and RBOT
46148     specify the number of off-window pixels at the top and bottom of
46149     the row at POSITION, ROWH specifies the visible height of that row,
46150     and VPOS specifies the vertical position (zero-based row number) of
46151     that row.
46152
46153     Here is an example:
46154
46155          ;; If point is off the screen now, recenter it now.
46156          (or (pos-visible-in-window-p
46157               (point) (selected-window))
46158              (recenter 0))
46159
46160 -- Function: pos-visible-in-window-group-p &optional position window
46161          partially
46162     This function is like ‘pos-visible-in-window-p’, except that when
46163     WINDOW is a part of a group of windows (*note Window Group::),
46164     ‘pos-visible-in-window-group-p’ tests the visibility of POS in the
46165     entire group, not just in the single WINDOW.  This condition holds
46166     when the buffer local variable
46167     ‘pos-visible-in-window-group-p-function’ is set to a function.  In
46168     this case ‘pos-visible-in-window-group-p’ calls the function with
46169     the three arguments POSITION, WINDOW, and PARTIALLY, then returns
46170     its result.  The arguments POSITION and PARTIALLY have the same
46171     meaning as in ‘pos-visible-in-window-p’.
46172
46173 -- Function: window-line-height &optional line window
46174     This function returns the height of text line LINE in WINDOW.  If
46175     LINE is one of ‘header-line’ or ‘mode-line’, ‘window-line-height’
46176     returns information about the corresponding line of the window.
46177     Otherwise, LINE is a text line number starting from 0.  A negative
46178     number counts from the end of the window.  The default for LINE is
46179     the current line in WINDOW; the default for WINDOW is the selected
46180     window.
46181
46182     If the display is not up to date, ‘window-line-height’ returns
46183     ‘nil’.  In that case, ‘pos-visible-in-window-p’ may be used to
46184     obtain related information.
46185
46186     If there is no line corresponding to the specified LINE,
46187     ‘window-line-height’ returns ‘nil’.  Otherwise, it returns a list
46188     ‘(HEIGHT VPOS YPOS OFFBOT)’, where HEIGHT is the height in pixels
46189     of the visible part of the line, VPOS and YPOS are the vertical
46190     position in lines and pixels of the line relative to the top of the
46191     first text line, and OFFBOT is the number of off-window pixels at
46192     the bottom of the text line.  If there are off-window pixels at the
46193     top of the (first) text line, YPOS is negative.
46194
46195
46196File: elisp.info,  Node: Textual Scrolling,  Next: Vertical Scrolling,  Prev: Window Start and End,  Up: Windows
46197
4619828.21 Textual Scrolling
46199=======================
46200
46201“Textual scrolling” means moving the text up or down through a window.
46202It works by changing the window’s display-start location.  It may also
46203change the value of ‘window-point’ to keep point on the screen (*note
46204Window Point::).
46205
46206   The basic textual scrolling functions are ‘scroll-up’ (which scrolls
46207forward) and ‘scroll-down’ (which scrolls backward).  In these function
46208names, “up” and “down” refer to the direction of motion of the buffer
46209text relative to the window.  Imagine that the text is written on a long
46210roll of paper and that the scrolling commands move the paper up and
46211down.  Thus, if you are looking at the middle of a buffer and repeatedly
46212call ‘scroll-down’, you will eventually see the beginning of the buffer.
46213
46214   Unfortunately, this sometimes causes confusion, because some people
46215tend to think in terms of the opposite convention: they imagine the
46216window moving over text that remains in place, so that “down” commands
46217take you to the end of the buffer.  This convention is consistent with
46218fact that such a command is bound to a key named <PageDown> on modern
46219keyboards.
46220
46221   Textual scrolling functions (aside from ‘scroll-other-window’) have
46222unpredictable results if the current buffer is not the one displayed in
46223the selected window.  *Note Current Buffer::.
46224
46225   If the window contains a row taller than the height of the window
46226(for example in the presence of a large image), the scroll functions
46227will adjust the window’s vertical scroll position to scroll the
46228partially visible row.  Lisp callers can disable this feature by binding
46229the variable ‘auto-window-vscroll’ to ‘nil’ (*note Vertical
46230Scrolling::).
46231
46232 -- Command: scroll-up &optional count
46233     This function scrolls forward by COUNT lines in the selected
46234     window.
46235
46236     If COUNT is negative, it scrolls backward instead.  If COUNT is
46237     ‘nil’ (or omitted), the distance scrolled is
46238     ‘next-screen-context-lines’ lines less than the height of the
46239     window’s text area.
46240
46241     If the selected window cannot be scrolled any further, this
46242     function signals an error.  Otherwise, it returns ‘nil’.
46243
46244 -- Command: scroll-down &optional count
46245     This function scrolls backward by COUNT lines in the selected
46246     window.
46247
46248     If COUNT is negative, it scrolls forward instead.  In other
46249     respects, it behaves the same way as ‘scroll-up’ does.
46250
46251 -- Command: scroll-up-command &optional count
46252     This behaves like ‘scroll-up’, except that if the selected window
46253     cannot be scrolled any further and the value of the variable
46254     ‘scroll-error-top-bottom’ is ‘t’, it tries to move to the end of
46255     the buffer instead.  If point is already there, it signals an
46256     error.
46257
46258 -- Command: scroll-down-command &optional count
46259     This behaves like ‘scroll-down’, except that if the selected window
46260     cannot be scrolled any further and the value of the variable
46261     ‘scroll-error-top-bottom’ is ‘t’, it tries to move to the beginning
46262     of the buffer instead.  If point is already there, it signals an
46263     error.
46264
46265 -- Command: scroll-other-window &optional count
46266     This function scrolls the text in another window upward COUNT
46267     lines.  Negative values of COUNT, or ‘nil’, are handled as in
46268     ‘scroll-up’.
46269
46270     You can specify which buffer to scroll by setting the variable
46271     ‘other-window-scroll-buffer’ to a buffer.  If that buffer isn’t
46272     already displayed, ‘scroll-other-window’ displays it in some
46273     window.
46274
46275     When the selected window is the minibuffer, the next window is
46276     normally the leftmost one immediately above it.  You can specify a
46277     different window to scroll, when the minibuffer is selected, by
46278     setting the variable ‘minibuffer-scroll-window’.  This variable has
46279     no effect when any other window is selected.  When it is non-‘nil’
46280     and the minibuffer is selected, it takes precedence over
46281     ‘other-window-scroll-buffer’.  *Note Definition of
46282     minibuffer-scroll-window::.
46283
46284     When the minibuffer is active, it is the next window if the
46285     selected window is the one at the bottom right corner.  In this
46286     case, ‘scroll-other-window’ attempts to scroll the minibuffer.  If
46287     the minibuffer contains just one line, it has nowhere to scroll to,
46288     so the line reappears after the echo area momentarily displays the
46289     message ‘End of buffer’.
46290
46291 -- Command: scroll-other-window-down &optional count
46292     This function scrolls the text in another window downward COUNT
46293     lines.  Negative values of COUNT, or ‘nil’, are handled as in
46294     ‘scroll-down’.  In other respects, it behaves the same way as
46295     ‘scroll-other-window’ does.
46296
46297 -- Variable: other-window-scroll-buffer
46298     If this variable is non-‘nil’, it tells ‘scroll-other-window’ which
46299     buffer’s window to scroll.
46300
46301 -- User Option: scroll-margin
46302     This option specifies the size of the scroll margin—a minimum
46303     number of lines between point and the top or bottom of a window.
46304     Whenever point gets within this many lines of the top or bottom of
46305     the window, redisplay scrolls the text automatically (if possible)
46306     to move point out of the margin, closer to the center of the
46307     window.
46308
46309 -- User Option: maximum-scroll-margin
46310     This variable limits the effective value of ‘scroll-margin’ to a
46311     fraction of the current window line height.  For example, if the
46312     current window has 20 lines and ‘maximum-scroll-margin’ is 0.1,
46313     then the scroll margins will never be larger than 2 lines, no
46314     matter how big ‘scroll-margin’ is.
46315
46316     ‘maximum-scroll-margin’ itself has a maximum value of 0.5, which
46317     allows setting margins large to keep the cursor at the middle line
46318     of the window (or two middle lines if the window has an even number
46319     of lines).  If it’s set to a larger value (or any value other than
46320     a float between 0.0 and 0.5) then the default value of 0.25 will be
46321     used instead.
46322
46323 -- User Option: scroll-conservatively
46324     This variable controls how scrolling is done automatically when
46325     point moves off the screen (or into the scroll margin).  If the
46326     value is a positive integer N, then redisplay scrolls the text up
46327     to N lines in either direction, if that will bring point back into
46328     proper view.  This behavior is called “conservative scrolling”.
46329     Otherwise, scrolling happens in the usual way, under the control of
46330     other variables such as ‘scroll-up-aggressively’ and
46331     ‘scroll-down-aggressively’.
46332
46333     The default value is zero, which means that conservative scrolling
46334     never happens.
46335
46336 -- User Option: scroll-down-aggressively
46337     The value of this variable should be either ‘nil’ or a fraction F
46338     between 0 and 1.  If it is a fraction, that specifies where on the
46339     screen to put point when scrolling down.  More precisely, when a
46340     window scrolls down because point is above the window start, the
46341     new start position is chosen to put point F part of the window
46342     height from the top.  The larger F, the more aggressive the
46343     scrolling.
46344
46345     A value of ‘nil’ is equivalent to .5, since its effect is to center
46346     point.  This variable automatically becomes buffer-local when set
46347     in any fashion.
46348
46349 -- User Option: scroll-up-aggressively
46350     Likewise, for scrolling up.  The value, F, specifies how far point
46351     should be placed from the bottom of the window; thus, as with
46352     ‘scroll-down-aggressively’, a larger value scrolls more
46353     aggressively.
46354
46355 -- User Option: scroll-step
46356     This variable is an older variant of ‘scroll-conservatively’.  The
46357     difference is that if its value is N, that permits scrolling only
46358     by precisely N lines, not a smaller number.  This feature does not
46359     work with ‘scroll-margin’.  The default value is zero.
46360
46361 -- User Option: scroll-preserve-screen-position
46362     If this option is ‘t’, whenever a scrolling command moves point
46363     off-window, Emacs tries to adjust point to keep the cursor at its
46364     old vertical position in the window, rather than the window edge.
46365
46366     If the value is non-‘nil’ and not ‘t’, Emacs adjusts point to keep
46367     the cursor at the same vertical position, even if the scrolling
46368     command didn’t move point off-window.
46369
46370     This option affects all scroll commands that have a non-‘nil’
46371     ‘scroll-command’ symbol property.
46372
46373 -- User Option: next-screen-context-lines
46374     The value of this variable is the number of lines of continuity to
46375     retain when scrolling by full screens.  For example, ‘scroll-up’
46376     with an argument of ‘nil’ scrolls so that this many lines at the
46377     bottom of the window appear instead at the top.  The default value
46378     is ‘2’.
46379
46380 -- User Option: scroll-error-top-bottom
46381     If this option is ‘nil’ (the default), ‘scroll-up-command’ and
46382     ‘scroll-down-command’ simply signal an error when no more scrolling
46383     is possible.
46384
46385     If the value is ‘t’, these commands instead move point to the
46386     beginning or end of the buffer (depending on scrolling direction);
46387     only if point is already on that position do they signal an error.
46388
46389 -- Command: recenter &optional count redisplay
46390     This function scrolls the text in the selected window so that point
46391     is displayed at a specified vertical position within the window.
46392     It does not move point with respect to the text.
46393
46394     If COUNT is a non-negative number, that puts the line containing
46395     point COUNT lines down from the top of the window.  If COUNT is a
46396     negative number, then it counts upward from the bottom of the
46397     window, so that −1 stands for the last usable line in the window.
46398
46399     If COUNT is ‘nil’ (or a non-‘nil’ list), ‘recenter’ puts the line
46400     containing point in the middle of the window.  If COUNT is ‘nil’
46401     and REDISPLAY is non-‘nil’, this function may redraw the frame,
46402     according to the value of ‘recenter-redisplay’.  Thus, omitting the
46403     second argument can be used to countermand the effect of
46404     ‘recenter-redisplay’ being non-‘nil’.  Interactive calls pass
46405     non-‘nil’ for REDISPLAY.
46406
46407     When ‘recenter’ is called interactively, COUNT is the raw prefix
46408     argument.  Thus, typing ‘C-u’ as the prefix sets the COUNT to a
46409     non-‘nil’ list, while typing ‘C-u 4’ sets COUNT to 4, which
46410     positions the current line four lines from the top.
46411
46412     With an argument of zero, ‘recenter’ positions the current line at
46413     the top of the window.  The command ‘recenter-top-bottom’ offers a
46414     more convenient way to achieve this.
46415
46416 -- Function: recenter-window-group &optional count
46417     This function is like ‘recenter’, except that when the selected
46418     window is part of a group of windows (*note Window Group::),
46419     ‘recenter-window-group’ scrolls the entire group.  This condition
46420     holds when the buffer local variable
46421     ‘recenter-window-group-function’ is set to a function.  In this
46422     case, ‘recenter-window-group’ calls the function with the argument
46423     COUNT, then returns its result.  The argument COUNT has the same
46424     meaning as in ‘recenter’, but with respect to the entire window
46425     group.
46426
46427 -- User Option: recenter-redisplay
46428     If this variable is non-‘nil’, calling ‘recenter’ with a ‘nil’
46429     COUNT argument and non-‘nil’ REDISPLAY argument redraws the frame.
46430     The default value is ‘tty’, which means only redraw the frame if it
46431     is a tty frame.
46432
46433 -- Command: recenter-top-bottom &optional count
46434     This command, which is the default binding for ‘C-l’, acts like
46435     ‘recenter’, except if called with no argument.  In that case,
46436     successive calls place point according to the cycling order defined
46437     by the variable ‘recenter-positions’.
46438
46439 -- User Option: recenter-positions
46440     This variable controls how ‘recenter-top-bottom’ behaves when
46441     called with no argument.  The default value is ‘(middle top
46442     bottom)’, which means that successive calls of
46443     ‘recenter-top-bottom’ with no argument cycle between placing point
46444     at the middle, top, and bottom of the window.
46445
46446
46447File: elisp.info,  Node: Vertical Scrolling,  Next: Horizontal Scrolling,  Prev: Textual Scrolling,  Up: Windows
46448
4644928.22 Vertical Fractional Scrolling
46450===================================
46451
46452“Vertical fractional scrolling” means shifting text in a window up or
46453down by a specified multiple or fraction of a line.  Emacs uses it, for
46454example, on images and screen lines which are taller than the window.
46455Each window has a “vertical scroll position”, which is a number, never
46456less than zero.  It specifies how far to raise the contents of the
46457window when displaying them.  Raising the window contents generally
46458makes all or part of some lines disappear off the top, and all or part
46459of some other lines appear at the bottom.  The usual value is zero.
46460
46461   The vertical scroll position is measured in units of the normal line
46462height, which is the height of the default font.  Thus, if the value is
46463.5, that means the window contents will be scrolled up half the normal
46464line height.  If it is 3.3, that means the window contents are scrolled
46465up somewhat over three times the normal line height.
46466
46467   What fraction of a line the vertical scrolling covers, or how many
46468lines, depends on what the lines contain.  A value of .5 could scroll a
46469line whose height is very short off the screen, while a value of 3.3
46470could scroll just part of the way through a tall line or an image.
46471
46472 -- Function: window-vscroll &optional window pixels-p
46473     This function returns the current vertical scroll position of
46474     WINDOW.  The default for WINDOW is the selected window.  If
46475     PIXELS-P is non-‘nil’, the return value is measured in pixels,
46476     rather than in units of the normal line height.
46477
46478          (window-vscroll)
46479               ⇒ 0
46480
46481 -- Function: set-window-vscroll window lines &optional pixels-p
46482     This function sets WINDOW’s vertical scroll position to LINES.  If
46483     WINDOW is ‘nil’, the selected window is used.  The argument LINES
46484     should be zero or positive; if not, it is taken as zero.
46485
46486     The actual vertical scroll position must always correspond to an
46487     integral number of pixels, so the value you specify is rounded
46488     accordingly.
46489
46490     The return value is the result of this rounding.
46491
46492          (set-window-vscroll (selected-window) 1.2)
46493               ⇒ 1.13
46494
46495     If PIXELS-P is non-‘nil’, LINES specifies a number of pixels.  In
46496     this case, the return value is LINES.
46497
46498 -- Variable: auto-window-vscroll
46499     If this variable is non-‘nil’, the ‘line-move’, ‘scroll-up’, and
46500     ‘scroll-down’ functions will automatically modify the vertical
46501     scroll position to scroll through display rows that are taller than
46502     the height of the window, for example in the presence of large
46503     images.
46504
46505
46506File: elisp.info,  Node: Horizontal Scrolling,  Next: Coordinates and Windows,  Prev: Vertical Scrolling,  Up: Windows
46507
4650828.23 Horizontal Scrolling
46509==========================
46510
46511“Horizontal scrolling” means shifting the image in the window left or
46512right by a specified multiple of the normal character width.  Each
46513window has a “horizontal scroll position”, which is a number, never less
46514than zero.  It specifies how far to shift the contents left.  Shifting
46515the window contents left generally makes all or part of some characters
46516disappear off the left, and all or part of some other characters appear
46517at the right.  The usual value is zero.
46518
46519   The horizontal scroll position is measured in units of the normal
46520character width, which is the width of space in the default font.  Thus,
46521if the value is 5, that means the window contents are scrolled left by 5
46522times the normal character width.  How many characters actually
46523disappear off to the left depends on their width, and could vary from
46524line to line.
46525
46526   Because we read from side to side in the inner loop, and from top to
46527bottom in the outer loop, the effect of horizontal scrolling is not like
46528that of textual or vertical scrolling.  Textual scrolling involves
46529selection of a portion of text to display, and vertical scrolling moves
46530the window contents contiguously; but horizontal scrolling causes part
46531of _each line_ to go off screen.
46532
46533   Usually, no horizontal scrolling is in effect; then the leftmost
46534column is at the left edge of the window.  In this state, scrolling to
46535the right is meaningless, since there is no data to the left of the edge
46536to be revealed by it; so this is not allowed.  Scrolling to the left is
46537allowed; it scrolls the first columns of text off the edge of the window
46538and can reveal additional columns on the right that were truncated
46539before.  Once a window has a nonzero amount of leftward horizontal
46540scrolling, you can scroll it back to the right, but only so far as to
46541reduce the net horizontal scroll to zero.  There is no limit to how far
46542left you can scroll, but eventually all the text will disappear off the
46543left edge.
46544
46545   If ‘auto-hscroll-mode’ is set, redisplay automatically alters the
46546horizontal scrolling of a window as necessary to ensure that point is
46547always visible.  However, you can still set the horizontal scrolling
46548value explicitly.  The value you specify serves as a lower bound for
46549automatic scrolling, i.e., automatic scrolling will not scroll a window
46550to a column less than the specified one.
46551
46552   The default value of ‘auto-hscroll-mode’ is ‘t’; setting it to
46553‘current-line’ activates a variant of automatic horizontal scrolling
46554whereby only the line showing the cursor is horizontally scrolled to
46555make point visible, the rest of the window is left either unscrolled, or
46556at the minimum scroll amount set by ‘scroll-left’ and ‘scroll-right’,
46557see below.
46558
46559 -- Command: scroll-left &optional count set-minimum
46560     This function scrolls the selected window COUNT columns to the left
46561     (or to the right if COUNT is negative).  The default for COUNT is
46562     the window width, minus 2.
46563
46564     The return value is the total amount of leftward horizontal
46565     scrolling in effect after the change—just like the value returned
46566     by ‘window-hscroll’ (below).
46567
46568     Note that text in paragraphs whose base direction is right-to-left
46569     (*note Bidirectional Display::) moves in the opposite direction:
46570     e.g., it moves to the right when ‘scroll-left’ is invoked with a
46571     positive value of COUNT.
46572
46573     Once you scroll a window as far right as it can go, back to its
46574     normal position where the total leftward scrolling is zero,
46575     attempts to scroll any farther right have no effect.
46576
46577     If SET-MINIMUM is non-‘nil’, the new scroll amount becomes the
46578     lower bound for automatic scrolling; that is, automatic scrolling
46579     will not scroll a window to a column less than the value returned
46580     by this function.  Interactive calls pass non-‘nil’ for
46581     SET-MINIMUM.
46582
46583 -- Command: scroll-right &optional count set-minimum
46584     This function scrolls the selected window COUNT columns to the
46585     right (or to the left if COUNT is negative).  The default for COUNT
46586     is the window width, minus 2.  Aside from the direction of
46587     scrolling, this works just like ‘scroll-left’.
46588
46589 -- Function: window-hscroll &optional window
46590     This function returns the total leftward horizontal scrolling of
46591     WINDOW—the number of columns by which the text in WINDOW is
46592     scrolled left past the left margin.  (In right-to-left paragraphs,
46593     the value is the total amount of the rightward scrolling instead.)
46594     The default for WINDOW is the selected window.
46595
46596     The return value is never negative.  It is zero when no horizontal
46597     scrolling has been done in WINDOW (which is usually the case).
46598
46599          (window-hscroll)
46600               ⇒ 0
46601          (scroll-left 5)
46602               ⇒ 5
46603          (window-hscroll)
46604               ⇒ 5
46605
46606 -- Function: set-window-hscroll window columns
46607     This function sets horizontal scrolling of WINDOW.  The value of
46608     COLUMNS specifies the amount of scrolling, in terms of columns from
46609     the left margin (right margin in right-to-left paragraphs).  The
46610     argument COLUMNS should be zero or positive; if not, it is taken as
46611     zero.  Fractional values of COLUMNS are not supported at present.
46612
46613     Note that ‘set-window-hscroll’ may appear not to work if you test
46614     it by evaluating a call with ‘M-:’ in a simple way.  What happens
46615     is that the function sets the horizontal scroll value and returns,
46616     but then redisplay adjusts the horizontal scrolling to make point
46617     visible, and this overrides what the function did.  You can observe
46618     the function’s effect if you call it while point is sufficiently
46619     far from the left margin that it will remain visible.
46620
46621     The value returned is COLUMNS.
46622
46623          (set-window-hscroll (selected-window) 10)
46624               ⇒ 10
46625
46626   Here is how you can determine whether a given position POSITION is
46627off the screen due to horizontal scrolling:
46628
46629     (defun hscroll-on-screen (window position)
46630       (save-excursion
46631         (goto-char position)
46632         (and
46633          (>= (- (current-column) (window-hscroll window)) 0)
46634          (< (- (current-column) (window-hscroll window))
46635             (window-width window)))))
46636
46637
46638File: elisp.info,  Node: Coordinates and Windows,  Next: Mouse Window Auto-selection,  Prev: Horizontal Scrolling,  Up: Windows
46639
4664028.24 Coordinates and Windows
46641=============================
46642
46643This section describes functions that report positions of and within a
46644window.  Most of these functions report positions relative to an origin
46645at the native position of the window’s frame (*note Frame Geometry::).
46646Some functions report positions relative to the origin of the display of
46647the window’s frame.  In any case, the origin has the coordinates (0, 0)
46648and X and Y coordinates increase rightward and downward respectively.
46649
46650   For the following functions, X and Y coordinates are reported in
46651integer character units, i.e., numbers of lines and columns
46652respectively.  On a graphical display, each “line” and “column”
46653corresponds to the height and width of the default character specified
46654by the frame’s default font (*note Frame Font::).
46655
46656 -- Function: window-edges &optional window body absolute pixelwise
46657     This function returns a list of the edge coordinates of WINDOW.  If
46658     WINDOW is omitted or ‘nil’, it defaults to the selected window.
46659
46660     The return value has the form ‘(LEFT TOP RIGHT BOTTOM)’.  These
46661     list elements are, respectively, the X coordinate of the leftmost
46662     column occupied by the window, the Y coordinate of the topmost row,
46663     the X coordinate one column to the right of the rightmost column,
46664     and the Y coordinate one row down from the bottommost row.
46665
46666     Note that these are the actual outer edges of the window, including
46667     any header line, mode line, scroll bar, fringes, window divider and
46668     display margins.  On a text terminal, if the window has a neighbor
46669     on its right, its right edge includes the separator line between
46670     the window and its neighbor.
46671
46672     If the optional argument BODY is ‘nil’, this means to return the
46673     edges corresponding to the total size of WINDOW.  BODY non-‘nil’
46674     means to return the edges of WINDOW’s body (aka text area).  If
46675     BODY is non-‘nil’, WINDOW must specify a live window.
46676
46677     If the optional argument ABSOLUTE is ‘nil’, this means to return
46678     edges relative to the native position of WINDOW’s frame.  ABSOLUTE
46679     non-‘nil’ means to return coordinates relative to the origin (0, 0)
46680     of WINDOW’s display.  On non-graphical systems this argument has no
46681     effect.
46682
46683     If the optional argument PIXELWISE is ‘nil’, this means to return
46684     the coordinates in terms of the default character width and height
46685     of WINDOW’s frame (*note Frame Font::), rounded if necessary.
46686     PIXELWISE non-‘nil’ means to return the coordinates in pixels.
46687     Note that the pixel specified by RIGHT and BOTTOM is immediately
46688     outside of these edges.  If ABSOLUTE is non-‘nil’, PIXELWISE is
46689     implicitly non-‘nil’ too.
46690
46691 -- Function: window-body-edges &optional window
46692     This function returns the edges of WINDOW’s body (*note Window
46693     Sizes::).  Calling ‘(window-body-edges window)’ is equivalent to
46694     calling ‘(window-edges window t)’, see above.
46695
46696   The following functions can be used to relate a set of frame-relative
46697coordinates to a window:
46698
46699 -- Function: window-at x y &optional frame
46700     This function returns the live window at the coordinates X and Y
46701     given in default character sizes (*note Frame Font::) relative to
46702     the native position of FRAME (*note Frame Geometry::).
46703
46704     If there is no window at that position, the return value is ‘nil’.
46705     If FRAME is omitted or ‘nil’, it defaults to the selected frame.
46706
46707 -- Function: coordinates-in-window-p coordinates window
46708     This function checks whether a window WINDOW occupies the frame
46709     relative coordinates COORDINATES, and if so, which part of the
46710     window that is.  WINDOW should be a live window.
46711
46712     COORDINATES should be a cons cell of the form ‘(X . Y)’, where X
46713     and Y are given in default character sizes (*note Frame Font::)
46714     relative to the native position of WINDOW’s frame (*note Frame
46715     Geometry::).
46716
46717     If there is no window at the specified position, the return value
46718     is ‘nil’ .  Otherwise, the return value is one of the following:
46719
46720     ‘(RELX . RELY)’
46721          The coordinates are inside WINDOW.  The numbers RELX and RELY
46722          are the equivalent window-relative coordinates for the
46723          specified position, counting from 0 at the top left corner of
46724          the window.
46725
46726     ‘mode-line’
46727          The coordinates are in the mode line of WINDOW.
46728
46729     ‘header-line’
46730          The coordinates are in the header line of WINDOW.
46731
46732     ‘tab-line’
46733          The coordinates are in the tab line of WINDOW.
46734
46735     ‘right-divider’
46736          The coordinates are in the divider separating WINDOW from a
46737          window on the right.
46738
46739     ‘bottom-divider’
46740          The coordinates are in the divider separating WINDOW from a
46741          window beneath.
46742
46743     ‘vertical-line’
46744          The coordinates are in the vertical line between WINDOW and
46745          its neighbor to the right.  This value occurs only if the
46746          window doesn’t have a scroll bar; positions in a scroll bar
46747          are considered outside the window for these purposes.
46748
46749     ‘left-fringe’
46750     ‘right-fringe’
46751          The coordinates are in the left or right fringe of the window.
46752
46753     ‘left-margin’
46754     ‘right-margin’
46755          The coordinates are in the left or right margin of the window.
46756
46757     ‘nil’
46758          The coordinates are not in any part of WINDOW.
46759
46760     The function ‘coordinates-in-window-p’ does not require a frame as
46761     argument because it always uses the frame that WINDOW is on.
46762
46763   The following functions return window positions in pixels, rather
46764than character units.  Though mostly useful on graphical displays, they
46765can also be called on text terminals, where the screen area of each text
46766character is taken to be one pixel.
46767
46768 -- Function: window-pixel-edges &optional window
46769     This function returns a list of pixel coordinates for the edges of
46770     WINDOW.  Calling ‘(window-pixel-edges window)’ is equivalent to
46771     calling ‘(window-edges window nil nil t)’, see above.
46772
46773 -- Function: window-body-pixel-edges &optional window
46774     This function returns the pixel edges of WINDOW’s body.  Calling
46775     ‘(window-body-pixel-edges window)’ is equivalent to calling
46776     ‘(window-edges window t nil t)’, see above.
46777
46778   The following functions return window positions in pixels, relative
46779to the origin of the display screen rather than that of the frame:
46780
46781 -- Function: window-absolute-pixel-edges &optional window
46782     This function returns the pixel coordinates of WINDOW relative to
46783     an origin at (0, 0) of the display of WINDOW’s frame.  Calling
46784     ‘(window-absolute-pixel-edges)’ is equivalent to calling
46785     ‘(window-edges window nil t t)’, see above.
46786
46787 -- Function: window-absolute-body-pixel-edges &optional window
46788     This function returns the pixel coordinates of WINDOW’s body
46789     relative to an origin at (0, 0) of the display of WINDOW’s frame.
46790     Calling ‘(window-absolute-body-pixel-edges window)’ is equivalent
46791     to calling ‘(window-edges window t t t)’, see above.
46792
46793     Combined with ‘set-mouse-absolute-pixel-position’, this function
46794     can be used to move the mouse pointer to an arbitrary buffer
46795     position visible in some window:
46796
46797          (let ((edges (window-absolute-body-pixel-edges))
46798                (position (pos-visible-in-window-p nil nil t)))
46799            (set-mouse-absolute-pixel-position
46800             (+ (nth 0 edges) (nth 0 position))
46801             (+ (nth 1 edges) (nth 1 position))))
46802
46803     On a graphical terminal this form “warps” the mouse cursor to the
46804     upper left corner of the glyph at the selected window’s point.  A
46805     position calculated this way can be also used to show a tooltip
46806     window there.
46807
46808   The following function returns the screen coordinates of a buffer
46809position visible in a window:
46810
46811 -- Function: window-absolute-pixel-position &optional position window
46812     If the buffer position POSITION is visible in window WINDOW, this
46813     function returns the display coordinates of the upper/left corner
46814     of the glyph at POSITION.  The return value is a cons of the X- and
46815     Y-coordinates of that corner, relative to an origin at (0, 0) of
46816     WINDOW’s display.  It returns ‘nil’ if POSITION is not visible in
46817     WINDOW.
46818
46819     WINDOW must be a live window and defaults to the selected window.
46820     POSITION defaults to the value of ‘window-point’ of WINDOW.
46821
46822     This means that in order to move the mouse pointer to the position
46823     of point in the selected window, it’s sufficient to write:
46824
46825          (let ((position (window-absolute-pixel-position)))
46826            (set-mouse-absolute-pixel-position
46827             (car position) (cdr position)))
46828
46829   The following function returns the largest rectangle that can be
46830inscribed in a window without covering text displayed in that window.
46831
46832 -- Function: window-largest-empty-rectangle &optional window count
46833          min-width min-height positions left
46834     This function calculates the dimensions of the largest empty
46835     rectangle that can be inscribed in the specified WINDOW’s text
46836     area.  WINDOW must be a live window and defaults to the selected
46837     one.
46838
46839     The return value is a triple of the width and the start and end
46840     y-coordinates of the largest rectangle that can be inscribed into
46841     the empty space (space not displaying any text) of the text area of
46842     WINDOW.  No x-coordinates are returned by this function—any such
46843     rectangle is assumed to end at the right edge of WINDOW’s text
46844     area.  If no empty space can be found, the return value is ‘nil’.
46845
46846     The optional argument COUNT, if non-‘nil’, specifies a maximum
46847     number of rectangles to return.  This means that the return value
46848     is a list of triples specifying rectangles with the largest
46849     rectangle first.  COUNT can be also a cons cell whose car specifies
46850     the number of rectangles to return and whose CDR, if non-‘nil’,
46851     states that all rectangles returned must be disjoint.
46852
46853     The optional arguments MIN-WIDTH and MIN-HEIGHT, if non-‘nil’,
46854     specify the minimum width and height of any rectangle returned.
46855
46856     The optional argument POSITIONS, if non-‘nil’, is a cons cell whose
46857     CAR specifies the uppermost and whose CDR specifies the lowermost
46858     pixel position that must be covered by any rectangle returned.
46859     These positions measure from the start of the text area of WINDOW.
46860
46861     The optional argument LEFT, if non-‘nil’, means to return values
46862     suitable for buffers displaying right to left text.  In that case,
46863     any rectangle returned is assumed to start at the left edge of
46864     WINDOW’s text area.
46865
46866     Note that this function has to retrieve the dimensions of each line
46867     of WINDOW’s glyph matrix via ‘window-lines-pixel-dimensions’ (*note
46868     Size of Displayed Text::).  Hence, this function may also return
46869     ‘nil’ when the current glyph matrix of WINDOW is not up-to-date.
46870
46871
46872File: elisp.info,  Node: Mouse Window Auto-selection,  Next: Window Configurations,  Prev: Coordinates and Windows,  Up: Windows
46873
4687428.25 Mouse Window Auto-selection
46875=================================
46876
46877The following option allows to automatically select the window under the
46878mouse pointer.  This accomplishes a policy similar to that of window
46879managers that give focus to a frame (and thus trigger its subsequent
46880selection) whenever the mouse pointer enters its window-system window
46881(*note Input Focus::).
46882
46883 -- User Option: mouse-autoselect-window
46884     If this variable is non-‘nil’, Emacs will try to automatically
46885     select the window under the mouse pointer.  The following values
46886     are meaningful:
46887
46888     A positive number
46889          This specifies a delay in seconds after which auto-selection
46890          triggers.  The window under the mouse pointer is selected
46891          after the mouse has remained in it for the entire duration of
46892          the delay.
46893
46894     A negative number
46895          A negative number has a similar effect as a positive number,
46896          but selects the window under the mouse pointer only after the
46897          mouse pointer has remained in it for the entire duration of
46898          the absolute value of that number and in addition has stopped
46899          moving.
46900
46901     Other value
46902          Any other non-‘nil’ value means to select a window
46903          instantaneously as soon as the mouse pointer enters it.
46904
46905     In either case, the mouse pointer must enter the text area of a
46906     window in order to trigger its selection.  Dragging the scroll bar
46907     slider or the mode line of a window conceptually should not cause
46908     its auto-selection.
46909
46910     Mouse auto-selection selects the minibuffer window only if it is
46911     active, and never deselects the active minibuffer window.
46912
46913   Mouse auto-selection can be used to emulate a focus follows mouse
46914policy for child frames (*note Child Frames::) which usually are not
46915tracked by the window manager.  This requires to set the value of
46916‘focus-follows-mouse’ (*note Input Focus::) to a non-‘nil’ value.  If
46917the value of ‘focus-follows-mouse’ is ‘auto-raise’, entering a child
46918frame with the mouse will raise it automatically above all other child
46919frames of that frame’s parent frame.
46920
46921
46922File: elisp.info,  Node: Window Configurations,  Next: Window Parameters,  Prev: Mouse Window Auto-selection,  Up: Windows
46923
4692428.26 Window Configurations
46925===========================
46926
46927A “window configuration” records the entire layout of one frame—all
46928windows, their sizes, which buffers they contain, how those buffers are
46929scrolled, and their value of point; also their fringes, margins, and
46930scroll bar settings.  It also includes the value of
46931‘minibuffer-scroll-window’.  As a special exception, the window
46932configuration does not record the value of point in the selected window
46933for the current buffer.
46934
46935   You can bring back an entire frame layout by restoring a previously
46936saved window configuration.  If you want to record the layout of all
46937frames instead of just one, use a frame configuration instead of a
46938window configuration.  *Note Frame Configurations::.
46939
46940 -- Function: current-window-configuration &optional frame
46941     This function returns a new object representing FRAME’s current
46942     window configuration.  The default for FRAME is the selected frame.
46943     The variable ‘window-persistent-parameters’ specifies which window
46944     parameters (if any) are saved by this function.  *Note Window
46945     Parameters::.
46946
46947 -- Function: set-window-configuration configuration
46948     This function restores the configuration of windows and buffers as
46949     specified by CONFIGURATION, for the frame that CONFIGURATION was
46950     created for, regardless of whether that frame is selected or not.
46951     The argument CONFIGURATION must be a value that was previously
46952     returned by ‘current-window-configuration’ for that frame.
46953
46954     If the frame from which CONFIGURATION was saved is dead, all this
46955     function does is to restore the value of the variable
46956     ‘minibuffer-scroll-window’ and to adjust the value returned by
46957     ‘minibuffer-selected-window’.  In this case, the function returns
46958     ‘nil’.  Otherwise, it returns ‘t’.
46959
46960     If the buffer of a window of CONFIGURATION has been killed since
46961     CONFIGURATION was made, that window is, as a rule, removed from the
46962     restored configuration.  However, if that window is the last window
46963     remaining in the restored configuration, another live buffer is
46964     shown in it.
46965
46966     Here is a way of using this function to get the same effect as
46967     ‘save-window-excursion’:
46968
46969          (let ((config (current-window-configuration)))
46970            (unwind-protect
46971                (progn (split-window-below nil)
46972                       ...)
46973              (set-window-configuration config)))
46974
46975 -- Macro: save-window-excursion forms...
46976     This macro records the window configuration of the selected frame,
46977     executes FORMS in sequence, then restores the earlier window
46978     configuration.  The return value is the value of the final form in
46979     FORMS.
46980
46981     Most Lisp code should not use this macro; ‘save-selected-window’ is
46982     typically sufficient.  In particular, this macro cannot reliably
46983     prevent the code in FORMS from opening new windows, because new
46984     windows might be opened in other frames (*note Choosing Window::),
46985     and ‘save-window-excursion’ only saves and restores the window
46986     configuration on the current frame.
46987
46988 -- Function: window-configuration-p object
46989     This function returns ‘t’ if OBJECT is a window configuration.
46990
46991 -- Function: compare-window-configurations config1 config2
46992     This function compares two window configurations as regards the
46993     structure of windows, but ignores the values of point and the saved
46994     scrolling positions—it can return ‘t’ even if those aspects differ.
46995
46996     The function ‘equal’ can also compare two window configurations; it
46997     regards configurations as unequal if they differ in any respect,
46998     even a saved point.
46999
47000 -- Function: window-configuration-frame config
47001     This function returns the frame for which the window configuration
47002     CONFIG was made.
47003
47004   Other primitives to look inside of window configurations would make
47005sense, but are not implemented because we did not need them.  See the
47006file ‘winner.el’ for some more operations on windows configurations.
47007
47008   The objects returned by ‘current-window-configuration’ die together
47009with the Emacs process.  In order to store a window configuration on
47010disk and read it back in another Emacs session, you can use the
47011functions described next.  These functions are also useful to clone the
47012state of a frame into an arbitrary live window
47013(‘set-window-configuration’ effectively clones the windows of a frame
47014into the root window of that very frame only).
47015
47016 -- Function: window-state-get &optional window writable
47017     This function returns the state of WINDOW as a Lisp object.  The
47018     argument WINDOW must be a valid window and defaults to the root
47019     window of the selected frame.
47020
47021     If the optional argument WRITABLE is non-‘nil’, this means to not
47022     use markers for sampling positions like ‘window-point’ or
47023     ‘window-start’.  This argument should be non-‘nil’ when the state
47024     will be written to disk and read back in another session.
47025
47026     Together, the argument WRITABLE and the variable
47027     ‘window-persistent-parameters’ specify which window parameters are
47028     saved by this function.  *Note Window Parameters::.
47029
47030   The value returned by ‘window-state-get’ can be used in the same
47031session to make a clone of a window in another window.  It can be also
47032written to disk and read back in another session.  In either case, use
47033the following function to restore the state of the window.
47034
47035 -- Function: window-state-put state &optional window ignore
47036     This function puts the window state STATE into WINDOW.  The
47037     argument STATE should be the state of a window returned by an
47038     earlier invocation of ‘window-state-get’, see above.  The optional
47039     argument WINDOW can be either a live window or an internal window
47040     (*note Windows and Frames::).  If WINDOW is not a live window, it
47041     is replaced by a new live window created on the same frame before
47042     putting STATE into it.  If WINDOW is ‘nil’, it puts the window
47043     state into a new window.
47044
47045     If the optional argument IGNORE is non-‘nil’, it means to ignore
47046     minimum window sizes and fixed-size restrictions.  If IGNORE is
47047     ‘safe’, this means windows can get as small as one line and/or two
47048     columns.
47049
47050   The functions ‘window-state-get’ and ‘window-state-put’ also allow to
47051exchange the contents of two live windows.  The following function does
47052precisely that:
47053
47054 -- Command: window-swap-states &optional window-1 window-2 size
47055     This command swaps the states of the two live windows WINDOW-1 and
47056     WINDOW-2.  WINDOW-1 must specify a live window and defaults to the
47057     selected one.  WINDOW-2 must specify a live window and defaults to
47058     the window following WINDOW-1 in the cyclic ordering of windows,
47059     excluding minibuffer windows and including live windows on all
47060     visible frames.
47061
47062     Optional argument SIZE non-‘nil’ means to try swapping the sizes of
47063     WINDOW-1 and WINDOW-2 as well.  A value of ‘height’ means to swap
47064     heights only, a value of ‘width’ means to swap widths only, while
47065     ‘t’ means to swap both widths and heights, if possible.  Frames are
47066     not resized by this function.
47067
47068
47069File: elisp.info,  Node: Window Parameters,  Next: Window Hooks,  Prev: Window Configurations,  Up: Windows
47070
4707128.27 Window Parameters
47072=======================
47073
47074This section describes the window parameters that can be used to
47075associate additional information with windows.
47076
47077 -- Function: window-parameter window parameter
47078     This function returns WINDOW’s value for PARAMETER.  The default
47079     for WINDOW is the selected window.  If WINDOW has no setting for
47080     PARAMETER, this function returns ‘nil’.
47081
47082 -- Function: window-parameters &optional window
47083     This function returns all parameters of WINDOW and their values.
47084     The default for WINDOW is the selected window.  The return value is
47085     either ‘nil’, or an association list whose elements have the form
47086     ‘(PARAMETER . VALUE)’.
47087
47088 -- Function: set-window-parameter window parameter value
47089     This function sets WINDOW’s value of PARAMETER to VALUE and returns
47090     VALUE.  The default for WINDOW is the selected window.
47091
47092   By default, the functions that save and restore window configurations
47093or the states of windows (*note Window Configurations::) do not care
47094about window parameters.  This means that when you change the value of a
47095parameter within the body of a ‘save-window-excursion’, the previous
47096value is not restored when that macro exits.  It also means that when
47097you restore via ‘window-state-put’ a window state saved earlier by
47098‘window-state-get’, all cloned windows have their parameters reset to
47099‘nil’.  The following variable allows you to override the standard
47100behavior:
47101
47102 -- Variable: window-persistent-parameters
47103     This variable is an alist specifying which parameters get saved by
47104     ‘current-window-configuration’ and ‘window-state-get’, and
47105     subsequently restored by ‘set-window-configuration’ and
47106     ‘window-state-put’.  *Note Window Configurations::.
47107
47108     The CAR of each entry of this alist is a symbol specifying the
47109     parameter.  The CDR should be one of the following:
47110
47111     ‘nil’
47112          This value means the parameter is saved neither by
47113          ‘window-state-get’ nor by ‘current-window-configuration’.
47114
47115     ‘t’
47116          This value specifies that the parameter is saved by
47117          ‘current-window-configuration’ and (provided its WRITABLE
47118          argument is ‘nil’) by ‘window-state-get’.
47119
47120     ‘writable’
47121          This means that the parameter is saved unconditionally by both
47122          ‘current-window-configuration’ and ‘window-state-get’.  This
47123          value should not be used for parameters whose values do not
47124          have a read syntax.  Otherwise, invoking ‘window-state-put’ in
47125          another session may fail with an ‘invalid-read-syntax’ error.
47126
47127   Some functions (notably ‘delete-window’, ‘delete-other-windows’ and
47128‘split-window’), may behave specially when the window specified by their
47129WINDOW argument has a parameter whose name is equal to the function’s
47130name.  You can override such special behavior by binding the following
47131variable to a non-‘nil’ value:
47132
47133 -- Variable: ignore-window-parameters
47134     If this variable is non-‘nil’, some standard functions do not
47135     process window parameters.  The functions currently affected by
47136     this are ‘split-window’, ‘delete-window’, ‘delete-other-windows’,
47137     and ‘other-window’.
47138
47139     An application can bind this variable to a non-‘nil’ value around
47140     calls to these functions.  If it does so, the application is fully
47141     responsible for correctly assigning the parameters of all involved
47142     windows when exiting that function.
47143
47144   The following parameters are currently used by the window management
47145code:
47146
47147‘delete-window’
47148     This parameter affects the execution of ‘delete-window’ (*note
47149     Deleting Windows::).
47150
47151‘delete-other-windows’
47152     This parameter affects the execution of ‘delete-other-windows’
47153     (*note Deleting Windows::).
47154
47155‘no-delete-other-windows’
47156     This parameter marks the window as not deletable by
47157     ‘delete-other-windows’ (*note Deleting Windows::).
47158
47159‘split-window’
47160     This parameter affects the execution of ‘split-window’ (*note
47161     Splitting Windows::).
47162
47163‘other-window’
47164     This parameter affects the execution of ‘other-window’ (*note
47165     Cyclic Window Ordering::).
47166
47167‘no-other-window’
47168     This parameter marks the window as not selectable by ‘other-window’
47169     (*note Cyclic Window Ordering::).
47170
47171‘clone-of’
47172     This parameter specifies the window that this one has been cloned
47173     from.  It is installed by ‘window-state-get’ (*note Window
47174     Configurations::).
47175
47176‘window-preserved-size’
47177     This parameter specifies a buffer, a direction where ‘nil’ means
47178     vertical and ‘t’ horizontal, and a size in pixels.  If this window
47179     displays the specified buffer and its size in the indicated
47180     direction equals the size specified by this parameter, then Emacs
47181     will try to preserve the size of this window in the indicated
47182     direction.  This parameter is installed and updated by the function
47183     ‘window-preserve-size’ (*note Preserving Window Sizes::).
47184
47185‘quit-restore’
47186     This parameter is installed by the buffer display functions (*note
47187     Choosing Window::) and consulted by ‘quit-restore-window’ (*note
47188     Quitting Windows::).  It is a list of four elements, see the
47189     description of ‘quit-restore-window’ in *note Quitting Windows::
47190     for details.
47191
47192‘window-side’
47193‘window-slot’
47194     These parameters are used internally for implementing side windows
47195     (*note Side Windows::).
47196
47197‘window-atom’
47198     This parameter is used internally for implementing atomic windows,
47199     see *note Atomic Windows::.
47200
47201‘mode-line-format’
47202     This parameter replaces the value of the buffer-local variable
47203     ‘mode-line-format’ (*note Mode Line Basics::) of this window’s
47204     buffer whenever this window is displayed.  The symbol ‘none’ means
47205     to suppress display of a mode line for this window.  Display and
47206     contents of the mode line on other windows showing this buffer are
47207     not affected.
47208
47209‘header-line-format’
47210     This parameter replaces the value of the buffer-local variable
47211     ‘header-line-format’ (*note Mode Line Basics::) of this window’s
47212     buffer whenever this window is displayed.  The symbol ‘none’ means
47213     to suppress display of a header line for this window.  Display and
47214     contents of the header line on other windows showing this buffer
47215     are not affected.
47216
47217‘tab-line-format’
47218     This parameter replaces the value of the buffer-local variable
47219     ‘tab-line-format’ (*note Mode Line Basics::) of this window’s
47220     buffer whenever this window is displayed.  The symbol ‘none’ means
47221     to suppress display of a tab line for this window.  Display and
47222     contents of the tab line on other windows showing this buffer are
47223     not affected.
47224
47225‘min-margins’
47226     The value of this parameter is a cons cell whose CAR and CDR, if
47227     non-‘nil’, specify the minimum values (in columns) for the left and
47228     right margin of this window (*note Display Margins::.  When
47229     present, Emacs will use these values instead of the actual margin
47230     widths for determining whether a window can be split or shrunk
47231     horizontally.
47232
47233     Emacs never auto-adjusts the margins of any window after splitting
47234     or resizing it.  It is the sole responsibility of any application
47235     setting this parameter to adjust the margins of this window as well
47236     as those of any new window that inherits this window’s margins due
47237     to a split.  Both ‘window-configuration-change-hook’ and
47238     ‘window-size-change-functions’ (*note Window Hooks::) should be
47239     employed for this purpose.
47240
47241     This parameter was introduced in Emacs version 25.1 to support
47242     applications that use large margins to center buffer text within a
47243     window and should be used, with due care, exclusively by those
47244     applications.  It might be replaced by an improved solution in
47245     future versions of Emacs.
47246
47247
47248File: elisp.info,  Node: Window Hooks,  Prev: Window Parameters,  Up: Windows
47249
4725028.28 Hooks for Window Scrolling and Changes
47251============================================
47252
47253This section describes how Lisp programs can take action after a window
47254has been scrolled or other window modifications occurred.  We first
47255consider the case where a window shows a different part of its buffer.
47256
47257 -- Variable: window-scroll-functions
47258     This variable holds a list of functions that Emacs should call
47259     before redisplaying a window with scrolling.  Displaying a
47260     different buffer in a window and making a new window also call
47261     these functions.
47262
47263     This variable is not a normal hook, because each function is called
47264     with two arguments: the window, and its new display-start position.
47265     At the time of the call, the display-start position of the argument
47266     window is already set to its new value, and the buffer to be
47267     displayed in the window is set as the current buffer.
47268
47269     These functions must take care when using ‘window-end’ (*note
47270     Window Start and End::); if you need an up-to-date value, you must
47271     use the UPDATE argument to ensure you get it.
47272
47273     *Warning:* don’t use this feature to alter the way the window is
47274     scrolled.  It’s not designed for that, and such use probably won’t
47275     work.
47276
47277   In addition, you can use ‘jit-lock-register’ to register a Font Lock
47278fontification function, which will be called whenever parts of a buffer
47279are (re)fontified because a window was scrolled or its size changed.
47280*Note Other Font Lock Variables::.
47281
47282   The remainder of this section covers six hooks that are called during
47283redisplay provided a significant, non-scrolling change of a window has
47284been detected.  For simplicity, these hooks and the functions they call
47285will be collectively referred to as “window change functions”.
47286
47287   The first of these hooks is run after a “window buffer change” is
47288detected, which means that a window was created, deleted or assigned
47289another buffer.
47290
47291 -- Variable: window-buffer-change-functions
47292     This variable specifies functions called during redisplay when
47293     window buffers have changed.  The value should be a list of
47294     functions that take one argument.
47295
47296     Functions specified buffer-locally are called for any window
47297     showing the corresponding buffer if that window has been created or
47298     assigned that buffer since the last time window change functions
47299     were run.  In this case the window is passed as argument.
47300
47301     Functions specified by the default value are called for a frame if
47302     at least one window on that frame has been added, deleted or
47303     assigned another buffer since the last time window change functions
47304     were run.  In this case the frame is passed as argument.
47305
47306   The second of these hooks is run when a “window size change” has been
47307detected which means that a window was created, assigned another buffer,
47308or changed its total size or that of its text area.
47309
47310 -- Variable: window-size-change-functions
47311     This variable specifies functions called during redisplay when a
47312     window size change occurred.  The value should be a list of
47313     functions that take one argument.
47314
47315     Functions specified buffer-locally are called for any window
47316     showing the corresponding buffer if that window has been added or
47317     assigned another buffer or changed its total or body size since the
47318     last time window change functions were run.  In this case the
47319     window is passed as argument.
47320
47321     Functions specified by the default value are called for a frame if
47322     at least one window on that frame has been added or assigned
47323     another buffer or changed its total or body size since the last
47324     time window change functions were run.  In this case the frame is
47325     passed as argument.
47326
47327   The third of these hooks is run when a “window selection change” has
47328selected another window since the last redisplay.
47329
47330 -- Variable: window-selection-change-functions
47331     This variable specifies functions called during redisplay when the
47332     selected window or a frame’s selected window has changed.  The
47333     value should be a list of functions that take one argument.
47334
47335     Functions specified buffer-locally are called for any window
47336     showing the corresponding buffer if that window has been selected
47337     or deselected (among all windows or among all windows on its frame)
47338     since the last time window change functions were run.  In this case
47339     the window is passed as argument.
47340
47341     Functions specified by the default value are called for a frame if
47342     that frame has been selected or deselected or the frame’s selected
47343     window has changed since the last time window change functions were
47344     run.  In this case the frame is passed as argument.
47345
47346   The fourth of these hooks is run when a “window state change” has
47347been detected, which means that at least one of the three preceding
47348window changes has occurred.
47349
47350 -- Variable: window-state-change-functions
47351     This variable specifies functions called during redisplay when a
47352     window buffer or size change occurred or the selected window or a
47353     frame’s selected window has changed.  The value should be a list of
47354     functions that take one argument.
47355
47356     Functions specified buffer-locally are called for any window
47357     showing the corresponding buffer if that window has been added or
47358     assigned another buffer, changed its total or body size or has been
47359     selected or deselected (among all windows or among all windows on
47360     its frame) since the last time window change functions were run.
47361     In this case the window is passed as argument.
47362
47363     Functions specified by the default value are called for a frame if
47364     at least one window on that frame has been added, deleted or
47365     assigned another buffer, changed its total or body size or that
47366     frame has been selected or deselected or the frame’s selected
47367     window has changed since the last time window change functions were
47368     run.  In this case the frame is passed as argument.
47369
47370     Functions specified by the default value are also run for a frame
47371     when that frame’s window state change flag (see below) has been set
47372     since last redisplay.
47373
47374   The fifth of these hooks is run when a “window configuration change”
47375has been detected which means that either the buffer or the size of a
47376window changed.  It differs from the four preceding hooks in the way it
47377is run.
47378
47379 -- Variable: window-configuration-change-hook
47380     This variable specifies functions called during redisplay when
47381     either the buffer or the size of a window has changed.  The value
47382     should be a list of functions that take no argument.
47383
47384     Functions specified buffer-locally are called for any window
47385     showing the corresponding buffer if at least one window on that
47386     frame has been added, deleted or assigned another buffer or changed
47387     its total or body size since the last time window change functions
47388     were run.  Each call is performed with the window showing the
47389     buffer temporarily selected and its buffer current.
47390
47391     Functions specified by the default value are called for each frame
47392     if at least one window on that frame has been added, deleted or
47393     assigned another buffer or changed its total or body size since the
47394     last time window change functions were run.  Each call is performed
47395     with the frame temporarily selected and the selected window’s
47396     buffer current.
47397
47398   Finally, Emacs runs a normal hook that generalizes the behavior of
47399‘window-state-change-functions’.
47400
47401 -- Variable: window-state-change-hook
47402     The default value of this variable specifies functions called
47403     during redisplay when a window state change has been detected or
47404     the window state change flag has been set on at least one frame.
47405     The value should be a list of functions that take no argument.
47406
47407     Applications should put a function on this hook only if they want
47408     to react to changes that happened on (or have been signaled for)
47409     two or more frames since last redisplay.  In every other case,
47410     putting the function on ‘window-state-change-functions’ should be
47411     preferred.
47412
47413   Window change functions are called during redisplay for each frame as
47414follows: First, any buffer-local window buffer change function, window
47415size change function, selected window change and window state change
47416functions are called in this order.  Next, the default values for these
47417functions are called in the same order.  Then any buffer-local window
47418configuration change functions are called followed by functions
47419specified by the default value of those functions.  Finally, functions
47420on ‘window-state-change-hook’ are run.
47421
47422   Window change functions are run for a specific frame only if a
47423corresponding change was registered for that frame earlier.  Such
47424changes include the creation or deletion of a window or the assignment
47425of another buffer or size to a window.  Note that even when such a
47426change has been registered, this does not mean that any of the hooks
47427described above is run.  If, for example, a change was registered within
47428the scope of a window excursion (*note Window Configurations::), this
47429will trigger a call of window change functions only if that excursion
47430still persists at the time change functions are run.  If it is exited
47431earlier, hooks will be run only if registered by a change outside the
47432scope of that excursion.
47433
47434   The “window state change flag” of a frame, if set, will cause the
47435default values of ‘window-state-change-functions’ (for that frame) and
47436‘window-state-change-hook’ to be run during next redisplay regardless of
47437whether a window state change actually occurred for that frame or not.
47438After running any functions on these hooks, the flag is reset for each
47439frame.  Applications can set that flag and inspect its value using the
47440following functions.
47441
47442 -- Function: set-frame-window-state-change &optional frame arg
47443     This function sets FRAME’s window state change flag if ARG is
47444     non-‘nil’ and resets it otherwise.  FRAME must be a live frame and
47445     defaults to the selected one.
47446
47447 -- Function: frame-window-state-change &optional frame
47448     This functions returns ‘t’ if FRAME’s window state change flag is
47449     set and ‘nil’ otherwise.  FRAME must be a live frame and defaults
47450     to the selected one.
47451
47452   While window change functions are run, the functions described next
47453can be called to get more insight into what has changed for a specific
47454window or frame since the last redisplay.  All these functions take a
47455live window as single, optional argument, defaulting to the selected
47456window.
47457
47458 -- Function: window-old-buffer &optional window
47459     This function returns the buffer shown in WINDOW at the last time
47460     window change functions were run for WINDOW’s frame.  If it returns
47461     ‘nil’, WINDOW has been created after that.  If it returns ‘t’,
47462     WINDOW was not shown at that time but has been restored from a
47463     previously saved window configuration afterwards.  Otherwise, the
47464     return value is the buffer shown by ‘window’ at that time.
47465
47466 -- Function: window-old-pixel-width &optional window
47467     This function returns the total pixel width of WINDOW the last time
47468     window change functions found ‘window’ live on its frame.  It is
47469     zero if ‘window’ was created after that.
47470
47471 -- Function: window-old-pixel-height &optional window
47472     This function returns the total pixel height of WINDOW the last
47473     time window change functions found ‘window’ live on its frame.  It
47474     is zero if ‘window’ was created after that.
47475
47476 -- Function: window-old-body-pixel-width &optional window
47477     This function returns the pixel width of WINDOW’s text area the
47478     last time window change functions found ‘window’ live on its frame.
47479     It is zero if ‘window’ was created after that.
47480
47481 -- Function: window-old-body-pixel-height &optional window
47482     This function returns the pixel height of WINDOW’s text area the
47483     last time window change functions found ‘window’ live on its frame.
47484     It is zero if ‘window’ was created after that.
47485
47486   In order to find out which window or frame was selected the last time
47487window change functions were run, the following functions can be used:
47488
47489 -- Function: frame-old-selected-window &optional frame
47490     This function returns the selected window of FRAME at the last time
47491     window change functions were run.  If omitted or ‘nil’ FRAME
47492     defaults to the selected frame.
47493
47494 -- Function: old-selected-window
47495     This function returns the selected window at the last time window
47496     change functions were run.
47497
47498 -- Function: old-selected-frame
47499     This function returns the selected frame at the last time window
47500     change functions were run.
47501
47502   Note that window change functions provide no information about which
47503windows have been deleted since the last time they were run.  If
47504necessary, applications should remember any window showing a specific
47505buffer in a local variable of that buffer and update it in a function
47506run by the default values of any of the hooks that are run when a window
47507buffer change was detected.
47508
47509   The following caveats should be considered when adding a function to
47510window change functions:
47511
47512   • Some operations will not trigger a call of window change functions.
47513     These include showing another buffer in a minibuffer window or any
47514     change of a tooltip window.
47515
47516   • Window change functions should not create or delete windows or
47517     change the buffer, size or selection status of any window because
47518     there is no guarantee that the information about such a change will
47519     be propagated to other window change functions.  If at all, any
47520     such change should be executed only by the last function listed by
47521     the default value of ‘window-state-change-hook’.
47522
47523   • Macros like ‘save-window-excursion’, ‘with-selected-window’ or
47524     ‘with-current-buffer’ can be used when running window change
47525     functions.
47526
47527   • Running window change functions does not save and restore match
47528     data.  Unless running ‘window-configuration-change-hook’ it does
47529     not save or restore the selected window or frame or the current
47530     buffer either.
47531
47532   • Any redisplay triggering the run of window change functions may be
47533     aborted.  If the abort occurs before window change functions have
47534     run to their completion, they will be run again with the previous
47535     values, that is, as if redisplay had not been performed.  If
47536     aborted later, they will be run with the new values, that is, as if
47537     redisplay had been actually performed.
47538
47539
47540File: elisp.info,  Node: Frames,  Next: Positions,  Prev: Windows,  Up: Top
47541
4754229 Frames
47543*********
47544
47545A “frame” is a screen object that contains one or more Emacs windows
47546(*note Windows::).  It is the kind of object called a “window” in the
47547terminology of graphical environments; but we can’t call it a “window”
47548here, because Emacs uses that word in a different way.  In Emacs Lisp, a
47549“frame object” is a Lisp object that represents a frame on the screen.
47550*Note Frame Type::.
47551
47552   A frame initially contains a single main window and/or a minibuffer
47553window; you can subdivide the main window vertically or horizontally
47554into smaller windows.  *Note Splitting Windows::.
47555
47556   A “terminal” is a display device capable of displaying one or more
47557Emacs frames.  In Emacs Lisp, a “terminal object” is a Lisp object that
47558represents a terminal.  *Note Terminal Type::.
47559
47560   There are two classes of terminals: “text terminals” and “graphical
47561terminals”.  Text terminals are non-graphics-capable displays, including
47562‘xterm’ and other terminal emulators.  On a text terminal, each Emacs
47563frame occupies the terminal’s entire screen; although you can create
47564additional frames and switch between them, the terminal only shows one
47565frame at a time.  Graphical terminals, on the other hand, are managed by
47566graphical display systems such as the X Window System, which allow Emacs
47567to show multiple frames simultaneously on the same display.
47568
47569   On GNU and Unix systems, you can create additional frames on any
47570available terminal, within a single Emacs session, regardless of whether
47571Emacs was started on a text or graphical terminal.  Emacs can display on
47572both graphical and text terminals simultaneously.  This comes in handy,
47573for instance, when you connect to the same session from several remote
47574locations.  *Note Multiple Terminals::.
47575
47576 -- Function: framep object
47577     This predicate returns a non-‘nil’ value if OBJECT is a frame, and
47578     ‘nil’ otherwise.  For a frame, the value indicates which kind of
47579     display the frame uses:
47580
47581     ‘t’
47582          The frame is displayed on a text terminal.
47583     ‘x’
47584          The frame is displayed on an X graphical terminal.
47585     ‘w32’
47586          The frame is displayed on a MS-Windows graphical terminal.
47587     ‘ns’
47588          The frame is displayed on a GNUstep or Macintosh Cocoa
47589          graphical terminal.
47590     ‘pc’
47591          The frame is displayed on an MS-DOS terminal.
47592
47593 -- Function: frame-terminal &optional frame
47594     This function returns the terminal object that displays FRAME.  If
47595     FRAME is ‘nil’ or unspecified, it defaults to the selected frame.
47596
47597 -- Function: terminal-live-p object
47598     This predicate returns a non-‘nil’ value if OBJECT is a terminal
47599     that is live (i.e., not deleted), and ‘nil’ otherwise.  For live
47600     terminals, the return value indicates what kind of frames are
47601     displayed on that terminal; the list of possible values is the same
47602     as for ‘framep’ above.
47603
47604   On a graphical terminal we distinguish two types of frames: A normal
47605“top-level frame” is a frame whose window-system window is a child of
47606the window-system’s root window for that terminal.  A child frame is a
47607frame whose window-system window is the child of the window-system
47608window of another Emacs frame.  *Note Child Frames::.
47609
47610* Menu:
47611
47612* Creating Frames::             Creating additional frames.
47613* Multiple Terminals::          Displaying on several different devices.
47614* Frame Geometry::              Geometric properties of frames.
47615* Frame Parameters::            Controlling frame size, position, font, etc.
47616* Terminal Parameters::         Parameters common for all frames on terminal.
47617* Frame Titles::                Automatic updating of frame titles.
47618* Deleting Frames::             Frames last until explicitly deleted.
47619* Finding All Frames::          How to examine all existing frames.
47620* Minibuffers and Frames::      How a frame finds the minibuffer to use.
47621* Input Focus::                 Specifying the selected frame.
47622* Visibility of Frames::        Frames may be visible or invisible, or icons.
47623* Raising and Lowering::        Raising, Lowering and Restacking Frames.
47624* Frame Configurations::        Saving the state of all frames.
47625* Child Frames::                Making a frame the child of another.
47626* Mouse Tracking::              Getting events that say when the mouse moves.
47627* Mouse Position::              Asking where the mouse is, or moving it.
47628* Pop-Up Menus::                Displaying a menu for the user to select from.
47629* Dialog Boxes::                Displaying a box to ask yes or no.
47630* Pointer Shape::               Specifying the shape of the mouse pointer.
47631* Window System Selections::    Transferring text to and from other X clients.
47632* Drag and Drop::               Internals of Drag-and-Drop implementation.
47633* Color Names::                 Getting the definitions of color names.
47634* Text Terminal Colors::        Defining colors for text terminals.
47635* Resources::                   Getting resource values from the server.
47636* Display Feature Testing::     Determining the features of a terminal.
47637
47638
47639File: elisp.info,  Node: Creating Frames,  Next: Multiple Terminals,  Up: Frames
47640
4764129.1 Creating Frames
47642====================
47643
47644To create a new frame, call the function ‘make-frame’.
47645
47646 -- Command: make-frame &optional parameters
47647     This function creates and returns a new frame, displaying the
47648     current buffer.
47649
47650     The PARAMETERS argument is an alist that specifies frame parameters
47651     for the new frame.  *Note Frame Parameters::.  If you specify the
47652     ‘terminal’ parameter in PARAMETERS, the new frame is created on
47653     that terminal.  Otherwise, if you specify the ‘window-system’ frame
47654     parameter in PARAMETERS, that determines whether the frame should
47655     be displayed on a text terminal or a graphical terminal.  *Note
47656     Window Systems::.  If neither is specified, the new frame is
47657     created in the same terminal as the selected frame.
47658
47659     Any parameters not mentioned in PARAMETERS default to the values in
47660     the alist ‘default-frame-alist’ (*note Initial Parameters::);
47661     parameters not specified there default from the X resources or its
47662     equivalent on your operating system (*note X Resources: (emacs)X
47663     Resources.).  After the frame is created, this function applies any
47664     parameters specified in ‘frame-inherited-parameters’ (see below) it
47665     has no assigned yet, taking the values from the frame that was
47666     selected when ‘make-frame’ was called.
47667
47668     Note that on multi-monitor displays (*note Multiple Terminals::),
47669     the window manager might position the frame differently than
47670     specified by the positional parameters in PARAMETERS (*note
47671     Position Parameters::).  For example, some window managers have a
47672     policy of displaying the frame on the monitor that contains the
47673     largest part of the window (a.k.a. the “dominating” monitor).
47674
47675     This function itself does not make the new frame the selected
47676     frame.  *Note Input Focus::.  The previously selected frame remains
47677     selected.  On graphical terminals, however, the windowing system
47678     may select the new frame for its own reasons.
47679
47680 -- Variable: before-make-frame-hook
47681     A normal hook run by ‘make-frame’ before it creates the frame.
47682
47683 -- Variable: after-make-frame-functions
47684     An abnormal hook run by ‘make-frame’ after it created the frame.
47685     Each function in ‘after-make-frame-functions’ receives one
47686     argument, the frame just created.
47687
47688   Note that any functions added to these hooks by your initial file are
47689usually not run for the initial frame, since Emacs reads the initial
47690file only after creating that frame.  However, if the initial frame is
47691specified to use a separate minibuffer frame (*note Minibuffers and
47692Frames::), the functions will be run for both, the minibuffer-less and
47693the minibuffer frame.
47694
47695 -- Variable: frame-inherited-parameters
47696     This variable specifies the list of frame parameters that a newly
47697     created frame inherits from the currently selected frame.  For each
47698     parameter (a symbol) that is an element in this list and has not
47699     been assigned earlier when processing ‘make-frame’, the function
47700     sets the value of that parameter in the created frame to its value
47701     in the selected frame.
47702
47703 -- User Option: server-after-make-frame-hook
47704     A normal hook run when the Emacs server creates a client frame.
47705     When this hook is called, the created frame is the selected one.
47706     *Note (emacs)Emacs Server::.
47707
47708
47709File: elisp.info,  Node: Multiple Terminals,  Next: Frame Geometry,  Prev: Creating Frames,  Up: Frames
47710
4771129.2 Multiple Terminals
47712=======================
47713
47714Emacs represents each terminal as a “terminal object” data type (*note
47715Terminal Type::).  On GNU and Unix systems, Emacs can use multiple
47716terminals simultaneously in each session.  On other systems, it can only
47717use a single terminal.  Each terminal object has the following
47718attributes:
47719
47720   • The name of the device used by the terminal (e.g., ‘:0.0’ or
47721/dev/tty’).
47722
47723   • The terminal and keyboard coding systems used on the terminal.
47724     *Note Terminal I/O Encoding::.
47725
47726   • The kind of display associated with the terminal.  This is the
47727     symbol returned by the function ‘terminal-live-p’ (i.e., ‘x’, ‘t’,
47728     ‘w32’, ‘ns’, or ‘pc’).  *Note Frames::.
47729
47730   • A list of terminal parameters.  *Note Terminal Parameters::.
47731
47732   There is no primitive for creating terminal objects.  Emacs creates
47733them as needed, such as when you call ‘make-frame-on-display’ (described
47734below).
47735
47736 -- Function: terminal-name &optional terminal
47737     This function returns the file name of the device used by TERMINAL.
47738     If TERMINAL is omitted or ‘nil’, it defaults to the selected
47739     frame’s terminal.  TERMINAL can also be a frame, meaning that
47740     frame’s terminal.
47741
47742 -- Function: terminal-list
47743     This function returns a list of all live terminal objects.
47744
47745 -- Function: get-device-terminal device
47746     This function returns a terminal whose device name is given by
47747     DEVICE.  If DEVICE is a string, it can be either the file name of a
47748     terminal device, or the name of an X display of the form
47749     ‘HOST:SERVER.SCREEN’.  If DEVICE is a frame, this function returns
47750     that frame’s terminal; ‘nil’ means the selected frame.  Finally, if
47751     DEVICE is a terminal object that represents a live terminal, that
47752     terminal is returned.  The function signals an error if its
47753     argument is none of the above.
47754
47755 -- Function: delete-terminal &optional terminal force
47756     This function deletes all frames on TERMINAL and frees the
47757     resources used by it.  It runs the abnormal hook
47758     ‘delete-terminal-functions’, passing TERMINAL as the argument to
47759     each function.
47760
47761     If TERMINAL is omitted or ‘nil’, it defaults to the selected
47762     frame’s terminal.  TERMINAL can also be a frame, meaning that
47763     frame’s terminal.
47764
47765     Normally, this function signals an error if you attempt to delete
47766     the sole active terminal, but if FORCE is non-‘nil’, you are
47767     allowed to do so.  Emacs automatically calls this function when the
47768     last frame on a terminal is deleted (*note Deleting Frames::).
47769
47770 -- Variable: delete-terminal-functions
47771     An abnormal hook run by ‘delete-terminal’.  Each function receives
47772     one argument, the TERMINAL argument passed to ‘delete-terminal’.
47773     Due to technical details, the functions may be called either just
47774     before the terminal is deleted, or just afterwards.
47775
47776   A few Lisp variables are “terminal-local”; that is, they have a
47777separate binding for each terminal.  The binding in effect at any time
47778is the one for the terminal that the currently selected frame belongs
47779to.  These variables include ‘default-minibuffer-frame’,
47780‘defining-kbd-macro’, ‘last-kbd-macro’, and ‘system-key-alist’.  They
47781are always terminal-local, and can never be buffer-local (*note
47782Buffer-Local Variables::).
47783
47784   On GNU and Unix systems, each X display is a separate graphical
47785terminal.  When Emacs is started from within the X window system, it
47786uses the X display specified by the ‘DISPLAY’ environment variable, or
47787by the ‘--display’ option (*note (emacs)Initial Options::).  Emacs can
47788connect to other X displays via the command ‘make-frame-on-display’.
47789Each X display has its own selected frame and its own minibuffer
47790windows; however, only one of those frames is _the_ selected frame at
47791any given moment (*note Input Focus::).  Emacs can even connect to other
47792text terminals, by interacting with the ‘emacsclient’ program.  *Note
47793(emacs)Emacs Server::.
47794
47795   A single X server can handle more than one display.  Each X display
47796has a three-part name, ‘HOSTNAME:DISPLAYNUMBER.SCREENNUMBER’.  The first
47797part, HOSTNAME, specifies the name of the machine to which the display
47798is physically connected.  The second part, DISPLAYNUMBER, is a
47799zero-based number that identifies one or more monitors connected to that
47800machine that share a common keyboard and pointing device (mouse, tablet,
47801etc.).  The third part, SCREENNUMBER, identifies a zero-based screen
47802number (a separate monitor) that is part of a single monitor collection
47803on that X server.  When you use two or more screens belonging to one
47804server, Emacs knows by the similarity in their names that they share a
47805single keyboard.
47806
47807   Systems that don’t use the X window system, such as MS-Windows, don’t
47808support the notion of X displays, and have only one display on each
47809host.  The display name on these systems doesn’t follow the above 3-part
47810format; for example, the display name on MS-Windows systems is a
47811constant string ‘w32’, and exists for compatibility, so that you could
47812pass it to functions that expect a display name.
47813
47814 -- Command: make-frame-on-display display &optional parameters
47815     This function creates and returns a new frame on DISPLAY, taking
47816     the other frame parameters from the alist PARAMETERS.  DISPLAY
47817     should be the name of an X display (a string).
47818
47819     Before creating the frame, this function ensures that Emacs is set
47820     up to display graphics.  For instance, if Emacs has not processed X
47821     resources (e.g., if it was started on a text terminal), it does so
47822     at this time.  In all other respects, this function behaves like
47823     ‘make-frame’ (*note Creating Frames::).
47824
47825 -- Function: x-display-list
47826     This function returns a list that indicates which X displays Emacs
47827     has a connection to.  The elements of the list are strings, and
47828     each one is a display name.
47829
47830 -- Function: x-open-connection display &optional xrm-string
47831          must-succeed
47832     This function opens a connection to the X display DISPLAY, without
47833     creating a frame on that display.  Normally, Emacs Lisp programs
47834     need not call this function, as ‘make-frame-on-display’ calls it
47835     automatically.  The only reason for calling it is to check whether
47836     communication can be established with a given X display.
47837
47838     The optional argument XRM-STRING, if not ‘nil’, is a string of
47839     resource names and values, in the same format used in the
47840     ‘.Xresources’ file.  *Note X Resources: (emacs)X Resources.  These
47841     values apply to all Emacs frames created on this display,
47842     overriding the resource values recorded in the X server.  Here’s an
47843     example of what this string might look like:
47844
47845          "*BorderWidth: 3\n*InternalBorder: 2\n"
47846
47847     If MUST-SUCCEED is non-‘nil’, failure to open the connection
47848     terminates Emacs.  Otherwise, it is an ordinary Lisp error.
47849
47850 -- Function: x-close-connection display
47851     This function closes the connection to display DISPLAY.  Before you
47852     can do this, you must first delete all the frames that were open on
47853     that display (*note Deleting Frames::).
47854
47855   On some multi-monitor setups, a single X display outputs to more than
47856one physical monitor.  You can use the functions
47857‘display-monitor-attributes-list’ and ‘frame-monitor-attributes’ to
47858obtain information about such setups.
47859
47860 -- Function: display-monitor-attributes-list &optional display
47861     This function returns a list of physical monitor attributes on
47862     DISPLAY, which can be a display name (a string), a terminal, or a
47863     frame; if omitted or ‘nil’, it defaults to the selected frame’s
47864     display.  Each element of the list is an association list,
47865     representing the attributes of a physical monitor.  The first
47866     element corresponds to the primary monitor.  The attribute keys and
47867     values are:
47868
47869     ‘geometry’
47870          Position of the top-left corner of the monitor’s screen and
47871          its size, in pixels, as ‘(X Y WIDTH HEIGHT)’.  Note that, if
47872          the monitor is not the primary monitor, some of the
47873          coordinates might be negative.
47874
47875     ‘workarea’
47876          Position of the top-left corner and size of the work area
47877          (usable space) in pixels as ‘(X Y WIDTH HEIGHT)’.  This may be
47878          different from ‘geometry’ in that space occupied by various
47879          window manager features (docks, taskbars, etc.) may be
47880          excluded from the work area.  Whether or not such features
47881          actually subtract from the work area depends on the platform
47882          and environment.  Again, if the monitor is not the primary
47883          monitor, some of the coordinates might be negative.
47884
47885     ‘mm-size’
47886          Width and height in millimeters as ‘(WIDTH HEIGHT)’
47887
47888     ‘frames’
47889          List of frames that this physical monitor dominates (see
47890          below).
47891
47892     ‘name’
47893          Name of the physical monitor as STRING.
47894
47895     ‘source’
47896          Source of the multi-monitor information as STRING; e.g.,
47897          ‘XRandr’ or ‘Xinerama’.
47898
47899     X, Y, WIDTH, and HEIGHT are integers.  ‘name’ and ‘source’ may be
47900     absent.
47901
47902     A frame is “dominated” by a physical monitor when either the
47903     largest area of the frame resides in that monitor, or (if the frame
47904     does not intersect any physical monitors) that monitor is the
47905     closest to the frame.  Every (non-tooltip) frame (whether visible
47906     or not) in a graphical display is dominated by exactly one physical
47907     monitor at a time, though the frame can span multiple (or no)
47908     physical monitors.
47909
47910     Here’s an example of the data produced by this function on a
47911     2-monitor display:
47912
47913            (display-monitor-attributes-list)
4791447915            (((geometry 0 0 1920 1080) ;; Left-hand, primary monitor
47916              (workarea 0 0 1920 1050) ;; A taskbar occupies some of the height
47917              (mm-size 677 381)
47918              (name . "DISPLAY1")
47919              (frames #<frame emacs@host *Messages* 0x11578c0>
47920                      #<frame emacs@host *scratch* 0x114b838>))
47921             ((geometry 1920 0 1680 1050) ;; Right-hand monitor
47922              (workarea 1920 0 1680 1050) ;; Whole screen can be used
47923              (mm-size 593 370)
47924              (name . "DISPLAY2")
47925              (frames)))
47926
47927 -- Function: frame-monitor-attributes &optional frame
47928     This function returns the attributes of the physical monitor
47929     dominating (see above) FRAME, which defaults to the selected frame.
47930
47931   On multi-monitor displays it is possible to use the command
47932‘make-frame-on-monitor’ to make frames on the specified monitor.
47933
47934 -- Command: make-frame-on-monitor monitor &optional display parameters
47935     This function creates and returns a new frame on MONITOR located on
47936     DISPLAY, taking the other frame parameters from the alist
47937     PARAMETERS.  MONITOR should be the name of the physical monitor,
47938     the same string as returned by the function
47939     ‘display-monitor-attributes-list’ in the attribute ‘name’.  DISPLAY
47940     should be the name of an X display (a string).
47941
47942
47943File: elisp.info,  Node: Frame Geometry,  Next: Frame Parameters,  Prev: Multiple Terminals,  Up: Frames
47944
4794529.3 Frame Geometry
47946===================
47947
47948The geometry of a frame depends on the toolkit that was used to build
47949this instance of Emacs and the terminal that displays the frame.  This
47950chapter describes these dependencies and some of the functions to deal
47951with them.  Note that the FRAME argument of all of these functions has
47952to specify a live frame (*note Deleting Frames::).  If omitted or ‘nil’,
47953it specifies the selected frame (*note Input Focus::).
47954
47955* Menu:
47956
47957* Frame Layout::            Basic layout of frames.
47958* Frame Font::              The default font of a frame and how to set it.
47959* Frame Position::          The position of a frame on its display.
47960* Frame Size::              Specifying and retrieving a frame’s size.
47961* Implied Frame Resizing::  Implied resizing of frames and how to prevent it.
47962
47963
47964File: elisp.info,  Node: Frame Layout,  Next: Frame Font,  Up: Frame Geometry
47965
4796629.3.1 Frame Layout
47967-------------------
47968
47969A visible frame occupies a rectangular area on its terminal’s display.
47970This area may contain a number of nested rectangles, each serving a
47971different purpose.  The drawing below sketches the layout of a frame on
47972a graphical terminal:
47973
47974             <------------ Outer Frame Width ----------->
47975             ____________________________________________
47976          ^(0)  ________ External/Outer Border _______   |
47977          | |  |_____________ Title Bar ______________|  |
47978          | | (1)_____________ Menu Bar ______________|  | ^
47979          | | (2)_____________ Tool Bar ______________|  | ^
47980          | | (3) _________ Internal Border ________  |  | ^
47981          | |  | |   ^                              | |  | |
47982          | |  | |   |                              | |  | |
47983     Outer  |  | | Inner                            | |  | Native
47984     Frame  |  | | Frame                            | |  | Frame
47985     Height |  | | Height                           | |  | Height
47986          | |  | |   |                              | |  | |
47987          | |  | |<--+--- Inner Frame Width ------->| |  | |
47988          | |  | |   |                              | |  | |
47989          | |  | |___v______________________________| |  | |
47990          | |  |___________ Internal Border __________|  | v
47991          v |___________ External/Outer Border __________|
47992                <-------- Native Frame Width -------->
47993
47994
47995   In practice not all of the areas shown in the drawing will or may be
47996present.  The meaning of these areas is described below.
47997
47998Outer Frame
47999     The “outer frame” is a rectangle comprising all areas shown in the
48000     drawing.  The edges of that rectangle are called the “outer edges”
48001     of the frame.  Together, the “outer width” and “outer height” of
48002     the frame specify the “outer size” of that rectangle.
48003
48004     Knowing the outer size of a frame is useful for fitting a frame
48005     into the working area of its display (*note Multiple Terminals::)
48006     or for placing two frames adjacent to each other on the screen.
48007     Usually, the outer size of a frame is available only after the
48008     frame has been mapped (made visible, *note Visibility of Frames::)
48009     at least once.  For the initial frame or a frame that has not been
48010     created yet, the outer size can be only estimated or must be
48011     calculated from the window-system’s or window manager’s defaults.
48012     One workaround is to obtain the differences of the outer and native
48013     (see below) sizes of a mapped frame and use them for calculating
48014     the outer size of the new frame.
48015
48016     The position of the upper left corner of the outer frame (indicated
48017     by ‘(0)’ in the drawing above) is the “outer position” of the
48018     frame.  The outer position of a graphical frame is also referred to
48019     as “the position” of the frame because it usually remains unchanged
48020     on its display whenever the frame is resized or its layout is
48021     changed.
48022
48023     The outer position is specified by and can be set via the ‘left’
48024     and ‘top’ frame parameters (*note Position Parameters::).  For a
48025     normal, top-level frame these parameters usually represent its
48026     absolute position (see below) with respect to its display’s origin.
48027     For a child frame (*note Child Frames::) these parameters represent
48028     its position relative to the native position (see below) of its
48029     parent frame.  For frames on text terminals the values of these
48030     parameters are meaningless and always zero.
48031
48032External Border
48033     The “external border” is part of the decorations supplied by the
48034     window manager.  It is typically used for resizing the frame with
48035     the mouse and is therefore not shown on “fullboth” and maximized
48036     frames (*note Size Parameters::).  Its width is determined by the
48037     window manager and cannot be changed by Emacs’ functions.
48038
48039     External borders don’t exist on text terminal frames.  For
48040     graphical frames, their display can be suppressed by setting the
48041     ‘override-redirect’ or ‘undecorated’ frame parameter (*note
48042     Management Parameters::).
48043
48044Outer Border
48045     The “outer border” is a separate border whose width can be
48046     specified with the ‘border-width’ frame parameter (*note Layout
48047     Parameters::).  In practice, either the external or the outer
48048     border of a frame are displayed but never both at the same time.
48049     Usually, the outer border is shown only for special frames that are
48050     not (fully) controlled by the window manager like tooltip frames
48051     (*note Tooltips::), child frames (*note Child Frames::) and
48052     ‘undecorated’ or ‘override-redirect’ frames (*note Management
48053     Parameters::).
48054
48055     Outer borders are never shown on text terminal frames and on frames
48056     generated by GTK+ routines.  On MS-Windows, the outer border is
48057     emulated with the help of a one pixel wide external border.
48058     Non-toolkit builds on X allow to change the color of the outer
48059     border by setting the ‘border-color’ frame parameter (*note Layout
48060     Parameters::).
48061
48062Title Bar
48063     The “title bar”, a.k.a. “caption bar”, is also part of the window
48064     manager’s decorations and typically displays the title of the frame
48065     (*note Frame Titles::) as well as buttons for minimizing,
48066     maximizing and deleting the frame.  It can be also used for
48067     dragging the frame with the mouse.  The title bar is usually not
48068     displayed for fullboth (*note Size Parameters::), tooltip (*note
48069     Tooltips::) and child frames (*note Child Frames::) and doesn’t
48070     exist for terminal frames.  Display of the title bar can be
48071     suppressed by setting the ‘override-redirect’ or the ‘undecorated’
48072     frame parameters (*note Management Parameters::).
48073
48074Menu Bar
48075     The menu bar (*note Menu Bar::) can be either internal (drawn by
48076     Emacs itself) or external (drawn by the toolkit).  Most builds
48077     (GTK+, Lucid, Motif and MS-Windows) rely on an external menu bar.
48078     NS also uses an external menu bar which, however, is not part of
48079     the outer frame.  Non-toolkit builds can provide an internal menu
48080     bar.  On text terminal frames, the menu bar is part of the frame’s
48081     root window (*note Windows and Frames::).  As a rule, menu bars are
48082     never shown on child frames (*note Child Frames::).  Display of the
48083     menu bar can be suppressed by setting the ‘menu-bar-lines’
48084     parameter (*note Layout Parameters::) to zero.
48085
48086     Whether the menu bar is wrapped or truncated whenever its width
48087     becomes too large to fit on its frame depends on the toolkit .
48088     Usually, only Motif and MS-Windows builds can wrap the menu bar.
48089     When they (un-)wrap the menu bar, they try to keep the outer height
48090     of the frame unchanged, so the native height of the frame (see
48091     below) will change instead.
48092
48093Tool Bar
48094     Like the menu bar, the tool bar (*note Tool Bar::) can be either
48095     internal (drawn by Emacs itself) or external (drawn by a toolkit).
48096     The GTK+ and NS builds have the tool bar drawn by the toolkit.  The
48097     remaining builds use internal tool bars.  With GTK+ the tool bar
48098     can be located on either side of the frame, immediately outside the
48099     internal border, see below.  Tool bars are usually not shown for
48100     child frames (*note Child Frames::).  Display of the tool bar can
48101     be suppressed by setting the ‘tool-bar-lines’ parameter (*note
48102     Layout Parameters::) to zero.
48103
48104     If the variable ‘auto-resize-tool-bars’ is non-‘nil’, Emacs wraps
48105     the internal tool bar when its width becomes too large for its
48106     frame.  If and when Emacs (un-)wraps the internal tool bar, it by
48107     default keeps the outer height of the frame unchanged, so the
48108     native height of the frame (see below) will change instead.  Emacs
48109     built with GTK+, on the other hand, never wraps the tool bar but
48110     may automatically increase the outer width of a frame in order to
48111     accommodate an overlong tool bar.
48112
48113Native Frame
48114     The “native frame” is a rectangle located entirely within the outer
48115     frame.  It excludes the areas occupied by an external or outer
48116     border, the title bar and any external menu or tool bar.  The edges
48117     of the native frame are called the “native edges” of the frame.
48118     Together, the “native width” and “native height” of a frame specify
48119     the “native size” of the frame.
48120
48121     The native size of a frame is the size Emacs passes to the
48122     window-system or window manager when creating or resizing the frame
48123     from within Emacs.  It is also the size Emacs receives from the
48124     window-system or window manager whenever these resize the frame’s
48125     window-system window, for example, after maximizing the frame by
48126     clicking on the corresponding button in the title bar or when
48127     dragging its external border with the mouse.
48128
48129     The position of the top left corner of the native frame specifies
48130     the “native position” of the frame.  (1)–(3) in the drawing above
48131     indicate that position for the various builds:
48132
48133          (1) non-toolkit and terminal frames
48134
48135          (2) Lucid, Motif and MS-Windows frames
48136
48137          (3) GTK+ and NS frames
48138
48139     Accordingly, the native height of a frame may include the height of
48140     the tool bar but not that of the menu bar (Lucid, Motif,
48141     MS-Windows) or those of the menu bar and the tool bar (non-toolkit
48142     and text terminal frames).
48143
48144     The native position of a frame is the reference position for
48145     functions that set or return the current position of the mouse
48146     (*note Mouse Position::) and for functions dealing with the
48147     position of windows like ‘window-edges’, ‘window-at’ or
48148     ‘coordinates-in-window-p’ (*note Coordinates and Windows::).  It
48149     also specifies the (0, 0) origin for locating and positioning child
48150     frames within this frame (*note Child Frames::).
48151
48152     Note also that the native position of a frame usually remains
48153     unaltered on its display when removing or adding the window manager
48154     decorations by changing the frame’s ‘override-redirect’ or
48155     ‘undecorated’ parameter (*note Management Parameters::).
48156
48157Internal Border
48158     The internal border is a border drawn by Emacs around the inner
48159     frame (see below).  Its width is specified by the
48160     ‘internal-border-width’ frame parameter (*note Layout
48161     Parameters::).  Its color is specified by the background of the
48162     ‘internal-border’ face.
48163
48164Inner Frame
48165     The “inner frame” is the rectangle reserved for the frame’s
48166     windows.  It’s enclosed by the internal border which, however, is
48167     not part of the inner frame.  Its edges are called the “inner
48168     edges” of the frame.  The “inner width” and “inner height” specify
48169     the “inner size” of the rectangle.  The inner frame is sometimes
48170     also referred to as the “display area” of the frame.
48171
48172     As a rule, the inner frame is subdivided into the frame’s root
48173     window (*note Windows and Frames::) and the frame’s minibuffer
48174     window (*note Minibuffer Windows::).  There are two notable
48175     exceptions to this rule: A “minibuffer-less frame” contains a root
48176     window only and does not contain a minibuffer window.  A
48177     “minibuffer-only frame” contains only a minibuffer window which
48178     also serves as that frame’s root window.  See *note Initial
48179     Parameters:: for how to create such frame configurations.
48180
48181Text Area
48182     The “text area” of a frame is a somewhat fictitious area that can
48183     be embedded in the native frame.  Its position is unspecified.  Its
48184     width can be obtained by removing from that of the native width the
48185     widths of the internal border, one vertical scroll bar, and one
48186     left and one right fringe if they are specified for this frame, see
48187     *note Layout Parameters::.  Its height can be obtained by removing
48188     from that of the native height the widths of the internal border
48189     and the heights of the frame’s internal menu and tool bars and one
48190     horizontal scroll bar if specified for this frame.
48191
48192   The “absolute position” of a frame is given as a pair (X, Y) of
48193horizontal and vertical pixel offsets relative to an origin (0, 0) of
48194the frame’s display.  Correspondingly, the “absolute edges” of a frame
48195are given as pixel offsets from that origin.
48196
48197   Note that with multiple monitors, the origin of the display does not
48198necessarily coincide with the top-left corner of the entire usable
48199display area of the terminal.  Hence the absolute position of a frame
48200can be negative in such an environment even when that frame is
48201completely visible.
48202
48203   By convention, vertical offsets increase “downwards”.  This means
48204that the height of a frame is obtained by subtracting the offset of its
48205top edge from that of its bottom edge.  Horizontal offsets increase
48206“rightwards”, as expected, so a frame’s width is calculated by
48207subtracting the offset of its left edge from that of its right edge.
48208
48209   For a frame on a graphical terminal the following function returns
48210the sizes of the areas described above:
48211
48212 -- Function: frame-geometry &optional frame
48213     This function returns geometric attributes of FRAME.  The return
48214     value is an association list of the attributes listed below.  All
48215     coordinate, height and width values are integers counting pixels.
48216     Note that if FRAME has not been mapped yet, (*note Visibility of
48217     Frames::) some of the return values may only represent
48218     approximations of the actual values—those that can be seen after
48219     the frame has been mapped.
48220
48221     ‘outer-position’
48222          A cons representing the absolute position of the outer FRAME,
48223          relative to the origin at position (0, 0) of FRAME’s display.
48224
48225     ‘outer-size’
48226          A cons of the outer width and height of FRAME.
48227
48228     ‘external-border-size’
48229          A cons of the horizontal and vertical width of FRAME’s
48230          external borders as supplied by the window manager.  If the
48231          window manager doesn’t supply these values, Emacs will try to
48232          guess them from the coordinates of the outer and inner frame.
48233
48234     ‘outer-border-width’
48235          The width of the outer border of FRAME.  The value is
48236          meaningful for non-GTK+ X builds only.
48237
48238     ‘title-bar-size’
48239          A cons of the width and height of the title bar of FRAME as
48240          supplied by the window manager or operating system.  If both
48241          of them are zero, the frame has no title bar.  If only the
48242          width is zero, Emacs was not able to retrieve the width
48243          information.
48244
48245     ‘menu-bar-external’
48246          If non-‘nil’, this means the menu bar is external (not part of
48247          the native frame of FRAME).
48248
48249     ‘menu-bar-size’
48250          A cons of the width and height of the menu bar of FRAME.
48251
48252     ‘tool-bar-external’
48253          If non-‘nil’, this means the tool bar is external (not part of
48254          the native frame of FRAME).
48255
48256     ‘tool-bar-position’
48257          This tells on which side the tool bar on FRAME is and can be
48258          one of ‘left’, ‘top’, ‘right’ or ‘bottom’.  The only toolkit
48259          that currently supports a value other than ‘top’ is GTK+.
48260
48261     ‘tool-bar-size’
48262          A cons of the width and height of the tool bar of FRAME.
48263
48264     ‘internal-border-width’
48265          The width of the internal border of FRAME.
48266
48267   The following function can be used to retrieve the edges of the
48268outer, native and inner frame.
48269
48270 -- Function: frame-edges &optional frame type
48271     This function returns the absolute edges of the outer, native or
48272     inner frame of FRAME.  FRAME must be a live frame and defaults to
48273     the selected one.  The returned list has the form
48274     ‘(LEFT TOP RIGHT BOTTOM)’ where all values are in pixels relative
48275     to the origin of FRAME’s display.  For terminal frames the values
48276     returned for LEFT and TOP are always zero.
48277
48278     Optional argument TYPE specifies the type of the edges to return:
48279     ‘outer-edges’ means to return the outer edges of FRAME,
48280     ‘native-edges’ (or ‘nil’) means to return its native edges and
48281     ‘inner-edges’ means to return its inner edges.
48282
48283     By convention, the pixels of the display at the values returned for
48284     LEFT and TOP are considered to be inside (part of) FRAME.  Hence,
48285     if LEFT and TOP are both zero, the pixel at the display’s origin is
48286     part of FRAME.  The pixels at BOTTOM and RIGHT, on the other hand,
48287     are considered to lie immediately outside FRAME.  This means that
48288     if you have, for example, two side-by-side frames positioned such
48289     that the right outer edge of the frame on the left equals the left
48290     outer edge of the frame on the right, the pixels at that edge show
48291     a part of the frame on the right.
48292
48293
48294File: elisp.info,  Node: Frame Font,  Next: Frame Position,  Prev: Frame Layout,  Up: Frame Geometry
48295
4829629.3.2 Frame Font
48297-----------------
48298
48299Each frame has a “default font” which specifies the default character
48300size for that frame.  This size is meant when retrieving or changing the
48301size of a frame in terms of columns or lines (*note Size Parameters::).
48302It is also used when resizing (*note Window Sizes::) or splitting (*note
48303Splitting Windows::) windows.
48304
48305   The terms “line height” and “canonical character height” are
48306sometimes used instead of “default character height”.  Similarly, the
48307terms “column width” and “canonical character width” are used instead of
48308“default character width”.
48309
48310 -- Function: frame-char-height &optional frame
48311 -- Function: frame-char-width &optional frame
48312     These functions return the default height and width of a character
48313     in FRAME, measured in pixels.  Together, these values establish the
48314     size of the default font on FRAME.  The values depend on the choice
48315     of font for FRAME, see *note Font and Color Parameters::.
48316
48317   The default font can be also set directly with the following
48318function:
48319
48320 -- Command: set-frame-font font &optional keep-size frames
48321     This sets the default font to FONT.  When called interactively, it
48322     prompts for the name of a font, and uses that font on the selected
48323     frame.  When called from Lisp, FONT should be a font name (a
48324     string), a font object, font entity, or a font spec.
48325
48326     If the optional argument KEEP-SIZE is ‘nil’, this keeps the number
48327     of frame lines and columns fixed.  (If non-‘nil’, the option
48328     ‘frame-inhibit-implied-resize’ described in the next section will
48329     override this.)  If KEEP-SIZE is non-‘nil’ (or with a prefix
48330     argument), it tries to keep the size of the display area of the
48331     current frame fixed by adjusting the number of lines and columns.
48332
48333     If the optional argument FRAMES is ‘nil’, this applies the font to
48334     the selected frame only.  If FRAMES is non-‘nil’, it should be a
48335     list of frames to act upon, or ‘t’ meaning all existing and all
48336     future graphical frames.
48337
48338
48339File: elisp.info,  Node: Frame Position,  Next: Frame Size,  Prev: Frame Font,  Up: Frame Geometry
48340
4834129.3.3 Frame Position
48342---------------------
48343
48344On graphical systems, the position of a normal top-level frame is
48345specified as the absolute position of its outer frame (*note Frame
48346Geometry::).  The position of a child frame (*note Child Frames::) is
48347specified via pixel offsets of its outer edges relative to the native
48348position of its parent frame.
48349
48350   You can access or change the position of a frame using the frame
48351parameters ‘left’ and ‘top’ (*note Position Parameters::).  Here are two
48352additional functions for working with the positions of an existing,
48353visible frame.  For both functions, the argument FRAME must denote a
48354live frame and defaults to the selected frame.
48355
48356 -- Function: frame-position &optional frame
48357     For a normal, non-child frame this function returns a cons of the
48358     pixel coordinates of its outer position (*note Frame Layout::) with
48359     respect to the origin ‘(0, 0)’ of its display.  For a child frame
48360     (*note Child Frames::) this function returns the pixel coordinates
48361     of its outer position with respect to an origin ‘(0, 0)’ at the
48362     native position of FRAME’s parent.
48363
48364     Negative values never indicate an offset from the right or bottom
48365     edge of FRAME’s display or parent frame.  Rather, they mean that
48366     FRAME’s outer position is on the left and/or above the origin of
48367     its display or the native position of its parent frame.  This
48368     usually means that FRAME is only partially visible (or completely
48369     invisible).  However, on systems where the display’s origin does
48370     not coincide with its top-left corner, the frame may be visible on
48371     a secondary monitor.
48372
48373     On a text terminal frame both values are zero.
48374
48375 -- Function: set-frame-position frame x y
48376     This function sets the outer frame position of FRAME to (X, Y).
48377     The latter arguments specify pixels and normally count from the
48378     origin at the position (0, 0) of FRAME’s display.  For child
48379     frames, they count from the native position of FRAME’s parent
48380     frame.
48381
48382     Negative parameter values position the right edge of the outer
48383     frame by -X pixels left from the right edge of the screen (or the
48384     parent frame’s native rectangle) and the bottom edge by -Y pixels
48385     up from the bottom edge of the screen (or the parent frame’s native
48386     rectangle).
48387
48388     Note that negative values do not permit to align the right or
48389     bottom edge of FRAME exactly at the right or bottom edge of its
48390     display or parent frame.  Neither do they allow to specify a
48391     position that does not lie within the edges of the display or
48392     parent frame.  The frame parameters ‘left’ and ‘top’ (*note
48393     Position Parameters::) allow to do that, but may still fail to
48394     provide good results for the initial or a new frame.
48395
48396     This function has no effect on text terminal frames.
48397
48398 -- Variable: move-frame-functions
48399     This hook specifies the functions that are run when an Emacs frame
48400     is moved (assigned a new position) by the window-system or window
48401     manager.  The functions are run with one argument, the frame that
48402     moved.  For a child frame (*note Child Frames::), the functions are
48403     run only when the position of the frame changes in relation to that
48404     of its parent frame.
48405
48406
48407File: elisp.info,  Node: Frame Size,  Next: Implied Frame Resizing,  Prev: Frame Position,  Up: Frame Geometry
48408
4840929.3.4 Frame Size
48410-----------------
48411
48412The canonical way to specify the “size of a frame” from within Emacs is
48413by specifying its “text size”—a tuple of the width and height of the
48414frame’s text area (*note Frame Layout::).  It can be measured either in
48415pixels or in terms of the frame’s canonical character size (*note Frame
48416Font::).
48417
48418   For frames with an internal menu or tool bar, the frame’s native
48419height cannot be told exactly before the frame has been actually drawn.
48420This means that in general you cannot use the native size to specify the
48421initial size of a frame.  As soon as you know the native size of a
48422visible frame, you can calculate its outer size (*note Frame Layout::)
48423by adding in the remaining components from the return value of
48424‘frame-geometry’.  For invisible frames or for frames that have yet to
48425be created, however, the outer size can only be estimated.  This also
48426means that calculating an exact initial position of a frame specified
48427via offsets from the right or bottom edge of the screen (*note Frame
48428Position::) is impossible.
48429
48430   The text size of any frame can be set and retrieved with the help of
48431the ‘height’ and ‘width’ frame parameters (*note Size Parameters::).
48432The text size of the initial frame can be also set with the help of an
48433X-style geometry specification.  *Note Command Line Arguments for Emacs
48434Invocation: (emacs)Emacs Invocation.  Below we list some functions to
48435access and set the size of an existing, visible frame, by default the
48436selected one.
48437
48438 -- Function: frame-height &optional frame
48439 -- Function: frame-width &optional frame
48440     These functions return the height and width of the text area of
48441     FRAME, measured in units of the default font height and width of
48442     FRAME (*note Frame Font::).  These functions are plain shorthands
48443     for writing ‘(frame-parameter frame 'height)’ and ‘(frame-parameter
48444     frame 'width)’.
48445
48446     If the text area of FRAME measured in pixels is not a multiple of
48447     its default font size, the values returned by these functions are
48448     rounded down to the number of characters of the default font that
48449     fully fit into the text area.
48450
48451   The functions following next return the pixel widths and heights of
48452the native, outer and inner frame and the text area (*note Frame
48453Layout::) of a given frame.  For a text terminal, the results are in
48454characters rather than pixels.
48455
48456 -- Function: frame-outer-width &optional frame
48457 -- Function: frame-outer-height &optional frame
48458     These functions return the outer width and height of FRAME in
48459     pixels.
48460
48461 -- Function: frame-native-height &optional frame
48462 -- Function: frame-native-width &optional frame
48463     These functions return the native width and height of FRAME in
48464     pixels.
48465
48466 -- Function: frame-inner-width &optional frame
48467 -- Function: frame-inner-height &optional frame
48468     These functions return the inner width and height of FRAME in
48469     pixels.
48470
48471 -- Function: frame-text-width &optional frame
48472 -- Function: frame-text-height &optional frame
48473     These functions return the width and height of the text area of
48474     FRAME in pixels.
48475
48476   On window systems that support it, Emacs tries by default to make the
48477text size of a frame measured in pixels a multiple of the frame’s
48478character size.  This, however, usually means that a frame can be
48479resized only in character size increments when dragging its external
48480borders.  It also may break attempts to truly maximize the frame or
48481making it “fullheight” or “fullwidth” (*note Size Parameters::) leaving
48482some empty space below and/or on the right of the frame.  The following
48483option may help in that case.
48484
48485 -- User Option: frame-resize-pixelwise
48486     If this option is ‘nil’ (the default), a frame’s text pixel size is
48487     usually rounded to a multiple of the current values of that frame’s
48488     ‘frame-char-height’ and ‘frame-char-width’ whenever the frame is
48489     resized.  If this is non-‘nil’, no rounding occurs, hence frame
48490     sizes can increase/decrease by one pixel.
48491
48492     Setting this variable usually causes the next resize operation to
48493     pass the corresponding size hints to the window manager.  This
48494     means that this variable should be set only in a user’s initial
48495     file; applications should never bind it temporarily.
48496
48497     The precise meaning of a value of ‘nil’ for this option depends on
48498     the toolkit used.  Dragging the external border with the mouse is
48499     done character-wise provided the window manager is willing to
48500     process the corresponding size hints.  Calling ‘set-frame-size’
48501     (see below) with arguments that do not specify the frame size as an
48502     integer multiple of its character size, however, may: be ignored,
48503     cause a rounding (GTK+), or be accepted (Lucid, Motif, MS-Windows).
48504
48505     With some window managers you may have to set this to non-‘nil’ in
48506     order to make a frame appear truly maximized or full-screen.
48507
48508 -- Function: set-frame-size frame width height &optional pixelwise
48509     This function sets the size of the text area of FRAME, measured in
48510     terms of the canonical height and width of a character on FRAME
48511     (*note Frame Font::).
48512
48513     The optional argument PIXELWISE non-‘nil’ means to measure the new
48514     width and height in units of pixels instead.  Note that if
48515     ‘frame-resize-pixelwise’ is ‘nil’, some toolkits may refuse to
48516     truly honor the request if it does not increase/decrease the frame
48517     size to a multiple of its character size.
48518
48519 -- Function: set-frame-height frame height &optional pretend pixelwise
48520     This function resizes the text area of FRAME to a height of HEIGHT
48521     lines.  The sizes of existing windows in FRAME are altered
48522     proportionally to fit.
48523
48524     If PRETEND is non-‘nil’, then Emacs displays HEIGHT lines of output
48525     in FRAME, but does not change its value for the actual height of
48526     the frame.  This is only useful on text terminals.  Using a smaller
48527     height than the terminal actually implements may be useful to
48528     reproduce behavior observed on a smaller screen, or if the terminal
48529     malfunctions when using its whole screen.  Setting the frame height
48530     directly does not always work, because knowing the correct actual
48531     size may be necessary for correct cursor positioning on text
48532     terminals.
48533
48534     The optional fourth argument PIXELWISE non-‘nil’ means that FRAME
48535     should be HEIGHT pixels high.  Note that if
48536     ‘frame-resize-pixelwise’ is ‘nil’, some window managers may refuse
48537     to truly honor the request if it does not increase/decrease the
48538     frame height to a multiple of its character height.
48539
48540     When used interactively, this command will set the height of the
48541     currently selected frame to the number of lines specified by the
48542     numeric prefix.
48543
48544 -- Function: set-frame-width frame width &optional pretend pixelwise
48545     This function sets the width of the text area of FRAME, measured in
48546     characters.  The argument PRETEND has the same meaning as in
48547     ‘set-frame-height’.
48548
48549     The optional fourth argument PIXELWISE non-‘nil’ means that FRAME
48550     should be WIDTH pixels wide.  Note that if ‘frame-resize-pixelwise’
48551     is ‘nil’, some window managers may refuse to fully honor the
48552     request if it does not increase/decrease the frame width to a
48553     multiple of its character width.
48554
48555     When used interactively, this command will set the width of the
48556     currently selected frame to the number of columns specified by the
48557     numeric prefix.
48558
48559   None of these three functions will make a frame smaller than needed
48560to display all of its windows together with their scroll bars, fringes,
48561margins, dividers, mode and header lines.  This contrasts with requests
48562by the window manager triggered, for example, by dragging the external
48563border of a frame with the mouse.  Such requests are always honored by
48564clipping, if necessary, portions that cannot be displayed at the right,
48565bottom corner of the frame.  The parameters ‘min-width’ and ‘min-height’
48566(*note Size Parameters::) can be used to obtain a similar behavior when
48567changing the frame size from within Emacs.
48568
48569   The abnormal hook ‘window-size-change-functions’ (*note Window
48570Hooks::) tracks all changes of the inner size of a frame including those
48571induced by request of the window-system or window manager.  To rule out
48572false positives that might occur when changing only the sizes of a
48573frame’s windows without actually changing the size of the inner frame,
48574use the following function.
48575
48576 -- Function: frame-size-changed-p &optional frame
48577     This function returns non-‘nil’ when the inner width or height of
48578     FRAME has changed since ‘window-size-change-functions’ was run the
48579     last time for FRAME.  It always returns ‘nil’ immediately after
48580     running ‘window-size-change-functions’ for FRAME.
48581
48582
48583File: elisp.info,  Node: Implied Frame Resizing,  Prev: Frame Size,  Up: Frame Geometry
48584
4858529.3.5 Implied Frame Resizing
48586-----------------------------
48587
48588By default, Emacs tries to keep the number of lines and columns of a
48589frame’s text area unaltered when, for example, toggling its menu or tool
48590bar, changing its default font or setting the width of any of its scroll
48591bars.  This means that in such case Emacs must ask the window manager to
48592resize the frame’s window in order to accommodate the size change.
48593
48594   Occasionally, such “implied frame resizing” may be unwanted, for
48595example, when a frame has been maximized or made full-screen (where it’s
48596turned off by default).  In general, users can disable implied resizing
48597with the following option:
48598
48599 -- User Option: frame-inhibit-implied-resize
48600     If this option is ‘nil’, changing a frame’s font, menu bar, tool
48601     bar, internal borders, fringes or scroll bars may resize its outer
48602     frame in order to keep the number of columns or lines of its text
48603     area unaltered.  If this option is ‘t’, no such resizing is done.
48604
48605     The value of this option can be also a list of frame parameters.
48606     In that case, implied resizing is inhibited for the change of a
48607     parameter that appears in this list.  Parameters currently handled
48608     by this option are ‘font’, ‘font-backend’, ‘internal-border-width’,
48609     ‘menu-bar-lines’ and ‘tool-bar-lines’.
48610
48611     Changing any of the ‘scroll-bar-width’, ‘scroll-bar-height’,
48612     ‘vertical-scroll-bars’, ‘horizontal-scroll-bars’, ‘left-fringe’ and
48613     ‘right-fringe’ frame parameters is handled as if the frame
48614     contained just one live window.  This means, for example, that
48615     removing vertical scroll bars on a frame containing several side by
48616     side windows will shrink the outer frame width by the width of one
48617     scroll bar provided this option is ‘nil’ and keep it unchanged if
48618     this option is ‘t’ or a list containing ‘vertical-scroll-bars’.
48619
48620     The default value is ‘'(tab-bar-lines tool-bar-lines)’ for Lucid,
48621     Motif and MS-Windows (which means that adding/removing a tool or
48622     tab bar there does not change the outer frame height),
48623     ‘'(tab-bar-lines)’ on all other window systems including GTK+
48624     (which means that changing any of the parameters listed above with
48625     the exception of ‘tab-bar-lines’ may change the size of the outer
48626     frame), and ‘t’ otherwise (which means the outer frame size never
48627     changes implicitly when there’s no window system support).
48628
48629     Note that when a frame is not large enough to accommodate a change
48630     of any of the parameters listed above, Emacs may try to enlarge the
48631     frame even if this option is non-‘nil’.
48632
48633     Note also that window managers usually do not ask for resizing a
48634     frame when they change the number of lines occupied by an external
48635     menu or tool bar.  Typically, such “wrappings” occur when a user
48636     shrinks a frame horizontally, making it impossible to display all
48637     elements of its menu or tool bar.  They may also result from a
48638     change of the major mode altering the number of items of a menu or
48639     tool bar.  Any such wrappings may implicitly alter the number of
48640     lines of a frame’s text area and are unaffected by the setting of
48641     this option.
48642
48643
48644File: elisp.info,  Node: Frame Parameters,  Next: Terminal Parameters,  Prev: Frame Geometry,  Up: Frames
48645
4864629.4 Frame Parameters
48647=====================
48648
48649A frame has many parameters that control its appearance and behavior.
48650Just what parameters a frame has depends on what display mechanism it
48651uses.
48652
48653   Frame parameters exist mostly for the sake of graphical displays.
48654Most frame parameters have no effect when applied to a frame on a text
48655terminal; only the ‘height’, ‘width’, ‘name’, ‘title’, ‘menu-bar-lines’,
48656‘buffer-list’ and ‘buffer-predicate’ parameters do something special.
48657If the terminal supports colors, the parameters ‘foreground-color’,
48658‘background-color’, ‘background-mode’ and ‘display-type’ are also
48659meaningful.  If the terminal supports frame transparency, the parameter
48660‘alpha’ is also meaningful.
48661
48662   By default, frame parameters are saved and restored by the desktop
48663library functions (*note Desktop Save Mode::) when the variable
48664‘desktop-restore-frames’ is non-‘nil’.  It’s the responsibility of
48665applications that their parameters are included in
48666‘frameset-persistent-filter-alist’ to avoid that they get meaningless or
48667even harmful values in restored sessions.
48668
48669* Menu:
48670
48671* Parameter Access::       How to change a frame’s parameters.
48672* Initial Parameters::     Specifying frame parameters when you make a frame.
48673* Window Frame Parameters:: List of frame parameters for window systems.
48674* Geometry::               Parsing geometry specifications.
48675
48676
48677File: elisp.info,  Node: Parameter Access,  Next: Initial Parameters,  Up: Frame Parameters
48678
4867929.4.1 Access to Frame Parameters
48680---------------------------------
48681
48682These functions let you read and change the parameter values of a frame.
48683
48684 -- Function: frame-parameter frame parameter
48685     This function returns the value of the parameter PARAMETER (a
48686     symbol) of FRAME.  If FRAME is ‘nil’, it returns the selected
48687     frame’s parameter.  If FRAME has no setting for PARAMETER, this
48688     function returns ‘nil’.
48689
48690 -- Function: frame-parameters &optional frame
48691     The function ‘frame-parameters’ returns an alist listing all the
48692     parameters of FRAME and their values.  If FRAME is ‘nil’ or
48693     omitted, this returns the selected frame’s parameters
48694
48695 -- Function: modify-frame-parameters frame alist
48696     This function alters the frame FRAME based on the elements of
48697     ALIST.  Each element of ALIST has the form ‘(PARM . VALUE)’, where
48698     PARM is a symbol naming a parameter.  If you don’t mention a
48699     parameter in ALIST, its value doesn’t change.  If FRAME is ‘nil’,
48700     it defaults to the selected frame.
48701
48702     Some parameters are only meaningful for frames on certain kinds of
48703     display (*note Frames::).  If ALIST includes parameters that are
48704     not meaningful for the FRAME’s display, this function will change
48705     its value in the frame’s parameter list, but will otherwise ignore
48706     it.
48707
48708     When ALIST specifies more than one parameter whose value can affect
48709     the new size of FRAME, the final size of the frame may differ
48710     according to the toolkit used.  For example, specifying that a
48711     frame should from now on have a menu and/or tool bar instead of
48712     none and simultaneously specifying the new height of the frame will
48713     inevitably lead to a recalculation of the frame’s height.
48714     Conceptually, in such case, this function will try to have the
48715     explicit height specification prevail.  It cannot be excluded,
48716     however, that the addition (or removal) of the menu or tool bar,
48717     when eventually performed by the toolkit, will defeat this
48718     intention.
48719
48720     Sometimes, binding ‘frame-inhibit-implied-resize’ (*note Implied
48721     Frame Resizing::) to a non-‘nil’ value around calls to this
48722     function may fix the problem sketched here.  Sometimes, however,
48723     exactly such binding may be hit by the problem.
48724
48725 -- Function: set-frame-parameter frame parm value
48726     This function sets the frame parameter PARM to the specified VALUE.
48727     If FRAME is ‘nil’, it defaults to the selected frame.
48728
48729 -- Function: modify-all-frames-parameters alist
48730     This function alters the frame parameters of all existing frames
48731     according to ALIST, then modifies ‘default-frame-alist’ (and, if
48732     necessary, ‘initial-frame-alist’) to apply the same parameter
48733     values to frames that will be created henceforth.
48734
48735
48736File: elisp.info,  Node: Initial Parameters,  Next: Window Frame Parameters,  Prev: Parameter Access,  Up: Frame Parameters
48737
4873829.4.2 Initial Frame Parameters
48739-------------------------------
48740
48741You can specify the parameters for the initial startup frame by setting
48742‘initial-frame-alist’ in your init file (*note Init File::).
48743
48744 -- User Option: initial-frame-alist
48745     This variable’s value is an alist of parameter values used when
48746     creating the initial frame.  You can set this variable to specify
48747     the appearance of the initial frame without altering subsequent
48748     frames.  Each element has the form:
48749
48750          (PARAMETER . VALUE)
48751
48752     Emacs creates the initial frame before it reads your init file.
48753     After reading that file, Emacs checks ‘initial-frame-alist’, and
48754     applies the parameter settings in the altered value to the already
48755     created initial frame.
48756
48757     If these settings affect the frame geometry and appearance, you’ll
48758     see the frame appear with the wrong ones and then change to the
48759     specified ones.  If that bothers you, you can specify the same
48760     geometry and appearance with X resources; those do take effect
48761     before the frame is created.  *Note X Resources: (emacs)X
48762     Resources.
48763
48764     X resource settings typically apply to all frames.  If you want to
48765     specify some X resources solely for the sake of the initial frame,
48766     and you don’t want them to apply to subsequent frames, here’s how
48767     to achieve this.  Specify parameters in ‘default-frame-alist’ to
48768     override the X resources for subsequent frames; then, to prevent
48769     these from affecting the initial frame, specify the same parameters
48770     in ‘initial-frame-alist’ with values that match the X resources.
48771
48772   If these parameters include ‘(minibuffer . nil)’, that indicates that
48773the initial frame should have no minibuffer.  In this case, Emacs
48774creates a separate “minibuffer-only frame” as well.
48775
48776 -- User Option: minibuffer-frame-alist
48777     This variable’s value is an alist of parameter values used when
48778     creating an initial minibuffer-only frame (i.e., the
48779     minibuffer-only frame that Emacs creates if ‘initial-frame-alist’
48780     specifies a frame with no minibuffer).
48781
48782 -- User Option: default-frame-alist
48783     This is an alist specifying default values of frame parameters for
48784     all Emacs frames—the first frame, and subsequent frames.  When
48785     using the X Window System, you can get the same results by means of
48786     X resources in many cases.
48787
48788     Setting this variable does not affect existing frames.
48789     Furthermore, functions that display a buffer in a separate frame
48790     may override the default parameters by supplying their own
48791     parameters.
48792
48793   If you invoke Emacs with command-line options that specify frame
48794appearance, those options take effect by adding elements to either
48795‘initial-frame-alist’ or ‘default-frame-alist’.  Options which affect
48796just the initial frame, such as ‘--geometry’ and ‘--maximized’, add to
48797‘initial-frame-alist’; the others add to ‘default-frame-alist’.  *note
48798Command Line Arguments for Emacs Invocation: (emacs)Emacs Invocation.
48799
48800
48801File: elisp.info,  Node: Window Frame Parameters,  Next: Geometry,  Prev: Initial Parameters,  Up: Frame Parameters
48802
4880329.4.3 Window Frame Parameters
48804------------------------------
48805
48806Just what parameters a frame has depends on what display mechanism it
48807uses.  This section describes the parameters that have special meanings
48808on some or all kinds of terminals.  Of these, ‘name’, ‘title’, ‘height’,
48809‘width’, ‘buffer-list’ and ‘buffer-predicate’ provide meaningful
48810information in terminal frames, and ‘tty-color-mode’ is meaningful only
48811for frames on text terminals.
48812
48813* Menu:
48814
48815* Basic Parameters::            Parameters that are fundamental.
48816* Position Parameters::         The position of the frame on the screen.
48817* Size Parameters::             Frame’s size.
48818* Layout Parameters::           Size of parts of the frame, and
48819                                  enabling or disabling some parts.
48820* Buffer Parameters::           Which buffers have been or should be shown.
48821* Frame Interaction Parameters::  Parameters for interacting with other
48822                                  frames.
48823* Mouse Dragging Parameters::   Parameters for resizing and moving
48824                                  frames with the mouse.
48825* Management Parameters::       Communicating with the window manager.
48826* Cursor Parameters::           Controlling the cursor appearance.
48827* Font and Color Parameters::   Fonts and colors for the frame text.
48828
48829
48830File: elisp.info,  Node: Basic Parameters,  Next: Position Parameters,  Up: Window Frame Parameters
48831
4883229.4.3.1 Basic Parameters
48833.........................
48834
48835These frame parameters give the most basic information about the frame.
48836‘title’ and ‘name’ are meaningful on all terminals.
48837
48838‘display’
48839     The display on which to open this frame.  It should be a string of
48840     the form ‘HOST:DPY.SCREEN’, just like the ‘DISPLAY’ environment
48841     variable.  *Note Multiple Terminals::, for more details about
48842     display names.
48843
48844‘display-type’
48845     This parameter describes the range of possible colors that can be
48846     used in this frame.  Its value is ‘color’, ‘grayscale’ or ‘mono’.
48847
48848‘title’
48849     If a frame has a non-‘nil’ title, it appears in the window system’s
48850     title bar at the top of the frame, and also in the mode line of
48851     windows in that frame if ‘mode-line-frame-identification’ uses ‘%F’
48852     (*note %-Constructs::).  This is normally the case when Emacs is
48853     not using a window system, and can only display one frame at a
48854     time.  *Note Frame Titles::.
48855
48856‘name’
48857     The name of the frame.  The frame name serves as a default for the
48858     frame title, if the ‘title’ parameter is unspecified or ‘nil’.  If
48859     you don’t specify a name, Emacs sets the frame name automatically
48860     (*note Frame Titles::).
48861
48862     If you specify the frame name explicitly when you create the frame,
48863     the name is also used (instead of the name of the Emacs executable)
48864     when looking up X resources for the frame.
48865
48866‘explicit-name’
48867     If the frame name was specified explicitly when the frame was
48868     created, this parameter will be that name.  If the frame wasn’t
48869     explicitly named, this parameter will be ‘nil’.
48870
48871
48872File: elisp.info,  Node: Position Parameters,  Next: Size Parameters,  Prev: Basic Parameters,  Up: Window Frame Parameters
48873
4887429.4.3.2 Position Parameters
48875............................
48876
48877Parameters describing the X- and Y-offsets of a frame are always
48878measured in pixels.  For a normal, non-child frame they specify the
48879frame’s outer position (*note Frame Geometry::) relative to its
48880display’s origin.  For a child frame (*note Child Frames::) they specify
48881the frame’s outer position relative to the native position of the
48882frame’s parent frame.  (Note that none of these parameters is meaningful
48883on TTY frames.)
48884
48885‘left’
48886     The position, in pixels, of the left outer edge of the frame with
48887     respect to the left edge of the frame’s display or parent frame.
48888     It can be specified in one of the following ways.
48889
48890     an integer
48891          A positive integer always relates the left edge of the frame
48892          to the left edge of its display or parent frame.  A negative
48893          integer relates the right frame edge to the right edge of the
48894          display or parent frame.
48895
48896     ‘(+ POS)’
48897          This specifies the position of the left frame edge relative to
48898          the left edge of its display or parent frame.  The integer POS
48899          may be positive or negative; a negative value specifies a
48900          position outside the screen or parent frame or on a monitor
48901          other than the primary one (for multi-monitor displays).
48902
48903     ‘(- POS)’
48904          This specifies the position of the right frame edge relative
48905          to the right edge of the display or parent frame.  The integer
48906          POS may be positive or negative; a negative value specifies a
48907          position outside the screen or parent frame or on a monitor
48908          other than the primary one (for multi-monitor displays).
48909
48910     a floating-point value
48911          A floating-point value in the range 0.0 to 1.0 specifies the
48912          left edge’s offset via the “left position ratio” of the
48913          frame—the ratio of the left edge of its outer frame to the
48914          width of the frame’s workarea (*note Multiple Terminals::) or
48915          its parent’s native frame (*note Child Frames::) minus the
48916          width of the outer frame.  Thus, a left position ratio of 0.0
48917          flushes a frame to the left, a ratio of 0.5 centers it and a
48918          ratio of 1.0 flushes it to the right of its display or parent
48919          frame.  Similarly, the “top position ratio” of a frame is the
48920          ratio of the frame’s top position to the height of its
48921          workarea or parent frame minus the height of the frame.
48922
48923          Emacs will try to keep the position ratios of a child frame
48924          unaltered if that frame has a non-‘nil’ ‘keep-ratio’ parameter
48925          (*note Frame Interaction Parameters::) and its parent frame is
48926          resized.
48927
48928          Since the outer size of a frame (*note Frame Geometry::) is
48929          usually unavailable before a frame has been made visible, it
48930          is generally not advisable to use floating-point values when
48931          creating decorated frames.  Floating-point values are more
48932          suited for ensuring that an (undecorated) child frame is
48933          positioned nicely within the area of its parent frame.
48934
48935     Some window managers ignore program-specified positions.  If you
48936     want to be sure the position you specify is not ignored, specify a
48937     non-‘nil’ value for the ‘user-position’ parameter as in the
48938     following example:
48939
48940          (modify-frame-parameters
48941            nil '((user-position . t) (left . (+ -4))))
48942
48943     In general, it is not a good idea to position a frame relative to
48944     the right or bottom edge of its display.  Positioning the initial
48945     or a new frame is either not accurate (because the size of the
48946     outer frame is not yet fully known before the frame has been made
48947     visible) or will cause additional flicker (if the frame has to be
48948     repositioned after becoming visible).
48949
48950     Note also, that positions specified relative to the right/bottom
48951     edge of a display, workarea or parent frame as well as
48952     floating-point offsets are stored internally as integer offsets
48953     relative to the left/top edge of the display, workarea or parent
48954     frame edge.  They are also returned as such by functions like
48955     ‘frame-parameters’ and restored as such by the desktop saving
48956     routines.
48957
48958‘top’
48959     The screen position of the top (or bottom) edge, in pixels, with
48960     respect to the top (or bottom) edge of the display or parent frame.
48961     It works just like ‘left’, except vertically instead of
48962     horizontally.
48963
48964‘icon-left’
48965     The screen position of the left edge of the frame’s icon, in
48966     pixels, counting from the left edge of the screen.  This takes
48967     effect when the frame is iconified, if the window manager supports
48968     this feature.  If you specify a value for this parameter, then you
48969     must also specify a value for ‘icon-top’ and vice versa.
48970
48971‘icon-top’
48972     The screen position of the top edge of the frame’s icon, in pixels,
48973     counting from the top edge of the screen.  This takes effect when
48974     the frame is iconified, if the window manager supports this
48975     feature.
48976
48977‘user-position’
48978     When you create a frame and specify its screen position with the
48979     ‘left’ and ‘top’ parameters, use this parameter to say whether the
48980     specified position was user-specified (explicitly requested in some
48981     way by a human user) or merely program-specified (chosen by a
48982     program).  A non-‘nil’ value says the position was user-specified.
48983
48984     Window managers generally heed user-specified positions, and some
48985     heed program-specified positions too.  But many ignore
48986     program-specified positions, placing the window in a default
48987     fashion or letting the user place it with the mouse.  Some window
48988     managers, including ‘twm’, let the user specify whether to obey
48989     program-specified positions or ignore them.
48990
48991     When you call ‘make-frame’, you should specify a non-‘nil’ value
48992     for this parameter if the values of the ‘left’ and ‘top’ parameters
48993     represent the user’s stated preference; otherwise, use ‘nil’.
48994
48995‘z-group’
48996     This parameter specifies a relative position of the frame’s
48997     window-system window in the stacking (Z-) order of the frame’s
48998     display.
48999
49000     If this is ‘above’, the window-system will display the window that
49001     corresponds to the frame above all other window-system windows that
49002     do not have the ‘above’ property set.  If this is ‘nil’, the
49003     frame’s window is displayed below all windows that have the ‘above’
49004     property set and above all windows that have the ‘below’ property
49005     set.  If this is ‘below’, the frame’s window is displayed below all
49006     windows that do not have the ‘below’ property set.
49007
49008     To position the frame above or below a specific other frame use the
49009     function ‘frame-restack’ (*note Raising and Lowering::).
49010
49011
49012File: elisp.info,  Node: Size Parameters,  Next: Layout Parameters,  Prev: Position Parameters,  Up: Window Frame Parameters
49013
4901429.4.3.3 Size Parameters
49015........................
49016
49017Frame parameters usually specify frame sizes in character units.  On
49018graphical displays, the ‘default’ face determines the actual pixel sizes
49019of these character units (*note Face Attributes::).
49020
49021‘width’
49022     This parameter specifies the width of the frame.  It can be
49023     specified as in the following ways:
49024
49025     an integer
49026          A positive integer specifies the width of the frame’s text
49027          area (*note Frame Geometry::) in characters.
49028
49029     a cons cell
49030          If this is a cons cell with the symbol ‘text-pixels’ in its
49031          CAR, the CDR of that cell specifies the width of the frame’s
49032          text area in pixels.
49033
49034     a floating-point value
49035          A floating-point number between 0.0 and 1.0 can be used to
49036          specify the width of a frame via its “width ratio”—the ratio
49037          of its outer width (*note Frame Geometry::) to the width of
49038          the frame’s workarea (*note Multiple Terminals::) or its
49039          parent frame’s (*note Child Frames::) native frame.  Thus, a
49040          value of 0.5 makes the frame occupy half of the width of its
49041          workarea or parent frame, a value of 1.0 the full width.
49042          Similarly, the “height ratio” of a frame is the ratio of its
49043          outer height to the height of its workarea or its parent’s
49044          native frame.
49045
49046          Emacs will try to keep the width and height ratio of a child
49047          frame unaltered if that frame has a non-‘nil’ ‘keep-ratio’
49048          parameter (*note Frame Interaction Parameters::) and its
49049          parent frame is resized.
49050
49051          Since the outer size of a frame is usually unavailable before
49052          a frame has been made visible, it is generally not advisable
49053          to use floating-point values when creating decorated frames.
49054          Floating-point values are more suited to ensure that a child
49055          frame always fits within the area of its parent frame as, for
49056          example, when customizing ‘display-buffer-alist’ (*note
49057          Choosing Window::) via ‘display-buffer-in-child-frame’.
49058
49059     Regardless of how this parameter was specified, functions reporting
49060     the value of this parameter like ‘frame-parameters’ always report
49061     the width of the frame’s text area in characters as an integer
49062     rounded, if necessary, to a multiple of the frame’s default
49063     character width.  That value is also used by the desktop saving
49064     routines.
49065
49066‘height’
49067     This parameter specifies the height of the frame.  It works just
49068     like ‘width’, except vertically instead of horizontally.
49069
49070‘user-size’
49071     This does for the size parameters ‘height’ and ‘width’ what the
49072     ‘user-position’ parameter (*note user-position: Position
49073     Parameters.) does for the position parameters ‘top’ and ‘left’.
49074
49075‘min-width’
49076     This parameter specifies the minimum native width (*note Frame
49077     Geometry::) of the frame, in characters.  Normally, the functions
49078     that establish a frame’s initial width or resize a frame
49079     horizontally make sure that all the frame’s windows, vertical
49080     scroll bars, fringes, margins and vertical dividers can be
49081     displayed.  This parameter, if non-‘nil’ allows to make a frame
49082     narrower than that with the consequence that any components that do
49083     not fit will be clipped by the window manager.
49084
49085‘min-height’
49086     This parameter specifies the minimum native height (*note Frame
49087     Geometry::) of the frame, in characters.  Normally, the functions
49088     that establish a frame’s initial size or resize a frame make sure
49089     that all the frame’s windows, horizontal scroll bars and dividers,
49090     mode and header lines, the echo area and the internal menu and tool
49091     bar can be displayed.  This parameter, if non-‘nil’ allows to make
49092     a frame smaller than that with the consequence that any components
49093     that do not fit will be clipped by the window manager.
49094
49095‘fullscreen’
49096     This parameter specifies whether to maximize the frame’s width,
49097     height or both.  Its value can be ‘fullwidth’, ‘fullheight’,
49098     ‘fullboth’, or ‘maximized’.  A “fullwidth” frame is as wide as
49099     possible, a “fullheight” frame is as tall as possible, and a
49100     “fullboth” frame is both as wide and as tall as possible.  A
49101     “maximized” frame is like a “fullboth” frame, except that it
49102     usually keeps its title bar and the buttons for resizing and
49103     closing the frame.  Also, maximized frames typically avoid hiding
49104     any task bar or panels displayed on the desktop.  A “fullboth”
49105     frame, on the other hand, usually omits the title bar and occupies
49106     the entire available screen space.
49107
49108     Full-height and full-width frames are more similar to maximized
49109     frames in this regard.  However, these typically display an
49110     external border which might be absent with maximized frames.  Hence
49111     the heights of maximized and full-height frames and the widths of
49112     maximized and full-width frames often differ by a few pixels.
49113
49114     With some window managers you may have to customize the variable
49115     ‘frame-resize-pixelwise’ (*note Frame Size::) in order to make a
49116     frame truly appear maximized or full-screen.  Moreover, some window
49117     managers might not support smooth transition between the various
49118     full-screen or maximization states.  Customizing the variable
49119     ‘x-frame-normalize-before-maximize’ can help to overcome that.
49120
49121     Full-screen on macOS hides both the tool-bar and the menu-bar,
49122     however both will be displayed if the mouse pointer is moved to the
49123     top of the screen.
49124
49125‘fullscreen-restore’
49126     This parameter specifies the desired fullscreen state of the frame
49127     after invoking the ‘toggle-frame-fullscreen’ command (*note
49128     (emacs)Frame Commands::) in the “fullboth” state.  Normally this
49129     parameter is installed automatically by that command when toggling
49130     the state to fullboth.  If, however, you start Emacs in the
49131     “fullboth” state, you have to specify the desired behavior in your
49132     initial file as, for example
49133
49134          (setq default-frame-alist
49135              '((fullscreen . fullboth)
49136                (fullscreen-restore . fullheight)))
49137
49138     This will give a new frame full height after typing in it <F11> for
49139     the first time.
49140
49141‘fit-frame-to-buffer-margins’
49142     This parameter allows to override the value of the option
49143     ‘fit-frame-to-buffer-margins’ when fitting this frame to the buffer
49144     of its root window with ‘fit-frame-to-buffer’ (*note Resizing
49145     Windows::).
49146
49147‘fit-frame-to-buffer-sizes’
49148     This parameter allows to override the value of the option
49149     ‘fit-frame-to-buffer-sizes’ when fitting this frame to the buffer
49150     of its root window with ‘fit-frame-to-buffer’ (*note Resizing
49151     Windows::).
49152
49153
49154File: elisp.info,  Node: Layout Parameters,  Next: Buffer Parameters,  Prev: Size Parameters,  Up: Window Frame Parameters
49155
4915629.4.3.4 Layout Parameters
49157..........................
49158
49159These frame parameters enable or disable various parts of the frame, or
49160control their sizes.
49161
49162‘border-width’
49163     The width in pixels of the frame’s outer border (*note Frame
49164     Geometry::).
49165
49166‘internal-border-width’
49167     The width in pixels of the frame’s internal border (*note Frame
49168     Geometry::).
49169
49170‘vertical-scroll-bars’
49171     Whether the frame has scroll bars (*note Scroll Bars::) for
49172     vertical scrolling, and which side of the frame they should be on.
49173     The possible values are ‘left’, ‘right’, and ‘nil’ for no scroll
49174     bars.
49175
49176‘horizontal-scroll-bars’
49177     Whether the frame has scroll bars for horizontal scrolling (‘t’ and
49178     ‘bottom’ mean yes, ‘nil’ means no).
49179
49180‘scroll-bar-width’
49181     The width of vertical scroll bars, in pixels, or ‘nil’ meaning to
49182     use the default width.
49183
49184‘scroll-bar-height’
49185     The height of horizontal scroll bars, in pixels, or ‘nil’ meaning
49186     to use the default height.
49187
49188‘left-fringe’
49189‘right-fringe’
49190     The default width of the left and right fringes of windows in this
49191     frame (*note Fringes::).  If either of these is zero, that
49192     effectively removes the corresponding fringe.
49193
49194     When you use ‘frame-parameter’ to query the value of either of
49195     these two frame parameters, the return value is always an integer.
49196     When using ‘set-frame-parameter’, passing a ‘nil’ value imposes an
49197     actual default value of 8 pixels.
49198
49199‘right-divider-width’
49200     The width (thickness) reserved for the right divider (*note Window
49201     Dividers::) of any window on the frame, in pixels.  A value of zero
49202     means to not draw right dividers.
49203
49204‘bottom-divider-width’
49205     The width (thickness) reserved for the bottom divider (*note Window
49206     Dividers::) of any window on the frame, in pixels.  A value of zero
49207     means to not draw bottom dividers.
49208
49209‘menu-bar-lines’
49210     The number of lines to allocate at the top of the frame for a menu
49211     bar (*note Menu Bar::).  The default is one if Menu Bar mode is
49212     enabled and zero otherwise.  *Note (emacs)Menu Bars::.  For an
49213     external menu bar (*note Frame Layout::), this value remains
49214     unchanged even when the menu bar wraps to two or more lines.  In
49215     that case, the ‘menu-bar-size’ value returned by ‘frame-geometry’
49216     (*note Frame Geometry::) allows to derive whether the menu bar
49217     actually occupies one or more lines.
49218
49219‘tool-bar-lines’
49220     The number of lines to use for the tool bar (*note Tool Bar::).
49221     The default is one if Tool Bar mode is enabled and zero otherwise.
49222     *Note (emacs)Tool Bars::.  This value may change whenever the tool
49223     bar wraps (*note Frame Layout::).
49224
49225‘tool-bar-position’
49226     The position of the tool bar when Emacs was built with GTK+.  Its
49227     value can be one of ‘top’, ‘bottom’ ‘left’, ‘right’.  The default
49228     is ‘top’.
49229
49230‘line-spacing’
49231     Additional space to leave below each text line, in pixels (a
49232     positive integer).  *Note Line Height::, for more information.
49233
49234‘no-special-glyphs’
49235     If this is non-‘nil’, it suppresses the display of any truncation
49236     and continuation glyphs (*note Truncation::) for all buffers
49237     displayed by this frame.  This is useful to eliminate such glyphs
49238     when fitting a frame to its buffer via ‘fit-frame-to-buffer’ (*note
49239     Resizing Windows::).
49240
49241
49242File: elisp.info,  Node: Buffer Parameters,  Next: Frame Interaction Parameters,  Prev: Layout Parameters,  Up: Window Frame Parameters
49243
4924429.4.3.5 Buffer Parameters
49245..........................
49246
49247These frame parameters, meaningful on all kinds of terminals, deal with
49248which buffers have been, or should, be displayed in the frame.
49249
49250‘minibuffer’
49251     Whether this frame has its own minibuffer.  The value ‘t’ means
49252     yes, ‘nil’ means no, ‘only’ means this frame is just a minibuffer.
49253     If the value is a minibuffer window (in some other frame), the
49254     frame uses that minibuffer.
49255
49256     This parameter takes effect when the frame is created.  If
49257     specified as ‘nil’, Emacs will try to set it to the minibuffer
49258     window of ‘default-minibuffer-frame’ (*note Minibuffers and
49259     Frames::).  For an existing frame, this parameter can be used
49260     exclusively to specify another minibuffer window.  It is not
49261     allowed to change it from a minibuffer window to ‘t’ and
49262     vice-versa, or from ‘t’ to ‘nil’.  If the parameter specifies a
49263     minibuffer window already, setting it to ‘nil’ has no effect.
49264
49265     The special value ‘child-frame’ means to make a minibuffer-only
49266     child frame (*note Child Frames::) whose parent becomes the frame
49267     created.  As if specified as ‘nil’, Emacs will set this parameter
49268     to the minibuffer window of the child frame but will not select the
49269     child frame after its creation.
49270
49271‘buffer-predicate’
49272     The buffer-predicate function for this frame.  The function
49273     ‘other-buffer’ uses this predicate (from the selected frame) to
49274     decide which buffers it should consider, if the predicate is not
49275     ‘nil’.  It calls the predicate with one argument, a buffer, once
49276     for each buffer; if the predicate returns a non-‘nil’ value, it
49277     considers that buffer.
49278
49279‘buffer-list’
49280     A list of buffers that have been selected in this frame, ordered
49281     most-recently-selected first.
49282
49283‘unsplittable’
49284     If non-‘nil’, this frame’s window is never split automatically.
49285
49286
49287File: elisp.info,  Node: Frame Interaction Parameters,  Next: Mouse Dragging Parameters,  Prev: Buffer Parameters,  Up: Window Frame Parameters
49288
4928929.4.3.6 Frame Interaction Parameters
49290.....................................
49291
49292These parameters supply forms of interactions between different frames.
49293
49294‘parent-frame’
49295     If non-‘nil’, this means that this frame is a child frame (*note
49296     Child Frames::), and this parameter specifies its parent frame.  If
49297     ‘nil’, this means that this frame is a normal, top-level frame.
49298
49299‘delete-before’
49300     If non-‘nil’, this parameter specifies another frame whose deletion
49301     will automatically trigger the deletion of this frame.  *Note
49302     Deleting Frames::.
49303
49304‘mouse-wheel-frame’
49305     If non-‘nil’, this parameter specifies the frame whose windows will
49306     be scrolled whenever the mouse wheel is scrolled with the mouse
49307     pointer hovering over this frame, see *note (emacs)Mouse
49308     Commands::.
49309
49310‘no-other-frame’
49311     If this is non-‘nil’, then this frame is not eligible as candidate
49312     for the functions ‘next-frame’, ‘previous-frame’ (*note Finding All
49313     Frames::) and ‘other-frame’, see *note (emacs)Frame Commands::.
49314
49315‘auto-hide-function’
49316     When this parameter specifies a function, that function will be
49317     called instead of the function specified by the variable
49318     ‘frame-auto-hide-function’ when quitting the frame’s only window
49319     (*note Quitting Windows::) and there are other frames left.
49320
49321‘minibuffer-exit’
49322     When this parameter is non-‘nil’, Emacs will by default make this
49323     frame invisible whenever the minibuffer (*note Minibuffers::) is
49324     exited.  Alternatively, it can specify the functions
49325     ‘iconify-frame’ and ‘delete-frame’.  This parameter is useful to
49326     make a child frame disappear automatically (similar to how Emacs
49327     deals with a window) when exiting the minibuffer.
49328
49329‘keep-ratio’
49330     This parameter is currently meaningful for child frames (*note
49331     Child Frames::) only.  If it is non-‘nil’, then Emacs will try to
49332     keep the frame’s size (width and height) ratios (*note Size
49333     Parameters::) as well as its left and right position ratios (*note
49334     Position Parameters::) unaltered whenever its parent frame is
49335     resized.
49336
49337     If the value of this parameter is ‘nil’, the frame’s position and
49338     size remain unaltered when the parent frame is resized, so the
49339     position and size ratios may change.  If the value of this
49340     parameter is ‘t’, Emacs will try to preserve the frame’s size and
49341     position ratios, hence the frame’s size and position relative to
49342     its parent frame may change.
49343
49344     More individual control is possible by using a cons cell: In that
49345     case the frame’s width ratio is preserved if the CAR of the cell is
49346     either ‘t’ or ‘width-only’.  The height ratio is preserved if the
49347     CAR of the cell is either ‘t’ or ‘height-only’.  The left position
49348     ratio is preserved if the CDR of the cell is either ‘t’ or
49349     ‘left-only’.  The top position ratio is preserved if the CDR of the
49350     cell is either ‘t’ or ‘top-only’.
49351
49352
49353File: elisp.info,  Node: Mouse Dragging Parameters,  Next: Management Parameters,  Prev: Frame Interaction Parameters,  Up: Window Frame Parameters
49354
4935529.4.3.7 Mouse Dragging Parameters
49356..................................
49357
49358The parameters described below provide support for resizing a frame by
49359dragging its internal borders with the mouse.  They also allow moving a
49360frame with the mouse by dragging the header line of its topmost or the
49361mode line of its bottommost window.
49362
49363   These parameters are mostly useful for child frames (*note Child
49364Frames::) that come without window manager decorations.  If necessary,
49365they can be used for undecorated top-level frames as well.
49366
49367‘drag-internal-border’
49368     If non-‘nil’, the frame can be resized by dragging its internal
49369     borders, if present, with the mouse.
49370
49371‘drag-with-header-line’
49372     If non-‘nil’, the frame can be moved with the mouse by dragging the
49373     header line of its topmost window.
49374
49375‘drag-with-mode-line’
49376     If non-‘nil’, the frame can be moved with the mouse by dragging the
49377     mode line of its bottommost window.  Note that such a frame is not
49378     allowed to have its own minibuffer window.
49379
49380‘snap-width’
49381     A frame that is moved with the mouse will “snap” at the border(s)
49382     of the display or its parent frame whenever it is dragged as near
49383     to such an edge as the number of pixels specified by this
49384     parameter.
49385
49386‘top-visible’
49387     If this parameter is a number, the top edge of the frame never
49388     appears above the top edge of its display or parent frame.
49389     Moreover, as many pixels of the frame as specified by that number
49390     will remain visible when the frame is moved against any of the
49391     remaining edges of its display or parent frame.  Setting this
49392     parameter is useful to guard against dragging a child frame with a
49393     non-‘nil’ ‘drag-with-header-line’ parameter completely out of the
49394     area of its parent frame.
49395
49396‘bottom-visible’
49397     If this parameter is a number, the bottom edge of the frame never
49398     appears below the bottom edge of its display or parent frame.
49399     Moreover, as many pixels of the frame as specified by that number
49400     will remain visible when the frame is moved against any of the
49401     remaining edges of its display or parent frame.  Setting this
49402     parameter is useful to guard against dragging a child frame with a
49403     non-‘nil’ ‘drag-with-mode-line’ parameter completely out of the
49404     area of its parent frame.
49405
49406
49407File: elisp.info,  Node: Management Parameters,  Next: Cursor Parameters,  Prev: Mouse Dragging Parameters,  Up: Window Frame Parameters
49408
4940929.4.3.8 Window Management Parameters
49410.....................................
49411
49412The following frame parameters control various aspects of the frame’s
49413interaction with the window manager or window system.  They have no
49414effect on text terminals.
49415
49416‘visibility’
49417     The state of visibility of the frame.  There are three
49418     possibilities: ‘nil’ for invisible, ‘t’ for visible, and ‘icon’ for
49419     iconified.  *Note Visibility of Frames::.
49420
49421‘auto-raise’
49422     If non-‘nil’, Emacs automatically raises the frame when it is
49423     selected.  Some window managers do not allow this.
49424
49425‘auto-lower’
49426     If non-‘nil’, Emacs automatically lowers the frame when it is
49427     deselected.  Some window managers do not allow this.
49428
49429‘icon-type’
49430     The type of icon to use for this frame.  If the value is a string,
49431     that specifies a file containing a bitmap to use; ‘nil’ specifies
49432     no icon (in which case the window manager decides what to show);
49433     any other non-‘nil’ value specifies the default Emacs icon.
49434
49435‘icon-name’
49436     The name to use in the icon for this frame, when and if the icon
49437     appears.  If this is ‘nil’, the frame’s title is used.
49438
49439‘window-id’
49440     The ID number which the graphical display uses for this frame.
49441     Emacs assigns this parameter when the frame is created; changing
49442     the parameter has no effect on the actual ID number.
49443
49444‘outer-window-id’
49445     The ID number of the outermost window-system window in which the
49446     frame exists.  As with ‘window-id’, changing this parameter has no
49447     actual effect.
49448
49449‘wait-for-wm’
49450     If non-‘nil’, tell Xt to wait for the window manager to confirm
49451     geometry changes.  Some window managers, including versions of
49452     Fvwm2 and KDE, fail to confirm, so Xt hangs.  Set this to ‘nil’ to
49453     prevent hanging with those window managers.
49454
49455‘sticky’
49456     If non-‘nil’, the frame is visible on all virtual desktops on
49457     systems with virtual desktops.
49458
49459‘inhibit-double-buffering’
49460     If non-‘nil’, the frame is drawn to the screen without double
49461     buffering.  Emacs normally attempts to use double buffering, where
49462     available, to reduce flicker.  Set this property if you experience
49463     display bugs or pine for that retro, flicker-y feeling.
49464
49465‘skip-taskbar’
49466     If non-‘nil’, this tells the window manager to remove the frame’s
49467     icon from the taskbar associated with the frame’s display and
49468     inhibit switching to the frame’s window via the combination
49469     ‘Alt-<TAB>’.  On MS-Windows, iconifying such a frame will "roll in"
49470     its window-system window at the bottom of the desktop.  Some window
49471     managers may not honor this parameter.
49472
49473‘no-focus-on-map’
49474     If non-‘nil’, this means that the frame does not want to receive
49475     input focus when it is mapped (*note Visibility of Frames::).  Some
49476     window managers may not honor this parameter.
49477
49478‘no-accept-focus’
49479     If non-‘nil’, this means that the frame does not want to receive
49480     input focus via explicit mouse clicks or when moving the mouse into
49481     it either via ‘focus-follows-mouse’ (*note Input Focus::) or
49482     ‘mouse-autoselect-window’ (*note Mouse Window Auto-selection::).
49483     This may have the unwanted side-effect that a user cannot scroll a
49484     non-selected frame with the mouse.  Some window managers may not
49485     honor this parameter.
49486
49487‘undecorated’
49488     If non-‘nil’, this frame’s window-system window is drawn without
49489     decorations, like the title, minimize/maximize boxes and external
49490     borders.  This usually means that the window cannot be dragged,
49491     resized, iconified, maximized or deleted with the mouse.  If ‘nil’,
49492     the frame’s window is usually drawn with all the elements listed
49493     above unless their display has been suspended via window manager
49494     settings.
49495
49496     Under X, Emacs uses the Motif window manager hints to turn off
49497     decorations.  Some window managers may not honor these hints.
49498
49499     NS builds consider the tool bar to be a decoration, and therefore
49500     hide it on an undecorated frame.
49501
49502‘override-redirect’
49503     If non-‘nil’, this means that this is an “override redirect”
49504     frame—a frame not handled by window managers under X.  Override
49505     redirect frames have no window manager decorations, can be
49506     positioned and resized only via Emacs’ positioning and resizing
49507     functions and are usually drawn on top of all other frames.
49508     Setting this parameter has no effect on MS-Windows.
49509
49510‘ns-appearance’
49511     Only available on macOS, if set to ‘dark’ draw this frame’s
49512     window-system window using the “vibrant dark” theme, otherwise use
49513     the system default.  The “vibrant dark” theme can be used to set
49514     the toolbar and scrollbars to a dark appearance when using an Emacs
49515     theme with a dark background.
49516
49517‘ns-transparent-titlebar’
49518     Only available on macOS, if non-‘nil’, set the titlebar and toolbar
49519     to be transparent.  This effectively sets the background color of
49520     both to match the Emacs background color.
49521
49522
49523File: elisp.info,  Node: Cursor Parameters,  Next: Font and Color Parameters,  Prev: Management Parameters,  Up: Window Frame Parameters
49524
4952529.4.3.9 Cursor Parameters
49526..........................
49527
49528This frame parameter controls the way the cursor looks.
49529
49530‘cursor-type’
49531     How to display the cursor.  Legitimate values are:
49532
49533     ‘box’
49534          Display a filled box.  (This is the default.)
49535     ‘hollow’
49536          Display a hollow box.
49537     ‘nil’
49538          Don’t display a cursor.
49539     ‘bar’
49540          Display a vertical bar between characters.
49541     ‘(bar . WIDTH)’
49542          Display a vertical bar WIDTH pixels wide between characters.
49543     ‘hbar’
49544          Display a horizontal bar.
49545     ‘(hbar . HEIGHT)’
49546          Display a horizontal bar HEIGHT pixels high.
49547
49548   The ‘cursor-type’ frame parameter may be overridden by the variables
49549‘cursor-type’ and ‘cursor-in-non-selected-windows’:
49550
49551 -- User Option: cursor-type
49552     This buffer-local variable controls how the cursor looks in a
49553     selected window showing the buffer.  If its value is ‘t’, that
49554     means to use the cursor specified by the ‘cursor-type’ frame
49555     parameter.  Otherwise, the value should be one of the cursor types
49556     listed above, and it overrides the ‘cursor-type’ frame parameter.
49557
49558 -- User Option: cursor-in-non-selected-windows
49559     This buffer-local variable controls how the cursor looks in a
49560     window that is not selected.  It supports the same values as the
49561     ‘cursor-type’ frame parameter; also, ‘nil’ means don’t display a
49562     cursor in nonselected windows, and ‘t’ (the default) means use a
49563     standard modification of the usual cursor type (solid box becomes
49564     hollow box, and bar becomes a narrower bar).
49565
49566 -- User Option: x-stretch-cursor
49567     This variable controls the width of the block cursor displayed on
49568     extra-wide glyphs such as a tab or a stretch of white space.  By
49569     default, the block cursor is only as wide as the font’s default
49570     character, and will not cover all of the width of the glyph under
49571     it if that glyph is extra-wide.  A non-‘nil’ value of this variable
49572     means draw the block cursor as wide as the glyph under it.  The
49573     default value is ‘nil’.
49574
49575     This variable has no effect on text-mode frames, since the
49576     text-mode cursor is drawn by the terminal out of Emacs’s control.
49577
49578 -- User Option: blink-cursor-alist
49579     This variable specifies how to blink the cursor.  Each element has
49580     the form ‘(ON-STATE . OFF-STATE)’.  Whenever the cursor type equals
49581     ON-STATE (comparing using ‘equal’), the corresponding OFF-STATE
49582     specifies what the cursor looks like when it blinks off.  Both
49583     ON-STATE and OFF-STATE should be suitable values for the
49584     ‘cursor-type’ frame parameter.
49585
49586     There are various defaults for how to blink each type of cursor, if
49587     the type is not mentioned as an ON-STATE here.  Changes in this
49588     variable do not take effect immediately, only when you specify the
49589     ‘cursor-type’ frame parameter.
49590
49591
49592File: elisp.info,  Node: Font and Color Parameters,  Prev: Cursor Parameters,  Up: Window Frame Parameters
49593
4959429.4.3.10 Font and Color Parameters
49595...................................
49596
49597These frame parameters control the use of fonts and colors.
49598
49599‘font-backend’
49600     A list of symbols, specifying the “font backends” to use for
49601     drawing characters on the frame, in order of priority.  In Emacs
49602     built without Cairo drawing on X, there are currently three
49603     potentially available font backends: ‘x’ (the X core font driver),
49604     ‘xft’ (the Xft font driver), and ‘xfthb’ (the Xft font driver with
49605     HarfBuzz text shaping).  If built with Cairo drawing, there are
49606     also three potentially available font backends on X: ‘x’, ‘ftcr’
49607     (the FreeType font driver on Cairo), and ‘ftcrhb’ (the FreeType
49608     font driver on Cairo with HarfBuzz text shaping).  When Emacs is
49609     built with HarfBuzz, the default font driver is ‘ftcrhb’, although
49610     use of the ‘ftcr’ driver is still possible, but not recommended.
49611     On MS-Windows, there are currently three available font backends:
49612     ‘gdi’ (the core MS-Windows font driver), ‘uniscribe’ (font driver
49613     for OTF and TTF fonts with text shaping by the Uniscribe engine),
49614     and ‘harfbuzz’ (font driver for OTF and TTF fonts with HarfBuzz
49615     text shaping) (*note (emacs)Windows Fonts::).  The ‘harfbuzz’
49616     driver is similarly recommended.  On other systems, there is only
49617     one available font backend, so it does not make sense to modify
49618     this frame parameter.
49619
49620‘background-mode’
49621     This parameter is either ‘dark’ or ‘light’, according to whether
49622     the background color is a light one or a dark one.
49623
49624‘tty-color-mode’
49625     This parameter overrides the terminal’s color support as given by
49626     the system’s terminal capabilities database in that this
49627     parameter’s value specifies the color mode to use on a text
49628     terminal.  The value can be either a symbol or a number.  A number
49629     specifies the number of colors to use (and, indirectly, what
49630     commands to issue to produce each color).  For example,
49631     ‘(tty-color-mode . 8)’ specifies use of the ANSI escape sequences
49632     for 8 standard text colors.  A value of −1 turns off color support.
49633
49634     If the parameter’s value is a symbol, it specifies a number through
49635     the value of ‘tty-color-mode-alist’, and the associated number is
49636     used instead.
49637
49638‘screen-gamma’
49639     If this is a number, Emacs performs gamma correction which adjusts
49640     the brightness of all colors.  The value should be the screen gamma
49641     of your display.
49642
49643     Usual PC monitors have a screen gamma of 2.2, so color values in
49644     Emacs, and in X windows generally, are calibrated to display
49645     properly on a monitor with that gamma value.  If you specify 2.2
49646     for ‘screen-gamma’, that means no correction is needed.  Other
49647     values request correction, designed to make the corrected colors
49648     appear on your screen the way they would have appeared without
49649     correction on an ordinary monitor with a gamma value of 2.2.
49650
49651     If your monitor displays colors too light, you should specify a
49652     ‘screen-gamma’ value smaller than 2.2.  This requests correction
49653     that makes colors darker.  A screen gamma value of 1.5 may give
49654     good results for LCD color displays.
49655
49656‘alpha’
49657     This parameter specifies the opacity of the frame, on graphical
49658     displays that support variable opacity.  It should be an integer
49659     between 0 and 100, where 0 means completely transparent and 100
49660     means completely opaque.  It can also have a ‘nil’ value, which
49661     tells Emacs not to set the frame opacity (leaving it to the window
49662     manager).
49663
49664     To prevent the frame from disappearing completely from view, the
49665     variable ‘frame-alpha-lower-limit’ defines a lower opacity limit.
49666     If the value of the frame parameter is less than the value of this
49667     variable, Emacs uses the latter.  By default,
49668     ‘frame-alpha-lower-limit’ is 20.
49669
49670     The ‘alpha’ frame parameter can also be a cons cell ‘(ACTIVE .
49671     INACTIVE)’, where ACTIVE is the opacity of the frame when it is
49672     selected, and INACTIVE is the opacity when it is not selected.
49673
49674     Some window systems do not support the ‘alpha’ parameter for child
49675     frames (*note Child Frames::).
49676
49677   The following frame parameters are semi-obsolete in that they are
49678automatically equivalent to particular face attributes of particular
49679faces (*note (emacs)Standard Faces::):
49680
49681‘font’
49682     The name of the font for displaying text in the frame.  This is a
49683     string, either a valid font name for your system or the name of an
49684     Emacs fontset (*note Fontsets::).  It is equivalent to the ‘font’
49685     attribute of the ‘default’ face.
49686
49687‘foreground-color’
49688     The color to use for the image of a character.  It is equivalent to
49689     the ‘:foreground’ attribute of the ‘default’ face.
49690
49691‘background-color’
49692     The color to use for the background of characters.  It is
49693     equivalent to the ‘:background’ attribute of the ‘default’ face.
49694
49695‘mouse-color’
49696     The color for the mouse pointer.  It is equivalent to the
49697     ‘:background’ attribute of the ‘mouse’ face.
49698
49699‘cursor-color’
49700     The color for the cursor that shows point.  It is equivalent to the
49701     ‘:background’ attribute of the ‘cursor’ face.
49702
49703‘border-color’
49704     The color for the border of the frame.  It is equivalent to the
49705     ‘:background’ attribute of the ‘border’ face.
49706
49707‘scroll-bar-foreground’
49708     If non-‘nil’, the color for the foreground of scroll bars.  It is
49709     equivalent to the ‘:foreground’ attribute of the ‘scroll-bar’ face.
49710
49711‘scroll-bar-background’
49712     If non-‘nil’, the color for the background of scroll bars.  It is
49713     equivalent to the ‘:background’ attribute of the ‘scroll-bar’ face.
49714
49715
49716File: elisp.info,  Node: Geometry,  Prev: Window Frame Parameters,  Up: Frame Parameters
49717
4971829.4.4 Geometry
49719---------------
49720
49721Here’s how to examine the data in an X-style window geometry
49722specification:
49723
49724 -- Function: x-parse-geometry geom
49725     The function ‘x-parse-geometry’ converts a standard X window
49726     geometry string to an alist that you can use as part of the
49727     argument to ‘make-frame’.
49728
49729     The alist describes which parameters were specified in GEOM, and
49730     gives the values specified for them.  Each element looks like
49731     ‘(PARAMETER . VALUE)’.  The possible PARAMETER values are ‘left’,
49732     ‘top’, ‘width’, and ‘height’.
49733
49734     For the size parameters, the value must be an integer.  The
49735     position parameter names ‘left’ and ‘top’ are not totally accurate,
49736     because some values indicate the position of the right or bottom
49737     edges instead.  The VALUE possibilities for the position parameters
49738     are: an integer, a list ‘(+ POS)’, or a list ‘(- POS)’; as
49739     previously described (*note Position Parameters::).
49740
49741     Here is an example:
49742
49743          (x-parse-geometry "35x70+0-0")
49744               ⇒ ((height . 70) (width . 35)
49745                   (top - 0) (left . 0))
49746
49747
49748File: elisp.info,  Node: Terminal Parameters,  Next: Frame Titles,  Prev: Frame Parameters,  Up: Frames
49749
4975029.5 Terminal Parameters
49751========================
49752
49753Each terminal has a list of associated parameters.  These “terminal
49754parameters” are mostly a convenient way of storage for terminal-local
49755variables, but some terminal parameters have a special meaning.
49756
49757   This section describes functions to read and change the parameter
49758values of a terminal.  They all accept as their argument either a
49759terminal or a frame; the latter means use that frame’s terminal.  An
49760argument of ‘nil’ means the selected frame’s terminal.
49761
49762 -- Function: terminal-parameters &optional terminal
49763     This function returns an alist listing all the parameters of
49764     TERMINAL and their values.
49765
49766 -- Function: terminal-parameter terminal parameter
49767     This function returns the value of the parameter PARAMETER (a
49768     symbol) of TERMINAL.  If TERMINAL has no setting for PARAMETER,
49769     this function returns ‘nil’.
49770
49771 -- Function: set-terminal-parameter terminal parameter value
49772     This function sets the parameter PARAMETER of TERMINAL to the
49773     specified VALUE, and returns the previous value of that parameter.
49774
49775   Here’s a list of a few terminal parameters that have a special
49776meaning:
49777
49778‘background-mode’
49779     The classification of the terminal’s background color, either
49780     ‘light’ or ‘dark’.
49781‘normal-erase-is-backspace’
49782     Value is either 1 or 0, depending on whether
49783     ‘normal-erase-is-backspace-mode’ is turned on or off on this
49784     terminal.  *Note (emacs)DEL Does Not Delete::.
49785‘terminal-initted’
49786     After the terminal is initialized, this is set to the
49787     terminal-specific initialization function.
49788‘tty-mode-set-strings’
49789     When present, a list of strings containing escape sequences that
49790     Emacs will output while configuring a tty for rendering.  Emacs
49791     emits these strings only when configuring a terminal: if you want
49792     to enable a mode on a terminal that is already active (for example,
49793     while in ‘tty-setup-hook’), explicitly output the necessary escape
49794     sequence using ‘send-string-to-terminal’ in addition to adding the
49795     sequence to ‘tty-mode-set-strings’.
49796‘tty-mode-reset-strings’
49797     When present, a list of strings that undo the effects of the
49798     strings in ‘tty-mode-set-strings’.  Emacs emits these strings when
49799     exiting, deleting a terminal, or suspending itself.
49800
49801
49802File: elisp.info,  Node: Frame Titles,  Next: Deleting Frames,  Prev: Terminal Parameters,  Up: Frames
49803
4980429.6 Frame Titles
49805=================
49806
49807Every frame has a ‘name’ parameter; this serves as the default for the
49808frame title which window systems typically display at the top of the
49809frame.  You can specify a name explicitly by setting the ‘name’ frame
49810property.
49811
49812   Normally you don’t specify the name explicitly, and Emacs computes
49813the frame name automatically based on a template stored in the variable
49814‘frame-title-format’.  Emacs recomputes the name each time the frame is
49815redisplayed.
49816
49817 -- Variable: frame-title-format
49818     This variable specifies how to compute a name for a frame when you
49819     have not explicitly specified one.  The variable’s value is
49820     actually a mode line construct, just like ‘mode-line-format’,
49821     except that the ‘%c’, ‘%C’, and ‘%l’ constructs are ignored.  *Note
49822     Mode Line Data::.
49823
49824 -- Variable: icon-title-format
49825     This variable specifies how to compute the name for an iconified
49826     frame, when you have not explicitly specified the frame title.
49827     This title appears in the icon itself.
49828
49829 -- Variable: multiple-frames
49830     This variable is set automatically by Emacs.  Its value is ‘t’ when
49831     there are two or more frames (not counting minibuffer-only frames
49832     or invisible frames).  The default value of ‘frame-title-format’
49833     uses ‘multiple-frames’ so as to put the buffer name in the frame
49834     title only when there is more than one frame.
49835
49836     The value of this variable is not guaranteed to be accurate except
49837     while processing ‘frame-title-format’ or ‘icon-title-format’.
49838
49839
49840File: elisp.info,  Node: Deleting Frames,  Next: Finding All Frames,  Prev: Frame Titles,  Up: Frames
49841
4984229.7 Deleting Frames
49843====================
49844
49845A “live frame” is one that has not been deleted.  When a frame is
49846deleted, it is removed from its terminal display, although it may
49847continue to exist as a Lisp object until there are no more references to
49848it.
49849
49850 -- Command: delete-frame &optional frame force
49851     This function deletes the frame FRAME.  The argument FRAME must
49852     specify a live frame (see below) and defaults to the selected
49853     frame.
49854
49855     It first deletes any child frame of FRAME (*note Child Frames::)
49856     and any frame whose ‘delete-before’ frame parameter (*note Frame
49857     Interaction Parameters::) specifies FRAME.  All such deletions are
49858     performed recursively; so this step makes sure that no other frames
49859     with FRAME as their ancestor will exist.  Then, unless FRAME
49860     specifies a tooltip, this function runs the hook
49861     ‘delete-frame-functions’ (each function getting one argument,
49862     FRAME) before actually killing the frame.  After actually killing
49863     the frame and removing the frame from the frame list,
49864     ‘delete-frame’ runs ‘after-delete-frame-functions’.
49865
49866     Note that a frame cannot be deleted as long as its minibuffer
49867     serves as surrogate minibuffer for another frame (*note Minibuffers
49868     and Frames::).  Normally, you cannot delete a frame if all other
49869     frames are invisible, but if FORCE is non-‘nil’, then you are
49870     allowed to do so.
49871
49872 -- Function: frame-live-p frame
49873     This function returns non-‘nil’ if the frame FRAME has not been
49874     deleted.  The possible non-‘nil’ return values are like those of
49875     ‘framep’.  *Note Frames::.
49876
49877   Some window managers provide a command to delete a window.  These
49878work by sending a special message to the program that operates the
49879window.  When Emacs gets one of these commands, it generates a
49880‘delete-frame’ event, whose normal definition is a command that calls
49881the function ‘delete-frame’.  *Note Misc Events::.
49882
49883 -- Command: delete-other-frames &optional frame
49884     This command deletes all frames on FRAME’s terminal, except FRAME.
49885     If FRAME uses another frame’s minibuffer, that minibuffer frame is
49886     left untouched.  The argument FRAME must specify a live frame and
49887     defaults to the selected frame.  Internally, this command works by
49888     calling ‘delete-frame’ with FORCE ‘nil’ for all frames that shall
49889     be deleted.
49890
49891     This function does not delete any of FRAME’s child frames (*note
49892     Child Frames::).  If FRAME is a child frame, it deletes FRAME’s
49893     siblings only.
49894
49895
49896File: elisp.info,  Node: Finding All Frames,  Next: Minibuffers and Frames,  Prev: Deleting Frames,  Up: Frames
49897
4989829.8 Finding All Frames
49899=======================
49900
49901 -- Function: frame-list
49902     This function returns a list of all the live frames, i.e., those
49903     that have not been deleted.  It is analogous to ‘buffer-list’ for
49904     buffers, and includes frames on all terminals.  The list that you
49905     get is newly created, so modifying the list doesn’t have any effect
49906     on the internals of Emacs.
49907
49908 -- Function: visible-frame-list
49909     This function returns a list of just the currently visible frames.
49910     *Note Visibility of Frames::.  Frames on text terminals always
49911     count as visible, even though only the selected one is actually
49912     displayed.
49913
49914 -- Function: frame-list-z-order &optional display
49915     This function returns a list of Emacs’ frames, in Z (stacking)
49916     order (*note Raising and Lowering::).  The optional argument
49917     DISPLAY specifies which display to poll.  DISPLAY should be either
49918     a frame or a display name (a string).  If omitted or ‘nil’, that
49919     stands for the selected frame’s display.  It returns ‘nil’ if
49920     DISPLAY contains no Emacs frame.
49921
49922     Frames are listed from topmost (first) to bottommost (last).  As a
49923     special case, if DISPLAY is non-‘nil’ and specifies a live frame,
49924     it returns the child frames of that frame in Z (stacking) order.
49925
49926     This function is not meaningful on text terminals.
49927
49928 -- Function: next-frame &optional frame minibuf
49929     This function lets you cycle conveniently through all the frames on
49930     a specific terminal from an arbitrary starting point.  It returns
49931     the frame following FRAME, in the list of all live frames, on
49932     FRAME’s terminal.  The argument FRAME must specify a live frame and
49933     defaults to the selected frame.  It never returns a frame whose
49934     ‘no-other-frame’ parameter (*note Frame Interaction Parameters::)
49935     is non-‘nil’.
49936
49937     The second argument, MINIBUF, says which frames to consider:
49938
49939     ‘nil’
49940          Exclude minibuffer-only frames.
49941     ‘visible’
49942          Consider all visible frames.
49943     0
49944          Consider all visible or iconified frames.
49945     a window
49946          Consider only the frames using that particular window as their
49947          minibuffer.
49948     anything else
49949          Consider all frames.
49950
49951 -- Function: previous-frame &optional frame minibuf
49952     Like ‘next-frame’, but cycles through all frames in the opposite
49953     direction.
49954
49955   See also ‘next-window’ and ‘previous-window’, in *note Cyclic Window
49956Ordering::.
49957
49958
49959File: elisp.info,  Node: Minibuffers and Frames,  Next: Input Focus,  Prev: Finding All Frames,  Up: Frames
49960
4996129.9 Minibuffers and Frames
49962===========================
49963
49964Normally, each frame has its own minibuffer window at the bottom, which
49965is used whenever that frame is selected.  You can get that window with
49966the function ‘minibuffer-window’ (*note Minibuffer Windows::).
49967
49968   However, you can also create a frame without a minibuffer.  Such a
49969frame must use the minibuffer window of some other frame.  That other
49970frame will serve as “surrogate minibuffer frame” for this frame and
49971cannot be deleted via ‘delete-frame’ (*note Deleting Frames::) as long
49972as this frame is live.
49973
49974   When you create the frame, you can explicitly specify its minibuffer
49975window (in some other frame) with the ‘minibuffer’ frame parameter
49976(*note Buffer Parameters::).  If you don’t, then the minibuffer is found
49977in the frame which is the value of the variable
49978‘default-minibuffer-frame’.  Its value should be a frame that does have
49979a minibuffer.
49980
49981   If you use a minibuffer-only frame, you might want that frame to
49982raise when you enter the minibuffer.  If so, set the variable
49983‘minibuffer-auto-raise’ to ‘t’.  *Note Raising and Lowering::.
49984
49985 -- Variable: default-minibuffer-frame
49986     This variable specifies the frame to use for the minibuffer window,
49987     by default.  It does not affect existing frames.  It is always
49988     local to the current terminal and cannot be buffer-local.  *Note
49989     Multiple Terminals::.
49990
49991
49992File: elisp.info,  Node: Input Focus,  Next: Visibility of Frames,  Prev: Minibuffers and Frames,  Up: Frames
49993
4999429.10 Input Focus
49995=================
49996
49997At any time, one frame in Emacs is the “selected frame”.  The selected
49998window always resides on the selected frame.
49999
50000   When Emacs displays its frames on several terminals (*note Multiple
50001Terminals::), each terminal has its own selected frame.  But only one of
50002these is _the_ selected frame: it’s the frame that belongs to the
50003terminal from which the most recent input came.  That is, when Emacs
50004runs a command that came from a certain terminal, the selected frame is
50005the one of that terminal.  Since Emacs runs only a single command at any
50006given time, it needs to consider only one selected frame at a time; this
50007frame is what we call “the selected frame” in this manual.  The display
50008on which the selected frame is shown is the “selected frame’s display”.
50009
50010 -- Function: selected-frame
50011     This function returns the selected frame.
50012
50013   Some window systems and window managers direct keyboard input to the
50014window object that the mouse is in; others require explicit clicks or
50015commands to “shift the focus” to various window objects.  Either way,
50016Emacs automatically keeps track of which frames have focus.  To
50017explicitly switch to a different frame from a Lisp function, call
50018‘select-frame-set-input-focus’.
50019
50020   The plural “frames” in the previous paragraph is deliberate: while
50021Emacs itself has only one selected frame, Emacs can have frames on many
50022different terminals (recall that a connection to a window system counts
50023as a terminal), and each terminal has its own idea of which frame has
50024input focus.  When you set the input focus to a frame, you set the focus
50025for that frame’s terminal, but frames on other terminals may still
50026remain focused.
50027
50028   Lisp programs can switch frames temporarily by calling the function
50029‘select-frame’.  This does not alter the window system’s concept of
50030focus; rather, it escapes from the window manager’s control until that
50031control is somehow reasserted.
50032
50033   When using a text terminal, only one frame can be displayed at a time
50034on the terminal, so after a call to ‘select-frame’, the next redisplay
50035actually displays the newly selected frame.  This frame remains selected
50036until a subsequent call to ‘select-frame’.  Each frame on a text
50037terminal has a number which appears in the mode line before the buffer
50038name (*note Mode Line Variables::).
50039
50040 -- Function: select-frame-set-input-focus frame &optional norecord
50041     This function selects FRAME, raises it (should it happen to be
50042     obscured by other frames) and tries to give it the window system’s
50043     focus.  On a text terminal, the next redisplay displays the new
50044     frame on the entire terminal screen.  The optional argument
50045     NORECORD has the same meaning as for ‘select-frame’ (see below).
50046     The return value of this function is not significant.
50047
50048   Ideally, the function described next should focus a frame without
50049also raising it above other frames.  Unfortunately, many window-systems
50050or window managers may refuse to comply.
50051
50052 -- Function: x-focus-frame frame &optional noactivate
50053     This function gives FRAME the focus of the X server without
50054     necessarily raising it.  FRAME ‘nil’ means use the selected frame.
50055     Under X, the optional argument NOACTIVATE, if non-‘nil’, means to
50056     avoid making FRAME’s window-system window the “active” window which
50057     should insist a bit more on avoiding to raise FRAME above other
50058     frames.
50059
50060     On MS-Windows the NOACTIVATE argument has no effect.  However, if
50061     FRAME is a child frame (*note Child Frames::), this function
50062     usually focuses FRAME without raising it above other child frames.
50063
50064     If there is no window system support, this function does nothing.
50065
50066 -- Command: select-frame frame &optional norecord
50067     This function selects frame FRAME, temporarily disregarding the
50068     focus of the X server if any.  The selection of FRAME lasts until
50069     the next time the user does something to select a different frame,
50070     or until the next time this function is called.  (If you are using
50071     a window system, the previously selected frame may be restored as
50072     the selected frame after return to the command loop, because it
50073     still may have the window system’s input focus.)
50074
50075     The specified FRAME becomes the selected frame, and its terminal
50076     becomes the selected terminal.  This function then calls
50077     ‘select-window’ as a subroutine, passing the window selected within
50078     FRAME as its first argument and NORECORD as its second argument
50079     (hence, if NORECORD is non-‘nil’, this avoids changing the order of
50080     recently selected windows and the buffer list).  *Note Selecting
50081     Windows::.
50082
50083     This function returns FRAME, or ‘nil’ if FRAME has been deleted.
50084
50085     In general, you should never use ‘select-frame’ in a way that could
50086     switch to a different terminal without switching back when you’re
50087     done.
50088
50089   Emacs cooperates with the window system by arranging to select frames
50090as the server and window manager request.  When a window system informs
50091Emacs that one of its frames has been selected, Emacs internally
50092generates a “focus-in” event.  When an Emacs frame is displayed on a
50093text-terminal emulator, such as ‘xterm’, which supports reporting of
50094focus-change notification, the focus-in and focus-out events are
50095available even for text-mode frames.  Focus events are normally handled
50096by ‘handle-focus-in’.
50097
50098 -- Command: handle-focus-in event
50099     This function handles focus-in events from window systems and
50100     terminals that support explicit focus notifications.  It updates
50101     the per-frame focus flags that ‘frame-focus-state’ queries and
50102     calls ‘after-focus-change-function’.  In addition, it generates a
50103     ‘switch-frame’ event in order to switch the Emacs notion of the
50104     selected frame to the frame most recently focused in some terminal.
50105     It’s important to note that this switching of the Emacs selected
50106     frame to the most recently focused frame does not mean that other
50107     frames do not continue to have the focus in their respective
50108     terminals.  Do not invoke this function yourself: instead, attach
50109     logic to ‘after-focus-change-function’.
50110
50111 -- Command: handle-switch-frame frame
50112     This function handles a switch-frame event, which Emacs generates
50113     for itself upon focus notification or under various other
50114     circumstances involving an input event arriving at a different
50115     frame from the last event.  Do not invoke this function yourself.
50116
50117 -- Function: redirect-frame-focus frame &optional focus-frame
50118     This function redirects focus from FRAME to FOCUS-FRAME.  This
50119     means that FOCUS-FRAME will receive subsequent keystrokes and
50120     events intended for FRAME.  After such an event, the value of
50121     ‘last-event-frame’ will be FOCUS-FRAME.  Also, switch-frame events
50122     specifying FRAME will instead select FOCUS-FRAME.
50123
50124     If FOCUS-FRAME is omitted or ‘nil’, that cancels any existing
50125     redirection for FRAME, which therefore once again receives its own
50126     events.
50127
50128     One use of focus redirection is for frames that don’t have
50129     minibuffers.  These frames use minibuffers on other frames.
50130     Activating a minibuffer on another frame redirects focus to that
50131     frame.  This puts the focus on the minibuffer’s frame, where it
50132     belongs, even though the mouse remains in the frame that activated
50133     the minibuffer.
50134
50135     Selecting a frame can also change focus redirections.  Selecting
50136     frame ‘bar’, when ‘foo’ had been selected, changes any redirections
50137     pointing to ‘foo’ so that they point to ‘bar’ instead.  This allows
50138     focus redirection to work properly when the user switches from one
50139     frame to another using ‘select-window’.
50140
50141     This means that a frame whose focus is redirected to itself is
50142     treated differently from a frame whose focus is not redirected.
50143     ‘select-frame’ affects the former but not the latter.
50144
50145     The redirection lasts until ‘redirect-frame-focus’ is called to
50146     change it.
50147
50148 -- Function: frame-focus-state frame
50149     This function retrieves the last known focus state of FRAME.
50150
50151     It returns ‘nil’ if the frame is known not to be focused, ‘t’ if
50152     the frame is known to be focused, or ‘unknown’ if Emacs does not
50153     know the focus state of the frame.  (You may see this last state in
50154     TTY frames running on terminals that do not support explicit focus
50155     notifications.)
50156
50157 -- Variable: after-focus-change-function
50158     This function is an extension point that code can use to receive a
50159     notification that focus has changed.
50160
50161     This function is called with no arguments when Emacs notices that
50162     the set of focused frames may have changed.  Code wanting to do
50163     something when frame focus changes should use ‘add-function’ to add
50164     a function to this one, and in this added function, re-scan the set
50165     of focused frames, calling ‘frame-focus-state’ to retrieve the last
50166     known focus state of each frame.  Focus events are delivered
50167     asynchronously, and frame input focus according to an external
50168     system may not correspond to the notion of the Emacs selected
50169     frame.  Multiple frames may appear to have input focus
50170     simultaneously due to focus event delivery differences, the
50171     presence of multiple Emacs terminals, and other factors, and code
50172     should be robust in the face of this situation.
50173
50174     Depending on window system, focus events may also be delivered
50175     repeatedly and with different focus states before settling to the
50176     expected values.  Code relying on focus notifications should
50177     “debounce” any user-visible updates arising from focus changes,
50178     perhaps by deferring work until redisplay.
50179
50180     This function may be called in arbitrary contexts, including from
50181     inside ‘read-event’, so take the same care as you might when
50182     writing a process filter.
50183
50184 -- User Option: focus-follows-mouse
50185     This option informs Emacs whether and how the window manager
50186     transfers focus when you move the mouse pointer into a frame.  It
50187     can have three meaningful values:
50188
50189     ‘nil’
50190          The default value ‘nil’ should be used when your window
50191          manager follows a “click-to-focus” policy where you have to
50192          click the mouse inside of a frame in order for that frame to
50193          gain focus.
50194
50195     ‘t’
50196          The value ‘t’ should be used when your window manager has the
50197          focus automatically follow the position of the mouse pointer
50198          but a frame that gains focus is not raised automatically and
50199          may even remain occluded by other window-system windows.
50200
50201     ‘auto-raise’
50202          The value ‘auto-raise’ should be used when your window manager
50203          has the focus automatically follow the position of the mouse
50204          pointer and a frame that gains focus is raised automatically.
50205
50206     If this option is non-‘nil’, Emacs moves the mouse pointer to the
50207     frame selected by ‘select-frame-set-input-focus’.  That function is
50208     used by a number of commands like, for example, ‘other-frame’ and
50209     ‘pop-to-buffer’.
50210
50211     The distinction between the values ‘t’ and ‘auto-raise’ is not
50212     needed for “normal” frames because the window manager usually takes
50213     care of raising them.  It is useful to automatically raise child
50214     frames via ‘mouse-autoselect-window’ (*note Mouse Window
50215     Auto-selection::).
50216
50217     Note that this option does not distinguish “sloppy” focus (where
50218     the frame that previously had focus retains focus as long as the
50219     mouse pointer does not move into another window manager window)
50220     from “strict” focus (where a frame immediately loses focus when
50221     it’s left by the mouse pointer).  Neither does it recognize whether
50222     your window manager supports delayed focusing or auto-raising where
50223     you can explicitly specify the time until a new frame gets focus or
50224     is auto-raised.
50225
50226     You can supply a “focus follows mouse” policy for individual Emacs
50227     windows by customizing the variable ‘mouse-autoselect-window’
50228     (*note Mouse Window Auto-selection::).
50229
50230
50231File: elisp.info,  Node: Visibility of Frames,  Next: Raising and Lowering,  Prev: Input Focus,  Up: Frames
50232
5023329.11 Visibility of Frames
50234==========================
50235
50236A frame on a graphical display may be “visible”, “invisible”, or
50237“iconified”.  If it is visible, its contents are displayed in the usual
50238manner.  If it is iconified, its contents are not displayed, but there
50239is a little icon somewhere to bring the frame back into view (some
50240window managers refer to this state as “minimized” rather than
50241“iconified”, but from Emacs’ point of view they are the same thing).  If
50242a frame is invisible, it is not displayed at all.
50243
50244   The concept of visibility is strongly related to that of (un-)mapped
50245frames.  A frame (or, more precisely, its window-system window) is and
50246becomes “mapped” when it is displayed for the first time and whenever it
50247changes its state of visibility from ‘iconified’ or ‘invisible’ to
50248‘visible’.  Conversely, a frame is and becomes “unmapped” whenever it
50249changes its status from ‘visible’ to ‘iconified’ or ‘invisible’.
50250
50251   Visibility is meaningless on text terminals, since only the selected
50252frame is actually displayed in any case.
50253
50254 -- Function: frame-visible-p frame
50255     This function returns the visibility status of frame FRAME.  The
50256     value is ‘t’ if FRAME is visible, ‘nil’ if it is invisible, and
50257     ‘icon’ if it is iconified.
50258
50259     On a text terminal, all frames are considered visible for the
50260     purposes of this function, even though only one frame is displayed.
50261     *Note Raising and Lowering::.
50262
50263 -- Command: iconify-frame &optional frame
50264     This function iconifies frame FRAME.  If you omit FRAME, it
50265     iconifies the selected frame.  This usually makes all child frames
50266     of FRAME (and their descendants) invisible (*note Child Frames::).
50267
50268 -- Command: make-frame-visible &optional frame
50269     This function makes frame FRAME visible.  If you omit FRAME, it
50270     makes the selected frame visible.  This does not raise the frame,
50271     but you can do that with ‘raise-frame’ if you wish (*note Raising
50272     and Lowering::).
50273
50274     Making a frame visible usually makes all its child frames (and
50275     their descendants) visible as well (*note Child Frames::).
50276
50277 -- Command: make-frame-invisible &optional frame force
50278     This function makes frame FRAME invisible.  If you omit FRAME, it
50279     makes the selected frame invisible.  Usually, this makes all child
50280     frames of FRAME (and their descendants) invisible too (*note Child
50281     Frames::).
50282
50283     Unless FORCE is non-‘nil’, this function refuses to make FRAME
50284     invisible if all other frames are invisible.
50285
50286   The visibility status of a frame is also available as a frame
50287parameter.  You can read or change it as such.  *Note Management
50288Parameters::.  The user can also iconify and deiconify frames with the
50289window manager.  This happens below the level at which Emacs can exert
50290any control, but Emacs does provide events that you can use to keep
50291track of such changes.  *Note Misc Events::.
50292
50293 -- Function: x-double-buffered-p &optional frame
50294     This function returns non-‘nil’ if FRAME is currently being
50295     rendered with double buffering.  FRAME defaults to the selected
50296     frame.
50297
50298
50299File: elisp.info,  Node: Raising and Lowering,  Next: Frame Configurations,  Prev: Visibility of Frames,  Up: Frames
50300
5030129.12 Raising, Lowering and Restacking Frames
50302=============================================
50303
50304Most window systems use a desktop metaphor.  Part of this metaphor is
50305the idea that system-level windows (representing, e.g., Emacs frames)
50306are stacked in a notional third dimension perpendicular to the screen
50307surface.  The order induced by stacking is total and usually referred to
50308as stacking (or Z-) order.  Where the areas of two windows overlap, the
50309one higher up in that order will (partially) cover the one underneath.
50310
50311   You can “raise” a frame to the top of that order or “lower” a frame
50312to its bottom by using the functions ‘raise-frame’ and ‘lower-frame’.
50313You can “restack” a frame directly above or below another frame using
50314the function ‘frame-restack’.
50315
50316   Note that all functions described below will respect the adherence of
50317frames (and all other window-system windows) to their respective z-group
50318(*note Position Parameters::).  For example, you usually cannot lower a
50319frame below that of the desktop window and you cannot raise a frame
50320whose ‘z-group’ parameter is ‘nil’ above the window-system’s taskbar or
50321tooltip window.
50322
50323 -- Command: raise-frame &optional frame
50324     This function raises frame FRAME (default, the selected frame)
50325     above all other frames belonging to the same or a lower z-group as
50326     FRAME.  If FRAME is invisible or iconified, this makes it visible.
50327     If FRAME is a child frame (*note Child Frames::), this raises FRAME
50328     above all other child frames of its parent.
50329
50330 -- Command: lower-frame &optional frame
50331     This function lowers frame FRAME (default, the selected frame)
50332     below all other frames belonging to the same or a higher z-group as
50333     FRAME.  If FRAME is a child frame (*note Child Frames::), this
50334     lowers FRAME below all other child frames of its parent.
50335
50336 -- Function: frame-restack frame1 frame2 &optional above
50337     This function restacks FRAME1 below FRAME2.  This implies that if
50338     both frames are visible and their display areas overlap, FRAME2
50339     will (partially) obscure FRAME1.  If the optional third argument
50340     ABOVE is non-‘nil’, this function restacks FRAME1 above FRAME2.
50341     This means that if both frames are visible and their display areas
50342     overlap, FRAME1 will (partially) obscure FRAME2.
50343
50344     Technically, this function may be thought of as an atomic action
50345     performed in two steps: The first step removes FRAME1’s
50346     window-system window from the display.  The second step reinserts
50347     FRAME1’s window into the display below (above if ABOVE is true)
50348     that of FRAME2.  Hence the position of FRAME2 in its display’s Z
50349     (stacking) order relative to all other frames excluding FRAME1
50350     remains unaltered.
50351
50352     Some window managers may refuse to restack windows.
50353
50354   Note that the effect of restacking will only hold as long as neither
50355of the involved frames is iconified or made invisible.  You can use the
50356‘z-group’ (*note Position Parameters::) frame parameter to add a frame
50357to a group of frames permanently shown above or below other frames.  As
50358long as a frame belongs to one of these groups, restacking it will only
50359affect its relative stacking position within that group.  The effect of
50360restacking frames belonging to different z-groups is undefined.  You can
50361list frames in their current stacking order with the function
50362‘frame-list-z-order’ (*note Finding All Frames::).
50363
50364 -- User Option: minibuffer-auto-raise
50365     If this is non-‘nil’, activation of the minibuffer raises the frame
50366     that the minibuffer window is in.
50367
50368   On window systems, you can also enable auto-raising (on frame
50369selection) or auto-lowering (on frame deselection) using frame
50370parameters.  *Note Management Parameters::.
50371
50372   The concept of raising and lowering frames also applies to text
50373terminal frames.  On each text terminal, only the top frame is displayed
50374at any one time.
50375
50376 -- Function: tty-top-frame &optional terminal
50377     This function returns the top frame on TERMINAL.  TERMINAL should
50378     be a terminal object, a frame (meaning that frame’s terminal), or
50379     ‘nil’ (meaning the selected frame’s terminal).  If it does not
50380     refer to a text terminal, the return value is ‘nil’.
50381
50382
50383File: elisp.info,  Node: Frame Configurations,  Next: Child Frames,  Prev: Raising and Lowering,  Up: Frames
50384
5038529.13 Frame Configurations
50386==========================
50387
50388A “frame configuration” records the current arrangement of frames, all
50389their properties, and the window configuration of each one.  (*Note
50390Window Configurations::.)
50391
50392 -- Function: current-frame-configuration
50393     This function returns a frame configuration list that describes the
50394     current arrangement of frames and their contents.
50395
50396 -- Function: set-frame-configuration configuration &optional nodelete
50397     This function restores the state of frames described in
50398     CONFIGURATION.  However, this function does not restore deleted
50399     frames.
50400
50401     Ordinarily, this function deletes all existing frames not listed in
50402     CONFIGURATION.  But if NODELETE is non-‘nil’, the unwanted frames
50403     are iconified instead.
50404
50405
50406File: elisp.info,  Node: Child Frames,  Next: Mouse Tracking,  Prev: Frame Configurations,  Up: Frames
50407
5040829.14 Child Frames
50409==================
50410
50411Child frames are objects halfway between windows (*note Windows::) and
50412“normal” frames.  Like windows, they are attached to an owning frame.
50413Unlike windows, they may overlap each other—changing the size or
50414position of one child frame does not change the size or position of any
50415of its sibling child frames.
50416
50417   By design, operations to make or modify child frames are implemented
50418with the help of frame parameters (*note Frame Parameters::) without any
50419specialized functions or customizable variables.  Note that child frames
50420are meaningful on graphical terminals only.
50421
50422   To create a new child frame or to convert a normal frame into a child
50423frame, set that frame’s ‘parent-frame’ parameter (*note Frame
50424Interaction Parameters::) to that of an already existing frame.  The
50425frame specified by that parameter will then be the frame’s parent frame
50426as long as the parameter is not changed or reset.  Technically, this
50427makes the child frame’s window-system window a child window of the
50428parent frame’s window-system window.
50429
50430   The ‘parent-frame’ parameter can be changed at any time.  Setting it
50431to another frame “reparents” the child frame.  Setting it to another
50432child frame makes the frame a “nested” child frame.  Setting it to ‘nil’
50433restores the frame’s status as a top-level frame—a frame whose
50434window-system window is a child of its display’s root window.
50435
50436   Since child frames can be arbitrarily nested, a frame can be both a
50437child and a parent frame.  Also, the relative roles of child and parent
50438frame may be reversed at any time (though it’s usually a good idea to
50439keep the size of a child frame sufficiently smaller than that of its
50440parent).  An error will be signaled for the attempt to make a frame an
50441ancestor of itself.
50442
50443   Most window-systems clip a child frame at the native edges (*note
50444Frame Geometry::) of its parent frame—everything outside these edges is
50445usually invisible.  A child frame’s ‘left’ and ‘top’ parameters specify
50446a position relative to the top-left corner of its parent’s native frame.
50447When the parent frame is resized, this position remains conceptually
50448unaltered.
50449
50450   NS builds do not clip child frames at the parent frame’s edges,
50451allowing them to be positioned so they do not obscure the parent frame
50452while still being visible themselves.
50453
50454   Usually, moving a parent frame moves along all its child frames and
50455their descendants as well, keeping their relative positions unaltered.
50456Note that the hook ‘move-frame-functions’ (*note Frame Position::) is
50457run for a child frame only when the position of the child frame relative
50458to its parent frame changes.
50459
50460   When a parent frame is resized, its child frames conceptually retain
50461their previous sizes and their positions relative to the left upper
50462corner of the parent.  This means that a child frame may become
50463(partially) invisible when its parent frame shrinks.  The parameter
50464‘keep-ratio’ (*note Frame Interaction Parameters::) can be used to
50465resize and reposition a child frame proportionally whenever its parent
50466frame is resized.  This may avoid obscuring parts of a frame when its
50467parent frame is shrunk.
50468
50469   A visible child frame always appears on top of its parent frame thus
50470obscuring parts of it, except on NS builds where it may be positioned
50471beneath the parent.  This is comparable to the window-system window of a
50472top-level frame which also always appears on top of its parent
50473window—the desktop’s root window.  When a parent frame is iconified or
50474made invisible (*note Visibility of Frames::), its child frames are made
50475invisible.  When a parent frame is deiconified or made visible, its
50476child frames are made visible.
50477
50478   When a parent frame is about to be deleted (*note Deleting Frames::),
50479its child frames are recursively deleted before it.  There is one
50480exception to this rule: When the child frame serves as a surrogate
50481minibuffer frame (*note Minibuffers and Frames::) for another frame, it
50482is retained until the parent frame has been deleted.  If, at this time,
50483no remaining frame uses the child frame as its minibuffer frame, Emacs
50484will try to delete the child frame too.  If that deletion fails for
50485whatever reason, the child frame is made a top-level frame.
50486
50487   Whether a child frame can have a menu or tool bar is window-system or
50488window manager dependent.  Most window-systems explicitly disallow menu
50489bars for child frames.  It seems advisable to disable both, menu and
50490tool bars, via the frame’s initial parameters settings.
50491
50492   Usually, child frames do not exhibit window manager decorations like
50493a title bar or external borders (*note Frame Geometry::).  When the
50494child frame does not show a menu or tool bar, any other of the frame’s
50495borders (*note Layout Parameters::) can be used instead of the external
50496borders.
50497
50498   In particular, under X (but not when building with GTK+), the frame’s
50499outer border can be used.  On MS-Windows, specifying a non-zero outer
50500border width will show a one-pixel wide external border.  Under all
50501window-systems, the internal border can be used.  In either case, it’s
50502advisable to disable a child frame’s window manager decorations with the
50503‘undecorated’ frame parameter (*note Management Parameters::).
50504
50505   To resize or move an undecorated child frame with the mouse, special
50506frame parameters (*note Mouse Dragging Parameters::) have to be used.
50507The internal border of a child frame, if present, can be used to resize
50508the frame with the mouse, provided that frame has a non-‘nil’
50509‘drag-internal-border’ parameter.  If set, the ‘snap-width’ parameter
50510indicates the number of pixels where the frame “snaps” at the respective
50511edge or corner of its parent frame.
50512
50513   There are two ways to drag an entire child frame with the mouse: The
50514‘drag-with-mode-line’ parameter, if non-‘nil’, allows to drag a frame
50515without minibuffer window (*note Minibuffer Windows::) via the mode line
50516area of its bottommost window.  The ‘drag-with-header-line’ parameter,
50517if non-‘nil’, allows to drag the frame via the header line area of its
50518topmost window.
50519
50520   In order to give a child frame a draggable header or mode line, the
50521window parameters ‘mode-line-format’ and ‘header-line-format’ are handy
50522(*note Window Parameters::).  These allow to remove an unwanted mode
50523line (when ‘drag-with-header-line’ is chosen) and to remove
50524mouse-sensitive areas which might interfere with frame dragging.
50525
50526   To avoid that dragging moves a frame completely out of its parent’s
50527native frame, something which might happen when the mouse cursor
50528overshoots and makes the frame difficult to retrieve once the mouse
50529button has been released, it is advisable to set the frame’s
50530‘top-visible’ or ‘bottom-visible’ parameter correspondingly.
50531
50532   The ‘top-visible’ parameter specifies the number of pixels at the top
50533of the frame that always remain visible within the parent’s native frame
50534during dragging and should be set when specifying a non-‘nil’
50535‘drag-with-header-line’ parameter.  The ‘bottom-visible’ parameter
50536specifies the number of pixels at the bottom of the frame that always
50537remain visible within the parent’s native frame during dragging and
50538should be preferred when specifying a non-‘nil’ ‘drag-with-mode-line’
50539parameter.
50540
50541   When a child frame is used for displaying a buffer via
50542‘display-buffer-in-child-frame’ (*note Buffer Display Action
50543Functions::), the frame’s ‘auto-hide-function’ parameter (*note Frame
50544Interaction Parameters::) can be set to a function, in order to
50545appropriately deal with the frame when the window displaying the buffer
50546shall be quit.
50547
50548   When a child frame is used during minibuffer interaction, for
50549example, to display completions in a separate window, the
50550‘minibuffer-exit’ parameter (*note Frame Interaction Parameters::) is
50551useful in order to deal with the frame when the minibuffer is exited.
50552
50553   The behavior of child frames deviates from that of top-level frames
50554in a number of other ways as well.  Here we sketch a few of them:
50555
50556   • The semantics of maximizing and iconifying child frames is highly
50557     window-system dependent.  As a rule, applications should never
50558     invoke these operations on child frames.  By default, invoking
50559     ‘iconify-frame’ on a child frame will try to iconify the top-level
50560     frame corresponding to that child frame instead.  To obtain a
50561     different behavior, users may customize the option
50562     ‘iconify-child-frame’ described below.
50563
50564   • Raising, lowering and restacking child frames (*note Raising and
50565     Lowering::) or changing the ‘z-group’ (*note Position Parameters::)
50566     of a child frame changes only the stacking order of child frames
50567     with the same parent.
50568
50569   • Many window-systems are not able to change the opacity (*note Font
50570     and Color Parameters::) of child frames.
50571
50572   • Transferring focus from a child frame to an ancestor that is not
50573     its parent by clicking with the mouse in a visible part of that
50574     ancestor’s window may fail with some window-systems.  You may have
50575     to click into the direct parent’s window-system window first.
50576
50577   • Window managers might not bother to extend their focus follows
50578     mouse policy to child frames.  Customizing
50579     ‘mouse-autoselect-window’ can help in this regard (*note Mouse
50580     Window Auto-selection::).
50581
50582   • Dropping (*note Drag and Drop::) on child frames is not guaranteed
50583     to work on all window-systems.  Some will drop the object on the
50584     parent frame or on some ancestor instead.
50585
50586   The following two functions can be useful when working with child and
50587parent frames:
50588
50589 -- Function: frame-parent &optional frame
50590     This function returns the parent frame of FRAME.  The parent frame
50591     of FRAME is the Emacs frame whose window-system window is the
50592     parent window of FRAME’s window-system window.  If such a frame
50593     exists, FRAME is considered a child frame of that frame.
50594
50595     This function returns ‘nil’ if FRAME has no parent frame.
50596
50597 -- Function: frame-ancestor-p ancestor descendant
50598     This functions returns non-‘nil’ if ANCESTOR is an ancestor of
50599     DESCENDANT.  ANCESTOR is an ancestor of DESCENDANT when it is
50600     either DESCENDANT’s parent frame or it is an ancestor of
50601     DESCENDANT’s parent frame.  Both, ANCESTOR and DESCENDANT must
50602     specify live frames.
50603
50604   Note also the function ‘window-largest-empty-rectangle’ (*note
50605Coordinates and Windows::) which can be used to inscribe a child frame
50606in the largest empty area of an existing window.  This can be useful to
50607avoid that a child frame obscures any text shown in that window.
50608
50609   Customizing the following option can be useful to tweak the behavior
50610of ‘iconify-frame’ for child frames.
50611
50612 -- User Option: iconify-child-frame
50613     This option tells Emacs how to proceed when it is asked to iconify
50614     a child frame.  If it is ‘nil’, ‘iconify-frame’ will do nothing
50615     when invoked on a child frame.  If it is ‘iconify-top-level’, Emacs
50616     will try to iconify the top-level frame that is the ancestor of
50617     this child frame instead.  If it is ‘make-invisible’, Emacs will
50618     try to make this child frame invisible instead of iconifying it.
50619
50620     Any other value means to try iconifying the child frame.  Since
50621     such an attempt may not be honored by all window managers and can
50622     even lead to making the child frame unresponsive to user actions,
50623     the default is to iconify the top level frame instead.
50624
50625
50626File: elisp.info,  Node: Mouse Tracking,  Next: Mouse Position,  Prev: Child Frames,  Up: Frames
50627
5062829.15 Mouse Tracking
50629====================
50630
50631Sometimes it is useful to “track” the mouse, which means to display
50632something to indicate where the mouse is and move the indicator as the
50633mouse moves.  For efficient mouse tracking, you need a way to wait until
50634the mouse actually moves.
50635
50636   The convenient way to track the mouse is to ask for events to
50637represent mouse motion.  Then you can wait for motion by waiting for an
50638event.  In addition, you can easily handle any other sorts of events
50639that may occur.  That is useful, because normally you don’t want to
50640track the mouse forever—only until some other event, such as the release
50641of a button.
50642
50643 -- Macro: track-mouse body...
50644     This macro executes BODY, with generation of mouse motion events
50645     enabled.  Typically, BODY would use ‘read-event’ to read the motion
50646     events and modify the display accordingly.  *Note Motion Events::,
50647     for the format of mouse motion events.
50648
50649     The value of ‘track-mouse’ is that of the last form in BODY.  You
50650     should design BODY to return when it sees the up-event that
50651     indicates the release of the button, or whatever kind of event
50652     means it is time to stop tracking.
50653
50654     The ‘track-mouse’ form causes Emacs to generate mouse motion events
50655     by binding the variable ‘track-mouse’ to a non-‘nil’ value.  If
50656     that variable has the special value ‘dragging’, it additionally
50657     instructs the display engine to refrain from changing the shape of
50658     the mouse pointer.  This is desirable in Lisp programs that require
50659     mouse dragging across large portions of Emacs display, which might
50660     otherwise cause the mouse pointer to change its shape according to
50661     the display portion it hovers on (*note Pointer Shape::).
50662     Therefore, Lisp programs that need the mouse pointer to retain its
50663     original shape during dragging should bind ‘track-mouse’ to the
50664     value ‘dragging’ at the beginning of their BODY.
50665
50666   The usual purpose of tracking mouse motion is to indicate on the
50667screen the consequences of pushing or releasing a button at the current
50668position.
50669
50670   In many cases, you can avoid the need to track the mouse by using the
50671‘mouse-face’ text property (*note Special Properties::).  That works at
50672a much lower level and runs more smoothly than Lisp-level mouse
50673tracking.
50674
50675
50676File: elisp.info,  Node: Mouse Position,  Next: Pop-Up Menus,  Prev: Mouse Tracking,  Up: Frames
50677
5067829.16 Mouse Position
50679====================
50680
50681The functions ‘mouse-position’ and ‘set-mouse-position’ give access to
50682the current position of the mouse.
50683
50684 -- Function: mouse-position
50685     This function returns a description of the position of the mouse.
50686     The value looks like ‘(FRAME X . Y)’, where X and Y are integers
50687     giving the (possibly rounded) position in multiples of the default
50688     character size of FRAME (*note Frame Font::) relative to the native
50689     position of FRAME (*note Frame Geometry::).
50690
50691 -- Variable: mouse-position-function
50692     If non-‘nil’, the value of this variable is a function for
50693     ‘mouse-position’ to call.  ‘mouse-position’ calls this function
50694     just before returning, with its normal return value as the sole
50695     argument, and it returns whatever this function returns to it.
50696
50697     This abnormal hook exists for the benefit of packages like
50698xt-mouse.el’ that need to do mouse handling at the Lisp level.
50699
50700 -- Function: set-mouse-position frame x y
50701     This function “warps the mouse” to position X, Y in frame FRAME.
50702     The arguments X and Y are integers, giving the position in
50703     multiples of the default character size of FRAME (*note Frame
50704     Font::) relative to the native position of FRAME (*note Frame
50705     Geometry::).
50706
50707     The resulting mouse position is constrained to the native frame of
50708     FRAME.  If FRAME is not visible, this function does nothing.  The
50709     return value is not significant.
50710
50711 -- Function: mouse-pixel-position
50712     This function is like ‘mouse-position’ except that it returns
50713     coordinates in units of pixels rather than units of characters.
50714
50715 -- Function: set-mouse-pixel-position frame x y
50716     This function warps the mouse like ‘set-mouse-position’ except that
50717     X and Y are in units of pixels rather than units of characters.
50718
50719     The resulting mouse position is not constrained to the native frame
50720     of FRAME.  If FRAME is not visible, this function does nothing.
50721     The return value is not significant.
50722
50723   On a graphical terminal the following two functions allow the
50724absolute position of the mouse cursor to be retrieved and set.
50725
50726 -- Function: mouse-absolute-pixel-position
50727     This function returns a cons cell (X .  Y) of the coordinates of
50728     the mouse cursor position in pixels, relative to a position (0, 0)
50729     of the selected frame’s display.
50730
50731 -- Function: set-mouse-absolute-pixel-position x y
50732     This function moves the mouse cursor to the position (X, Y).  The
50733     coordinates X and Y are interpreted in pixels relative to a
50734     position (0, 0) of the selected frame’s display.
50735
50736   The following function can tell whether the mouse cursor is currently
50737visible on a frame:
50738
50739 -- Function: frame-pointer-visible-p &optional frame
50740     This predicate function returns non-‘nil’ if the mouse pointer
50741     displayed on FRAME is visible; otherwise it returns ‘nil’.  FRAME
50742     omitted or ‘nil’ means the selected frame.  This is useful when
50743     ‘make-pointer-invisible’ is set to ‘t’: it allows you to know if
50744     the pointer has been hidden.  *Note (emacs)Mouse Avoidance::.
50745
50746
50747File: elisp.info,  Node: Pop-Up Menus,  Next: Dialog Boxes,  Prev: Mouse Position,  Up: Frames
50748
5074929.17 Pop-Up Menus
50750==================
50751
50752A Lisp program can pop up a menu so that the user can choose an
50753alternative with the mouse.  On a text terminal, if the mouse is not
50754available, the user can choose an alternative using the keyboard motion
50755keys—‘C-n’, ‘C-p’, or up- and down-arrow keys.
50756
50757 -- Function: x-popup-menu position menu
50758     This function displays a pop-up menu and returns an indication of
50759     what selection the user makes.
50760
50761     The argument POSITION specifies where on the screen to put the top
50762     left corner of the menu.  It can be either a mouse button event
50763     (which says to put the menu where the user actuated the button) or
50764     a list of this form:
50765
50766          ((XOFFSET YOFFSET) WINDOW)
50767
50768     where XOFFSET and YOFFSET are coordinates, measured in pixels,
50769     counting from the top left corner of WINDOW.  WINDOW may be a
50770     window or a frame.
50771
50772     If POSITION is ‘t’, it means to use the current mouse position (or
50773     the top-left corner of the frame if the mouse is not available on a
50774     text terminal).  If POSITION is ‘nil’, it means to precompute the
50775     key binding equivalents for the keymaps specified in MENU, without
50776     actually displaying or popping up the menu.
50777
50778     The argument MENU says what to display in the menu.  It can be a
50779     keymap or a list of keymaps (*note Menu Keymaps::).  In this case,
50780     the return value is the list of events corresponding to the user’s
50781     choice.  This list has more than one element if the choice occurred
50782     in a submenu.  (Note that ‘x-popup-menu’ does not actually execute
50783     the command bound to that sequence of events.)  On text terminals
50784     and toolkits that support menu titles, the title is taken from the
50785     prompt string of MENU if MENU is a keymap, or from the prompt
50786     string of the first keymap in MENU if it is a list of keymaps
50787     (*note Defining Menus::).
50788
50789     Alternatively, MENU can have the following form:
50790
50791          (TITLE PANE1 PANE2...)
50792
50793     where each pane is a list of form
50794
50795          (TITLE ITEM1 ITEM2...)
50796
50797     Each ITEM should be a cons cell, ‘(LINE . VALUE)’, where LINE is a
50798     string and VALUE is the value to return if that LINE is chosen.
50799     Unlike in a menu keymap, a ‘nil’ VALUE does not make the menu item
50800     non-selectable.  Alternatively, each ITEM can be a string rather
50801     than a cons cell; this makes a non-selectable menu item.
50802
50803     If the user gets rid of the menu without making a valid choice, for
50804     instance by clicking the mouse away from a valid choice or by
50805     typing ‘C-g’, then this normally results in a quit and
50806     ‘x-popup-menu’ does not return.  But if POSITION is a mouse button
50807     event (indicating that the user invoked the menu with the mouse)
50808     then no quit occurs and ‘x-popup-menu’ returns ‘nil’.
50809
50810   *Usage note:* Don’t use ‘x-popup-menu’ to display a menu if you could
50811do the job with a prefix key defined with a menu keymap.  If you use a
50812menu keymap to implement a menu, ‘C-h c’ and ‘C-h a’ can see the
50813individual items in that menu and provide help for them.  If instead you
50814implement the menu by defining a command that calls ‘x-popup-menu’, the
50815help facilities cannot know what happens inside that command, so they
50816cannot give any help for the menu’s items.
50817
50818   The menu bar mechanism, which lets you switch between submenus by
50819moving the mouse, cannot look within the definition of a command to see
50820that it calls ‘x-popup-menu’.  Therefore, if you try to implement a
50821submenu using ‘x-popup-menu’, it cannot work with the menu bar in an
50822integrated fashion.  This is why all menu bar submenus are implemented
50823with menu keymaps within the parent menu, and never with ‘x-popup-menu’.
50824*Note Menu Bar::.
50825
50826   If you want a menu bar submenu to have contents that vary, you should
50827still use a menu keymap to implement it.  To make the contents vary, add
50828a hook function to ‘menu-bar-update-hook’ to update the contents of the
50829menu keymap as necessary.
50830
50831
50832File: elisp.info,  Node: Dialog Boxes,  Next: Pointer Shape,  Prev: Pop-Up Menus,  Up: Frames
50833
5083429.18 Dialog Boxes
50835==================
50836
50837A dialog box is a variant of a pop-up menu—it looks a little different,
50838it always appears in the center of a frame, and it has just one level
50839and one or more buttons.  The main use of dialog boxes is for asking
50840questions that the user can answer with “yes”, “no”, and a few other
50841alternatives.  With a single button, they can also force the user to
50842acknowledge important information.  The functions ‘y-or-n-p’ and
50843‘yes-or-no-p’ use dialog boxes instead of the keyboard, when called from
50844commands invoked by mouse clicks.
50845
50846 -- Function: x-popup-dialog position contents &optional header
50847     This function displays a pop-up dialog box and returns an
50848     indication of what selection the user makes.  The argument CONTENTS
50849     specifies the alternatives to offer; it has this format:
50850
50851          (TITLE (STRING . VALUE)...)
50852
50853     which looks like the list that specifies a single pane for
50854     ‘x-popup-menu’.
50855
50856     The return value is VALUE from the chosen alternative.
50857
50858     As for ‘x-popup-menu’, an element of the list may be just a string
50859     instead of a cons cell ‘(STRING . VALUE)’.  That makes a box that
50860     cannot be selected.
50861
50862     If ‘nil’ appears in the list, it separates the left-hand items from
50863     the right-hand items; items that precede the ‘nil’ appear on the
50864     left, and items that follow the ‘nil’ appear on the right.  If you
50865     don’t include a ‘nil’ in the list, then approximately half the
50866     items appear on each side.
50867
50868     Dialog boxes always appear in the center of a frame; the argument
50869     POSITION specifies which frame.  The possible values are as in
50870     ‘x-popup-menu’, but the precise coordinates or the individual
50871     window don’t matter; only the frame matters.
50872
50873     If HEADER is non-‘nil’, the frame title for the box is
50874     ‘Information’, otherwise it is ‘Question’.  The former is used for
50875     ‘message-box’ (*note message-box::).  (On text terminals, the box
50876     title is not displayed.)
50877
50878     In some configurations, Emacs cannot display a real dialog box; so
50879     instead it displays the same items in a pop-up menu in the center
50880     of the frame.
50881
50882     If the user gets rid of the dialog box without making a valid
50883     choice, for instance using the window manager, then this produces a
50884     quit and ‘x-popup-dialog’ does not return.
50885
50886
50887File: elisp.info,  Node: Pointer Shape,  Next: Window System Selections,  Prev: Dialog Boxes,  Up: Frames
50888
5088929.19 Pointer Shape
50890===================
50891
50892You can specify the mouse pointer style for particular text or images
50893using the ‘pointer’ text property, and for images with the ‘:pointer’
50894and ‘:map’ image properties.  The values you can use in these properties
50895are ‘text’ (or ‘nil’), ‘arrow’, ‘hand’, ‘vdrag’, ‘hdrag’, ‘modeline’,
50896and ‘hourglass’.  ‘text’ stands for the usual mouse pointer style used
50897over text.
50898
50899   Over void parts of the window (parts that do not correspond to any of
50900the buffer contents), the mouse pointer usually uses the ‘arrow’ style,
50901but you can specify a different style (one of those above) by setting
50902‘void-text-area-pointer’.
50903
50904 -- User Option: void-text-area-pointer
50905     This variable specifies the mouse pointer style for void text
50906     areas.  These include the areas after the end of a line or below
50907     the last line in the buffer.  The default is to use the ‘arrow’
50908     (non-text) pointer style.
50909
50910   When using X, you can specify what the ‘text’ pointer style really
50911looks like by setting the variable ‘x-pointer-shape’.
50912
50913 -- Variable: x-pointer-shape
50914     This variable specifies the pointer shape to use ordinarily in the
50915     Emacs frame, for the ‘text’ pointer style.
50916
50917 -- Variable: x-sensitive-text-pointer-shape
50918     This variable specifies the pointer shape to use when the mouse is
50919     over mouse-sensitive text.
50920
50921   These variables affect newly created frames.  They do not normally
50922affect existing frames; however, if you set the mouse color of a frame,
50923that also installs the current value of those two variables.  *Note Font
50924and Color Parameters::.
50925
50926   The values you can use, to specify either of these pointer shapes,
50927are defined in the file ‘lisp/term/x-win.el’.  Use ‘M-x apropos <RET>
50928x-pointer <RET>’ to see a list of them.
50929
50930
50931File: elisp.info,  Node: Window System Selections,  Next: Drag and Drop,  Prev: Pointer Shape,  Up: Frames
50932
5093329.20 Window System Selections
50934==============================
50935
50936In window systems, such as X, data can be transferred between different
50937applications by means of “selections”.  X defines an arbitrary number of
50938“selection types”, each of which can store its own data; however, only
50939three are commonly used: the “clipboard”, “primary selection”, and
50940“secondary selection”.  Other window systems support only the clipboard.
50941*Note Cut and Paste: (emacs)Cut and Paste, for Emacs commands that make
50942use of these selections.  This section documents the low-level functions
50943for reading and setting window-system selections.
50944
50945 -- Command: gui-set-selection type data
50946     This function sets a window-system selection.  It takes two
50947     arguments: a selection type TYPE, and the value to assign to it,
50948     DATA.
50949
50950     TYPE should be a symbol; it is usually one of ‘PRIMARY’,
50951     ‘SECONDARY’ or ‘CLIPBOARD’.  These are symbols with upper-case
50952     names, in accord with X Window System conventions.  If TYPE is
50953     ‘nil’, that stands for ‘PRIMARY’.
50954
50955     If DATA is ‘nil’, it means to clear out the selection.  Otherwise,
50956     DATA may be a string, a symbol, an integer (or a cons of two
50957     integers or list of two integers), an overlay, or a cons of two
50958     markers pointing to the same buffer.  An overlay or a pair of
50959     markers stands for text in the overlay or between the markers.  The
50960     argument DATA may also be a vector of valid non-vector selection
50961     values.
50962
50963     This function returns DATA.
50964
50965 -- Function: gui-get-selection &optional type data-type
50966     This function accesses selections set up by Emacs or by other
50967     programs.  It takes two optional arguments, TYPE and DATA-TYPE.
50968     The default for TYPE, the selection type, is ‘PRIMARY’.
50969
50970     The DATA-TYPE argument specifies the form of data conversion to
50971     use, to convert the raw data obtained from another program into
50972     Lisp data.  Meaningful values include ‘TEXT’, ‘STRING’,
50973     ‘UTF8_STRING’, ‘TARGETS’, ‘LENGTH’, ‘DELETE’, ‘FILE_NAME’,
50974     ‘CHARACTER_POSITION’, ‘NAME’, ‘LINE_NUMBER’, ‘COLUMN_NUMBER’,
50975     ‘OWNER_OS’, ‘HOST_NAME’, ‘USER’, ‘CLASS’, ‘ATOM’, and ‘INTEGER’.
50976     (These are symbols with upper-case names in accord with X
50977     conventions.)  The default for DATA-TYPE is ‘STRING’.  Window
50978     systems other than X usually support only a small subset of these
50979     types, in addition to ‘STRING’.
50980
50981 -- User Option: selection-coding-system
50982     This variable specifies the coding system to use when reading and
50983     writing selections or the clipboard.  *Note Coding Systems::.  The
50984     default is ‘compound-text-with-extensions’, which converts to the
50985     text representation that X11 normally uses.
50986
50987   When Emacs runs on MS-Windows, it does not implement X selections in
50988general, but it does support the clipboard.  ‘gui-get-selection’ and
50989‘gui-set-selection’ on MS-Windows support the text data type only; if
50990the clipboard holds other types of data, Emacs treats the clipboard as
50991empty.  The supported data type is ‘STRING’.
50992
50993   For backward compatibility, there are obsolete aliases
50994‘x-get-selection’ and ‘x-set-selection’, which were the names of
50995‘gui-get-selection’ and ‘gui-set-selection’ before Emacs 25.1.
50996
50997
50998File: elisp.info,  Node: Drag and Drop,  Next: Color Names,  Prev: Window System Selections,  Up: Frames
50999
5100029.21 Drag and Drop
51001===================
51002
51003When a user drags something from another application over Emacs, that
51004other application expects Emacs to tell it if Emacs can handle the data
51005that is dragged.  The variable ‘x-dnd-test-function’ is used by Emacs to
51006determine what to reply.  The default value is
51007‘x-dnd-default-test-function’ which accepts drops if the type of the
51008data to be dropped is present in ‘x-dnd-known-types’.  You can customize
51009‘x-dnd-test-function’ and/or ‘x-dnd-known-types’ if you want Emacs to
51010accept or reject drops based on some other criteria.
51011
51012   If you want to change the way Emacs handles drop of different types
51013or add a new type, customize ‘x-dnd-types-alist’.  This requires
51014detailed knowledge of what types other applications use for drag and
51015drop.
51016
51017   When an URL is dropped on Emacs it may be a file, but it may also be
51018another URL type (https, etc.).  Emacs first checks ‘dnd-protocol-alist’
51019to determine what to do with the URL.  If there is no match there and if
51020‘browse-url-browser-function’ is an alist, Emacs looks for a match
51021there.  If no match is found the text for the URL is inserted.  If you
51022want to alter Emacs behavior, you can customize these variables.
51023
51024
51025File: elisp.info,  Node: Color Names,  Next: Text Terminal Colors,  Prev: Drag and Drop,  Up: Frames
51026
5102729.22 Color Names
51028=================
51029
51030A color name is text (usually in a string) that specifies a color.
51031Symbolic names such as ‘black’, ‘white’, ‘red’, etc., are allowed; use
51032‘M-x list-colors-display’ to see a list of defined names.  You can also
51033specify colors numerically in forms such as ‘#RGB’ and ‘RGB:R/G/B’,
51034where R specifies the red level, G specifies the green level, and B
51035specifies the blue level.  You can use either one, two, three, or four
51036hex digits for R; then you must use the same number of hex digits for
51037all G and B as well, making either 3, 6, 9 or 12 hex digits in all.
51038(See the documentation of the X Window System for more details about
51039numerical RGB specification of colors.)
51040
51041   These functions provide a way to determine which color names are
51042valid, and what they look like.  In some cases, the value depends on the
51043“selected frame”, as described below; see *note Input Focus::, for the
51044meaning of the term “selected frame”.
51045
51046   To read user input of color names with completion, use ‘read-color’
51047(*note read-color: High-Level Completion.).
51048
51049 -- Function: color-defined-p color &optional frame
51050     This function reports whether a color name is meaningful.  It
51051     returns ‘t’ if so; otherwise, ‘nil’.  The argument FRAME says which
51052     frame’s display to ask about; if FRAME is omitted or ‘nil’, the
51053     selected frame is used.
51054
51055     Note that this does not tell you whether the display you are using
51056     really supports that color.  When using X, you can ask for any
51057     defined color on any kind of display, and you will get some
51058     result—typically, the closest it can do.  To determine whether a
51059     frame can really display a certain color, use ‘color-supported-p’
51060     (see below).
51061
51062     This function used to be called ‘x-color-defined-p’, and that name
51063     is still supported as an alias.
51064
51065 -- Function: defined-colors &optional frame
51066     This function returns a list of the color names that are defined
51067     and supported on frame FRAME (default, the selected frame).  If
51068     FRAME does not support colors, the value is ‘nil’.
51069
51070     This function used to be called ‘x-defined-colors’, and that name
51071     is still supported as an alias.
51072
51073 -- Function: color-supported-p color &optional frame background-p
51074     This returns ‘t’ if FRAME can really display the color COLOR (or at
51075     least something close to it).  If FRAME is omitted or ‘nil’, the
51076     question applies to the selected frame.
51077
51078     Some terminals support a different set of colors for foreground and
51079     background.  If BACKGROUND-P is non-‘nil’, that means you are
51080     asking whether COLOR can be used as a background; otherwise you are
51081     asking whether it can be used as a foreground.
51082
51083     The argument COLOR must be a valid color name.
51084
51085 -- Function: color-gray-p color &optional frame
51086     This returns ‘t’ if COLOR is a shade of gray, as defined on FRAME’s
51087     display.  If FRAME is omitted or ‘nil’, the question applies to the
51088     selected frame.  If COLOR is not a valid color name, this function
51089     returns ‘nil’.
51090
51091 -- Function: color-values color &optional frame
51092     This function returns a value that describes what COLOR should
51093     ideally look like on FRAME.  If COLOR is defined, the value is a
51094     list of three integers, which give the amount of red, the amount of
51095     green, and the amount of blue.  Each integer ranges in principle
51096     from 0 to 65535, but some displays may not use the full range.
51097     This three-element list is called the “rgb values” of the color.
51098
51099     If COLOR is not defined, the value is ‘nil’.
51100
51101          (color-values "black")
51102               ⇒ (0 0 0)
51103          (color-values "white")
51104               ⇒ (65280 65280 65280)
51105          (color-values "red")
51106               ⇒ (65280 0 0)
51107          (color-values "pink")
51108               ⇒ (65280 49152 51968)
51109          (color-values "hungry")
51110               ⇒ nil
51111
51112     The color values are returned for FRAME’s display.  If FRAME is
51113     omitted or ‘nil’, the information is returned for the selected
51114     frame’s display.  If the frame cannot display colors, the value is
51115     ‘nil’.
51116
51117     This function used to be called ‘x-color-values’, and that name is
51118     still supported as an alias.
51119
51120
51121File: elisp.info,  Node: Text Terminal Colors,  Next: Resources,  Prev: Color Names,  Up: Frames
51122
5112329.23 Text Terminal Colors
51124==========================
51125
51126Text terminals usually support only a small number of colors, and the
51127computer uses small integers to select colors on the terminal.  This
51128means that the computer cannot reliably tell what the selected color
51129looks like; instead, you have to inform your application which small
51130integers correspond to which colors.  However, Emacs does know the
51131standard set of colors and will try to use them automatically.
51132
51133   The functions described in this section control how terminal colors
51134are used by Emacs.
51135
51136   Several of these functions use or return “rgb values”, described in
51137*note Color Names::.
51138
51139   These functions accept a display (either a frame or the name of a
51140terminal) as an optional argument.  We hope in the future to make Emacs
51141support different colors on different text terminals; then this argument
51142will specify which terminal to operate on (the default being the
51143selected frame’s terminal; *note Input Focus::).  At present, though,
51144the FRAME argument has no effect.
51145
51146 -- Function: tty-color-define name number &optional rgb frame
51147     This function associates the color name NAME with color number
51148     NUMBER on the terminal.
51149
51150     The optional argument RGB, if specified, is an rgb value, a list of
51151     three numbers that specify what the color actually looks like.  If
51152     you do not specify RGB, then this color cannot be used by
51153     ‘tty-color-approximate’ to approximate other colors, because Emacs
51154     will not know what it looks like.
51155
51156 -- Function: tty-color-clear &optional frame
51157     This function clears the table of defined colors for a text
51158     terminal.
51159
51160 -- Function: tty-color-alist &optional frame
51161     This function returns an alist recording the known colors supported
51162     by a text terminal.
51163
51164     Each element has the form ‘(NAME NUMBER . RGB)’ or ‘(NAME NUMBER)’.
51165     Here, NAME is the color name, NUMBER is the number used to specify
51166     it to the terminal.  If present, RGB is a list of three color
51167     values (for red, green, and blue) that says what the color actually
51168     looks like.
51169
51170 -- Function: tty-color-approximate rgb &optional frame
51171     This function finds the closest color, among the known colors
51172     supported for DISPLAY, to that described by the rgb value RGB (a
51173     list of color values).  The return value is an element of
51174     ‘tty-color-alist’.
51175
51176 -- Function: tty-color-translate color &optional frame
51177     This function finds the closest color to COLOR among the known
51178     colors supported for DISPLAY and returns its index (an integer).
51179     If the name COLOR is not defined, the value is ‘nil’.
51180
51181
51182File: elisp.info,  Node: Resources,  Next: Display Feature Testing,  Prev: Text Terminal Colors,  Up: Frames
51183
5118429.24 X Resources
51185=================
51186
51187This section describes some of the functions and variables for querying
51188and using X resources, or their equivalent on your operating system.
51189*Note X Resources: (emacs)X Resources, for more information about X
51190resources.
51191
51192 -- Function: x-get-resource attribute class &optional component
51193          subclass
51194     The function ‘x-get-resource’ retrieves a resource value from the X
51195     Window defaults database.
51196
51197     Resources are indexed by a combination of a “key” and a “class”.
51198     This function searches using a key of the form ‘INSTANCE.ATTRIBUTE51199     (where INSTANCE is the name under which Emacs was invoked), and
51200     using ‘Emacs.CLASS’ as the class.
51201
51202     The optional arguments COMPONENT and SUBCLASS add to the key and
51203     the class, respectively.  You must specify both of them or neither.
51204     If you specify them, the key is ‘INSTANCE.COMPONENT.ATTRIBUTE’, and
51205     the class is ‘Emacs.CLASS.SUBCLASS’.
51206
51207 -- Variable: x-resource-class
51208     This variable specifies the application name that ‘x-get-resource’
51209     should look up.  The default value is ‘"Emacs"’.  You can examine X
51210     resources for other application names by binding this variable to
51211     some other string, around a call to ‘x-get-resource’.
51212
51213 -- Variable: x-resource-name
51214     This variable specifies the instance name that ‘x-get-resource’
51215     should look up.  The default value is the name Emacs was invoked
51216     with, or the value specified with the ‘-name’ or ‘-rn’ switches.
51217
51218   To illustrate some of the above, suppose that you have the line:
51219
51220     xterm.vt100.background: yellow
51221
51222in your X resources file (whose name is usually ‘~/.Xdefaults’ or
51223‘~/.Xresources’).  Then:
51224
51225     (let ((x-resource-class "XTerm") (x-resource-name "xterm"))
51226       (x-get-resource "vt100.background" "VT100.Background"))
51227          ⇒ "yellow"
51228     (let ((x-resource-class "XTerm") (x-resource-name "xterm"))
51229       (x-get-resource "background" "VT100" "vt100" "Background"))
51230          ⇒ "yellow"
51231
51232 -- Variable: inhibit-x-resources
51233     If this variable is non-‘nil’, Emacs does not look up X resources,
51234     and X resources do not have any effect when creating new frames.
51235
51236
51237File: elisp.info,  Node: Display Feature Testing,  Prev: Resources,  Up: Frames
51238
5123929.25 Display Feature Testing
51240=============================
51241
51242The functions in this section describe the basic capabilities of a
51243particular display.  Lisp programs can use them to adapt their behavior
51244to what the display can do.  For example, a program that ordinarily uses
51245a popup menu could use the minibuffer if popup menus are not supported.
51246
51247   The optional argument DISPLAY in these functions specifies which
51248display to ask the question about.  It can be a display name, a frame
51249(which designates the display that frame is on), or ‘nil’ (which refers
51250to the selected frame’s display, *note Input Focus::).
51251
51252   *Note Color Names::, *note Text Terminal Colors::, for other
51253functions to obtain information about displays.
51254
51255 -- Function: display-popup-menus-p &optional display
51256     This function returns ‘t’ if popup menus are supported on DISPLAY,
51257     ‘nil’ if not.  Support for popup menus requires that the mouse be
51258     available, since the menu is popped up by clicking the mouse on
51259     some portion of the Emacs display.
51260
51261 -- Function: display-graphic-p &optional display
51262     This function returns ‘t’ if DISPLAY is a graphic display capable
51263     of displaying several frames and several different fonts at once.
51264     This is true for displays that use a window system such as X, and
51265     false for text terminals.
51266
51267 -- Function: display-mouse-p &optional display
51268     This function returns ‘t’ if DISPLAY has a mouse available, ‘nil’
51269     if not.
51270
51271 -- Function: display-color-p &optional display
51272     This function returns ‘t’ if the screen is a color screen.  It used
51273     to be called ‘x-display-color-p’, and that name is still supported
51274     as an alias.
51275
51276 -- Function: display-grayscale-p &optional display
51277     This function returns ‘t’ if the screen can display shades of gray.
51278     (All color displays can do this.)
51279
51280 -- Function: display-supports-face-attributes-p attributes &optional
51281          display
51282     This function returns non-‘nil’ if all the face attributes in
51283     ATTRIBUTES are supported (*note Face Attributes::).
51284
51285     The definition of “supported” is somewhat heuristic, but basically
51286     means that a face containing all the attributes in ATTRIBUTES, when
51287     merged with the default face for display, can be represented in a
51288     way that’s
51289
51290       1. different in appearance than the default face, and
51291
51292       2. close in spirit to what the attributes specify, if not exact.
51293
51294     Point (2) implies that a ‘:weight black’ attribute will be
51295     satisfied by any display that can display bold, as will
51296     ‘:foreground "yellow"’ as long as some yellowish color can be
51297     displayed, but ‘:slant italic’ will _not_ be satisfied by the tty
51298     display code’s automatic substitution of a dim face for italic.
51299
51300 -- Function: display-selections-p &optional display
51301     This function returns ‘t’ if DISPLAY supports selections.  Windowed
51302     displays normally support selections, but they may also be
51303     supported in some other cases.
51304
51305 -- Function: display-images-p &optional display
51306     This function returns ‘t’ if DISPLAY can display images.  Windowed
51307     displays ought in principle to handle images, but some systems lack
51308     the support for that.  On a display that does not support images,
51309     Emacs cannot display a tool bar.
51310
51311 -- Function: display-screens &optional display
51312     This function returns the number of screens associated with the
51313     display.
51314
51315 -- Function: display-pixel-height &optional display
51316     This function returns the height of the screen in pixels.  On a
51317     character terminal, it gives the height in characters.
51318
51319     For graphical terminals, note that on multi-monitor setups this
51320     refers to the pixel height for all physical monitors associated
51321     with DISPLAY.  *Note Multiple Terminals::.
51322
51323 -- Function: display-pixel-width &optional display
51324     This function returns the width of the screen in pixels.  On a
51325     character terminal, it gives the width in characters.
51326
51327     For graphical terminals, note that on multi-monitor setups this
51328     refers to the pixel width for all physical monitors associated with
51329     DISPLAY.  *Note Multiple Terminals::.
51330
51331 -- Function: display-mm-height &optional display
51332     This function returns the height of the screen in millimeters, or
51333     ‘nil’ if Emacs cannot get that information.
51334
51335     For graphical terminals, note that on multi-monitor setups this
51336     refers to the height for all physical monitors associated with
51337     DISPLAY.  *Note Multiple Terminals::.
51338
51339 -- Function: display-mm-width &optional display
51340     This function returns the width of the screen in millimeters, or
51341     ‘nil’ if Emacs cannot get that information.
51342
51343     For graphical terminals, note that on multi-monitor setups this
51344     refers to the width for all physical monitors associated with
51345     DISPLAY.  *Note Multiple Terminals::.
51346
51347 -- User Option: display-mm-dimensions-alist
51348     This variable allows the user to specify the dimensions of
51349     graphical displays returned by ‘display-mm-height’ and
51350     ‘display-mm-width’ in case the system provides incorrect values.
51351
51352 -- Function: display-backing-store &optional display
51353     This function returns the backing store capability of the display.
51354     Backing store means recording the pixels of windows (and parts of
51355     windows) that are not exposed, so that when exposed they can be
51356     displayed very quickly.
51357
51358     Values can be the symbols ‘always’, ‘when-mapped’, or ‘not-useful’.
51359     The function can also return ‘nil’ when the question is
51360     inapplicable to a certain kind of display.
51361
51362 -- Function: display-save-under &optional display
51363     This function returns non-‘nil’ if the display supports the
51364     SaveUnder feature.  That feature is used by pop-up windows to save
51365     the pixels they obscure, so that they can pop down quickly.
51366
51367 -- Function: display-planes &optional display
51368     This function returns the number of planes the display supports.
51369     This is typically the number of bits per pixel.  For a tty display,
51370     it is log to base two of the number of colors supported.
51371
51372 -- Function: display-visual-class &optional display
51373     This function returns the visual class for the screen.  The value
51374     is one of the symbols ‘static-gray’ (a limited, unchangeable number
51375     of grays), ‘gray-scale’ (a full range of grays), ‘static-color’ (a
51376     limited, unchangeable number of colors), ‘pseudo-color’ (a limited
51377     number of colors), ‘true-color’ (a full range of colors), and
51378     ‘direct-color’ (a full range of colors).
51379
51380 -- Function: display-color-cells &optional display
51381     This function returns the number of color cells the screen
51382     supports.
51383
51384   These functions obtain additional information about the window system
51385in use where Emacs shows the specified DISPLAY.  (Their names begin with
51386‘x-’ for historical reasons.)
51387
51388 -- Function: x-server-version &optional display
51389     This function returns the list of version numbers of the GUI window
51390     system running on DISPLAY, such as the X server on GNU and Unix
51391     systems.  The value is a list of three integers: the major and
51392     minor version numbers of the protocol, and the distributor-specific
51393     release number of the window system software itself.  On GNU and
51394     Unix systems, these are normally the version of the X protocol and
51395     the distributor-specific release number of the X server software.
51396     On MS-Windows, this is the version of the Windows OS.
51397
51398 -- Function: x-server-vendor &optional display
51399     This function returns the vendor that provided the window system
51400     software (as a string).  On GNU and Unix systems this really means
51401     whoever distributes the X server.  On MS-Windows this is the vendor
51402     ID string of the Windows OS (Microsoft).
51403
51404     When the developers of X labeled software distributors as
51405     “vendors”, they showed their false assumption that no system could
51406     ever be developed and distributed noncommercially.
51407
51408
51409File: elisp.info,  Node: Positions,  Next: Markers,  Prev: Frames,  Up: Top
51410
5141130 Positions
51412************
51413
51414A “position” is the index of a character in the text of a buffer.  More
51415precisely, a position identifies the place between two characters (or
51416before the first character, or after the last character), so we can
51417speak of the character before or after a given position.  However, we
51418often speak of the character “at” a position, meaning the character
51419after that position.
51420
51421   Positions are usually represented as integers starting from 1, but
51422can also be represented as “markers”—special objects that relocate
51423automatically when text is inserted or deleted so they stay with the
51424surrounding characters.  Functions that expect an argument to be a
51425position (an integer), but accept a marker as a substitute, normally
51426ignore which buffer the marker points into; they convert the marker to
51427an integer, and use that integer, exactly as if you had passed the
51428integer as the argument, even if the marker points to the wrong buffer.
51429A marker that points nowhere cannot convert to an integer; using it
51430instead of an integer causes an error.  *Note Markers::.
51431
51432   See also the field feature (*note Fields::), which provides functions
51433that are used by many cursor-motion commands.
51434
51435* Menu:
51436
51437* Point::         The special position where editing takes place.
51438* Motion::        Changing point.
51439* Excursions::    Temporary motion and buffer changes.
51440* Narrowing::     Restricting editing to a portion of the buffer.
51441
51442
51443File: elisp.info,  Node: Point,  Next: Motion,  Up: Positions
51444
5144530.1 Point
51446==========
51447
51448“Point” is a special buffer position used by many editing commands,
51449including the self-inserting typed characters and text insertion
51450functions.  Other commands move point through the text to allow editing
51451and insertion at different places.
51452
51453   Like other positions, point designates a place between two characters
51454(or before the first character, or after the last character), rather
51455than a particular character.  Usually terminals display the cursor over
51456the character that immediately follows point; point is actually before
51457the character on which the cursor sits.
51458
51459   The value of point is a number no less than 1, and no greater than
51460the buffer size plus 1.  If narrowing is in effect (*note Narrowing::),
51461then point is constrained to fall within the accessible portion of the
51462buffer (possibly at one end of it).
51463
51464   Each buffer has its own value of point, which is independent of the
51465value of point in other buffers.  Each window also has a value of point,
51466which is independent of the value of point in other windows on the same
51467buffer.  This is why point can have different values in various windows
51468that display the same buffer.  When a buffer appears in only one window,
51469the buffer’s point and the window’s point normally have the same value,
51470so the distinction is rarely important.  *Note Window Point::, for more
51471details.
51472
51473 -- Function: point
51474     This function returns the value of point in the current buffer, as
51475     an integer.
51476
51477          (point)
51478               ⇒ 175
51479
51480 -- Function: point-min
51481     This function returns the minimum accessible value of point in the
51482     current buffer.  This is normally 1, but if narrowing is in effect,
51483     it is the position of the start of the region that you narrowed to.
51484     (*Note Narrowing::.)
51485
51486 -- Function: point-max
51487     This function returns the maximum accessible value of point in the
51488     current buffer.  This is ‘(1+ (buffer-size))’, unless narrowing is
51489     in effect, in which case it is the position of the end of the
51490     region that you narrowed to.  (*Note Narrowing::.)
51491
51492 -- Function: buffer-end flag
51493     This function returns ‘(point-max)’ if FLAG is greater than 0,
51494     ‘(point-min)’ otherwise.  The argument FLAG must be a number.
51495
51496 -- Function: buffer-size &optional buffer
51497     This function returns the total number of characters in the current
51498     buffer.  In the absence of any narrowing (*note Narrowing::),
51499     ‘point-max’ returns a value one larger than this.
51500
51501     If you specify a buffer, BUFFER, then the value is the size of
51502     BUFFER.
51503
51504          (buffer-size)
51505               ⇒ 35
51506          (point-max)
51507               ⇒ 36
51508
51509
51510File: elisp.info,  Node: Motion,  Next: Excursions,  Prev: Point,  Up: Positions
51511
5151230.2 Motion
51513===========
51514
51515Motion functions change the value of point, either relative to the
51516current value of point, relative to the beginning or end of the buffer,
51517or relative to the edges of the selected window.  *Note Point::.
51518
51519* Menu:
51520
51521* Character Motion::       Moving in terms of characters.
51522* Word Motion::            Moving in terms of words.
51523* Buffer End Motion::      Moving to the beginning or end of the buffer.
51524* Text Lines::             Moving in terms of lines of text.
51525* Screen Lines::           Moving in terms of lines as displayed.
51526* List Motion::            Moving by parsing lists and sexps.
51527* Skipping Characters::    Skipping characters belonging to a certain set.
51528
51529
51530File: elisp.info,  Node: Character Motion,  Next: Word Motion,  Up: Motion
51531
5153230.2.1 Motion by Characters
51533---------------------------
51534
51535These functions move point based on a count of characters.  ‘goto-char’
51536is the fundamental primitive; the other functions use that.
51537
51538 -- Command: goto-char position
51539     This function sets point in the current buffer to the value
51540     POSITION.
51541
51542     If narrowing is in effect, POSITION still counts from the beginning
51543     of the buffer, but point cannot go outside the accessible portion.
51544     If POSITION is out of range, ‘goto-char’ moves point to the
51545     beginning or the end of the accessible portion.
51546
51547     When this function is called interactively, POSITION is the numeric
51548     prefix argument, if provided; otherwise it is read from the
51549     minibuffer.
51550
51551     ‘goto-char’ returns POSITION.
51552
51553 -- Command: forward-char &optional count
51554     This function moves point COUNT characters forward, towards the end
51555     of the buffer (or backward, towards the beginning of the buffer, if
51556     COUNT is negative).  If COUNT is ‘nil’, the default is 1.
51557
51558     If this attempts to move past the beginning or end of the buffer
51559     (or the limits of the accessible portion, when narrowing is in
51560     effect), it signals an error with error symbol
51561     ‘beginning-of-buffer’ or ‘end-of-buffer’.
51562
51563     In an interactive call, COUNT is the numeric prefix argument.
51564
51565 -- Command: backward-char &optional count
51566     This is just like ‘forward-char’ except that it moves in the
51567     opposite direction.
51568
51569
51570File: elisp.info,  Node: Word Motion,  Next: Buffer End Motion,  Prev: Character Motion,  Up: Motion
51571
5157230.2.2 Motion by Words
51573----------------------
51574
51575The functions for parsing words described below use the syntax table and
51576‘char-script-table’ to decide whether a given character is part of a
51577word.  *Note Syntax Tables::, and see *note Character Properties::.
51578
51579 -- Command: forward-word &optional count
51580     This function moves point forward COUNT words (or backward if COUNT
51581     is negative).  If COUNT is omitted or ‘nil’, it defaults to 1.  In
51582     an interactive call, COUNT is specified by the numeric prefix
51583     argument.
51584
51585     “Moving one word” means moving until point crosses a
51586     word-constituent character, which indicates the beginning of a
51587     word, and then continue moving until the word ends.  By default,
51588     characters that begin and end words, known as “word boundaries”,
51589     are defined by the current buffer’s syntax table (*note Syntax
51590     Class Table::), but modes can override that by setting up a
51591     suitable ‘find-word-boundary-function-table’, described below.
51592     Characters that belong to different scripts (as defined by
51593     ‘char-script-table’), also define a word boundary (*note Character
51594     Properties::).  In any case, this function cannot move point past
51595     the boundary of the accessible portion of the buffer, or across a
51596     field boundary (*note Fields::).  The most common case of a field
51597     boundary is the end of the prompt in the minibuffer.
51598
51599     If it is possible to move COUNT words, without being stopped
51600     prematurely by the buffer boundary or a field boundary, the value
51601     is ‘t’.  Otherwise, the return value is ‘nil’ and point stops at
51602     the buffer boundary or field boundary.
51603
51604     If ‘inhibit-field-text-motion’ is non-‘nil’, this function ignores
51605     field boundaries.
51606
51607 -- Command: backward-word &optional count
51608     This function is just like ‘forward-word’, except that it moves
51609     backward until encountering the front of a word, rather than
51610     forward.
51611
51612 -- User Option: words-include-escapes
51613     This variable affects the behavior of ‘forward-word’ and
51614     ‘backward-word’, and everything that uses them.  If it is
51615     non-‘nil’, then characters in the escape and character-quote syntax
51616     classes count as part of words.  Otherwise, they do not.
51617
51618 -- Variable: inhibit-field-text-motion
51619     If this variable is non-‘nil’, certain motion functions including
51620     ‘forward-word’, ‘forward-sentence’, and ‘forward-paragraph’ ignore
51621     field boundaries.
51622
51623 -- Variable: find-word-boundary-function-table
51624     This variable affects the behavior of ‘forward-word’ and
51625     ‘backward-word’, and everything that uses them.  Its value is a
51626     char-table (*note Char-Tables::) of functions to search for word
51627     boundaries.  If a character has a non-‘nil’ entry in this table,
51628     then when a word starts or ends with that character, the
51629     corresponding function will be called with 2 arguments: POS and
51630     LIMIT.  The function should return the position of the other word
51631     boundary.  Specifically, if POS is smaller than LIMIT, then POS is
51632     at the beginning of a word, and the function should return the
51633     position after the last character of the word; otherwise, POS is at
51634     the last character of a word, and the function should return the
51635     position of that word’s first character.
51636
51637 -- Function: forward-word-strictly &optional count
51638     This function is like ‘forward-word’, but it is not affected by
51639     ‘find-word-boundary-function-table’.  Lisp programs that should not
51640     change behavior when word movement is modified by modes which set
51641     that table, such as ‘subword-mode’, should use this function
51642     instead of ‘forward-word’.
51643
51644 -- Function: backward-word-strictly &optional count
51645     This function is like ‘backward-word’, but it is not affected by
51646     ‘find-word-boundary-function-table’.  Like with
51647     ‘forward-word-strictly’, use this function instead of
51648     ‘backward-word’ when movement by words should only consider syntax
51649     tables.
51650
51651
51652File: elisp.info,  Node: Buffer End Motion,  Next: Text Lines,  Prev: Word Motion,  Up: Motion
51653
5165430.2.3 Motion to an End of the Buffer
51655-------------------------------------
51656
51657To move point to the beginning of the buffer, write:
51658
51659     (goto-char (point-min))
51660
51661Likewise, to move to the end of the buffer, use:
51662
51663     (goto-char (point-max))
51664
51665   Here are two commands that users use to do these things.  They are
51666documented here to warn you not to use them in Lisp programs, because
51667they set the mark and display messages in the echo area.
51668
51669 -- Command: beginning-of-buffer &optional n
51670     This function moves point to the beginning of the buffer (or the
51671     limits of the accessible portion, when narrowing is in effect),
51672     setting the mark at the previous position (except in Transient Mark
51673     mode, if the mark is already active, it does not set the mark.)
51674
51675     If N is non-‘nil’, then it puts point N tenths of the way from the
51676     beginning of the accessible portion of the buffer.  In an
51677     interactive call, N is the numeric prefix argument, if provided;
51678     otherwise N defaults to ‘nil’.
51679
51680     *Warning:* Don’t use this function in Lisp programs!
51681
51682 -- Command: end-of-buffer &optional n
51683     This function moves point to the end of the buffer (or the limits
51684     of the accessible portion, when narrowing is in effect), setting
51685     the mark at the previous position (except in Transient Mark mode
51686     when the mark is already active).  If N is non-‘nil’, then it puts
51687     point N tenths of the way from the end of the accessible portion of
51688     the buffer.
51689
51690     In an interactive call, N is the numeric prefix argument, if
51691     provided; otherwise N defaults to ‘nil’.
51692
51693     *Warning:* Don’t use this function in Lisp programs!
51694
51695
51696File: elisp.info,  Node: Text Lines,  Next: Screen Lines,  Prev: Buffer End Motion,  Up: Motion
51697
5169830.2.4 Motion by Text Lines
51699---------------------------
51700
51701Text lines are portions of the buffer delimited by newline characters,
51702which are regarded as part of the previous line.  The first text line
51703begins at the beginning of the buffer, and the last text line ends at
51704the end of the buffer whether or not the last character is a newline.
51705The division of the buffer into text lines is not affected by the width
51706of the window, by line continuation in display, or by how tabs and
51707control characters are displayed.
51708
51709 -- Command: beginning-of-line &optional count
51710     This function moves point to the beginning of the current line.
51711     With an argument COUNT not ‘nil’ or 1, it moves forward COUNT−1
51712     lines and then to the beginning of the line.
51713
51714     This function does not move point across a field boundary (*note
51715     Fields::) unless doing so would move beyond there to a different
51716     line; therefore, if COUNT is ‘nil’ or 1, and point starts at a
51717     field boundary, point does not move.  To ignore field boundaries,
51718     either bind ‘inhibit-field-text-motion’ to ‘t’, or use the
51719     ‘forward-line’ function instead.  For instance, ‘(forward-line 0)’
51720     does the same thing as ‘(beginning-of-line)’, except that it
51721     ignores field boundaries.
51722
51723     If this function reaches the end of the buffer (or of the
51724     accessible portion, if narrowing is in effect), it positions point
51725     there.  No error is signaled.
51726
51727 -- Function: line-beginning-position &optional count
51728     Return the position that ‘(beginning-of-line COUNT)’ would move to.
51729
51730 -- Command: end-of-line &optional count
51731     This function moves point to the end of the current line.  With an
51732     argument COUNT not ‘nil’ or 1, it moves forward COUNT−1 lines and
51733     then to the end of the line.
51734
51735     This function does not move point across a field boundary (*note
51736     Fields::) unless doing so would move beyond there to a different
51737     line; therefore, if COUNT is ‘nil’ or 1, and point starts at a
51738     field boundary, point does not move.  To ignore field boundaries,
51739     bind ‘inhibit-field-text-motion’ to ‘t’.
51740
51741     If this function reaches the end of the buffer (or of the
51742     accessible portion, if narrowing is in effect), it positions point
51743     there.  No error is signaled.
51744
51745 -- Function: line-end-position &optional count
51746     Return the position that ‘(end-of-line COUNT)’ would move to.
51747
51748 -- Command: forward-line &optional count
51749     This function moves point forward COUNT lines, to the beginning of
51750     the line following that.  If COUNT is negative, it moves point
51751     −COUNT lines backward, to the beginning of a line preceding that.
51752     If COUNT is zero, it moves point to the beginning of the current
51753     line.  If COUNT is ‘nil’, that means 1.
51754
51755     If ‘forward-line’ encounters the beginning or end of the buffer (or
51756     of the accessible portion) before finding that many lines, it sets
51757     point there.  No error is signaled.
51758
51759     ‘forward-line’ returns the difference between COUNT and the number
51760     of lines actually moved.  If you attempt to move down five lines
51761     from the beginning of a buffer that has only three lines, point
51762     stops at the end of the last line, and the value will be 2.  As an
51763     explicit exception, if the last accessible line is non-empty, but
51764     has no newline (e.g., if the buffer ends without a newline), the
51765     function sets point to the end of that line, and the value returned
51766     by the function counts that line as one line successfully moved.
51767
51768     In an interactive call, COUNT is the numeric prefix argument.
51769
51770 -- Function: count-lines start end
51771     This function returns the number of lines between the positions
51772     START and END in the current buffer.  If START and END are equal,
51773     then it returns 0.  Otherwise it returns at least 1, even if START
51774     and END are on the same line.  This is because the text between
51775     them, considered in isolation, must contain at least one line
51776     unless it is empty.
51777
51778 -- Command: count-words start end
51779     This function returns the number of words between the positions
51780     START and END in the current buffer.
51781
51782     This function can also be called interactively.  In that case, it
51783     prints a message reporting the number of lines, words, and
51784     characters in the buffer, or in the region if the region is active.
51785
51786 -- Function: line-number-at-pos &optional pos absolute
51787     This function returns the line number in the current buffer
51788     corresponding to the buffer position POS.  If POS is ‘nil’ or
51789     omitted, the current buffer position is used.  If ABSOLUTE is
51790     ‘nil’, the default, counting starts at ‘(point-min)’, so the value
51791     refers to the contents of the accessible portion of the
51792     (potentially narrowed) buffer.  If ABSOLUTE is non-‘nil’, ignore
51793     any narrowing and return the absolute line number.
51794
51795   Also see the functions ‘bolp’ and ‘eolp’ in *note Near Point::.
51796These functions do not move point, but test whether it is already at the
51797beginning or end of a line.
51798
51799
51800File: elisp.info,  Node: Screen Lines,  Next: List Motion,  Prev: Text Lines,  Up: Motion
51801
5180230.2.5 Motion by Screen Lines
51803-----------------------------
51804
51805The line functions in the previous section count text lines, delimited
51806only by newline characters.  By contrast, these functions count screen
51807lines, which are defined by the way the text appears on the screen.  A
51808text line is a single screen line if it is short enough to fit the width
51809of the selected window, but otherwise it may occupy several screen
51810lines.
51811
51812   In some cases, text lines are truncated on the screen rather than
51813continued onto additional screen lines.  In these cases,
51814‘vertical-motion’ moves point much like ‘forward-line’.  *Note
51815Truncation::.
51816
51817   Because the width of a given string depends on the flags that control
51818the appearance of certain characters, ‘vertical-motion’ behaves
51819differently, for a given piece of text, depending on the buffer it is
51820in, and even on the selected window (because the width, the truncation
51821flag, and display table may vary between windows).  *Note Usual
51822Display::.
51823
51824   These functions scan text to determine where screen lines break, and
51825thus take time proportional to the distance scanned.
51826
51827 -- Function: vertical-motion count &optional window cur-col
51828     This function moves point to the start of the screen line COUNT
51829     screen lines down from the screen line containing point.  If COUNT
51830     is negative, it moves up instead.
51831
51832     The COUNT argument can be a cons cell, ‘(COLS . LINES)’, instead of
51833     an integer.  Then the function moves by LINES screen lines, and
51834     puts point COLS columns from the visual start of that screen line.
51835     Note that COLS are counted from the _visual_ start of the line; if
51836     the window is scrolled horizontally (*note Horizontal Scrolling::),
51837     the column on which point will end is in addition to the number of
51838     columns by which the text is scrolled.
51839
51840     The return value is the number of screen lines over which point was
51841     moved.  The value may be less in absolute value than COUNT if the
51842     beginning or end of the buffer was reached.
51843
51844     The window WINDOW is used for obtaining parameters such as the
51845     width, the horizontal scrolling, and the display table.  But
51846     ‘vertical-motion’ always operates on the current buffer, even if
51847     WINDOW currently displays some other buffer.
51848
51849     The optional argument CUR-COL specifies the current column when the
51850     function is called.  This is the window-relative horizontal
51851     coordinate of point, measured in units of font width of the frame’s
51852     default face.  Providing it speeds up the function, especially in
51853     very long lines, because the function doesn’t have to go back in
51854     the buffer in order to determine the current column.  Note that
51855     CUR-COL is also counted from the visual start of the line.
51856
51857 -- Function: count-screen-lines &optional beg end count-final-newline
51858          window
51859     This function returns the number of screen lines in the text from
51860     BEG to END.  The number of screen lines may be different from the
51861     number of actual lines, due to line continuation, the display
51862     table, etc.  If BEG and END are ‘nil’ or omitted, they default to
51863     the beginning and end of the accessible portion of the buffer.
51864
51865     If the region ends with a newline, that is ignored unless the
51866     optional third argument COUNT-FINAL-NEWLINE is non-‘nil’.
51867
51868     The optional fourth argument WINDOW specifies the window for
51869     obtaining parameters such as width, horizontal scrolling, and so
51870     on.  The default is to use the selected window’s parameters.
51871
51872     Like ‘vertical-motion’, ‘count-screen-lines’ always uses the
51873     current buffer, regardless of which buffer is displayed in WINDOW.
51874     This makes possible to use ‘count-screen-lines’ in any buffer,
51875     whether or not it is currently displayed in some window.
51876
51877 -- Command: move-to-window-line count
51878     This function moves point with respect to the text currently
51879     displayed in the selected window.  It moves point to the beginning
51880     of the screen line COUNT screen lines from the top of the window;
51881     zero means the topmost line.  If COUNT is negative, that specifies
51882     a position −COUNT lines from the bottom (or the last line of the
51883     buffer, if the buffer ends above the specified screen position);
51884     thus, COUNT of −1 specifies the last fully visible screen line of
51885     the window.
51886
51887     If COUNT is ‘nil’, then point moves to the beginning of the line in
51888     the middle of the window.  If the absolute value of COUNT is
51889     greater than the size of the window, then point moves to the place
51890     that would appear on that screen line if the window were tall
51891     enough.  This will probably cause the next redisplay to scroll to
51892     bring that location onto the screen.
51893
51894     In an interactive call, COUNT is the numeric prefix argument.
51895
51896     The value returned is the screen line number point has moved to,
51897     relative to the top line of the window.
51898
51899 -- Function: move-to-window-group-line count
51900     This function is like ‘move-to-window-line’, except that when the
51901     selected window is a part of a group of windows (*note Window
51902     Group::), ‘move-to-window-group-line’ will move to a position with
51903     respect to the entire group, not just the single window.  This
51904     condition holds when the buffer local variable
51905     ‘move-to-window-group-line-function’ is set to a function.  In this
51906     case, ‘move-to-window-group-line’ calls the function with the
51907     argument COUNT, then returns its result.
51908
51909 -- Function: compute-motion from frompos to topos width offsets window
51910     This function scans the current buffer, calculating screen
51911     positions.  It scans the buffer forward from position FROM,
51912     assuming that is at screen coordinates FROMPOS, to position TO or
51913     coordinates TOPOS, whichever comes first.  It returns the ending
51914     buffer position and screen coordinates.
51915
51916     The coordinate arguments FROMPOS and TOPOS are cons cells of the
51917     form ‘(HPOS . VPOS)’.
51918
51919     The argument WIDTH is the number of columns available to display
51920     text; this affects handling of continuation lines.  ‘nil’ means the
51921     actual number of usable text columns in the window, which is
51922     equivalent to the value returned by ‘(window-width window)’.
51923
51924     The argument OFFSETS is either ‘nil’ or a cons cell of the form
51925     ‘(HSCROLL . TAB-OFFSET)’.  Here HSCROLL is the number of columns
51926     not being displayed at the left margin; most callers get this by
51927     calling ‘window-hscroll’.  Meanwhile, TAB-OFFSET is the offset
51928     between column numbers on the screen and column numbers in the
51929     buffer.  This can be nonzero in a continuation line, when the
51930     previous screen lines’ widths do not add up to a multiple of
51931     ‘tab-width’.  It is always zero in a non-continuation line.
51932
51933     The window WINDOW serves only to specify which display table to
51934     use.  ‘compute-motion’ always operates on the current buffer,
51935     regardless of what buffer is displayed in WINDOW.
51936
51937     The return value is a list of five elements:
51938
51939          (POS HPOS VPOS PREVHPOS CONTIN)
51940
51941     Here POS is the buffer position where the scan stopped, VPOS is the
51942     vertical screen position, and HPOS is the horizontal screen
51943     position.
51944
51945     The result PREVHPOS is the horizontal position one character back
51946     from POS.  The result CONTIN is ‘t’ if the last line was continued
51947     after (or within) the previous character.
51948
51949     For example, to find the buffer position of column COL of screen
51950     line LINE of a certain window, pass the window’s display start
51951     location as FROM and the window’s upper-left coordinates as
51952     FROMPOS.  Pass the buffer’s ‘(point-max)’ as TO, to limit the scan
51953     to the end of the accessible portion of the buffer, and pass LINE
51954     and COL as TOPOS.  Here’s a function that does this:
51955
51956          (defun coordinates-of-position (col line)
51957            (car (compute-motion (window-start)
51958                                 '(0 . 0)
51959                                 (point-max)
51960                                 (cons col line)
51961                                 (window-width)
51962                                 (cons (window-hscroll) 0)
51963                                 (selected-window))))
51964
51965     When you use ‘compute-motion’ for the minibuffer, you need to use
51966     ‘minibuffer-prompt-width’ to get the horizontal position of the
51967     beginning of the first screen line.  *Note Minibuffer Contents::.
51968
51969
51970File: elisp.info,  Node: List Motion,  Next: Skipping Characters,  Prev: Screen Lines,  Up: Motion
51971
5197230.2.6 Moving over Balanced Expressions
51973---------------------------------------
51974
51975Here are several functions concerned with balanced-parenthesis
51976expressions (also called “sexps” in connection with moving across them
51977in Emacs).  The syntax table controls how these functions interpret
51978various characters; see *note Syntax Tables::.  *Note Parsing
51979Expressions::, for lower-level primitives for scanning sexps or parts of
51980sexps.  For user-level commands, see *note Commands for Editing with
51981Parentheses: (emacs)Parentheses.
51982
51983 -- Command: forward-list &optional arg
51984     This function moves forward across ARG (default 1) balanced groups
51985     of parentheses.  (Other syntactic entities such as words or paired
51986     string quotes are ignored.)
51987
51988 -- Command: backward-list &optional arg
51989     This function moves backward across ARG (default 1) balanced groups
51990     of parentheses.  (Other syntactic entities such as words or paired
51991     string quotes are ignored.)
51992
51993 -- Command: up-list &optional arg escape-strings no-syntax-crossing
51994     This function moves forward out of ARG (default 1) levels of
51995     parentheses.  A negative argument means move backward but still to
51996     a less deep spot.  If ESCAPE-STRINGS is non-‘nil’ (as it is
51997     interactively), move out of enclosing strings as well.  If
51998     NO-SYNTAX-CROSSING is non-‘nil’ (as it is interactively), prefer to
51999     break out of any enclosing string instead of moving to the start of
52000     a list broken across multiple strings.  On error, location of point
52001     is unspecified.
52002
52003 -- Command: backward-up-list &optional arg escape-strings
52004          no-syntax-crossing
52005     This function is just like ‘up-list’, but with a negated argument.
52006
52007 -- Command: down-list &optional arg
52008     This function moves forward into ARG (default 1) levels of
52009     parentheses.  A negative argument means move backward but still go
52010     deeper in parentheses (−ARG levels).
52011
52012 -- Command: forward-sexp &optional arg
52013     This function moves forward across ARG (default 1) balanced
52014     expressions.  Balanced expressions include both those delimited by
52015     parentheses and other kinds, such as words and string constants.
52016     *Note Parsing Expressions::.  For example,
52017
52018          ---------- Buffer: foo ----------
52019          (concat★ "foo " (car x) y z)
52020          ---------- Buffer: foo ----------
52021
52022          (forward-sexp 3)
52023               ⇒ nil
52024
52025          ---------- Buffer: foo ----------
52026          (concat "foo " (car x) y★ z)
52027          ---------- Buffer: foo ----------
52028
52029 -- Command: backward-sexp &optional arg
52030     This function moves backward across ARG (default 1) balanced
52031     expressions.
52032
52033 -- Command: beginning-of-defun &optional arg
52034     This function moves back to the ARGth beginning of a defun.  If ARG
52035     is negative, this actually moves forward, but it still moves to the
52036     beginning of a defun, not to the end of one.  ARG defaults to 1.
52037
52038 -- Command: end-of-defun &optional arg
52039     This function moves forward to the ARGth end of a defun.  If ARG is
52040     negative, this actually moves backward, but it still moves to the
52041     end of a defun, not to the beginning of one.  ARG defaults to 1.
52042
52043 -- User Option: defun-prompt-regexp
52044     If non-‘nil’, this buffer-local variable holds a regular expression
52045     that specifies what text can appear before the open-parenthesis
52046     that starts a defun.  That is to say, a defun begins on a line that
52047     starts with a match for this regular expression, followed by a
52048     character with open-parenthesis syntax.
52049
52050 -- User Option: open-paren-in-column-0-is-defun-start
52051     If this variable’s value is non-‘nil’, an open parenthesis in
52052     column 0 is considered to be the start of a defun.  If it is ‘nil’,
52053     an open parenthesis in column 0 has no special meaning.  The
52054     default is ‘t’.  If a string literal happens to have a parenthesis
52055     in column 0, escape it with a backslash to avoid a false positive.
52056
52057 -- Variable: beginning-of-defun-function
52058     If non-‘nil’, this variable holds a function for finding the
52059     beginning of a defun.  The function ‘beginning-of-defun’ calls this
52060     function instead of using its normal method, passing it its
52061     optional argument.  If the argument is non-‘nil’, the function
52062     should move back by that many functions, like ‘beginning-of-defun’
52063     does.
52064
52065 -- Variable: end-of-defun-function
52066     If non-‘nil’, this variable holds a function for finding the end of
52067     a defun.  The function ‘end-of-defun’ calls this function instead
52068     of using its normal method.
52069
52070
52071File: elisp.info,  Node: Skipping Characters,  Prev: List Motion,  Up: Motion
52072
5207330.2.7 Skipping Characters
52074--------------------------
52075
52076The following two functions move point over a specified set of
52077characters.  For example, they are often used to skip whitespace.  For
52078related functions, see *note Motion and Syntax::.
52079
52080   These functions convert the set string to multibyte if the buffer is
52081multibyte, and they convert it to unibyte if the buffer is unibyte, as
52082the search functions do (*note Searching and Matching::).
52083
52084 -- Function: skip-chars-forward character-set &optional limit
52085     This function moves point in the current buffer forward, skipping
52086     over a given set of characters.  It examines the character
52087     following point, then advances point if the character matches
52088     CHARACTER-SET.  This continues until it reaches a character that
52089     does not match.  The function returns the number of characters
52090     moved over.
52091
52092     The argument CHARACTER-SET is a string, like the inside of a
52093     ‘[...]’ in a regular expression except that ‘]’ does not terminate
52094     it, and ‘\’ quotes ‘^’, ‘-’ or ‘\’.  Thus, ‘"a-zA-Z"’ skips over
52095     all letters, stopping before the first nonletter, and ‘"^a-zA-Z"’
52096     skips nonletters stopping before the first letter (*note Regular
52097     Expressions::).  Character classes can also be used, e.g.,
52098     ‘"[:alnum:]"’ (*note Char Classes::).
52099
52100     If LIMIT is supplied (it must be a number or a marker), it
52101     specifies the maximum position in the buffer that point can be
52102     skipped to.  Point will stop at or before LIMIT.
52103
52104     In the following example, point is initially located directly
52105     before the ‘T’.  After the form is evaluated, point is located at
52106     the end of that line (between the ‘t’ of ‘hat’ and the newline).
52107     The function skips all letters and spaces, but not newlines.
52108
52109          ---------- Buffer: foo ----------
52110          I read "★The cat in the hat
52111          comes back" twice.
52112          ---------- Buffer: foo ----------
52113
52114          (skip-chars-forward "a-zA-Z ")
52115               ⇒ 18
52116
52117          ---------- Buffer: foo ----------
52118          I read "The cat in the hat★
52119          comes back" twice.
52120          ---------- Buffer: foo ----------
52121
52122 -- Function: skip-chars-backward character-set &optional limit
52123     This function moves point backward, skipping characters that match
52124     CHARACTER-SET, until LIMIT.  It is just like ‘skip-chars-forward’
52125     except for the direction of motion.
52126
52127     The return value indicates the distance traveled.  It is an integer
52128     that is zero or less.
52129
52130
52131File: elisp.info,  Node: Excursions,  Next: Narrowing,  Prev: Motion,  Up: Positions
52132
5213330.3 Excursions
52134===============
52135
52136It is often useful to move point temporarily within a localized portion
52137of the program.  This is called an “excursion”, and it is done with the
52138‘save-excursion’ special form.  This construct remembers the initial
52139identity of the current buffer, and its value of point, and restores
52140them after the excursion completes.  It is the standard way to move
52141point within one part of a program and avoid affecting the rest of the
52142program, and is used thousands of times in the Lisp sources of Emacs.
52143
52144   If you only need to save and restore the identity of the current
52145buffer, use ‘save-current-buffer’ or ‘with-current-buffer’ instead
52146(*note Current Buffer::).  If you need to save or restore window
52147configurations, see the forms described in *note Window Configurations::
52148and in *note Frame Configurations::.
52149
52150 -- Special Form: save-excursion body...
52151     This special form saves the identity of the current buffer and the
52152     value of point in it, evaluates BODY, and finally restores the
52153     buffer and its saved value of point.  Both saved values are
52154     restored even in case of an abnormal exit via ‘throw’ or error
52155     (*note Nonlocal Exits::).
52156
52157     The value returned by ‘save-excursion’ is the result of the last
52158     form in BODY, or ‘nil’ if no body forms were given.
52159
52160   Because ‘save-excursion’ only saves point for the buffer that was
52161current at the start of the excursion, any changes made to point in
52162other buffers, during the excursion, will remain in effect afterward.
52163This frequently leads to unintended consequences, so the byte compiler
52164warns if you call ‘set-buffer’ during an excursion:
52165
52166     Warning: Use ‘with-current-buffer’ rather than
52167              save-excursion+set-buffer
52168
52169To avoid such problems, you should call ‘save-excursion’ only after
52170setting the desired current buffer, as in the following example:
52171
52172     (defun append-string-to-buffer (string buffer)
52173       "Append STRING to the end of BUFFER."
52174       (with-current-buffer buffer
52175         (save-excursion
52176           (goto-char (point-max))
52177           (insert string))))
52178
52179   Likewise, ‘save-excursion’ does not restore window-buffer
52180correspondences altered by functions such as ‘switch-to-buffer’.
52181
52182   *Warning:* Ordinary insertion of text adjacent to the saved point
52183value relocates the saved value, just as it relocates all markers.  More
52184precisely, the saved value is a marker with insertion type ‘nil’.  *Note
52185Marker Insertion Types::.  Therefore, when the saved point value is
52186restored, it normally comes before the inserted text.
52187
52188 -- Macro: save-mark-and-excursion body...
52189     This macro is like ‘save-excursion’, but also saves and restores
52190     the mark location and ‘mark-active’.  This macro does what
52191     ‘save-excursion’ did before Emacs 25.1.
52192
52193
52194File: elisp.info,  Node: Narrowing,  Prev: Excursions,  Up: Positions
52195
5219630.4 Narrowing
52197==============
52198
52199“Narrowing” means limiting the text addressable by Emacs editing
52200commands to a limited range of characters in a buffer.  The text that
52201remains addressable is called the “accessible portion” of the buffer.
52202
52203   Narrowing is specified with two buffer positions, which become the
52204beginning and end of the accessible portion.  For most editing commands
52205and primitives, these positions replace the values of the beginning and
52206end of the buffer.  While narrowing is in effect, no text outside the
52207accessible portion is displayed, and point cannot move outside the
52208accessible portion.  Note that narrowing does not alter actual buffer
52209positions (*note Point::); it only determines which positions are
52210considered the accessible portion of the buffer.  Most functions refuse
52211to operate on text that is outside the accessible portion.
52212
52213   Commands for saving buffers are unaffected by narrowing; they save
52214the entire buffer regardless of any narrowing.
52215
52216   If you need to display in a single buffer several very different
52217types of text, consider using an alternative facility described in *note
52218Swapping Text::.
52219
52220 -- Command: narrow-to-region start end
52221     This function sets the accessible portion of the current buffer to
52222     start at START and end at END.  Both arguments should be character
52223     positions.
52224
52225     In an interactive call, START and END are set to the bounds of the
52226     current region (point and the mark, with the smallest first).
52227
52228 -- Command: narrow-to-page &optional move-count
52229     This function sets the accessible portion of the current buffer to
52230     include just the current page.  An optional first argument
52231     MOVE-COUNT non-‘nil’ means to move forward or backward by
52232     MOVE-COUNT pages and then narrow to one page.  The variable
52233     ‘page-delimiter’ specifies where pages start and end (*note
52234     Standard Regexps::).
52235
52236     In an interactive call, MOVE-COUNT is set to the numeric prefix
52237     argument.
52238
52239 -- Command: widen
52240     This function cancels any narrowing in the current buffer, so that
52241     the entire contents are accessible.  This is called “widening”.  It
52242     is equivalent to the following expression:
52243
52244          (narrow-to-region 1 (1+ (buffer-size)))
52245
52246 -- Function: buffer-narrowed-p
52247     This function returns non-‘nil’ if the buffer is narrowed, and
52248     ‘nil’ otherwise.
52249
52250 -- Special Form: save-restriction body...
52251     This special form saves the current bounds of the accessible
52252     portion, evaluates the BODY forms, and finally restores the saved
52253     bounds, thus restoring the same state of narrowing (or absence
52254     thereof) formerly in effect.  The state of narrowing is restored
52255     even in the event of an abnormal exit via ‘throw’ or error (*note
52256     Nonlocal Exits::).  Therefore, this construct is a clean way to
52257     narrow a buffer temporarily.
52258
52259     The value returned by ‘save-restriction’ is that returned by the
52260     last form in BODY, or ‘nil’ if no body forms were given.
52261
52262     *Caution:* it is easy to make a mistake when using the
52263     ‘save-restriction’ construct.  Read the entire description here
52264     before you try it.
52265
52266     If BODY changes the current buffer, ‘save-restriction’ still
52267     restores the restrictions on the original buffer (the buffer whose
52268     restrictions it saved from), but it does not restore the identity
52269     of the current buffer.
52270
52271     ‘save-restriction’ does _not_ restore point; use ‘save-excursion’
52272     for that.  If you use both ‘save-restriction’ and ‘save-excursion’
52273     together, ‘save-excursion’ should come first (on the outside).
52274     Otherwise, the old point value would be restored with temporary
52275     narrowing still in effect.  If the old point value were outside the
52276     limits of the temporary narrowing, this would fail to restore it
52277     accurately.
52278
52279     Here is a simple example of correct use of ‘save-restriction’:
52280
52281          ---------- Buffer: foo ----------
52282          This is the contents of foo
52283          This is the contents of foo
52284          This is the contents of foo★
52285          ---------- Buffer: foo ----------
52286
52287          (save-excursion
52288            (save-restriction
52289              (goto-char 1)
52290              (forward-line 2)
52291              (narrow-to-region 1 (point))
52292              (goto-char (point-min))
52293              (replace-string "foo" "bar")))
52294
52295          ---------- Buffer: foo ----------
52296          This is the contents of bar
52297          This is the contents of bar
52298          This is the contents of foo★
52299          ---------- Buffer: foo ----------
52300
52301
52302File: elisp.info,  Node: Markers,  Next: Text,  Prev: Positions,  Up: Top
52303
5230431 Markers
52305**********
52306
52307A “marker” is a Lisp object used to specify a position in a buffer
52308relative to the surrounding text.  A marker changes its offset from the
52309beginning of the buffer automatically whenever text is inserted or
52310deleted, so that it stays with the two characters on either side of it.
52311
52312* Menu:
52313
52314* Overview of Markers::      The components of a marker, and how it relocates.
52315* Predicates on Markers::    Testing whether an object is a marker.
52316* Creating Markers::         Making empty markers or markers at certain places.
52317* Information from Markers:: Finding the marker’s buffer or character position.
52318* Marker Insertion Types::   Two ways a marker can relocate when you
52319                               insert where it points.
52320* Moving Markers::           Moving the marker to a new buffer or position.
52321* The Mark::                 How the mark is implemented with a marker.
52322* The Region::               How to access the region.
52323
52324
52325File: elisp.info,  Node: Overview of Markers,  Next: Predicates on Markers,  Up: Markers
52326
5232731.1 Overview of Markers
52328========================
52329
52330A marker specifies a buffer and a position in that buffer.  A marker can
52331be used to represent a position in functions that require one, just as
52332an integer could be used.  In that case, the marker’s buffer is normally
52333ignored.  Of course, a marker used in this way usually points to a
52334position in the buffer that the function operates on, but that is
52335entirely the programmer’s responsibility.  *Note Positions::, for a
52336complete description of positions.
52337
52338   A marker has three attributes: the marker position, the marker
52339buffer, and the insertion type.  The marker position is an integer that
52340is equivalent (at a given time) to the marker as a position in that
52341buffer.  But the marker’s position value can change during the life of
52342the marker, and often does.  Insertion and deletion of text in the
52343buffer relocate the marker.  The idea is that a marker positioned
52344between two characters remains between those two characters despite
52345insertion and deletion elsewhere in the buffer.  Relocation changes the
52346integer equivalent of the marker.
52347
52348   Deleting text around a marker’s position leaves the marker between
52349the characters immediately before and after the deleted text.  Inserting
52350text at the position of a marker normally leaves the marker either in
52351front of or after the new text, depending on the marker’s “insertion
52352type” (*note Marker Insertion Types::)—unless the insertion is done with
52353‘insert-before-markers’ (*note Insertion::).
52354
52355   Insertion and deletion in a buffer must check all the markers and
52356relocate them if necessary.  This slows processing in a buffer with a
52357large number of markers.  For this reason, it is a good idea to make a
52358marker point nowhere if you are sure you don’t need it any more.
52359Markers that can no longer be accessed are eventually removed (*note
52360Garbage Collection::).
52361
52362   Because it is common to perform arithmetic operations on a marker
52363position, most of these operations (including ‘+’ and ‘-’) accept
52364markers as arguments.  In such cases, the marker stands for its current
52365position.
52366
52367   Here are examples of creating markers, setting markers, and moving
52368point to markers:
52369
52370     ;; Make a new marker that initially does not point anywhere:
52371     (setq m1 (make-marker))
52372          ⇒ #<marker in no buffer>
52373
52374     ;; Set ‘m1’ to point between the 99th and 100th characters
52375     ;;   in the current buffer:
52376     (set-marker m1 100)
52377          ⇒ #<marker at 100 in markers.texi>
52378
52379     ;; Now insert one character at the beginning of the buffer:
52380     (goto-char (point-min))
52381          ⇒ 1
52382     (insert "Q")
52383          ⇒ nil
52384
52385     ;; ‘m1’ is updated appropriately.
52386     m1
52387          ⇒ #<marker at 101 in markers.texi>
52388
52389     ;; Two markers that point to the same position
52390     ;;   are not ‘eq’, but they are ‘equal’.
52391     (setq m2 (copy-marker m1))
52392          ⇒ #<marker at 101 in markers.texi>
52393     (eq m1 m2)
52394          ⇒ nil
52395     (equal m1 m2)
52396          ⇒ t
52397
52398     ;; When you are finished using a marker, make it point nowhere.
52399     (set-marker m1 nil)
52400          ⇒ #<marker in no buffer>
52401
52402
52403File: elisp.info,  Node: Predicates on Markers,  Next: Creating Markers,  Prev: Overview of Markers,  Up: Markers
52404
5240531.2 Predicates on Markers
52406==========================
52407
52408You can test an object to see whether it is a marker, or whether it is
52409either an integer or a marker.  The latter test is useful in connection
52410with the arithmetic functions that work with both markers and integers.
52411
52412 -- Function: markerp object
52413     This function returns ‘t’ if OBJECT is a marker, ‘nil’ otherwise.
52414     Note that integers are not markers, even though many functions will
52415     accept either a marker or an integer.
52416
52417 -- Function: integer-or-marker-p object
52418     This function returns ‘t’ if OBJECT is an integer or a marker,
52419     ‘nil’ otherwise.
52420
52421 -- Function: number-or-marker-p object
52422     This function returns ‘t’ if OBJECT is a number (either integer or
52423     floating point) or a marker, ‘nil’ otherwise.
52424
52425
52426File: elisp.info,  Node: Creating Markers,  Next: Information from Markers,  Prev: Predicates on Markers,  Up: Markers
52427
5242831.3 Functions that Create Markers
52429==================================
52430
52431When you create a new marker, you can make it point nowhere, or point to
52432the present position of point, or to the beginning or end of the
52433accessible portion of the buffer, or to the same place as another given
52434marker.
52435
52436   The next four functions all return markers with insertion type ‘nil’.
52437*Note Marker Insertion Types::.
52438
52439 -- Function: make-marker
52440     This function returns a newly created marker that does not point
52441     anywhere.
52442
52443          (make-marker)
52444               ⇒ #<marker in no buffer>
52445
52446 -- Function: point-marker
52447     This function returns a new marker that points to the present
52448     position of point in the current buffer.  *Note Point::.  For an
52449     example, see ‘copy-marker’, below.
52450
52451 -- Function: point-min-marker
52452     This function returns a new marker that points to the beginning of
52453     the accessible portion of the buffer.  This will be the beginning
52454     of the buffer unless narrowing is in effect.  *Note Narrowing::.
52455
52456 -- Function: point-max-marker
52457     This function returns a new marker that points to the end of the
52458     accessible portion of the buffer.  This will be the end of the
52459     buffer unless narrowing is in effect.  *Note Narrowing::.
52460
52461     Here are examples of this function and ‘point-min-marker’, shown in
52462     a buffer containing a version of the source file for the text of
52463     this chapter.
52464
52465          (point-min-marker)
52466               ⇒ #<marker at 1 in markers.texi>
52467          (point-max-marker)
52468               ⇒ #<marker at 24080 in markers.texi>
52469
52470          (narrow-to-region 100 200)
52471               ⇒ nil
52472          (point-min-marker)
52473               ⇒ #<marker at 100 in markers.texi>
52474          (point-max-marker)
52475               ⇒ #<marker at 200 in markers.texi>
52476
52477 -- Function: copy-marker &optional marker-or-integer insertion-type
52478     If passed a marker as its argument, ‘copy-marker’ returns a new
52479     marker that points to the same place and the same buffer as does
52480     MARKER-OR-INTEGER.  If passed an integer as its argument,
52481     ‘copy-marker’ returns a new marker that points to position
52482     MARKER-OR-INTEGER in the current buffer.
52483
52484     The new marker’s insertion type is specified by the argument
52485     INSERTION-TYPE.  *Note Marker Insertion Types::.
52486
52487          (copy-marker 0)
52488               ⇒ #<marker at 1 in markers.texi>
52489
52490          (copy-marker 90000)
52491               ⇒ #<marker at 24080 in markers.texi>
52492
52493     An error is signaled if MARKER is neither a marker nor an integer.
52494
52495   Two distinct markers are considered ‘equal’ (even though not ‘eq’) to
52496each other if they have the same position and buffer, or if they both
52497point nowhere.
52498
52499     (setq p (point-marker))
52500          ⇒ #<marker at 2139 in markers.texi>
52501
52502     (setq q (copy-marker p))
52503          ⇒ #<marker at 2139 in markers.texi>
52504
52505     (eq p q)
52506          ⇒ nil
52507
52508     (equal p q)
52509          ⇒ t
52510
52511
52512File: elisp.info,  Node: Information from Markers,  Next: Marker Insertion Types,  Prev: Creating Markers,  Up: Markers
52513
5251431.4 Information from Markers
52515=============================
52516
52517This section describes the functions for accessing the components of a
52518marker object.
52519
52520 -- Function: marker-position marker
52521     This function returns the position that MARKER points to, or ‘nil’
52522     if it points nowhere.
52523
52524 -- Function: marker-buffer marker
52525     This function returns the buffer that MARKER points into, or ‘nil’
52526     if it points nowhere.
52527
52528          (setq m (make-marker))
52529               ⇒ #<marker in no buffer>
52530          (marker-position m)
52531               ⇒ nil
52532          (marker-buffer m)
52533               ⇒ nil
52534
52535          (set-marker m 3770 (current-buffer))
52536               ⇒ #<marker at 3770 in markers.texi>
52537          (marker-buffer m)
52538               ⇒ #<buffer markers.texi>
52539          (marker-position m)
52540               ⇒ 3770
52541
52542
52543File: elisp.info,  Node: Marker Insertion Types,  Next: Moving Markers,  Prev: Information from Markers,  Up: Markers
52544
5254531.5 Marker Insertion Types
52546===========================
52547
52548When you insert text directly at the place where a marker points, there
52549are two possible ways to relocate that marker: it can point before the
52550inserted text, or point after it.  You can specify which one a given
52551marker should do by setting its “insertion type”.  Note that use of
52552‘insert-before-markers’ ignores markers’ insertion types, always
52553relocating a marker to point after the inserted text.
52554
52555 -- Function: set-marker-insertion-type marker type
52556     This function sets the insertion type of marker MARKER to TYPE.  If
52557     TYPE is ‘t’, MARKER will advance when text is inserted at its
52558     position.  If TYPE is ‘nil’, MARKER does not advance when text is
52559     inserted there.
52560
52561 -- Function: marker-insertion-type marker
52562     This function reports the current insertion type of MARKER.
52563
52564   All functions that create markers without accepting an argument that
52565specifies the insertion type, create them with insertion type ‘nil’
52566(*note Creating Markers::).  Also, the mark has, by default, insertion
52567type ‘nil’.
52568
52569
52570File: elisp.info,  Node: Moving Markers,  Next: The Mark,  Prev: Marker Insertion Types,  Up: Markers
52571
5257231.6 Moving Marker Positions
52573============================
52574
52575This section describes how to change the position of an existing marker.
52576When you do this, be sure you know whether the marker is used outside of
52577your program, and, if so, what effects will result from moving
52578it—otherwise, confusing things may happen in other parts of Emacs.
52579
52580 -- Function: set-marker marker position &optional buffer
52581     This function moves MARKER to POSITION in BUFFER.  If BUFFER is not
52582     provided, it defaults to the current buffer.
52583
52584     If POSITION is ‘nil’ or a marker that points nowhere, then MARKER
52585     is set to point nowhere.
52586
52587     The value returned is MARKER.
52588
52589          (setq m (point-marker))
52590               ⇒ #<marker at 4714 in markers.texi>
52591          (set-marker m 55)
52592               ⇒ #<marker at 55 in markers.texi>
52593          (setq b (get-buffer "foo"))
52594               ⇒ #<buffer foo>
52595          (set-marker m 0 b)
52596               ⇒ #<marker at 1 in foo>
52597
52598 -- Function: move-marker marker position &optional buffer
52599     This is another name for ‘set-marker’.
52600
52601
52602File: elisp.info,  Node: The Mark,  Next: The Region,  Prev: Moving Markers,  Up: Markers
52603
5260431.7 The Mark
52605=============
52606
52607Each buffer has a special marker, which is designated “the mark”.  When
52608a buffer is newly created, this marker exists but does not point
52609anywhere; this means that the mark doesn’t exist in that buffer yet.
52610Subsequent commands can set the mark.
52611
52612   The mark specifies a position to bound a range of text for many
52613commands, such as ‘kill-region’ and ‘indent-rigidly’.  These commands
52614typically act on the text between point and the mark, which is called
52615the “region”.  If you are writing a command that operates on the region,
52616don’t examine the mark directly; instead, use ‘interactive’ with the ‘r’
52617specification.  This provides the values of point and the mark as
52618arguments to the command in an interactive call, but permits other Lisp
52619programs to specify arguments explicitly.  *Note Interactive Codes::.
52620
52621   Some commands set the mark as a side-effect.  Commands should do this
52622only if it has a potential use to the user, and never for their own
52623internal purposes.  For example, the ‘replace-regexp’ command sets the
52624mark to the value of point before doing any replacements, because this
52625enables the user to move back there conveniently after the replace is
52626finished.
52627
52628   Once the mark exists in a buffer, it normally never ceases to exist.
52629However, it may become “inactive”, if Transient Mark mode is enabled.
52630The buffer-local variable ‘mark-active’, if non-‘nil’, means that the
52631mark is active.  A command can call the function ‘deactivate-mark’ to
52632deactivate the mark directly, or it can request deactivation of the mark
52633upon return to the editor command loop by setting the variable
52634‘deactivate-mark’ to a non-‘nil’ value.
52635
52636   If Transient Mark mode is enabled, certain editing commands that
52637normally apply to text near point, apply instead to the region when the
52638mark is active.  This is the main motivation for using Transient Mark
52639mode.  (Another is that this enables highlighting of the region when the
52640mark is active.  *Note Display::.)
52641
52642   In addition to the mark, each buffer has a “mark ring” which is a
52643list of markers containing previous values of the mark.  When editing
52644commands change the mark, they should normally save the old value of the
52645mark on the mark ring.  The variable ‘mark-ring-max’ specifies the
52646maximum number of entries in the mark ring; once the list becomes this
52647long, adding a new element deletes the last element.
52648
52649   There is also a separate global mark ring, but that is used only in a
52650few particular user-level commands, and is not relevant to Lisp
52651programming.  So we do not describe it here.
52652
52653 -- Function: mark &optional force
52654     This function returns the current buffer’s mark position as an
52655     integer, or ‘nil’ if no mark has ever been set in this buffer.
52656
52657     If Transient Mark mode is enabled, and ‘mark-even-if-inactive’ is
52658     ‘nil’, ‘mark’ signals an error if the mark is inactive.  However,
52659     if FORCE is non-‘nil’, then ‘mark’ disregards inactivity of the
52660     mark, and returns the mark position (or ‘nil’) anyway.
52661
52662 -- Function: mark-marker
52663     This function returns the marker that represents the current
52664     buffer’s mark.  It is not a copy, it is the marker used internally.
52665     Therefore, changing this marker’s position will directly affect the
52666     buffer’s mark.  Don’t do that unless that is the effect you want.
52667
52668          (setq m (mark-marker))
52669               ⇒ #<marker at 3420 in markers.texi>
52670          (set-marker m 100)
52671               ⇒ #<marker at 100 in markers.texi>
52672          (mark-marker)
52673               ⇒ #<marker at 100 in markers.texi>
52674
52675     Like any marker, this marker can be set to point at any buffer you
52676     like.  If you make it point at any buffer other than the one of
52677     which it is the mark, it will yield perfectly consistent, but
52678     rather odd, results.  We recommend that you not do it!
52679
52680 -- Function: set-mark position
52681     This function sets the mark to POSITION, and activates the mark.
52682     The old value of the mark is _not_ pushed onto the mark ring.
52683
52684     *Please note:* Use this function only if you want the user to see
52685     that the mark has moved, and you want the previous mark position to
52686     be lost.  Normally, when a new mark is set, the old one should go
52687     on the ‘mark-ring’.  For this reason, most applications should use
52688     ‘push-mark’ and ‘pop-mark’, not ‘set-mark’.
52689
52690     Novice Emacs Lisp programmers often try to use the mark for the
52691     wrong purposes.  The mark saves a location for the user’s
52692     convenience.  An editing command should not alter the mark unless
52693     altering the mark is part of the user-level functionality of the
52694     command.  (And, in that case, this effect should be documented.)
52695     To remember a location for internal use in the Lisp program, store
52696     it in a Lisp variable.  For example:
52697
52698          (let ((beg (point)))
52699            (forward-line 1)
52700            (delete-region beg (point))).
52701
52702 -- Function: push-mark &optional position nomsg activate
52703     This function sets the current buffer’s mark to POSITION, and
52704     pushes a copy of the previous mark onto ‘mark-ring’.  If POSITION
52705     is ‘nil’, then the value of point is used.
52706
52707     The function ‘push-mark’ normally _does not_ activate the mark.  To
52708     do that, specify ‘t’ for the argument ACTIVATE.
52709
52710     A ‘Mark set’ message is displayed unless NOMSG is non-‘nil’.
52711
52712 -- Function: pop-mark
52713     This function pops off the top element of ‘mark-ring’ and makes
52714     that mark become the buffer’s actual mark.  This does not move
52715     point in the buffer, and it does nothing if ‘mark-ring’ is empty.
52716     It deactivates the mark.
52717
52718 -- User Option: transient-mark-mode
52719     This variable, if non-‘nil’, enables Transient Mark mode.  In
52720     Transient Mark mode, every buffer-modifying primitive sets
52721     ‘deactivate-mark’.  As a consequence, most commands that modify the
52722     buffer also deactivate the mark.
52723
52724     When Transient Mark mode is enabled and the mark is active, many
52725     commands that normally apply to the text near point instead apply
52726     to the region.  Such commands should use the function
52727     ‘use-region-p’ to test whether they should operate on the region.
52728     *Note The Region::.
52729
52730     Lisp programs can set ‘transient-mark-mode’ to non-‘nil’, non-‘t’
52731     values to enable Transient Mark mode temporarily.  If the value is
52732     ‘lambda’, Transient Mark mode is automatically turned off after any
52733     action, such as buffer modification, that would normally deactivate
52734     the mark.  If the value is ‘(only . OLDVAL)’, then
52735     ‘transient-mark-mode’ is set to the value OLDVAL after any
52736     subsequent command that moves point and is not shift-translated
52737     (*note shift-translation: Key Sequence Input.), or after any other
52738     action that would normally deactivate the mark.
52739
52740 -- User Option: mark-even-if-inactive
52741     If this is non-‘nil’, Lisp programs and the Emacs user can use the
52742     mark even when it is inactive.  This option affects the behavior of
52743     Transient Mark mode.  When the option is non-‘nil’, deactivation of
52744     the mark turns off region highlighting, but commands that use the
52745     mark behave as if the mark were still active.
52746
52747 -- Variable: deactivate-mark
52748     If an editor command sets this variable non-‘nil’, then the editor
52749     command loop deactivates the mark after the command returns (if
52750     Transient Mark mode is enabled).  All the primitives that change
52751     the buffer set ‘deactivate-mark’, to deactivate the mark when the
52752     command is finished.  Setting this variable makes it buffer-local.
52753
52754     To write Lisp code that modifies the buffer without causing
52755     deactivation of the mark at the end of the command, bind
52756     ‘deactivate-mark’ to ‘nil’ around the code that does the
52757     modification.  For example:
52758
52759          (let (deactivate-mark)
52760            (insert " "))
52761
52762 -- Function: deactivate-mark &optional force
52763     If Transient Mark mode is enabled or FORCE is non-‘nil’, this
52764     function deactivates the mark and runs the normal hook
52765     ‘deactivate-mark-hook’.  Otherwise, it does nothing.
52766
52767 -- Variable: mark-active
52768     The mark is active when this variable is non-‘nil’.  This variable
52769     is always buffer-local in each buffer.  Do _not_ use the value of
52770     this variable to decide whether a command that normally operates on
52771     text near point should operate on the region instead.  Use the
52772     function ‘use-region-p’ for that (*note The Region::).
52773
52774 -- Variable: activate-mark-hook
52775 -- Variable: deactivate-mark-hook
52776     These normal hooks are run, respectively, when the mark becomes
52777     active and when it becomes inactive.  The hook ‘activate-mark-hook’
52778     is also run when the region is reactivated, for instance after
52779     using a command that switches back to a buffer that has an active
52780     mark.
52781
52782 -- Function: handle-shift-selection
52783     This function implements the shift-selection behavior of
52784     point-motion commands.  *Note (emacs)Shift Selection::.  It is
52785     called automatically by the Emacs command loop whenever a command
52786     with a ‘^’ character in its ‘interactive’ spec is invoked, before
52787     the command itself is executed (*note ^: Interactive Codes.).
52788
52789     If ‘shift-select-mode’ is non-‘nil’ and the current command was
52790     invoked via shift translation (*note shift-translation: Key
52791     Sequence Input.), this function sets the mark and temporarily
52792     activates the region, unless the region was already temporarily
52793     activated in this way.  Otherwise, if the region has been activated
52794     temporarily, it deactivates the mark and restores the variable
52795     ‘transient-mark-mode’ to its earlier value.
52796
52797 -- Variable: mark-ring
52798     The value of this buffer-local variable is the list of saved former
52799     marks of the current buffer, most recent first.
52800
52801          mark-ring
52802          ⇒ (#<marker at 11050 in markers.texi>
52803              #<marker at 10832 in markers.texi>
52804              ...)
52805
52806 -- User Option: mark-ring-max
52807     The value of this variable is the maximum size of ‘mark-ring’.  If
52808     more marks than this are pushed onto the ‘mark-ring’, ‘push-mark’
52809     discards an old mark when it adds a new one.
52810
52811   When Delete Selection mode (*note Delete Selection: (emacs)Using
52812Region.) is enabled, commands that operate on the active region (a.k.a.
52813“selection”) behave slightly differently.  This works by adding the
52814function ‘delete-selection-pre-hook’ to the ‘pre-command-hook’ (*note
52815Command Overview::).  That function calls ‘delete-selection-helper’ to
52816delete the selection as appropriate for the command.  If you want to
52817adapt a command to Delete Selection mode, put the ‘delete-selection’
52818property on the function’s symbol (*note Symbol Plists::); commands that
52819don’t have this property on their symbol won’t delete the selection.
52820This property can have one of several values to tailor the behavior to
52821what the command is supposed to do; see the doc strings of
52822‘delete-selection-pre-hook’ and ‘delete-selection-helper’ for the
52823details.
52824
52825
52826File: elisp.info,  Node: The Region,  Prev: The Mark,  Up: Markers
52827
5282831.8 The Region
52829===============
52830
52831The text between point and the mark is known as “the region”.  Various
52832functions operate on text delimited by point and the mark, but only
52833those functions specifically related to the region itself are described
52834here.
52835
52836   The next two functions signal an error if the mark does not point
52837anywhere.  If Transient Mark mode is enabled and ‘mark-even-if-inactive’
52838is ‘nil’, they also signal an error if the mark is inactive.
52839
52840 -- Function: region-beginning
52841     This function returns the position of the beginning of the region
52842     (as an integer).  This is the position of either point or the mark,
52843     whichever is smaller.
52844
52845 -- Function: region-end
52846     This function returns the position of the end of the region (as an
52847     integer).  This is the position of either point or the mark,
52848     whichever is larger.
52849
52850   Instead of using ‘region-beginning’ and ‘region-end’, a command
52851designed to operate on a region should normally use ‘interactive’ with
52852the ‘r’ specification to find the beginning and end of the region.  This
52853lets other Lisp programs specify the bounds explicitly as arguments.
52854*Note Interactive Codes::.
52855
52856 -- Function: use-region-p
52857     This function returns ‘t’ if Transient Mark mode is enabled, the
52858     mark is active, and there is a valid region in the buffer.  This
52859     function is intended to be used by commands that operate on the
52860     region, instead of on text near point, when the mark is active.
52861
52862     A region is valid if it has a non-zero size, or if the user option
52863     ‘use-empty-active-region’ is non-‘nil’ (by default, it is ‘nil’).
52864     The function ‘region-active-p’ is similar to ‘use-region-p’, but
52865     considers all regions as valid.  In most cases, you should not use
52866     ‘region-active-p’, since if the region is empty it is often more
52867     appropriate to operate on point.
52868
52869
52870File: elisp.info,  Node: Text,  Next: Non-ASCII Characters,  Prev: Markers,  Up: Top
52871
5287232 Text
52873*******
52874
52875This chapter describes the functions that deal with the text in a
52876buffer.  Most examine, insert, or delete text in the current buffer,
52877often operating at point or on text adjacent to point.  Many are
52878interactive.  All the functions that change the text provide for undoing
52879the changes (*note Undo::).
52880
52881   Many text-related functions operate on a region of text defined by
52882two buffer positions passed in arguments named START and END.  These
52883arguments should be either markers (*note Markers::) or numeric
52884character positions (*note Positions::).  The order of these arguments
52885does not matter; it is all right for START to be the end of the region
52886and END the beginning.  For example, ‘(delete-region 1 10)’ and
52887‘(delete-region 10 1)’ are equivalent.  An ‘args-out-of-range’ error is
52888signaled if either START or END is outside the accessible portion of the
52889buffer.  In an interactive call, point and the mark are used for these
52890arguments.
52891
52892   Throughout this chapter, “text” refers to the characters in the
52893buffer, together with their properties (when relevant).  Keep in mind
52894that point is always between two characters, and the cursor appears on
52895the character after point.
52896
52897* Menu:
52898
52899* Near Point::       Examining text in the vicinity of point.
52900* Buffer Contents::  Examining text in a general fashion.
52901* Comparing Text::   Comparing substrings of buffers.
52902* Insertion::        Adding new text to a buffer.
52903* Commands for Insertion::  User-level commands to insert text.
52904* Deletion::         Removing text from a buffer.
52905* User-Level Deletion::     User-level commands to delete text.
52906* The Kill Ring::    Where removed text sometimes is saved for later use.
52907* Undo::             Undoing changes to the text of a buffer.
52908* Maintaining Undo:: How to enable and disable undo information.
52909                        How to control how much information is kept.
52910* Filling::          Functions for explicit filling.
52911* Margins::          How to specify margins for filling commands.
52912* Adaptive Fill::    Adaptive Fill mode chooses a fill prefix from context.
52913* Auto Filling::     How auto-fill mode is implemented to break lines.
52914* Sorting::          Functions for sorting parts of the buffer.
52915* Columns::          Computing horizontal positions, and using them.
52916* Indentation::      Functions to insert or adjust indentation.
52917* Case Changes::     Case conversion of parts of the buffer.
52918* Text Properties::  Assigning Lisp property lists to text characters.
52919* Substitution::     Replacing a given character wherever it appears.
52920* Registers::        How registers are implemented.  Accessing the text or
52921                       position stored in a register.
52922* Transposition::    Swapping two portions of a buffer.
52923* Replacing::        Replacing the text of one buffer with the text
52924                       of another buffer.
52925* Decompression::    Dealing with compressed data.
52926* Base 64::          Conversion to or from base 64 encoding.
52927* Checksum/Hash::    Computing cryptographic hashes.
52928* GnuTLS Cryptography:: Cryptographic algorithms imported from GnuTLS.
52929* Parsing HTML/XML:: Parsing HTML and XML.
52930* Parsing JSON::     Parsing and generating JSON values.
52931* JSONRPC::          JSON Remote Procedure Call protocol
52932* Atomic Changes::   Installing several buffer changes atomically.
52933* Change Hooks::     Supplying functions to be run when text is changed.
52934
52935
52936File: elisp.info,  Node: Near Point,  Next: Buffer Contents,  Up: Text
52937
5293832.1 Examining Text Near Point
52939==============================
52940
52941Many functions are provided to look at the characters around point.
52942Several simple functions are described here.  See also ‘looking-at’ in
52943*note Regexp Search::.
52944
52945   In the following four functions, “beginning” or “end” of buffer
52946refers to the beginning or end of the accessible portion.
52947
52948 -- Function: char-after &optional position
52949     This function returns the character in the current buffer at (i.e.,
52950     immediately after) position POSITION.  If POSITION is out of range
52951     for this purpose, either before the beginning of the buffer, or at
52952     or beyond the end, then the value is ‘nil’.  The default for
52953     POSITION is point.
52954
52955     In the following example, assume that the first character in the
52956     buffer is ‘@’:
52957
52958          (string (char-after 1))
52959               ⇒ "@"
52960
52961 -- Function: char-before &optional position
52962     This function returns the character in the current buffer
52963     immediately before position POSITION.  If POSITION is out of range
52964     for this purpose, either at or before the beginning of the buffer,
52965     or beyond the end, then the value is ‘nil’.  The default for
52966     POSITION is point.
52967
52968 -- Function: following-char
52969     This function returns the character following point in the current
52970     buffer.  This is similar to ‘(char-after (point))’.  However, if
52971     point is at the end of the buffer, then ‘following-char’ returns 0.
52972
52973     Remember that point is always between characters, and the cursor
52974     normally appears over the character following point.  Therefore,
52975     the character returned by ‘following-char’ is the character the
52976     cursor is over.
52977
52978     In this example, point is between the ‘a’ and the ‘c’.
52979
52980          ---------- Buffer: foo ----------
52981          Gentlemen may cry ``Pea★ce! Peace!,''
52982          but there is no peace.
52983          ---------- Buffer: foo ----------
52984
52985          (string (preceding-char))
52986               ⇒ "a"
52987          (string (following-char))
52988               ⇒ "c"
52989
52990 -- Function: preceding-char
52991     This function returns the character preceding point in the current
52992     buffer.  See above, under ‘following-char’, for an example.  If
52993     point is at the beginning of the buffer, ‘preceding-char’ returns
52994     0.
52995
52996 -- Function: bobp
52997     This function returns ‘t’ if point is at the beginning of the
52998     buffer.  If narrowing is in effect, this means the beginning of the
52999     accessible portion of the text.  See also ‘point-min’ in *note
53000     Point::.
53001
53002 -- Function: eobp
53003     This function returns ‘t’ if point is at the end of the buffer.  If
53004     narrowing is in effect, this means the end of accessible portion of
53005     the text.  See also ‘point-max’ in *Note Point::.
53006
53007 -- Function: bolp
53008     This function returns ‘t’ if point is at the beginning of a line.
53009     *Note Text Lines::.  The beginning of the buffer (or of its
53010     accessible portion) always counts as the beginning of a line.
53011
53012 -- Function: eolp
53013     This function returns ‘t’ if point is at the end of a line.  The
53014     end of the buffer (or of its accessible portion) is always
53015     considered the end of a line.
53016
53017
53018File: elisp.info,  Node: Buffer Contents,  Next: Comparing Text,  Prev: Near Point,  Up: Text
53019
5302032.2 Examining Buffer Contents
53021==============================
53022
53023This section describes functions that allow a Lisp program to convert
53024any portion of the text in the buffer into a string.
53025
53026 -- Function: buffer-substring start end
53027     This function returns a string containing a copy of the text of the
53028     region defined by positions START and END in the current buffer.
53029     If the arguments are not positions in the accessible portion of the
53030     buffer, ‘buffer-substring’ signals an ‘args-out-of-range’ error.
53031
53032     Here’s an example which assumes Font-Lock mode is not enabled:
53033
53034          ---------- Buffer: foo ----------
53035          This is the contents of buffer foo
53036
53037          ---------- Buffer: foo ----------
53038
53039          (buffer-substring 1 10)
53040               ⇒ "This is t"
53041          (buffer-substring (point-max) 10)
53042               ⇒ "he contents of buffer foo\n"
53043
53044     If the text being copied has any text properties, these are copied
53045     into the string along with the characters they belong to.  *Note
53046     Text Properties::.  However, overlays (*note Overlays::) in the
53047     buffer and their properties are ignored, not copied.
53048
53049     For example, if Font-Lock mode is enabled, you might get results
53050     like these:
53051
53052          (buffer-substring 1 10)
53053               ⇒ #("This is t" 0 1 (fontified t) 1 9 (fontified t))
53054
53055 -- Function: buffer-substring-no-properties start end
53056     This is like ‘buffer-substring’, except that it does not copy text
53057     properties, just the characters themselves.  *Note Text
53058     Properties::.
53059
53060 -- Function: buffer-string
53061     This function returns the contents of the entire accessible portion
53062     of the current buffer, as a string.  If the text being copied has
53063     any text properties, these are copied into the string along with
53064     the characters they belong to.
53065
53066   If you need to make sure the resulting string, when copied to a
53067different location, will not change its visual appearance due to
53068reordering of bidirectional text, use the
53069‘buffer-substring-with-bidi-context’ function (*note
53070buffer-substring-with-bidi-context: Bidirectional Display.).
53071
53072 -- Function: filter-buffer-substring start end &optional delete
53073     This function filters the buffer text between START and END using a
53074     function specified by the variable
53075     ‘filter-buffer-substring-function’, and returns the result.
53076
53077     The default filter function consults the obsolete wrapper hook
53078     ‘filter-buffer-substring-functions’ (see the documentation string
53079     of the macro ‘with-wrapper-hook’ for the details about this
53080     obsolete facility), and the obsolete variable
53081     ‘buffer-substring-filters’.  If both of these are ‘nil’, it returns
53082     the unaltered text from the buffer, i.e., what ‘buffer-substring’
53083     would return.
53084
53085     If DELETE is non-‘nil’, the function deletes the text between START
53086     and END after copying it, like ‘delete-and-extract-region’.
53087
53088     Lisp code should use this function instead of ‘buffer-substring’,
53089     ‘buffer-substring-no-properties’, or ‘delete-and-extract-region’
53090     when copying into user-accessible data structures such as the
53091     kill-ring, X clipboard, and registers.  Major and minor modes can
53092     modify ‘filter-buffer-substring-function’ to alter such text as it
53093     is copied out of the buffer.
53094
53095 -- Variable: filter-buffer-substring-function
53096     The value of this variable is a function that
53097     ‘filter-buffer-substring’ will call to do the actual work.  The
53098     function receives three arguments, the same as those of
53099     ‘filter-buffer-substring’, which it should treat as per the
53100     documentation of that function.  It should return the filtered text
53101     (and optionally delete the source text).
53102
53103The following two variables are obsoleted by
53104‘filter-buffer-substring-function’, but are still supported for backward
53105compatibility.
53106
53107 -- Variable: filter-buffer-substring-functions
53108     This obsolete variable is a wrapper hook, whose members should be
53109     functions that accept four arguments: FUN, START, END, and DELETE.
53110     FUN is a function that takes three arguments (START, END, and
53111     DELETE), and returns a string.  In both cases, the START, END, and
53112     DELETE arguments are the same as those of
53113     ‘filter-buffer-substring’.
53114
53115     The first hook function is passed a FUN that is equivalent to the
53116     default operation of ‘filter-buffer-substring’, i.e., it returns
53117     the buffer-substring between START and END (processed by any
53118     ‘buffer-substring-filters’) and optionally deletes the original
53119     text from the buffer.  In most cases, the hook function will call
53120     FUN once, and then do its own processing of the result.  The next
53121     hook function receives a FUN equivalent to this, and so on.  The
53122     actual return value is the result of all the hook functions acting
53123     in sequence.
53124
53125 -- Variable: buffer-substring-filters
53126     The value of this obsolete variable should be a list of functions
53127     that accept a single string argument and return another string.
53128     The default ‘filter-buffer-substring’ function passes the buffer
53129     substring to the first function in this list, and the return value
53130     of each function is passed to the next function.  The return value
53131     of the last function is passed to
53132     ‘filter-buffer-substring-functions’.
53133
53134 -- Function: current-word &optional strict really-word
53135     This function returns the symbol (or word) at or near point, as a
53136     string.  The return value includes no text properties.
53137
53138     If the optional argument REALLY-WORD is non-‘nil’, it finds a word;
53139     otherwise, it finds a symbol (which includes both word characters
53140     and symbol constituent characters).
53141
53142     If the optional argument STRICT is non-‘nil’, then point must be in
53143     or next to the symbol or word—if no symbol or word is there, the
53144     function returns ‘nil’.  Otherwise, a nearby symbol or word on the
53145     same line is acceptable.
53146
53147 -- Function: thing-at-point thing &optional no-properties
53148     Return the THING around or next to point, as a string.
53149
53150     The argument THING is a symbol which specifies a kind of syntactic
53151     entity.  Possibilities include ‘symbol’, ‘list’, ‘sexp’, ‘defun’,
53152     ‘filename’, ‘url’, ‘word’, ‘sentence’, ‘whitespace’, ‘line’,
53153     ‘page’, and others.
53154
53155     When the optional argument NO-PROPERTIES is non-‘nil’, this
53156     function strips text properties from the return value.
53157
53158          ---------- Buffer: foo ----------
53159          Gentlemen may cry ``Pea★ce! Peace!,''
53160          but there is no peace.
53161          ---------- Buffer: foo ----------
53162
53163          (thing-at-point 'word)
53164               ⇒ "Peace"
53165          (thing-at-point 'line)
53166               ⇒ "Gentlemen may cry ``Peace! Peace!,''\n"
53167          (thing-at-point 'whitespace)
53168               ⇒ nil
53169
53170
53171File: elisp.info,  Node: Comparing Text,  Next: Insertion,  Prev: Buffer Contents,  Up: Text
53172
5317332.3 Comparing Text
53174===================
53175
53176This function lets you compare portions of the text in a buffer, without
53177copying them into strings first.
53178
53179 -- Function: compare-buffer-substrings buffer1 start1 end1 buffer2
53180          start2 end2
53181     This function lets you compare two substrings of the same buffer or
53182     two different buffers.  The first three arguments specify one
53183     substring, giving a buffer (or a buffer name) and two positions
53184     within the buffer.  The last three arguments specify the other
53185     substring in the same way.  You can use ‘nil’ for BUFFER1, BUFFER2,
53186     or both to stand for the current buffer.
53187
53188     The value is negative if the first substring is less, positive if
53189     the first is greater, and zero if they are equal.  The absolute
53190     value of the result is one plus the index of the first differing
53191     characters within the substrings.
53192
53193     This function ignores case when comparing characters if
53194     ‘case-fold-search’ is non-‘nil’.  It always ignores text
53195     properties.
53196
53197     Suppose you have the text ‘foobarbar haha!rara!’ in the current
53198     buffer; then in this example the two substrings are ‘rbar ’ and
53199     ‘rara!’.  The value is 2 because the first substring is greater at
53200     the second character.
53201
53202          (compare-buffer-substrings nil 6 11 nil 16 21)
53203               ⇒ 2
53204
53205
53206File: elisp.info,  Node: Insertion,  Next: Commands for Insertion,  Prev: Comparing Text,  Up: Text
53207
5320832.4 Inserting Text
53209===================
53210
53211“Insertion” means adding new text to a buffer.  The inserted text goes
53212at point—between the character before point and the character after
53213point.  Some insertion functions leave point before the inserted text,
53214while other functions leave it after.  We call the former insertion
53215“after point” and the latter insertion “before point”.
53216
53217   Insertion moves markers located at positions after the insertion
53218point, so that they stay with the surrounding text (*note Markers::).
53219When a marker points at the place of insertion, insertion may or may not
53220relocate the marker, depending on the marker’s insertion type (*note
53221Marker Insertion Types::).  Certain special functions such as
53222‘insert-before-markers’ relocate all such markers to point after the
53223inserted text, regardless of the markers’ insertion type.
53224
53225   Insertion functions signal an error if the current buffer is
53226read-only (*note Read Only Buffers::) or if they insert within read-only
53227text (*note Special Properties::).
53228
53229   These functions copy text characters from strings and buffers along
53230with their properties.  The inserted characters have exactly the same
53231properties as the characters they were copied from.  By contrast,
53232characters specified as separate arguments, not part of a string or
53233buffer, inherit their text properties from the neighboring text.
53234
53235   The insertion functions convert text from unibyte to multibyte in
53236order to insert in a multibyte buffer, and vice versa—if the text comes
53237from a string or from a buffer.  However, they do not convert unibyte
53238character codes 128 through 255 to multibyte characters, not even if the
53239current buffer is a multibyte buffer.  *Note Converting
53240Representations::.
53241
53242 -- Function: insert &rest args
53243     This function inserts the strings and/or characters ARGS into the
53244     current buffer, at point, moving point forward.  In other words, it
53245     inserts the text before point.  An error is signaled unless all
53246     ARGS are either strings or characters.  The value is ‘nil’.
53247
53248 -- Function: insert-before-markers &rest args
53249     This function inserts the strings and/or characters ARGS into the
53250     current buffer, at point, moving point forward.  An error is
53251     signaled unless all ARGS are either strings or characters.  The
53252     value is ‘nil’.
53253
53254     This function is unlike the other insertion functions in that it
53255     relocates markers initially pointing at the insertion point, to
53256     point after the inserted text.  If an overlay begins at the
53257     insertion point, the inserted text falls outside the overlay; if a
53258     nonempty overlay ends at the insertion point, the inserted text
53259     falls inside that overlay.
53260
53261 -- Command: insert-char character &optional count inherit
53262     This command inserts COUNT instances of CHARACTER into the current
53263     buffer before point.  The argument COUNT must be an integer, and
53264     CHARACTER must be a character.
53265
53266     If called interactively, this command prompts for CHARACTER using
53267     its Unicode name or its code point.  *Note (emacs)Inserting Text::.
53268
53269     This function does not convert unibyte character codes 128 through
53270     255 to multibyte characters, not even if the current buffer is a
53271     multibyte buffer.  *Note Converting Representations::.
53272
53273     If INHERIT is non-‘nil’, the inserted characters inherit sticky
53274     text properties from the two characters before and after the
53275     insertion point.  *Note Sticky Properties::.
53276
53277 -- Function: insert-buffer-substring from-buffer-or-name &optional
53278          start end
53279     This function inserts a portion of buffer FROM-BUFFER-OR-NAME into
53280     the current buffer before point.  The text inserted is the region
53281     between START (inclusive) and END (exclusive).  (These arguments
53282     default to the beginning and end of the accessible portion of that
53283     buffer.)  This function returns ‘nil’.
53284
53285     In this example, the form is executed with buffer ‘bar’ as the
53286     current buffer.  We assume that buffer ‘bar’ is initially empty.
53287
53288          ---------- Buffer: foo ----------
53289          We hold these truths to be self-evident, that all
53290          ---------- Buffer: foo ----------
53291
53292          (insert-buffer-substring "foo" 1 20)
53293               ⇒ nil
53294
53295          ---------- Buffer: bar ----------
53296          We hold these truth★
53297          ---------- Buffer: bar ----------
53298
53299 -- Function: insert-buffer-substring-no-properties from-buffer-or-name
53300          &optional start end
53301     This is like ‘insert-buffer-substring’ except that it does not copy
53302     any text properties.
53303
53304   *Note Sticky Properties::, for other insertion functions that inherit
53305text properties from the nearby text in addition to inserting it.
53306Whitespace inserted by indentation functions also inherits text
53307properties.
53308
53309
53310File: elisp.info,  Node: Commands for Insertion,  Next: Deletion,  Prev: Insertion,  Up: Text
53311
5331232.5 User-Level Insertion Commands
53313==================================
53314
53315This section describes higher-level commands for inserting text,
53316commands intended primarily for the user but useful also in Lisp
53317programs.
53318
53319 -- Command: insert-buffer from-buffer-or-name
53320     This command inserts the entire accessible contents of
53321     FROM-BUFFER-OR-NAME (which must exist) into the current buffer
53322     after point.  It leaves the mark after the inserted text.  The
53323     value is ‘nil’.
53324
53325 -- Command: self-insert-command count &optional char
53326     This command inserts the character CHAR (the last character typed);
53327     it does so COUNT times, before point, and returns ‘nil’.  Most
53328     printing characters are bound to this command.  In routine use,
53329     ‘self-insert-command’ is the most frequently called function in
53330     Emacs, but programs rarely use it except to install it on a keymap.
53331
53332     In an interactive call, COUNT is the numeric prefix argument.
53333
53334     Self-insertion translates the input character through
53335     ‘translation-table-for-input’.  *Note Translation of Characters::.
53336
53337     This command calls ‘auto-fill-function’ whenever that is non-‘nil’
53338     and the character inserted is in the table ‘auto-fill-chars’ (*note
53339     Auto Filling::).
53340
53341     This command performs abbrev expansion if Abbrev mode is enabled
53342     and the inserted character does not have word-constituent syntax.
53343     (*Note Abbrevs::, and *note Syntax Class Table::.)  It is also
53344     responsible for calling ‘blink-paren-function’ when the inserted
53345     character has close parenthesis syntax (*note Blinking::).
53346
53347     The final thing this command does is to run the hook
53348     ‘post-self-insert-hook’.  You could use this to automatically
53349     reindent text as it is typed, for example.  If any function on this
53350     hook needs to act on the region (*note The Region::), it should
53351     make sure Delete Selection mode (*note Delete Selection:
53352     (emacs)Using Region.) doesn’t delete the region before
53353     ‘post-self-insert-hook’ functions are invoked.  The way to do so is
53354     to add a function that returns ‘nil’ to
53355     ‘self-insert-uses-region-functions’, a special hook that tells
53356     Delete Selection mode it should not delete the region.
53357
53358     Do not try substituting your own definition of
53359     ‘self-insert-command’ for the standard one.  The editor command
53360     loop handles this function specially.
53361
53362 -- Command: newline &optional number-of-newlines interactive
53363     This command inserts newlines into the current buffer before point.
53364     If NUMBER-OF-NEWLINES is supplied, that many newline characters are
53365     inserted.  In an interactive call, NUMBER-OF-NEWLINES is the
53366     numeric prefix argument.
53367
53368     This command calls ‘self-insert-command’ to insert newlines, which
53369     may subsequently break the preceding line by calling
53370     ‘auto-fill-function’ (*note Auto Filling::).  Typically what
53371     ‘auto-fill-function’ does is insert a newline; thus, the overall
53372     result in this case is to insert two newlines at different places:
53373     one at point, and another earlier in the line.  ‘newline’ does not
53374     auto-fill if NUMBER-OF-NEWLINES is non-‘nil’.
53375
53376     This command does not run the hook ‘post-self-insert-hook’ unless
53377     called interactively or INTERACTIVE is non-‘nil’.
53378
53379     This command indents to the left margin if that is not zero.  *Note
53380     Margins::.
53381
53382     The value returned is ‘nil’.
53383
53384 -- Variable: overwrite-mode
53385     This variable controls whether overwrite mode is in effect.  The
53386     value should be ‘overwrite-mode-textual’, ‘overwrite-mode-binary’,
53387     or ‘nil’.  ‘overwrite-mode-textual’ specifies textual overwrite
53388     mode (treats newlines and tabs specially), and
53389     ‘overwrite-mode-binary’ specifies binary overwrite mode (treats
53390     newlines and tabs like any other characters).
53391
53392
53393File: elisp.info,  Node: Deletion,  Next: User-Level Deletion,  Prev: Commands for Insertion,  Up: Text
53394
5339532.6 Deleting Text
53396==================
53397
53398Deletion means removing part of the text in a buffer, without saving it
53399in the kill ring (*note The Kill Ring::).  Deleted text can’t be yanked,
53400but can be reinserted using the undo mechanism (*note Undo::).  Some
53401deletion functions do save text in the kill ring in some special cases.
53402
53403   All of the deletion functions operate on the current buffer.
53404
53405 -- Command: erase-buffer
53406     This function deletes the entire text of the current buffer (_not_
53407     just the accessible portion), leaving it empty.  If the buffer is
53408     read-only, it signals a ‘buffer-read-only’ error; if some of the
53409     text in it is read-only, it signals a ‘text-read-only’ error.
53410     Otherwise, it deletes the text without asking for any confirmation.
53411     It returns ‘nil’.
53412
53413     Normally, deleting a large amount of text from a buffer inhibits
53414     further auto-saving of that buffer because it has shrunk.  However,
53415     ‘erase-buffer’ does not do this, the idea being that the future
53416     text is not really related to the former text, and its size should
53417     not be compared with that of the former text.
53418
53419 -- Command: delete-region start end
53420     This command deletes the text between positions START and END in
53421     the current buffer, and returns ‘nil’.  If point was inside the
53422     deleted region, its value afterward is START.  Otherwise, point
53423     relocates with the surrounding text, as markers do.
53424
53425 -- Function: delete-and-extract-region start end
53426     This function deletes the text between positions START and END in
53427     the current buffer, and returns a string containing the text just
53428     deleted.
53429
53430     If point was inside the deleted region, its value afterward is
53431     START.  Otherwise, point relocates with the surrounding text, as
53432     markers do.
53433
53434 -- Command: delete-char count &optional killp
53435     This command deletes COUNT characters directly after point, or
53436     before point if COUNT is negative.  If KILLP is non-‘nil’, then it
53437     saves the deleted characters in the kill ring.
53438
53439     In an interactive call, COUNT is the numeric prefix argument, and
53440     KILLP is the unprocessed prefix argument.  Therefore, if a prefix
53441     argument is supplied, the text is saved in the kill ring.  If no
53442     prefix argument is supplied, then one character is deleted, but not
53443     saved in the kill ring.
53444
53445     The value returned is always ‘nil’.
53446
53447 -- Command: delete-backward-char count &optional killp
53448     This command deletes COUNT characters directly before point, or
53449     after point if COUNT is negative.  If KILLP is non-‘nil’, then it
53450     saves the deleted characters in the kill ring.
53451
53452     In an interactive call, COUNT is the numeric prefix argument, and
53453     KILLP is the unprocessed prefix argument.  Therefore, if a prefix
53454     argument is supplied, the text is saved in the kill ring.  If no
53455     prefix argument is supplied, then one character is deleted, but not
53456     saved in the kill ring.
53457
53458     The value returned is always ‘nil’.
53459
53460 -- Command: backward-delete-char-untabify count &optional killp
53461     This command deletes COUNT characters backward, changing tabs into
53462     spaces.  When the next character to be deleted is a tab, it is
53463     first replaced with the proper number of spaces to preserve
53464     alignment and then one of those spaces is deleted instead of the
53465     tab.  If KILLP is non-‘nil’, then the command saves the deleted
53466     characters in the kill ring.
53467
53468     Conversion of tabs to spaces happens only if COUNT is positive.  If
53469     it is negative, exactly −COUNT characters after point are deleted.
53470
53471     In an interactive call, COUNT is the numeric prefix argument, and
53472     KILLP is the unprocessed prefix argument.  Therefore, if a prefix
53473     argument is supplied, the text is saved in the kill ring.  If no
53474     prefix argument is supplied, then one character is deleted, but not
53475     saved in the kill ring.
53476
53477     The value returned is always ‘nil’.
53478
53479 -- User Option: backward-delete-char-untabify-method
53480     This option specifies how ‘backward-delete-char-untabify’ should
53481     deal with whitespace.  Possible values include ‘untabify’, the
53482     default, meaning convert a tab to many spaces and delete one;
53483     ‘hungry’, meaning delete all tabs and spaces before point with one
53484     command; ‘all’ meaning delete all tabs, spaces and newlines before
53485     point, and ‘nil’, meaning do nothing special for whitespace
53486     characters.
53487
53488
53489File: elisp.info,  Node: User-Level Deletion,  Next: The Kill Ring,  Prev: Deletion,  Up: Text
53490
5349132.7 User-Level Deletion Commands
53492=================================
53493
53494This section describes higher-level commands for deleting text, commands
53495intended primarily for the user but useful also in Lisp programs.
53496
53497 -- Command: delete-horizontal-space &optional backward-only
53498     This function deletes all spaces and tabs around point.  It returns
53499     ‘nil’.
53500
53501     If BACKWARD-ONLY is non-‘nil’, the function deletes spaces and tabs
53502     before point, but not after point.
53503
53504     In the following examples, we call ‘delete-horizontal-space’ four
53505     times, once on each line, with point between the second and third
53506     characters on the line each time.
53507
53508          ---------- Buffer: foo ----------
53509          I ★thought
53510          I ★     thought
53511          We★ thought
53512          Yo★u thought
53513          ---------- Buffer: foo ----------
53514
53515          (delete-horizontal-space)   ; Four times.
53516               ⇒ nil
53517
53518          ---------- Buffer: foo ----------
53519          Ithought
53520          Ithought
53521          Wethought
53522          You thought
53523          ---------- Buffer: foo ----------
53524
53525 -- Command: delete-indentation &optional join-following-p beg end
53526     This function joins the line point is on to the previous line,
53527     deleting any whitespace at the join and in some cases replacing it
53528     with one space.  If JOIN-FOLLOWING-P is non-‘nil’,
53529     ‘delete-indentation’ joins this line to the following line instead.
53530     Otherwise, if BEG and END are non-‘nil’, this function joins all
53531     lines in the region they define.
53532
53533     In an interactive call, JOIN-FOLLOWING-P is the prefix argument,
53534     and BEG and END are, respectively, the start and end of the region
53535     if it is active, else ‘nil’.  The function returns ‘nil’.
53536
53537     If there is a fill prefix, and the second of the lines being joined
53538     starts with the prefix, then ‘delete-indentation’ deletes the fill
53539     prefix before joining the lines.  *Note Margins::.
53540
53541     In the example below, point is located on the line starting
53542     ‘events’, and it makes no difference if there are trailing spaces
53543     in the preceding line.
53544
53545          ---------- Buffer: foo ----------
53546          When in the course of human
53547          ★    events, it becomes necessary
53548          ---------- Buffer: foo ----------
53549
53550          (delete-indentation)
53551               ⇒ nil
53552
53553          ---------- Buffer: foo ----------
53554          When in the course of human★ events, it becomes necessary
53555          ---------- Buffer: foo ----------
53556
53557     After the lines are joined, the function ‘fixup-whitespace’ is
53558     responsible for deciding whether to leave a space at the junction.
53559
53560 -- Command: fixup-whitespace
53561     This function replaces all the horizontal whitespace surrounding
53562     point with either one space or no space, according to the context.
53563     It returns ‘nil’.
53564
53565     At the beginning or end of a line, the appropriate amount of space
53566     is none.  Before a character with close parenthesis syntax, or
53567     after a character with open parenthesis or expression-prefix
53568     syntax, no space is also appropriate.  Otherwise, one space is
53569     appropriate.  *Note Syntax Class Table::.
53570
53571     In the example below, ‘fixup-whitespace’ is called the first time
53572     with point before the word ‘spaces’ in the first line.  For the
53573     second invocation, point is directly after the ‘(’.
53574
53575          ---------- Buffer: foo ----------
53576          This has too many     ★spaces
53577          This has too many spaces at the start of (★   this list)
53578          ---------- Buffer: foo ----------
53579
53580          (fixup-whitespace)
53581               ⇒ nil
53582          (fixup-whitespace)
53583               ⇒ nil
53584
53585          ---------- Buffer: foo ----------
53586          This has too many spaces
53587          This has too many spaces at the start of (this list)
53588          ---------- Buffer: foo ----------
53589
53590 -- Command: just-one-space &optional n
53591     This command replaces any spaces and tabs around point with a
53592     single space, or N spaces if N is specified.  It returns ‘nil’.
53593
53594 -- Command: delete-blank-lines
53595     This function deletes blank lines surrounding point.  If point is
53596     on a blank line with one or more blank lines before or after it,
53597     then all but one of them are deleted.  If point is on an isolated
53598     blank line, then it is deleted.  If point is on a nonblank line,
53599     the command deletes all blank lines immediately following it.
53600
53601     A blank line is defined as a line containing only tabs and spaces.
53602
53603     ‘delete-blank-lines’ returns ‘nil’.
53604
53605 -- Command: delete-trailing-whitespace &optional start end
53606     Delete trailing whitespace in the region defined by START and END.
53607
53608     This command deletes whitespace characters after the last
53609     non-whitespace character in each line in the region.
53610
53611     If this command acts on the entire buffer (i.e., if called
53612     interactively with the mark inactive, or called from Lisp with END
53613     ‘nil’), it also deletes all trailing lines at the end of the buffer
53614     if the variable ‘delete-trailing-lines’ is non-‘nil’.
53615
53616
53617File: elisp.info,  Node: The Kill Ring,  Next: Undo,  Prev: User-Level Deletion,  Up: Text
53618
5361932.8 The Kill Ring
53620==================
53621
53622“Kill functions” delete text like the deletion functions, but save it so
53623that the user can reinsert it by “yanking”.  Most of these functions
53624have ‘kill-’ in their name.  By contrast, the functions whose names
53625start with ‘delete-’ normally do not save text for yanking (though they
53626can still be undone); these are deletion functions.
53627
53628   Most of the kill commands are primarily for interactive use, and are
53629not described here.  What we do describe are the functions provided for
53630use in writing such commands.  You can use these functions to write
53631commands for killing text.  When you need to delete text for internal
53632purposes within a Lisp function, you should normally use deletion
53633functions, so as not to disturb the kill ring contents.  *Note
53634Deletion::.
53635
53636   Killed text is saved for later yanking in the “kill ring”.  This is a
53637list that holds a number of recent kills, not just the last text kill.
53638We call this a “ring” because yanking treats it as having elements in a
53639cyclic order.  The list is kept in the variable ‘kill-ring’, and can be
53640operated on with the usual functions for lists; there are also
53641specialized functions, described in this section, that treat it as a
53642ring.
53643
53644   Some people think this use of the word “kill” is unfortunate, since
53645it refers to operations that specifically _do not_ destroy the entities
53646killed.  This is in sharp contrast to ordinary life, in which death is
53647permanent and killed entities do not come back to life.  Therefore,
53648other metaphors have been proposed.  For example, the term “cut ring”
53649makes sense to people who, in pre-computer days, used scissors and paste
53650to cut up and rearrange manuscripts.  However, it would be difficult to
53651change the terminology now.
53652
53653* Menu:
53654
53655* Kill Ring Concepts::     What text looks like in the kill ring.
53656* Kill Functions::         Functions that kill text.
53657* Yanking::                How yanking is done.
53658* Yank Commands::          Commands that access the kill ring.
53659* Low-Level Kill Ring::    Functions and variables for kill ring access.
53660* Internals of Kill Ring:: Variables that hold kill ring data.
53661
53662
53663File: elisp.info,  Node: Kill Ring Concepts,  Next: Kill Functions,  Up: The Kill Ring
53664
5366532.8.1 Kill Ring Concepts
53666-------------------------
53667
53668The kill ring records killed text as strings in a list, most recent
53669first.  A short kill ring, for example, might look like this:
53670
53671     ("some text" "a different piece of text" "even older text")
53672
53673When the list reaches ‘kill-ring-max’ entries in length, adding a new
53674entry automatically deletes the last entry.
53675
53676   When kill commands are interwoven with other commands, each kill
53677command makes a new entry in the kill ring.  Multiple kill commands in
53678succession build up a single kill ring entry, which would be yanked as a
53679unit; the second and subsequent consecutive kill commands add text to
53680the entry made by the first one.
53681
53682   For yanking, one entry in the kill ring is designated the front of
53683the ring.  Some yank commands rotate the ring by designating a different
53684element as the front.  But this virtual rotation doesn’t change the list
53685itself—the most recent entry always comes first in the list.
53686
53687
53688File: elisp.info,  Node: Kill Functions,  Next: Yanking,  Prev: Kill Ring Concepts,  Up: The Kill Ring
53689
5369032.8.2 Functions for Killing
53691----------------------------
53692
53693‘kill-region’ is the usual subroutine for killing text.  Any command
53694that calls this function is a kill command (and should probably have
53695‘kill’ in its name).  ‘kill-region’ puts the newly killed text in a new
53696element at the beginning of the kill ring or adds it to the most recent
53697element.  It determines automatically (using ‘last-command’) whether the
53698previous command was a kill command, and if so appends the killed text
53699to the most recent entry.
53700
53701   The commands described below can filter the killed text before they
53702save it in the kill ring.  They call ‘filter-buffer-substring’ (*note
53703Buffer Contents::) to perform the filtering.  By default, there’s no
53704filtering, but major and minor modes and hook functions can set up
53705filtering, so that text saved in the kill ring is different from what
53706was in the buffer.
53707
53708 -- Command: kill-region start end &optional region
53709     This function kills the stretch of text between START and END; but
53710     if the optional argument REGION is non-‘nil’, it ignores START and
53711     END, and kills the text in the current region instead.  The text is
53712     deleted but saved in the kill ring, along with its text properties.
53713     The value is always ‘nil’.
53714
53715     In an interactive call, START and END are point and the mark, and
53716     REGION is always non-‘nil’, so the command always kills the text in
53717     the current region.
53718
53719     If the buffer or text is read-only, ‘kill-region’ modifies the kill
53720     ring just the same, then signals an error without modifying the
53721     buffer.  This is convenient because it lets the user use a series
53722     of kill commands to copy text from a read-only buffer into the kill
53723     ring.
53724
53725 -- User Option: kill-read-only-ok
53726     If this option is non-‘nil’, ‘kill-region’ does not signal an error
53727     if the buffer or text is read-only.  Instead, it simply returns,
53728     updating the kill ring but not changing the buffer.
53729
53730 -- Command: copy-region-as-kill start end &optional region
53731     This function saves the stretch of text between START and END on
53732     the kill ring (including text properties), but does not delete the
53733     text from the buffer.  However, if the optional argument REGION is
53734     non-‘nil’, the function ignores START and END, and saves the
53735     current region instead.  It always returns ‘nil’.
53736
53737     In an interactive call, START and END are point and the mark, and
53738     REGION is always non-‘nil’, so the command always saves the text in
53739     the current region.
53740
53741     The command does not set ‘this-command’ to ‘kill-region’, so a
53742     subsequent kill command does not append to the same kill ring
53743     entry.
53744
53745
53746File: elisp.info,  Node: Yanking,  Next: Yank Commands,  Prev: Kill Functions,  Up: The Kill Ring
53747
5374832.8.3 Yanking
53749--------------
53750
53751Yanking means inserting text from the kill ring, but it does not insert
53752the text blindly.  The ‘yank’ command, and related commands, use
53753‘insert-for-yank’ to perform special processing on the text before it is
53754inserted.
53755
53756 -- Function: insert-for-yank string
53757     This function works like ‘insert’, except that it processes the
53758     text in STRING according to the ‘yank-handler’ text property, as
53759     well as the variables ‘yank-handled-properties’ and
53760     ‘yank-excluded-properties’ (see below), before inserting the result
53761     into the current buffer.
53762
53763 -- Function: insert-buffer-substring-as-yank buf &optional start end
53764     This function resembles ‘insert-buffer-substring’, except that it
53765     processes the text according to ‘yank-handled-properties’ and
53766     ‘yank-excluded-properties’.  (It does not handle the ‘yank-handler’
53767     property, which does not normally occur in buffer text anyway.)
53768
53769   If you put a ‘yank-handler’ text property on all or part of a string,
53770that alters how ‘insert-for-yank’ inserts the string.  If different
53771parts of the string have different ‘yank-handler’ values (comparison
53772being done with ‘eq’), each substring is handled separately.  The
53773property value must be a list of one to four elements, with the
53774following format (where elements after the first may be omitted):
53775
53776     (FUNCTION PARAM NOEXCLUDE UNDO)
53777
53778   Here is what the elements do:
53779
53780FUNCTION
53781     When FUNCTION is non-‘nil’, it is called instead of ‘insert’ to
53782     insert the string, with one argument—the string to insert.
53783
53784PARAM
53785     If PARAM is present and non-‘nil’, it replaces STRING (or the
53786     substring of STRING being processed) as the object passed to
53787     FUNCTION (or ‘insert’).  For example, if FUNCTION is
53788     ‘yank-rectangle’, PARAM should be a list of strings to insert as a
53789     rectangle.
53790
53791NOEXCLUDE
53792     If NOEXCLUDE is present and non-‘nil’, that disables the normal
53793     action of ‘yank-handled-properties’ and ‘yank-excluded-properties’
53794     on the inserted string.
53795
53796UNDO
53797     If UNDO is present and non-‘nil’, it is a function that will be
53798     called by ‘yank-pop’ to undo the insertion of the current object.
53799     It is called with two arguments, the start and end of the current
53800     region.  FUNCTION can set ‘yank-undo-function’ to override the UNDO
53801     value.
53802
53803 -- User Option: yank-handled-properties
53804     This variable specifies special text property handling conditions
53805     for yanked text.  It takes effect after the text has been inserted
53806     (either normally, or via the ‘yank-handler’ property), and prior to
53807     ‘yank-excluded-properties’ taking effect.
53808
53809     The value should be an alist of elements ‘(PROP . FUN)’.  Each
53810     alist element is handled in order.  The inserted text is scanned
53811     for stretches of text having text properties ‘eq’ to PROP; for each
53812     such stretch, FUN is called with three arguments: the value of the
53813     property, and the start and end positions of the text.
53814
53815 -- User Option: yank-excluded-properties
53816     The value of this variable is the list of properties to remove from
53817     inserted text.  Its default value contains properties that might
53818     lead to annoying results, such as causing the text to respond to
53819     the mouse or specifying key bindings.  It takes effect after
53820     ‘yank-handled-properties’.
53821
53822
53823File: elisp.info,  Node: Yank Commands,  Next: Low-Level Kill Ring,  Prev: Yanking,  Up: The Kill Ring
53824
5382532.8.4 Functions for Yanking
53826----------------------------
53827
53828This section describes higher-level commands for yanking, which are
53829intended primarily for the user but useful also in Lisp programs.  Both
53830‘yank’ and ‘yank-pop’ honor the ‘yank-excluded-properties’ variable and
53831‘yank-handler’ text property (*note Yanking::).
53832
53833 -- Command: yank &optional arg
53834     This command inserts before point the text at the front of the kill
53835     ring.  It sets the mark at the beginning of that text, using
53836     ‘push-mark’ (*note The Mark::), and puts point at the end.
53837
53838     If ARG is a non-‘nil’ list (which occurs interactively when the
53839     user types ‘C-u’ with no digits), then ‘yank’ inserts the text as
53840     described above, but puts point before the yanked text and sets the
53841     mark after it.
53842
53843     If ARG is a number, then ‘yank’ inserts the ARGth most recently
53844     killed text—the ARGth element of the kill ring list, counted
53845     cyclically from the front, which is considered the first element
53846     for this purpose.
53847
53848     ‘yank’ does not alter the contents of the kill ring, unless it used
53849     text provided by another program, in which case it pushes that text
53850     onto the kill ring.  However if ARG is an integer different from
53851     one, it rotates the kill ring to place the yanked string at the
53852     front.
53853
53854     ‘yank’ returns ‘nil’.
53855
53856 -- Command: yank-pop &optional arg
53857     This command replaces the just-yanked entry from the kill ring with
53858     a different entry from the kill ring.
53859
53860     This is allowed only immediately after a ‘yank’ or another
53861     ‘yank-pop’.  At such a time, the region contains text that was just
53862     inserted by yanking.  ‘yank-pop’ deletes that text and inserts in
53863     its place a different piece of killed text.  It does not add the
53864     deleted text to the kill ring, since it is already in the kill ring
53865     somewhere.  It does however rotate the kill ring to place the newly
53866     yanked string at the front.
53867
53868     If ARG is ‘nil’, then the replacement text is the previous element
53869     of the kill ring.  If ARG is numeric, the replacement is the ARGth
53870     previous kill.  If ARG is negative, a more recent kill is the
53871     replacement.
53872
53873     The sequence of kills in the kill ring wraps around, so that after
53874     the oldest one comes the newest one, and before the newest one goes
53875     the oldest.
53876
53877     The return value is always ‘nil’.
53878
53879 -- Variable: yank-undo-function
53880     If this variable is non-‘nil’, the function ‘yank-pop’ uses its
53881     value instead of ‘delete-region’ to delete the text inserted by the
53882     previous ‘yank’ or ‘yank-pop’ command.  The value must be a
53883     function of two arguments, the start and end of the current region.
53884
53885     The function ‘insert-for-yank’ automatically sets this variable
53886     according to the UNDO element of the ‘yank-handler’ text property,
53887     if there is one.
53888
53889
53890File: elisp.info,  Node: Low-Level Kill Ring,  Next: Internals of Kill Ring,  Prev: Yank Commands,  Up: The Kill Ring
53891
5389232.8.5 Low-Level Kill Ring
53893--------------------------
53894
53895These functions and variables provide access to the kill ring at a lower
53896level, but are still convenient for use in Lisp programs, because they
53897take care of interaction with window system selections (*note Window
53898System Selections::).
53899
53900 -- Function: current-kill n &optional do-not-move
53901     The function ‘current-kill’ rotates the yanking pointer, which
53902     designates the front of the kill ring, by N places (from newer
53903     kills to older ones), and returns the text at that place in the
53904     ring.
53905
53906     If the optional second argument DO-NOT-MOVE is non-‘nil’, then
53907     ‘current-kill’ doesn’t alter the yanking pointer; it just returns
53908     the Nth kill, counting from the current yanking pointer.
53909
53910     If N is zero, indicating a request for the latest kill,
53911     ‘current-kill’ calls the value of ‘interprogram-paste-function’
53912     (documented below) before consulting the kill ring.  If that value
53913     is a function and calling it returns a string or a list of several
53914     strings, ‘current-kill’ pushes the strings onto the kill ring and
53915     returns the first string.  It also sets the yanking pointer to
53916     point to the kill-ring entry of the first string returned by
53917     ‘interprogram-paste-function’, regardless of the value of
53918     DO-NOT-MOVE.  Otherwise, ‘current-kill’ does not treat a zero value
53919     for N specially: it returns the entry pointed at by the yanking
53920     pointer and does not move the yanking pointer.
53921
53922 -- Function: kill-new string &optional replace
53923     This function pushes the text STRING onto the kill ring and makes
53924     the yanking pointer point to it.  It discards the oldest entry if
53925     appropriate.  It also invokes the values of
53926     ‘interprogram-paste-function’ (subject to the user option
53927     ‘save-interprogram-paste-before-kill’) and
53928     ‘interprogram-cut-function’ (see below).
53929
53930     If REPLACE is non-‘nil’, then ‘kill-new’ replaces the first element
53931     of the kill ring with STRING, rather than pushing STRING onto the
53932     kill ring.
53933
53934 -- Function: kill-append string before-p
53935     This function appends the text STRING to the first entry in the
53936     kill ring and makes the yanking pointer point to the combined
53937     entry.  Normally STRING goes at the end of the entry, but if
53938     BEFORE-P is non-‘nil’, it goes at the beginning.  This function
53939     calls ‘kill-new’ as a subroutine, thus causing the values of
53940     ‘interprogram-cut-function’ and possibly
53941     ‘interprogram-paste-function’ (see below) to be invoked by
53942     extension.
53943
53944 -- Variable: interprogram-paste-function
53945     This variable provides a way of transferring killed text from other
53946     programs, when you are using a window system.  Its value should be
53947     ‘nil’ or a function of no arguments.
53948
53949     If the value is a function, ‘current-kill’ calls it to get the most
53950     recent kill.  If the function returns a non-‘nil’ value, then that
53951     value is used as the most recent kill.  If it returns ‘nil’, then
53952     the front of the kill ring is used.
53953
53954     To facilitate support for window systems that support multiple
53955     selections, this function may also return a list of strings.  In
53956     that case, the first string is used as the most recent kill, and
53957     all the other strings are pushed onto the kill ring, for easy
53958     access by ‘yank-pop’.
53959
53960     The normal use of this function is to get the window system’s
53961     clipboard as the most recent kill, even if the selection belongs to
53962     another application.  *Note Window System Selections::.  However,
53963     if the clipboard contents come from the current Emacs session, this
53964     function should return ‘nil’.
53965
53966 -- Variable: interprogram-cut-function
53967     This variable provides a way of communicating killed text to other
53968     programs, when you are using a window system.  Its value should be
53969     ‘nil’ or a function of one required argument.
53970
53971     If the value is a function, ‘kill-new’ and ‘kill-append’ call it
53972     with the new first element of the kill ring as the argument.
53973
53974     The normal use of this function is to put newly killed text in the
53975     window system’s clipboard.  *Note Window System Selections::.
53976
53977
53978File: elisp.info,  Node: Internals of Kill Ring,  Prev: Low-Level Kill Ring,  Up: The Kill Ring
53979
5398032.8.6 Internals of the Kill Ring
53981---------------------------------
53982
53983The variable ‘kill-ring’ holds the kill ring contents, in the form of a
53984list of strings.  The most recent kill is always at the front of the
53985list.
53986
53987   The ‘kill-ring-yank-pointer’ variable points to a link in the kill
53988ring list, whose CAR is the text to yank next.  We say it identifies the
53989front of the ring.  Moving ‘kill-ring-yank-pointer’ to a different link
53990is called “rotating the kill ring”.  We call the kill ring a “ring”
53991because the functions that move the yank pointer wrap around from the
53992end of the list to the beginning, or vice-versa.  Rotation of the kill
53993ring is virtual; it does not change the value of ‘kill-ring’.
53994
53995   Both ‘kill-ring’ and ‘kill-ring-yank-pointer’ are Lisp variables
53996whose values are normally lists.  The word “pointer” in the name of the
53997‘kill-ring-yank-pointer’ indicates that the variable’s purpose is to
53998identify one element of the list for use by the next yank command.
53999
54000   The value of ‘kill-ring-yank-pointer’ is always ‘eq’ to one of the
54001links in the kill ring list.  The element it identifies is the CAR of
54002that link.  Kill commands, which change the kill ring, also set this
54003variable to the value of ‘kill-ring’.  The effect is to rotate the ring
54004so that the newly killed text is at the front.
54005
54006   Here is a diagram that shows the variable ‘kill-ring-yank-pointer’
54007pointing to the second entry in the kill ring ‘("some text" "a different
54008piece of text" "yet older text")’.
54009
54010     kill-ring                  ---- kill-ring-yank-pointer
54011       |                       |
54012       |                       v
54013       |     --- ---          --- ---      --- ---
54014        --> |   |   |------> |   |   |--> |   |   |--> nil
54015             --- ---          --- ---      --- ---
54016              |                |            |
54017              |                |            |
54018              |                |             -->"yet older text"
54019              |                |
54020              |                 --> "a different piece of text"
54021              |
54022               --> "some text"
54023
54024This state of affairs might occur after ‘C-y’ (‘yank’) immediately
54025followed by ‘M-y’ (‘yank-pop’).
54026
54027 -- Variable: kill-ring
54028     This variable holds the list of killed text sequences, most
54029     recently killed first.
54030
54031 -- Variable: kill-ring-yank-pointer
54032     This variable’s value indicates which element of the kill ring is
54033     at the front of the ring for yanking.  More precisely, the value is
54034     a tail of the value of ‘kill-ring’, and its CAR is the kill string
54035     that ‘C-y’ should yank.
54036
54037 -- User Option: kill-ring-max
54038     The value of this variable is the maximum length to which the kill
54039     ring can grow, before elements are thrown away at the end.  The
54040     default value for ‘kill-ring-max’ is 60.
54041
54042
54043File: elisp.info,  Node: Undo,  Next: Maintaining Undo,  Prev: The Kill Ring,  Up: Text
54044
5404532.9 Undo
54046=========
54047
54048Most buffers have an “undo list”, which records all changes made to the
54049buffer’s text so that they can be undone.  (The buffers that don’t have
54050one are usually special-purpose buffers for which Emacs assumes that
54051undoing is not useful.  In particular, any buffer whose name begins with
54052a space has its undo recording off by default; see *note Buffer
54053Names::.)  All the primitives that modify the text in the buffer
54054automatically add elements to the front of the undo list, which is in
54055the variable ‘buffer-undo-list’.
54056
54057 -- Variable: buffer-undo-list
54058     This buffer-local variable’s value is the undo list of the current
54059     buffer.  A value of ‘t’ disables the recording of undo information.
54060
54061   Here are the kinds of elements an undo list can have:
54062
54063‘POSITION’
54064     This kind of element records a previous value of point; undoing
54065     this element moves point to POSITION.  Ordinary cursor motion does
54066     not make any sort of undo record, but deletion operations use these
54067     entries to record where point was before the command.
54068
54069‘(BEG . END)’
54070     This kind of element indicates how to delete text that was
54071     inserted.  Upon insertion, the text occupied the range BEG–END in
54072     the buffer.
54073
54074‘(TEXT . POSITION)’
54075     This kind of element indicates how to reinsert text that was
54076     deleted.  The deleted text itself is the string TEXT.  The place to
54077     reinsert it is ‘(abs POSITION)’.  If POSITION is positive, point
54078     was at the beginning of the deleted text, otherwise it was at the
54079     end.  Zero or more (MARKER .  ADJUSTMENT) elements follow
54080     immediately after this element.
54081
54082‘(t . TIME-FLAG)’
54083     This kind of element indicates that an unmodified buffer became
54084     modified.  A TIME-FLAG that is a non-integer Lisp timestamp
54085     represents the visited file’s modification time as of when it was
54086     previously visited or saved, using the same format as
54087     ‘current-time’; see *note Time of Day::.  A TIME-FLAG of 0 means
54088     the buffer does not correspond to any file; −1 means the visited
54089     file previously did not exist.  ‘primitive-undo’ uses these values
54090     to determine whether to mark the buffer as unmodified once again;
54091     it does so only if the file’s status matches that of TIME-FLAG.
54092
54093‘(nil PROPERTY VALUE BEG . END)’
54094     This kind of element records a change in a text property.  Here’s
54095     how you might undo the change:
54096
54097          (put-text-property BEG END PROPERTY VALUE)
54098
54099‘(MARKER . ADJUSTMENT)’
54100     This kind of element records the fact that the marker MARKER was
54101     relocated due to deletion of surrounding text, and that it moved
54102     ADJUSTMENT character positions.  If the marker’s location is
54103     consistent with the (TEXT .  POSITION) element preceding it in the
54104     undo list, then undoing this element moves MARKER − ADJUSTMENT
54105     characters.
54106
54107‘(apply FUNNAME . ARGS)’
54108     This is an extensible undo item, which is undone by calling FUNNAME
54109     with arguments ARGS.
54110
54111‘(apply DELTA BEG END FUNNAME . ARGS)’
54112     This is an extensible undo item, which records a change limited to
54113     the range BEG to END, which increased the size of the buffer by
54114     DELTA characters.  It is undone by calling FUNNAME with arguments
54115     ARGS.
54116
54117     This kind of element enables undo limited to a region to determine
54118     whether the element pertains to that region.
54119
54120‘nil’
54121     This element is a boundary.  The elements between two boundaries
54122     are called a “change group”; normally, each change group
54123     corresponds to one keyboard command, and undo commands normally
54124     undo an entire group as a unit.
54125
54126 -- Function: undo-boundary
54127     This function places a boundary element in the undo list.  The undo
54128     command stops at such a boundary, and successive undo commands undo
54129     to earlier and earlier boundaries.  This function returns ‘nil’.
54130
54131     Calling this function explicitly is useful for splitting the
54132     effects of a command into more than one unit.  For example,
54133     ‘query-replace’ calls ‘undo-boundary’ after each replacement, so
54134     that the user can undo individual replacements one by one.
54135
54136     Mostly, however, this function is called automatically at an
54137     appropriate time.
54138
54139 -- Function: undo-auto-amalgamate
54140     The editor command loop automatically calls ‘undo-boundary’ just
54141     before executing each key sequence, so that each undo normally
54142     undoes the effects of one command.  A few exceptional commands are
54143     “amalgamating”: these commands generally cause small changes to
54144     buffers, so with these a boundary is inserted only every 20th
54145     command, allowing the changes to be undone as a group.  By default,
54146     the commands ‘self-insert-command’, which produces self-inserting
54147     input characters (*note Commands for Insertion::), and
54148     ‘delete-char’, which deletes characters (*note Deletion::), are
54149     amalgamating.  Where a command affects the contents of several
54150     buffers, as may happen, for example, when a function on the
54151     ‘post-command-hook’ affects a buffer other than the
54152     ‘current-buffer’, then ‘undo-boundary’ will be called in each of
54153     the affected buffers.
54154
54155     This function can be called before an amalgamating command.  It
54156     removes the previous ‘undo-boundary’ if a series of such calls have
54157     been made.
54158
54159     The maximum number of changes that can be amalgamated is controlled
54160     by the ‘amalgamating-undo-limit’ variable.  If this variable is 1,
54161     no changes are amalgamated.
54162
54163   A Lisp program can amalgamate a series of changes into a single
54164change group by calling ‘undo-amalgamate-change-group’ (*note Atomic
54165Changes::).  Note that ‘amalgamating-undo-limit’ has no effect on the
54166groups produced by that function.
54167
54168 -- Variable: undo-auto-current-boundary-timer
54169     Some buffers, such as process buffers, can change even when no
54170     commands are executing.  In these cases, ‘undo-boundary’ is
54171     normally called periodically by the timer in this variable.
54172     Setting this variable to non-‘nil’ prevents this behavior.
54173
54174 -- Variable: undo-in-progress
54175     This variable is normally ‘nil’, but the undo commands bind it to
54176     ‘t’.  This is so that various kinds of change hooks can tell when
54177     they’re being called for the sake of undoing.
54178
54179 -- Function: primitive-undo count list
54180     This is the basic function for undoing elements of an undo list.
54181     It undoes the first COUNT elements of LIST, returning the rest of
54182     LIST.
54183
54184     ‘primitive-undo’ adds elements to the buffer’s undo list when it
54185     changes the buffer.  Undo commands avoid confusion by saving the
54186     undo list value at the beginning of a sequence of undo operations.
54187     Then the undo operations use and update the saved value.  The new
54188     elements added by undoing are not part of this saved value, so they
54189     don’t interfere with continuing to undo.
54190
54191     This function does not bind ‘undo-in-progress’.
54192
54193   Some commands leave the region active after execution in such a way
54194that it interferes with selective undo of that command.  To make ‘undo’
54195ignore the active region when invoked immediately after such a command,
54196set the property ‘undo-inhibit-region’ of the command’s function symbol
54197to a non-nil value.  *Note Standard Properties::.
54198
54199
54200File: elisp.info,  Node: Maintaining Undo,  Next: Filling,  Prev: Undo,  Up: Text
54201
5420232.10 Maintaining Undo Lists
54203============================
54204
54205This section describes how to enable and disable undo information for a
54206given buffer.  It also explains how the undo list is truncated
54207automatically so it doesn’t get too big.
54208
54209   Recording of undo information in a newly created buffer is normally
54210enabled to start with; but if the buffer name starts with a space, the
54211undo recording is initially disabled.  You can explicitly enable or
54212disable undo recording with the following two functions, or by setting
54213‘buffer-undo-list’ yourself.
54214
54215 -- Command: buffer-enable-undo &optional buffer-or-name
54216     This command enables recording undo information for buffer
54217     BUFFER-OR-NAME, so that subsequent changes can be undone.  If no
54218     argument is supplied, then the current buffer is used.  This
54219     function does nothing if undo recording is already enabled in the
54220     buffer.  It returns ‘nil’.
54221
54222     In an interactive call, BUFFER-OR-NAME is the current buffer.  You
54223     cannot specify any other buffer.
54224
54225 -- Command: buffer-disable-undo &optional buffer-or-name
54226     This function discards the undo list of BUFFER-OR-NAME, and
54227     disables further recording of undo information.  As a result, it is
54228     no longer possible to undo either previous changes or any
54229     subsequent changes.  If the undo list of BUFFER-OR-NAME is already
54230     disabled, this function has no effect.
54231
54232     In an interactive call, BUFFER-OR-NAME is the current buffer.  You
54233     cannot specify any other buffer.  This function returns ‘nil’.
54234
54235   As editing continues, undo lists get longer and longer.  To prevent
54236them from using up all available memory space, garbage collection trims
54237them back to size limits you can set.  (For this purpose, the size of an
54238undo list measures the cons cells that make up the list, plus the
54239strings of deleted text.)  Three variables control the range of
54240acceptable sizes: ‘undo-limit’, ‘undo-strong-limit’ and
54241‘undo-outer-limit’.  In these variables, size is counted as the number
54242of bytes occupied, which includes both saved text and other data.
54243
54244 -- User Option: undo-limit
54245     This is the soft limit for the acceptable size of an undo list.
54246     The change group at which this size is exceeded is the last one
54247     kept.
54248
54249 -- User Option: undo-strong-limit
54250     This is the upper limit for the acceptable size of an undo list.
54251     The change group at which this size is exceeded is discarded itself
54252     (along with all older change groups).  There is one exception: the
54253     very latest change group is only discarded if it exceeds
54254     ‘undo-outer-limit’.
54255
54256 -- User Option: undo-outer-limit
54257     If at garbage collection time the undo info for the current command
54258     exceeds this limit, Emacs discards the info and displays a warning.
54259     This is a last ditch limit to prevent memory overflow.
54260
54261 -- User Option: undo-ask-before-discard
54262     If this variable is non-‘nil’, when the undo info exceeds
54263     ‘undo-outer-limit’, Emacs asks in the echo area whether to discard
54264     the info.  The default value is ‘nil’, which means to discard it
54265     automatically.
54266
54267     This option is mainly intended for debugging.  Garbage collection
54268     is inhibited while the question is asked, which means that Emacs
54269     might leak memory if the user waits too long before answering the
54270     question.
54271
54272
54273File: elisp.info,  Node: Filling,  Next: Margins,  Prev: Maintaining Undo,  Up: Text
54274
5427532.11 Filling
54276=============
54277
54278“Filling” means adjusting the lengths of lines (by moving the line
54279breaks) so that they are nearly (but no greater than) a specified
54280maximum width.  Additionally, lines can be “justified”, which means
54281inserting spaces to make the left and/or right margins line up
54282precisely.  The width is controlled by the variable ‘fill-column’.  For
54283ease of reading, lines should be no longer than 70 or so columns.
54284
54285   You can use Auto Fill mode (*note Auto Filling::) to fill text
54286automatically as you insert it, but changes to existing text may leave
54287it improperly filled.  Then you must fill the text explicitly.
54288
54289   Most of the commands in this section return values that are not
54290meaningful.  All the functions that do filling take note of the current
54291left margin, current right margin, and current justification style
54292(*note Margins::).  If the current justification style is ‘none’, the
54293filling functions don’t actually do anything.
54294
54295   Several of the filling functions have an argument JUSTIFY.  If it is
54296non-‘nil’, that requests some kind of justification.  It can be ‘left’,
54297‘right’, ‘full’, or ‘center’, to request a specific style of
54298justification.  If it is ‘t’, that means to use the current
54299justification style for this part of the text (see
54300‘current-justification’, below).  Any other value is treated as ‘full’.
54301
54302   When you call the filling functions interactively, using a prefix
54303argument implies the value ‘full’ for JUSTIFY.
54304
54305 -- Command: fill-paragraph &optional justify region
54306     This command fills the paragraph at or after point.  If JUSTIFY is
54307     non-‘nil’, each line is justified as well.  It uses the ordinary
54308     paragraph motion commands to find paragraph boundaries.  *Note
54309     (emacs)Paragraphs::.
54310
54311     When REGION is non-‘nil’, then if Transient Mark mode is enabled
54312     and the mark is active, this command calls ‘fill-region’ to fill
54313     all the paragraphs in the region, instead of filling only the
54314     current paragraph.  When this command is called interactively,
54315     REGION is ‘t’.
54316
54317 -- Command: fill-region start end &optional justify nosqueeze to-eop
54318     This command fills each of the paragraphs in the region from START
54319     to END.  It justifies as well if JUSTIFY is non-‘nil’.
54320
54321     If NOSQUEEZE is non-‘nil’, that means to leave whitespace other
54322     than line breaks untouched.  If TO-EOP is non-‘nil’, that means to
54323     keep filling to the end of the paragraph—or the next hard newline,
54324     if ‘use-hard-newlines’ is enabled (see below).
54325
54326     The variable ‘paragraph-separate’ controls how to distinguish
54327     paragraphs.  *Note Standard Regexps::.
54328
54329 -- Command: fill-individual-paragraphs start end &optional justify
54330          citation-regexp
54331     This command fills each paragraph in the region according to its
54332     individual fill prefix.  Thus, if the lines of a paragraph were
54333     indented with spaces, the filled paragraph will remain indented in
54334     the same fashion.
54335
54336     The first two arguments, START and END, are the beginning and end
54337     of the region to be filled.  The third and fourth arguments,
54338     JUSTIFY and CITATION-REGEXP, are optional.  If JUSTIFY is
54339     non-‘nil’, the paragraphs are justified as well as filled.  If
54340     CITATION-REGEXP is non-‘nil’, it means the function is operating on
54341     a mail message and therefore should not fill the header lines.  If
54342     CITATION-REGEXP is a string, it is used as a regular expression; if
54343     it matches the beginning of a line, that line is treated as a
54344     citation marker.
54345
54346     Ordinarily, ‘fill-individual-paragraphs’ regards each change in
54347     indentation as starting a new paragraph.  If
54348     ‘fill-individual-varying-indent’ is non-‘nil’, then only separator
54349     lines separate paragraphs.  That mode can handle indented
54350     paragraphs with additional indentation on the first line.
54351
54352 -- User Option: fill-individual-varying-indent
54353     This variable alters the action of ‘fill-individual-paragraphs’ as
54354     described above.
54355
54356 -- Command: fill-region-as-paragraph start end &optional justify
54357          nosqueeze squeeze-after
54358     This command considers a region of text as a single paragraph and
54359     fills it.  If the region was made up of many paragraphs, the blank
54360     lines between paragraphs are removed.  This function justifies as
54361     well as filling when JUSTIFY is non-‘nil’.
54362
54363     If NOSQUEEZE is non-‘nil’, that means to leave whitespace other
54364     than line breaks untouched.  If SQUEEZE-AFTER is non-‘nil’, it
54365     specifies a position in the region, and means don’t canonicalize
54366     spaces before that position.
54367
54368     In Adaptive Fill mode, this command calls ‘fill-context-prefix’ to
54369     choose a fill prefix by default.  *Note Adaptive Fill::.
54370
54371 -- Command: justify-current-line &optional how eop nosqueeze
54372     This command inserts spaces between the words of the current line
54373     so that the line ends exactly at ‘fill-column’.  It returns ‘nil’.
54374
54375     The argument HOW, if non-‘nil’ specifies explicitly the style of
54376     justification.  It can be ‘left’, ‘right’, ‘full’, ‘center’, or
54377     ‘none’.  If it is ‘t’, that means to follow specified justification
54378     style (see ‘current-justification’, below).  ‘nil’ means to do full
54379     justification.
54380
54381     If EOP is non-‘nil’, that means do only left-justification if
54382     ‘current-justification’ specifies full justification.  This is used
54383     for the last line of a paragraph; even if the paragraph as a whole
54384     is fully justified, the last line should not be.
54385
54386     If NOSQUEEZE is non-‘nil’, that means do not change interior
54387     whitespace.
54388
54389 -- User Option: default-justification
54390     This variable’s value specifies the style of justification to use
54391     for text that doesn’t specify a style with a text property.  The
54392     possible values are ‘left’, ‘right’, ‘full’, ‘center’, or ‘none’.
54393     The default value is ‘left’.
54394
54395 -- Function: current-justification
54396     This function returns the proper justification style to use for
54397     filling the text around point.
54398
54399     This returns the value of the ‘justification’ text property at
54400     point, or the variable ‘default-justification’ if there is no such
54401     text property.  However, it returns ‘nil’ rather than ‘none’ to
54402     mean “don’t justify”.
54403
54404 -- User Option: sentence-end-double-space
54405     If this variable is non-‘nil’, a period followed by just one space
54406     does not count as the end of a sentence, and the filling functions
54407     avoid breaking the line at such a place.
54408
54409 -- User Option: sentence-end-without-period
54410     If this variable is non-‘nil’, a sentence can end without a period.
54411     This is used for languages like Thai, where sentences end with a
54412     double space but without a period.
54413
54414 -- User Option: sentence-end-without-space
54415     If this variable is non-‘nil’, it should be a string of characters
54416     that can end a sentence without following spaces.
54417
54418 -- User Option: fill-separate-heterogeneous-words-with-space
54419     If this variable is non-‘nil’, two words of different kind (e.g.,
54420     English and CJK) will be separated with a space when concatenating
54421     one that is in the end of a line and the other that is in the
54422     beginning of the next line for filling.
54423
54424 -- Variable: fill-paragraph-function
54425     This variable provides a way to override the filling of paragraphs.
54426     If its value is non-‘nil’, ‘fill-paragraph’ calls this function to
54427     do the work.  If the function returns a non-‘nil’ value,
54428     ‘fill-paragraph’ assumes the job is done, and immediately returns
54429     that value.
54430
54431     The usual use of this feature is to fill comments in programming
54432     language modes.  If the function needs to fill a paragraph in the
54433     usual way, it can do so as follows:
54434
54435          (let ((fill-paragraph-function nil))
54436            (fill-paragraph arg))
54437
54438 -- Variable: fill-forward-paragraph-function
54439     This variable provides a way to override how the filling functions,
54440     such as ‘fill-region’ and ‘fill-paragraph’, move forward to the
54441     next paragraph.  Its value should be a function, which is called
54442     with a single argument N, the number of paragraphs to move, and
54443     should return the difference between N and the number of paragraphs
54444     actually moved.  The default value of this variable is
54445     ‘forward-paragraph’.  *Note (emacs)Paragraphs::.
54446
54447 -- Variable: use-hard-newlines
54448     If this variable is non-‘nil’, the filling functions do not delete
54449     newlines that have the ‘hard’ text property.  These hard newlines
54450     act as paragraph separators.  *Note Hard and Soft Newlines:
54451     (emacs)Hard and Soft Newlines.
54452
54453
54454File: elisp.info,  Node: Margins,  Next: Adaptive Fill,  Prev: Filling,  Up: Text
54455
5445632.12 Margins for Filling
54457=========================
54458
54459 -- User Option: fill-prefix
54460     This buffer-local variable, if non-‘nil’, specifies a string of
54461     text that appears at the beginning of normal text lines and should
54462     be disregarded when filling them.  Any line that fails to start
54463     with the fill prefix is considered the start of a paragraph; so is
54464     any line that starts with the fill prefix followed by additional
54465     whitespace.  Lines that start with the fill prefix but no
54466     additional whitespace are ordinary text lines that can be filled
54467     together.  The resulting filled lines also start with the fill
54468     prefix.
54469
54470     The fill prefix follows the left margin whitespace, if any.
54471
54472 -- User Option: fill-column
54473     This buffer-local variable specifies the maximum width of filled
54474     lines.  Its value should be an integer, which is a number of
54475     columns.  All the filling, justification, and centering commands
54476     are affected by this variable, including Auto Fill mode (*note Auto
54477     Filling::).
54478
54479     As a practical matter, if you are writing text for other people to
54480     read, you should set ‘fill-column’ to no more than 70.  Otherwise
54481     the line will be too long for people to read comfortably, and this
54482     can make the text seem clumsy.
54483
54484     The default value for ‘fill-column’ is 70.
54485
54486 -- Command: set-left-margin from to margin
54487     This sets the ‘left-margin’ property on the text from FROM to TO to
54488     the value MARGIN.  If Auto Fill mode is enabled, this command also
54489     refills the region to fit the new margin.
54490
54491 -- Command: set-right-margin from to margin
54492     This sets the ‘right-margin’ property on the text from FROM to TO
54493     to the value MARGIN.  If Auto Fill mode is enabled, this command
54494     also refills the region to fit the new margin.
54495
54496 -- Function: current-left-margin
54497     This function returns the proper left margin value to use for
54498     filling the text around point.  The value is the sum of the
54499     ‘left-margin’ property of the character at the start of the current
54500     line (or zero if none), and the value of the variable
54501     ‘left-margin’.
54502
54503 -- Function: current-fill-column
54504     This function returns the proper fill column value to use for
54505     filling the text around point.  The value is the value of the
54506     ‘fill-column’ variable, minus the value of the ‘right-margin’
54507     property of the character after point.
54508
54509 -- Command: move-to-left-margin &optional n force
54510     This function moves point to the left margin of the current line.
54511     The column moved to is determined by calling the function
54512     ‘current-left-margin’.  If the argument N is non-‘nil’,
54513     ‘move-to-left-margin’ moves forward N−1 lines first.
54514
54515     If FORCE is non-‘nil’, that says to fix the line’s indentation if
54516     that doesn’t match the left margin value.
54517
54518 -- Function: delete-to-left-margin &optional from to
54519     This function removes left margin indentation from the text between
54520     FROM and TO.  The amount of indentation to delete is determined by
54521     calling ‘current-left-margin’.  In no case does this function
54522     delete non-whitespace.  If FROM and TO are omitted, they default to
54523     the whole buffer.
54524
54525 -- Function: indent-to-left-margin
54526     This function adjusts the indentation at the beginning of the
54527     current line to the value specified by the variable ‘left-margin’.
54528     (That may involve either inserting or deleting whitespace.)  This
54529     function is value of ‘indent-line-function’ in Paragraph-Indent
54530     Text mode.
54531
54532 -- User Option: left-margin
54533     This variable specifies the base left margin column.  In
54534     Fundamental mode, <RET> indents to this column.  This variable
54535     automatically becomes buffer-local when set in any fashion.
54536
54537 -- User Option: fill-nobreak-predicate
54538     This variable gives major modes a way to specify not to break a
54539     line at certain places.  Its value should be a list of functions.
54540     Whenever filling considers breaking the line at a certain place in
54541     the buffer, it calls each of these functions with no arguments and
54542     with point located at that place.  If any of the functions returns
54543     non-‘nil’, then the line won’t be broken there.
54544
54545
54546File: elisp.info,  Node: Adaptive Fill,  Next: Auto Filling,  Prev: Margins,  Up: Text
54547
5454832.13 Adaptive Fill Mode
54549========================
54550
54551When “Adaptive Fill Mode” is enabled, Emacs determines the fill prefix
54552automatically from the text in each paragraph being filled rather than
54553using a predetermined value.  During filling, this fill prefix gets
54554inserted at the start of the second and subsequent lines of the
54555paragraph as described in *note Filling::, and in *note Auto Filling::.
54556
54557 -- User Option: adaptive-fill-mode
54558     Adaptive Fill mode is enabled when this variable is non-‘nil’.  It
54559     is ‘t’ by default.
54560
54561 -- Function: fill-context-prefix from to
54562     This function implements the heart of Adaptive Fill mode; it
54563     chooses a fill prefix based on the text between FROM and TO,
54564     typically the start and end of a paragraph.  It does this by
54565     looking at the first two lines of the paragraph, based on the
54566     variables described below.
54567
54568     Usually, this function returns the fill prefix, a string.  However,
54569     before doing this, the function makes a final check (not specially
54570     mentioned in the following) that a line starting with this prefix
54571     wouldn’t look like the start of a paragraph.  Should this happen,
54572     the function signals the anomaly by returning ‘nil’ instead.
54573
54574     In detail, ‘fill-context-prefix’ does this:
54575
54576       1. It takes a candidate for the fill prefix from the first
54577          line—it tries first the function in ‘adaptive-fill-function’
54578          (if any), then the regular expression ‘adaptive-fill-regexp’
54579          (see below).  The first non-‘nil’ result of these, or the
54580          empty string if they’re both ‘nil’, becomes the first line’s
54581          candidate.
54582       2. If the paragraph has as yet only one line, the function tests
54583          the validity of the prefix candidate just found.  The function
54584          then returns the candidate if it’s valid, or a string of
54585          spaces otherwise.  (see the description of
54586          ‘adaptive-fill-first-line-regexp’ below).
54587       3. When the paragraph already has two lines, the function next
54588          looks for a prefix candidate on the second line, in just the
54589          same way it did for the first line.  If it doesn’t find one,
54590          it returns ‘nil’.
54591       4. The function now compares the two candidate prefixes
54592          heuristically: if the non-whitespace characters in the line 2
54593          candidate occur in the same order in the line 1 candidate, the
54594          function returns the line 2 candidate.  Otherwise, it returns
54595          the largest initial substring which is common to both
54596          candidates (which might be the empty string).
54597
54598 -- User Option: adaptive-fill-regexp
54599     Adaptive Fill mode matches this regular expression against the text
54600     starting after the left margin whitespace (if any) on a line; the
54601     characters it matches are that line’s candidate for the fill
54602     prefix.
54603
54604     The default value matches whitespace with certain punctuation
54605     characters intermingled.
54606
54607 -- User Option: adaptive-fill-first-line-regexp
54608     Used only in one-line paragraphs, this regular expression acts as
54609     an additional check of the validity of the one available candidate
54610     fill prefix: the candidate must match this regular expression, or
54611     match ‘comment-start-skip’.  If it doesn’t, ‘fill-context-prefix’
54612     replaces the candidate with a string of spaces of the same width as
54613     it.
54614
54615     The default value of this variable is ‘"\\`[ \t]*\\'"’, which
54616     matches only a string of whitespace.  The effect of this default is
54617     to force the fill prefixes found in one-line paragraphs always to
54618     be pure whitespace.
54619
54620 -- User Option: adaptive-fill-function
54621     You can specify more complex ways of choosing a fill prefix
54622     automatically by setting this variable to a function.  The function
54623     is called with point after the left margin (if any) of a line, and
54624     it must preserve point.  It should return either that line’s fill
54625     prefix or ‘nil’, meaning it has failed to determine a prefix.
54626
54627
54628File: elisp.info,  Node: Auto Filling,  Next: Sorting,  Prev: Adaptive Fill,  Up: Text
54629
5463032.14 Auto Filling
54631==================
54632
54633Auto Fill mode is a minor mode that fills lines automatically as text is
54634inserted.  *Note (emacs)Auto Fill::.  This section describes some
54635variables used by Auto Fill mode.  For a description of functions that
54636you can call explicitly to fill and justify existing text, see *note
54637Filling::.
54638
54639   Auto Fill mode also enables the functions that change the margins and
54640justification style to refill portions of the text.  *Note Margins::.
54641
54642 -- Variable: auto-fill-function
54643     The value of this buffer-local variable should be a function (of no
54644     arguments) to be called after self-inserting a character from the
54645     table ‘auto-fill-chars’, see below.  It may be ‘nil’, in which case
54646     nothing special is done in that case.
54647
54648     The value of ‘auto-fill-function’ is ‘do-auto-fill’ when Auto Fill
54649     mode is enabled.  That is a function whose sole purpose is to
54650     implement the usual strategy for breaking a line.
54651
54652 -- Variable: normal-auto-fill-function
54653     This variable specifies the function to use for
54654     ‘auto-fill-function’, if and when Auto Fill is turned on.  Major
54655     modes can set buffer-local values for this variable to alter how
54656     Auto Fill works.
54657
54658 -- Variable: auto-fill-chars
54659     A char table of characters which invoke ‘auto-fill-function’ when
54660     self-inserted—space and newline in most language environments.
54661     They have an entry ‘t’ in the table.
54662
54663 -- User Option: comment-auto-fill-only-comments
54664     This variable, if non-‘nil’, means to fill lines automatically
54665     within comments only.  More precisely, this means that if a comment
54666     syntax was defined for the current buffer, then self-inserting a
54667     character outside of a comment will not call ‘auto-fill-function’.
54668
54669
54670File: elisp.info,  Node: Sorting,  Next: Columns,  Prev: Auto Filling,  Up: Text
54671
5467232.15 Sorting Text
54673==================
54674
54675The sorting functions described in this section all rearrange text in a
54676buffer.  This is in contrast to the function ‘sort’, which rearranges
54677the order of the elements of a list (*note Rearrangement::).  The values
54678returned by these functions are not meaningful.
54679
54680 -- Function: sort-subr reverse nextrecfun endrecfun &optional
54681          startkeyfun endkeyfun predicate
54682     This function is the general text-sorting routine that subdivides a
54683     buffer into records and then sorts them.  Most of the commands in
54684     this section use this function.
54685
54686     To understand how ‘sort-subr’ works, consider the whole accessible
54687     portion of the buffer as being divided into disjoint pieces called
54688     “sort records”.  The records may or may not be contiguous, but they
54689     must not overlap.  A portion of each sort record (perhaps all of
54690     it) is designated as the sort key.  Sorting rearranges the records
54691     in order by their sort keys.
54692
54693     Usually, the records are rearranged in order of ascending sort key.
54694     If the first argument to the ‘sort-subr’ function, REVERSE, is
54695     non-‘nil’, the sort records are rearranged in order of descending
54696     sort key.
54697
54698     The next four arguments to ‘sort-subr’ are functions that are
54699     called to move point across a sort record.  They are called many
54700     times from within ‘sort-subr’.
54701
54702       1. NEXTRECFUN is called with point at the end of a record.  This
54703          function moves point to the start of the next record.  The
54704          first record is assumed to start at the position of point when
54705          ‘sort-subr’ is called.  Therefore, you should usually move
54706          point to the beginning of the buffer before calling
54707          ‘sort-subr’.
54708
54709          This function can indicate there are no more sort records by
54710          leaving point at the end of the buffer.
54711
54712       2. ENDRECFUN is called with point within a record.  It moves
54713          point to the end of the record.
54714
54715       3. STARTKEYFUN is called to move point from the start of a record
54716          to the start of the sort key.  This argument is optional; if
54717          it is omitted, the whole record is the sort key.  If supplied,
54718          the function should either return a non-‘nil’ value to be used
54719          as the sort key, or return ‘nil’ to indicate that the sort key
54720          is in the buffer starting at point.  In the latter case,
54721          ENDKEYFUN is called to find the end of the sort key.
54722
54723       4. ENDKEYFUN is called to move point from the start of the sort
54724          key to the end of the sort key.  This argument is optional.
54725          If STARTKEYFUN returns ‘nil’ and this argument is omitted (or
54726          ‘nil’), then the sort key extends to the end of the record.
54727          There is no need for ENDKEYFUN if STARTKEYFUN returns a
54728          non-‘nil’ value.
54729
54730     The argument PREDICATE is the function to use to compare keys.  It
54731     is called with two arguments, the keys to compare, and should
54732     return non-‘nil’ if the first key should come before the second in
54733     the sorting order.  What exactly are the key arguments depends on
54734     what STARTKEYFUN and ENDKEYFUN return.  If PREDICATE is omitted or
54735     ‘nil’, it defaults to ‘<’ if the keys are numbers, to
54736     ‘compare-buffer-substrings’ if the keys are cons cells (whose ‘car’
54737     and ‘cdr’ are start and end buffer positions of the key), and to
54738     ‘string<’ otherwise (with keys assumed to be strings).
54739
54740     As an example of ‘sort-subr’, here is the complete function
54741     definition for ‘sort-lines’:
54742
54743          ;; Note that the first two lines of doc string
54744          ;; are effectively one line when viewed by a user.
54745          (defun sort-lines (reverse beg end)
54746            "Sort lines in region alphabetically;\
54747           argument means descending order.
54748          Called from a program, there are three arguments:
54749          REVERSE (non-nil means reverse order),\
54750           BEG and END (region to sort).
54751          The variable `sort-fold-case' determines\
54752           whether alphabetic case affects
54753          the sort order."
54754            (interactive "P\nr")
54755            (save-excursion
54756              (save-restriction
54757                (narrow-to-region beg end)
54758                (goto-char (point-min))
54759                (let ((inhibit-field-text-motion t))
54760                  (sort-subr reverse 'forward-line 'end-of-line)))))
54761
54762     Here ‘forward-line’ moves point to the start of the next record,
54763     and ‘end-of-line’ moves point to the end of record.  We do not pass
54764     the arguments STARTKEYFUN and ENDKEYFUN, because the entire record
54765     is used as the sort key.
54766
54767     The ‘sort-paragraphs’ function is very much the same, except that
54768     its ‘sort-subr’ call looks like this:
54769
54770          (sort-subr reverse
54771                     (lambda ()
54772                       (while (and (not (eobp))
54773                                   (looking-at paragraph-separate))
54774                         (forward-line 1)))
54775                     'forward-paragraph)
54776
54777     Markers pointing into any sort records are left with no useful
54778     position after ‘sort-subr’ returns.
54779
54780 -- User Option: sort-fold-case
54781     If this variable is non-‘nil’, ‘sort-subr’ and the other buffer
54782     sorting functions ignore case when comparing strings.
54783
54784 -- Command: sort-regexp-fields reverse record-regexp key-regexp start
54785          end
54786     This command sorts the region between START and END alphabetically
54787     as specified by RECORD-REGEXP and KEY-REGEXP.  If REVERSE is a
54788     negative integer, then sorting is in reverse order.
54789
54790     Alphabetical sorting means that two sort keys are compared by
54791     comparing the first characters of each, the second characters of
54792     each, and so on.  If a mismatch is found, it means that the sort
54793     keys are unequal; the sort key whose character is less at the point
54794     of first mismatch is the lesser sort key.  The individual
54795     characters are compared according to their numerical character
54796     codes in the Emacs character set.
54797
54798     The value of the RECORD-REGEXP argument specifies how to divide the
54799     buffer into sort records.  At the end of each record, a search is
54800     done for this regular expression, and the text that matches it is
54801     taken as the next record.  For example, the regular expression
54802     ‘^.+$’, which matches lines with at least one character besides a
54803     newline, would make each such line into a sort record.  *Note
54804     Regular Expressions::, for a description of the syntax and meaning
54805     of regular expressions.
54806
54807     The value of the KEY-REGEXP argument specifies what part of each
54808     record is the sort key.  The KEY-REGEXP could match the whole
54809     record, or only a part.  In the latter case, the rest of the record
54810     has no effect on the sorted order of records, but it is carried
54811     along when the record moves to its new position.
54812
54813     The KEY-REGEXP argument can refer to the text matched by a
54814     subexpression of RECORD-REGEXP, or it can be a regular expression
54815     on its own.
54816
54817     If KEY-REGEXP is:
54818
54819     ‘\DIGIT’
54820          then the text matched by the DIGITth ‘\(...\)’ parenthesis
54821          grouping in RECORD-REGEXP is the sort key.
54822
54823     ‘\&’
54824          then the whole record is the sort key.
54825
54826     a regular expression
54827          then ‘sort-regexp-fields’ searches for a match for the regular
54828          expression within the record.  If such a match is found, it is
54829          the sort key.  If there is no match for KEY-REGEXP within a
54830          record then that record is ignored, which means its position
54831          in the buffer is not changed.  (The other records may move
54832          around it.)
54833
54834     For example, if you plan to sort all the lines in the region by the
54835     first word on each line starting with the letter ‘f’, you should
54836     set RECORD-REGEXP to ‘^.*$’ and set KEY-REGEXP to ‘\<f\w*\>’.  The
54837     resulting expression looks like this:
54838
54839          (sort-regexp-fields nil "^.*$" "\\<f\\w*\\>"
54840                              (region-beginning)
54841                              (region-end))
54842
54843     If you call ‘sort-regexp-fields’ interactively, it prompts for
54844     RECORD-REGEXP and KEY-REGEXP in the minibuffer.
54845
54846 -- Command: sort-lines reverse start end
54847     This command alphabetically sorts lines in the region between START
54848     and END.  If REVERSE is non-‘nil’, the sort is in reverse order.
54849
54850 -- Command: sort-paragraphs reverse start end
54851     This command alphabetically sorts paragraphs in the region between
54852     START and END.  If REVERSE is non-‘nil’, the sort is in reverse
54853     order.
54854
54855 -- Command: sort-pages reverse start end
54856     This command alphabetically sorts pages in the region between START
54857     and END.  If REVERSE is non-‘nil’, the sort is in reverse order.
54858
54859 -- Command: sort-fields field start end
54860     This command sorts lines in the region between START and END,
54861     comparing them alphabetically by the FIELDth field of each line.
54862     Fields are separated by whitespace and numbered starting from 1.
54863     If FIELD is negative, sorting is by the −FIELDth field from the end
54864     of the line.  This command is useful for sorting tables.
54865
54866 -- Command: sort-numeric-fields field start end
54867     This command sorts lines in the region between START and END,
54868     comparing them numerically by the FIELDth field of each line.
54869     Fields are separated by whitespace and numbered starting from 1.
54870     The specified field must contain a number in each line of the
54871     region.  Numbers starting with 0 are treated as octal, and numbers
54872     starting with ‘0x’ are treated as hexadecimal.
54873
54874     If FIELD is negative, sorting is by the −FIELDth field from the end
54875     of the line.  This command is useful for sorting tables.
54876
54877 -- User Option: sort-numeric-base
54878     This variable specifies the default radix for ‘sort-numeric-fields’
54879     to parse numbers.
54880
54881 -- Command: sort-columns reverse &optional beg end
54882     This command sorts the lines in the region between BEG and END,
54883     comparing them alphabetically by a certain range of columns.  The
54884     column positions of BEG and END bound the range of columns to sort
54885     on.
54886
54887     If REVERSE is non-‘nil’, the sort is in reverse order.
54888
54889     One unusual thing about this command is that the entire line
54890     containing position BEG, and the entire line containing position
54891     END, are included in the region sorted.
54892
54893     Note that ‘sort-columns’ rejects text that contains tabs, because
54894     tabs could be split across the specified columns.  Use ‘M-x
54895     untabify’ to convert tabs to spaces before sorting.
54896
54897     When possible, this command actually works by calling the ‘sort’
54898     utility program.
54899
54900
54901File: elisp.info,  Node: Columns,  Next: Indentation,  Prev: Sorting,  Up: Text
54902
5490332.16 Counting Columns
54904======================
54905
54906The column functions convert between a character position (counting
54907characters from the beginning of the buffer) and a column position
54908(counting screen characters from the beginning of a line).
54909
54910   These functions count each character according to the number of
54911columns it occupies on the screen.  This means control characters count
54912as occupying 2 or 4 columns, depending upon the value of ‘ctl-arrow’,
54913and tabs count as occupying a number of columns that depends on the
54914value of ‘tab-width’ and on the column where the tab begins.  *Note
54915Usual Display::.
54916
54917   Column number computations ignore the width of the window and the
54918amount of horizontal scrolling.  Consequently, a column value can be
54919arbitrarily high.  The first (or leftmost) column is numbered 0.  They
54920also ignore overlays and text properties, aside from invisibility.
54921
54922 -- Function: current-column
54923     This function returns the horizontal position of point, measured in
54924     columns, counting from 0 at the left margin.  The column position
54925     is the sum of the widths of all the displayed representations of
54926     the characters between the start of the current line and point.
54927
54928 -- Command: move-to-column column &optional force
54929     This function moves point to COLUMN in the current line.  The
54930     calculation of COLUMN takes into account the widths of the
54931     displayed representations of the characters between the start of
54932     the line and point.
54933
54934     When called interactively, COLUMN is the value of prefix numeric
54935     argument.  If COLUMN is not an integer, an error is signaled.
54936
54937     If it is impossible to move to column COLUMN because that is in the
54938     middle of a multicolumn character such as a tab, point moves to the
54939     end of that character.  However, if FORCE is non-‘nil’, and COLUMN
54940     is in the middle of a tab, then ‘move-to-column’ either converts
54941     the tab into spaces (when ‘indent-tabs-mode’ is ‘nil’), or inserts
54942     enough spaces before it (otherwise), so that point can move
54943     precisely to column COLUMN.  Other multicolumn characters can cause
54944     anomalies despite FORCE, since there is no way to split them.
54945
54946     The argument FORCE also has an effect if the line isn’t long enough
54947     to reach column COLUMN; if it is ‘t’, that means to add whitespace
54948     at the end of the line to reach that column.
54949
54950     The return value is the column number actually moved to.
54951
54952
54953File: elisp.info,  Node: Indentation,  Next: Case Changes,  Prev: Columns,  Up: Text
54954
5495532.17 Indentation
54956=================
54957
54958The indentation functions are used to examine, move to, and change
54959whitespace that is at the beginning of a line.  Some of the functions
54960can also change whitespace elsewhere on a line.  Columns and indentation
54961count from zero at the left margin.
54962
54963* Menu:
54964
54965* Primitive Indent::      Functions used to count and insert indentation.
54966* Mode-Specific Indent::  Customize indentation for different modes.
54967* Region Indent::         Indent all the lines in a region.
54968* Relative Indent::       Indent the current line based on previous lines.
54969* Indent Tabs::           Adjustable, typewriter-like tab stops.
54970* Motion by Indent::      Move to first non-blank character.
54971
54972
54973File: elisp.info,  Node: Primitive Indent,  Next: Mode-Specific Indent,  Up: Indentation
54974
5497532.17.1 Indentation Primitives
54976------------------------------
54977
54978This section describes the primitive functions used to count and insert
54979indentation.  The functions in the following sections use these
54980primitives.  *Note Size of Displayed Text::, for related functions.
54981
54982 -- Function: current-indentation
54983     This function returns the indentation of the current line, which is
54984     the horizontal position of the first nonblank character.  If the
54985     contents are entirely blank, then this is the horizontal position
54986     of the end of the line.
54987
54988 -- Command: indent-to column &optional minimum
54989     This function indents from point with tabs and spaces until COLUMN
54990     is reached.  If MINIMUM is specified and non-‘nil’, then at least
54991     that many spaces are inserted even if this requires going beyond
54992     COLUMN.  Otherwise the function does nothing if point is already
54993     beyond COLUMN.  The value is the column at which the inserted
54994     indentation ends.
54995
54996     The inserted whitespace characters inherit text properties from the
54997     surrounding text (usually, from the preceding text only).  *Note
54998     Sticky Properties::.
54999
55000 -- User Option: indent-tabs-mode
55001     If this variable is non-‘nil’, indentation functions can insert
55002     tabs as well as spaces.  Otherwise, they insert only spaces.
55003     Setting this variable automatically makes it buffer-local in the
55004     current buffer.
55005
55006
55007File: elisp.info,  Node: Mode-Specific Indent,  Next: Region Indent,  Prev: Primitive Indent,  Up: Indentation
55008
5500932.17.2 Indentation Controlled by Major Mode
55010--------------------------------------------
55011
55012An important function of each major mode is to customize the <TAB> key
55013to indent properly for the language being edited.  This section
55014describes the mechanism of the <TAB> key and how to control it.  The
55015functions in this section return unpredictable values.
55016
55017 -- Command: indent-for-tab-command &optional rigid
55018     This is the command bound to <TAB> in most editing modes.  Its
55019     usual action is to indent the current line, but it can
55020     alternatively insert a tab character or indent a region.
55021
55022     Here is what it does:
55023
55024        • First, it checks whether Transient Mark mode is enabled and
55025          the region is active.  If so, it calls ‘indent-region’ to
55026          indent all the text in the region (*note Region Indent::).
55027
55028        • Otherwise, if the indentation function in
55029          ‘indent-line-function’ is ‘indent-to-left-margin’ (a trivial
55030          command that inserts a tab character), or if the variable
55031          ‘tab-always-indent’ specifies that a tab character ought to be
55032          inserted (see below), then it inserts a tab character.
55033
55034        • Otherwise, it indents the current line; this is done by
55035          calling the function in ‘indent-line-function’.  If the line
55036          is already indented, and the value of ‘tab-always-indent’ is
55037          ‘complete’ (see below), it tries completing the text at point.
55038
55039     If RIGID is non-‘nil’ (interactively, with a prefix argument), then
55040     after this command indents a line or inserts a tab, it also rigidly
55041     indents the entire balanced expression which starts at the
55042     beginning of the current line, in order to reflect the new
55043     indentation.  This argument is ignored if the command indents the
55044     region.
55045
55046 -- Variable: indent-line-function
55047     This variable’s value is the function to be used by
55048     ‘indent-for-tab-command’, and various other indentation commands,
55049     to indent the current line.  It is usually assigned by the major
55050     mode; for instance, Lisp mode sets it to ‘lisp-indent-line’, C mode
55051     sets it to ‘c-indent-line’, and so on.  The default value is
55052     ‘indent-relative’.  *Note Auto-Indentation::.
55053
55054 -- Command: indent-according-to-mode
55055     This command calls the function in ‘indent-line-function’ to indent
55056     the current line in a way appropriate for the current major mode.
55057
55058 -- Command: newline-and-indent
55059     This function inserts a newline, then indents the new line (the one
55060     following the newline just inserted) according to the major mode.
55061     It does indentation by calling ‘indent-according-to-mode’.
55062
55063 -- Command: reindent-then-newline-and-indent
55064     This command reindents the current line, inserts a newline at
55065     point, and then indents the new line (the one following the newline
55066     just inserted).  It does indentation on both lines by calling
55067     ‘indent-according-to-mode’.
55068
55069 -- User Option: tab-always-indent
55070     This variable can be used to customize the behavior of the <TAB>
55071     (‘indent-for-tab-command’) command.  If the value is ‘t’ (the
55072     default), the command normally just indents the current line.  If
55073     the value is ‘nil’, the command indents the current line only if
55074     point is at the left margin or in the line’s indentation;
55075     otherwise, it inserts a tab character.  If the value is ‘complete’,
55076     the command first tries to indent the current line, and if the line
55077     was already indented, it calls ‘completion-at-point’ to complete
55078     the text at point (*note Completion in Buffers::).
55079
55080   Some major modes need to support embedded regions of text whose
55081syntax belongs to a different major mode.  Examples include “literate
55082programming” source files that combine documentation and snippets of
55083source code, Yacc/Bison programs that include snippets of Python or JS
55084code, etc.  To correctly indent the embedded chunks, the primary mode
55085needs to delegate the indentation to another mode’s indentation engine
55086(e.g., call ‘js-indent-line’ for JS code or ‘python-indent-line’ for
55087Python), while providing it with some context to guide the indentation.
55088Major modes, for their part, should avoid calling ‘widen’ in their
55089indentation code and obey ‘prog-first-column’.
55090
55091 -- Variable: prog-indentation-context
55092     This variable, when non-‘nil’, holds the indentation context for
55093     the sub-mode’s indentation engine provided by the superior major
55094     mode.  The value should be a list of the form ‘(FIRST-COLUMN .
55095     REST’.  The members of the list have the following meaning:
55096
55097     FIRST-COLUMN
55098          The column to be used for top-level constructs.  This replaces
55099          the default value of the top-level column used by the
55100          sub-mode, usually zero.
55101     REST
55102          This value is currently unused.
55103
55104   The following convenience function should be used by major mode’s
55105indentation engine in support of invocations as sub-modes of another
55106major mode.
55107
55108 -- Function: prog-first-column
55109     Call this function instead of using a literal value (usually, zero)
55110     of the column number for indenting top-level program constructs.
55111     The function’s value is the column number to use for top-level
55112     constructs.  When no superior mode is in effect, this function
55113     returns zero.
55114
55115
55116File: elisp.info,  Node: Region Indent,  Next: Relative Indent,  Prev: Mode-Specific Indent,  Up: Indentation
55117
5511832.17.3 Indenting an Entire Region
55119----------------------------------
55120
55121This section describes commands that indent all the lines in the region.
55122They return unpredictable values.
55123
55124 -- Command: indent-region start end &optional to-column
55125     This command indents each nonblank line starting between START
55126     (inclusive) and END (exclusive).  If TO-COLUMN is ‘nil’,
55127     ‘indent-region’ indents each nonblank line by calling the current
55128     mode’s indentation function, the value of ‘indent-line-function’.
55129
55130     If TO-COLUMN is non-‘nil’, it should be an integer specifying the
55131     number of columns of indentation; then this function gives each
55132     line exactly that much indentation, by either adding or deleting
55133     whitespace.
55134
55135     If there is a fill prefix, ‘indent-region’ indents each line by
55136     making it start with the fill prefix.
55137
55138 -- Variable: indent-region-function
55139     The value of this variable is a function that can be used by
55140     ‘indent-region’ as a short cut.  It should take two arguments, the
55141     start and end of the region.  You should design the function so
55142     that it will produce the same results as indenting the lines of the
55143     region one by one, but presumably faster.
55144
55145     If the value is ‘nil’, there is no short cut, and ‘indent-region’
55146     actually works line by line.
55147
55148     A short-cut function is useful in modes such as C mode and Lisp
55149     mode, where the ‘indent-line-function’ must scan from the beginning
55150     of the function definition: applying it to each line would be
55151     quadratic in time.  The short cut can update the scan information
55152     as it moves through the lines indenting them; this takes linear
55153     time.  In a mode where indenting a line individually is fast, there
55154     is no need for a short cut.
55155
55156     ‘indent-region’ with a non-‘nil’ argument TO-COLUMN has a different
55157     meaning and does not use this variable.
55158
55159 -- Command: indent-rigidly start end count
55160     This function indents all lines starting between START (inclusive)
55161     and END (exclusive) sideways by COUNT columns.  This preserves the
55162     shape of the affected region, moving it as a rigid unit.
55163
55164     This is useful not only for indenting regions of unindented text,
55165     but also for indenting regions of formatted code.  For example, if
55166     COUNT is 3, this command adds 3 columns of indentation to every
55167     line that begins in the specified region.
55168
55169     If called interactively with no prefix argument, this command
55170     invokes a transient mode for adjusting indentation rigidly.  *Note
55171     (emacs)Indentation Commands::.
55172
55173 -- Command: indent-code-rigidly start end columns &optional
55174          nochange-regexp
55175     This is like ‘indent-rigidly’, except that it doesn’t alter lines
55176     that start within strings or comments.
55177
55178     In addition, it doesn’t alter a line if NOCHANGE-REGEXP matches at
55179     the beginning of the line (if NOCHANGE-REGEXP is non-‘nil’).
55180
55181
55182File: elisp.info,  Node: Relative Indent,  Next: Indent Tabs,  Prev: Region Indent,  Up: Indentation
55183
5518432.17.4 Indentation Relative to Previous Lines
55185----------------------------------------------
55186
55187This section describes two commands that indent the current line based
55188on the contents of previous lines.
55189
55190 -- Command: indent-relative &optional unindented-ok
55191     This command inserts whitespace at point, extending to the same
55192     column as the next “indent point” of the previous nonblank line.
55193     An indent point is a non-whitespace character following whitespace.
55194     The next indent point is the first one at a column greater than the
55195     current column of point.  For example, if point is underneath and
55196     to the left of the first non-blank character of a line of text, it
55197     moves to that column by inserting whitespace.
55198
55199     If the previous nonblank line has no next indent point (i.e., none
55200     at a great enough column position), ‘indent-relative’ either does
55201     nothing (if UNINDENTED-OK is non-‘nil’) or calls ‘tab-to-tab-stop’.
55202     Thus, if point is underneath and to the right of the last column of
55203     a short line of text, this command ordinarily moves point to the
55204     next tab stop by inserting whitespace.
55205
55206     The return value of ‘indent-relative’ is unpredictable.
55207
55208     In the following example, point is at the beginning of the second
55209     line:
55210
55211                      This line is indented twelve spaces.
55212          ★The quick brown fox jumped.
55213
55214     Evaluation of the expression ‘(indent-relative nil)’ produces the
55215     following:
55216
55217                      This line is indented twelve spaces.
55218                      ★The quick brown fox jumped.
55219
55220     In this next example, point is between the ‘m’ and ‘p’ of ‘jumped’:
55221
55222                      This line is indented twelve spaces.
55223          The quick brown fox jum★ped.
55224
55225     Evaluation of the expression ‘(indent-relative nil)’ produces the
55226     following:
55227
55228                      This line is indented twelve spaces.
55229          The quick brown fox jum  ★ped.
55230
55231 -- Command: indent-relative-first-indent-point
55232     This command indents the current line like the previous nonblank
55233     line, by calling ‘indent-relative’ with ‘t’ as the FIRST-ONLY
55234     argument.  The return value is unpredictable.
55235
55236     If the previous nonblank line has no indent points beyond the
55237     current column, this command does nothing.
55238
55239
55240File: elisp.info,  Node: Indent Tabs,  Next: Motion by Indent,  Prev: Relative Indent,  Up: Indentation
55241
5524232.17.5 Adjustable Tab Stops
55243----------------------------
55244
55245This section explains the mechanism for user-specified tab stops and the
55246mechanisms that use and set them.  The name “tab stops” is used because
55247the feature is similar to that of the tab stops on a typewriter.  The
55248feature works by inserting an appropriate number of spaces and tab
55249characters to reach the next tab stop column; it does not affect the
55250display of tab characters in the buffer (*note Usual Display::).  Note
55251that the <TAB> character as input uses this tab stop feature only in a
55252few major modes, such as Text mode.  *Note (emacs)Tab Stops::.
55253
55254 -- Command: tab-to-tab-stop
55255     This command inserts spaces or tabs before point, up to the next
55256     tab stop column defined by ‘tab-stop-list’.
55257
55258 -- User Option: tab-stop-list
55259     This variable defines the tab stop columns used by
55260     ‘tab-to-tab-stop’.  It should be either ‘nil’, or a list of
55261     increasing integers, which need not be evenly spaced.  The list is
55262     implicitly extended to infinity through repetition of the interval
55263     between the last and penultimate elements (or ‘tab-width’ if the
55264     list has fewer than two elements).  A value of ‘nil’ means a tab
55265     stop every ‘tab-width’ columns.
55266
55267     Use ‘M-x edit-tab-stops’ to edit the location of tab stops
55268     interactively.
55269
55270
55271File: elisp.info,  Node: Motion by Indent,  Prev: Indent Tabs,  Up: Indentation
55272
5527332.17.6 Indentation-Based Motion Commands
55274-----------------------------------------
55275
55276These commands, primarily for interactive use, act based on the
55277indentation in the text.
55278
55279 -- Command: back-to-indentation
55280     This command moves point to the first non-whitespace character in
55281     the current line (which is the line in which point is located).  It
55282     returns ‘nil’.
55283
55284 -- Command: backward-to-indentation &optional arg
55285     This command moves point backward ARG lines and then to the first
55286     nonblank character on that line.  It returns ‘nil’.  If ARG is
55287     omitted or ‘nil’, it defaults to 1.
55288
55289 -- Command: forward-to-indentation &optional arg
55290     This command moves point forward ARG lines and then to the first
55291     nonblank character on that line.  It returns ‘nil’.  If ARG is
55292     omitted or ‘nil’, it defaults to 1.
55293
55294
55295File: elisp.info,  Node: Case Changes,  Next: Text Properties,  Prev: Indentation,  Up: Text
55296
5529732.18 Case Changes
55298==================
55299
55300The case change commands described here work on text in the current
55301buffer.  *Note Case Conversion::, for case conversion functions that
55302work on strings and characters.  *Note Case Tables::, for how to
55303customize which characters are upper or lower case and how to convert
55304them.
55305
55306 -- Command: capitalize-region start end
55307     This function capitalizes all words in the region defined by START
55308     and END.  To capitalize means to convert each word’s first
55309     character to upper case and convert the rest of each word to lower
55310     case.  The function returns ‘nil’.
55311
55312     If one end of the region is in the middle of a word, the part of
55313     the word within the region is treated as an entire word.
55314
55315     When ‘capitalize-region’ is called interactively, START and END are
55316     point and the mark, with the smallest first.
55317
55318          ---------- Buffer: foo ----------
55319          This is the contents of the 5th foo.
55320          ---------- Buffer: foo ----------
55321
55322          (capitalize-region 1 37)
55323          ⇒ nil
55324
55325          ---------- Buffer: foo ----------
55326          This Is The Contents Of The 5th Foo.
55327          ---------- Buffer: foo ----------
55328
55329 -- Command: downcase-region start end
55330     This function converts all of the letters in the region defined by
55331     START and END to lower case.  The function returns ‘nil’.
55332
55333     When ‘downcase-region’ is called interactively, START and END are
55334     point and the mark, with the smallest first.
55335
55336 -- Command: upcase-region start end
55337     This function converts all of the letters in the region defined by
55338     START and END to upper case.  The function returns ‘nil’.
55339
55340     When ‘upcase-region’ is called interactively, START and END are
55341     point and the mark, with the smallest first.
55342
55343 -- Command: capitalize-word count
55344     This function capitalizes COUNT words after point, moving point
55345     over as it does.  To capitalize means to convert each word’s first
55346     character to upper case and convert the rest of each word to lower
55347     case.  If COUNT is negative, the function capitalizes the −COUNT
55348     previous words but does not move point.  The value is ‘nil’.
55349
55350     If point is in the middle of a word, the part of the word before
55351     point is ignored when moving forward.  The rest is treated as an
55352     entire word.
55353
55354     When ‘capitalize-word’ is called interactively, COUNT is set to the
55355     numeric prefix argument.
55356
55357 -- Command: downcase-word count
55358     This function converts the COUNT words after point to all lower
55359     case, moving point over as it does.  If COUNT is negative, it
55360     converts the −COUNT previous words but does not move point.  The
55361     value is ‘nil’.
55362
55363     When ‘downcase-word’ is called interactively, COUNT is set to the
55364     numeric prefix argument.
55365
55366 -- Command: upcase-word count
55367     This function converts the COUNT words after point to all upper
55368     case, moving point over as it does.  If COUNT is negative, it
55369     converts the −COUNT previous words but does not move point.  The
55370     value is ‘nil’.
55371
55372     When ‘upcase-word’ is called interactively, COUNT is set to the
55373     numeric prefix argument.
55374
55375
55376File: elisp.info,  Node: Text Properties,  Next: Substitution,  Prev: Case Changes,  Up: Text
55377
5537832.19 Text Properties
55379=====================
55380
55381Each character position in a buffer or a string can have a “text
55382property list”, much like the property list of a symbol (*note Property
55383Lists::).  The properties belong to a particular character at a
55384particular place, such as, the letter ‘T’ at the beginning of this
55385sentence or the first ‘o’ in ‘foo’—if the same character occurs in two
55386different places, the two occurrences in general have different
55387properties.
55388
55389   Each property has a name and a value.  Both of these can be any Lisp
55390object, but the name is normally a symbol.  Typically each property name
55391symbol is used for a particular purpose; for instance, the text property
55392‘face’ specifies the faces for displaying the character (*note Special
55393Properties::).  The usual way to access the property list is to specify
55394a name and ask what value corresponds to it.
55395
55396   If a character has a ‘category’ property, we call it the “property
55397category” of the character.  It should be a symbol.  The properties of
55398the symbol serve as defaults for the properties of the character.
55399
55400   Copying text between strings and buffers preserves the properties
55401along with the characters; this includes such diverse functions as
55402‘substring’, ‘insert’, and ‘buffer-substring’.
55403
55404* Menu:
55405
55406* Examining Properties::   Looking at the properties of one character.
55407* Changing Properties::    Setting the properties of a range of text.
55408* Property Search::        Searching for where a property changes value.
55409* Special Properties::     Particular properties with special meanings.
55410* Format Properties::      Properties for representing formatting of text.
55411* Sticky Properties::      How inserted text gets properties from
55412                             neighboring text.
55413* Lazy Properties::        Computing text properties in a lazy fashion
55414                             only when text is examined.
55415* Clickable Text::         Using text properties to make regions of text
55416                             do something when you click on them.
55417* Fields::                 The ‘field’ property defines
55418                             fields within the buffer.
55419* Not Intervals::          Why text properties do not use
55420                             Lisp-visible text intervals.
55421
55422
55423File: elisp.info,  Node: Examining Properties,  Next: Changing Properties,  Up: Text Properties
55424
5542532.19.1 Examining Text Properties
55426---------------------------------
55427
55428The simplest way to examine text properties is to ask for the value of a
55429particular property of a particular character.  For that, use
55430‘get-text-property’.  Use ‘text-properties-at’ to get the entire
55431property list of a character.  *Note Property Search::, for functions to
55432examine the properties of a number of characters at once.
55433
55434   These functions handle both strings and buffers.  Keep in mind that
55435positions in a string start from 0, whereas positions in a buffer start
55436from 1.  Passing a buffer other than the current buffer may be slow.
55437
55438 -- Function: get-text-property pos prop &optional object
55439     This function returns the value of the PROP property of the
55440     character after position POS in OBJECT (a buffer or string).  The
55441     argument OBJECT is optional and defaults to the current buffer.
55442
55443     If there is no PROP property strictly speaking, but the character
55444     has a property category that is a symbol, then ‘get-text-property’
55445     returns the PROP property of that symbol.
55446
55447 -- Function: get-char-property position prop &optional object
55448     This function is like ‘get-text-property’, except that it checks
55449     overlays first and then text properties.  *Note Overlays::.
55450
55451     The argument OBJECT may be a string, a buffer, or a window.  If it
55452     is a window, then the buffer displayed in that window is used for
55453     text properties and overlays, but only the overlays active for that
55454     window are considered.  If OBJECT is a buffer, then overlays in
55455     that buffer are considered first, in order of decreasing priority,
55456     followed by the text properties.  If OBJECT is a string, only text
55457     properties are considered, since strings never have overlays.
55458
55459 -- Function: get-pos-property position prop &optional object
55460     This function is like ‘get-char-property’, except that it pays
55461     attention to properties’ stickiness and overlays’ advancement
55462     settings instead of the property of the character at (i.e., right
55463     after) POSITION.
55464
55465 -- Function: get-char-property-and-overlay position prop &optional
55466          object
55467     This is like ‘get-char-property’, but gives extra information about
55468     the overlay that the property value comes from.
55469
55470     Its value is a cons cell whose CAR is the property value, the same
55471     value ‘get-char-property’ would return with the same arguments.
55472     Its CDR is the overlay in which the property was found, or ‘nil’,
55473     if it was found as a text property or not found at all.
55474
55475     If POSITION is at the end of OBJECT, both the CAR and the CDR of
55476     the value are ‘nil’.
55477
55478 -- Variable: char-property-alias-alist
55479     This variable holds an alist which maps property names to a list of
55480     alternative property names.  If a character does not specify a
55481     direct value for a property, the alternative property names are
55482     consulted in order; the first non-‘nil’ value is used.  This
55483     variable takes precedence over ‘default-text-properties’, and
55484     ‘category’ properties take precedence over this variable.
55485
55486 -- Function: text-properties-at position &optional object
55487     This function returns the entire property list of the character at
55488     POSITION in the string or buffer OBJECT.  If OBJECT is ‘nil’, it
55489     defaults to the current buffer.
55490
55491 -- Variable: default-text-properties
55492     This variable holds a property list giving default values for text
55493     properties.  Whenever a character does not specify a value for a
55494     property, neither directly, through a category symbol, or through
55495     ‘char-property-alias-alist’, the value stored in this list is used
55496     instead.  Here is an example:
55497
55498          (setq default-text-properties '(foo 69)
55499                char-property-alias-alist nil)
55500          ;; Make sure character 1 has no properties of its own.
55501          (set-text-properties 1 2 nil)
55502          ;; What we get, when we ask, is the default value.
55503          (get-text-property 1 'foo)
55504               ⇒ 69
55505
55506
55507File: elisp.info,  Node: Changing Properties,  Next: Property Search,  Prev: Examining Properties,  Up: Text Properties
55508
5550932.19.2 Changing Text Properties
55510--------------------------------
55511
55512The primitives for changing properties apply to a specified range of
55513text in a buffer or string.  The function ‘set-text-properties’ (see end
55514of section) sets the entire property list of the text in that range;
55515more often, it is useful to add, change, or delete just certain
55516properties specified by name.
55517
55518   Since text properties are considered part of the contents of the
55519buffer (or string), and can affect how a buffer looks on the screen, any
55520change in buffer text properties marks the buffer as modified.  Buffer
55521text property changes are undoable also (*note Undo::).  Positions in a
55522string start from 0, whereas positions in a buffer start from 1.
55523
55524 -- Function: put-text-property start end prop value &optional object
55525     This function sets the PROP property to VALUE for the text between
55526     START and END in the string or buffer OBJECT.  If OBJECT is ‘nil’,
55527     it defaults to the current buffer.
55528
55529 -- Function: add-text-properties start end props &optional object
55530     This function adds or overrides text properties for the text
55531     between START and END in the string or buffer OBJECT.  If OBJECT is
55532     ‘nil’, it defaults to the current buffer.
55533
55534     The argument PROPS specifies which properties to add.  It should
55535     have the form of a property list (*note Property Lists::): a list
55536     whose elements include the property names followed alternately by
55537     the corresponding values.
55538
55539     The return value is ‘t’ if the function actually changed some
55540     property’s value; ‘nil’ otherwise (if PROPS is ‘nil’ or its values
55541     agree with those in the text).
55542
55543     For example, here is how to set the ‘comment’ and ‘face’ properties
55544     of a range of text:
55545
55546          (add-text-properties START END
55547                               '(comment t face highlight))
55548
55549 -- Function: remove-text-properties start end props &optional object
55550     This function deletes specified text properties from the text
55551     between START and END in the string or buffer OBJECT.  If OBJECT is
55552     ‘nil’, it defaults to the current buffer.
55553
55554     The argument PROPS specifies which properties to delete.  It should
55555     have the form of a property list (*note Property Lists::): a list
55556     whose elements are property names alternating with corresponding
55557     values.  But only the names matter—the values that accompany them
55558     are ignored.  For example, here’s how to remove the ‘face’
55559     property.
55560
55561          (remove-text-properties START END '(face nil))
55562
55563     The return value is ‘t’ if the function actually changed some
55564     property’s value; ‘nil’ otherwise (if PROPS is ‘nil’ or if no
55565     character in the specified text had any of those properties).
55566
55567     To remove all text properties from certain text, use
55568     ‘set-text-properties’ and specify ‘nil’ for the new property list.
55569
55570 -- Function: remove-list-of-text-properties start end
55571          list-of-properties &optional object
55572     Like ‘remove-text-properties’ except that LIST-OF-PROPERTIES is a
55573     list of property names only, not an alternating list of property
55574     names and values.
55575
55576 -- Function: set-text-properties start end props &optional object
55577     This function completely replaces the text property list for the
55578     text between START and END in the string or buffer OBJECT.  If
55579     OBJECT is ‘nil’, it defaults to the current buffer.
55580
55581     The argument PROPS is the new property list.  It should be a list
55582     whose elements are property names alternating with corresponding
55583     values.
55584
55585     After ‘set-text-properties’ returns, all the characters in the
55586     specified range have identical properties.
55587
55588     If PROPS is ‘nil’, the effect is to get rid of all properties from
55589     the specified range of text.  Here’s an example:
55590
55591          (set-text-properties START END nil)
55592
55593     Do not rely on the return value of this function.
55594
55595 -- Function: add-face-text-property start end face &optional appendp
55596          object
55597     This function acts on the text between START and END, adding the
55598     face FACE to the ‘face’ text property.  FACE should be a valid
55599     value for the ‘face’ property (*note Special Properties::), such as
55600     a face name or an anonymous face (*note Faces::).
55601
55602     If any text in the region already has a non-‘nil’ ‘face’ property,
55603     those face(s) are retained.  This function sets the ‘face’ property
55604     to a list of faces, with FACE as the first element (by default) and
55605     the pre-existing faces as the remaining elements.  If the optional
55606     argument APPENDP is non-‘nil’, FACE is appended to the end of the
55607     list instead.  Note that in a face list, the first occurring value
55608     for each attribute takes precedence.
55609
55610     For example, the following code would assign an italicized green
55611     face to the text between START and END:
55612
55613          (add-face-text-property START END 'italic)
55614          (add-face-text-property START END '(:foreground "red"))
55615          (add-face-text-property START END '(:foreground "green"))
55616
55617     The optional argument OBJECT, if non-‘nil’, specifies a buffer or
55618     string to act on, rather than the current buffer.  If OBJECT is a
55619     string, then START and END are zero-based indices into the string.
55620
55621   The easiest way to make a string with text properties is with
55622‘propertize’:
55623
55624 -- Function: propertize string &rest properties
55625     This function returns a copy of STRING with the text properties
55626     PROPERTIES added.  These properties apply to all the characters in
55627     the string that is returned.  Here is an example that constructs a
55628     string with a ‘face’ property and a ‘mouse-face’ property:
55629
55630          (propertize "foo" 'face 'italic
55631                      'mouse-face 'bold-italic)
55632               ⇒ #("foo" 0 3 (mouse-face bold-italic face italic))
55633
55634     To put different properties on various parts of a string, you can
55635     construct each part with ‘propertize’ and then combine them with
55636     ‘concat’:
55637
55638          (concat
55639           (propertize "foo" 'face 'italic
55640                       'mouse-face 'bold-italic)
55641           " and "
55642           (propertize "bar" 'face 'italic
55643                       'mouse-face 'bold-italic))
55644               ⇒ #("foo and bar"
55645                           0 3 (face italic mouse-face bold-italic)
55646                           3 8 nil
55647                           8 11 (face italic mouse-face bold-italic))
55648
55649   *Note Buffer Contents::, for the function
55650‘buffer-substring-no-properties’, which copies text from the buffer but
55651does not copy its properties.
55652
55653   If you wish to add text properties to a buffer or remove them without
55654marking the buffer as modified, you can wrap the calls above in the
55655‘with-silent-modifications’ macro.  *Note Buffer Modification::.
55656
55657
55658File: elisp.info,  Node: Property Search,  Next: Special Properties,  Prev: Changing Properties,  Up: Text Properties
55659
5566032.19.3 Text Property Search Functions
55661--------------------------------------
55662
55663In typical use of text properties, most of the time several or many
55664consecutive characters have the same value for a property.  Rather than
55665writing your programs to examine characters one by one, it is much
55666faster to process chunks of text that have the same property value.
55667
55668   Here are functions you can use to do this.  They use ‘eq’ for
55669comparing property values.  In all cases, OBJECT defaults to the current
55670buffer.
55671
55672   For good performance, it’s very important to use the LIMIT argument
55673to these functions, especially the ones that search for a single
55674property—otherwise, they may spend a long time scanning to the end of
55675the buffer, if the property you are interested in does not change.
55676
55677   These functions do not move point; instead, they return a position
55678(or ‘nil’).  Remember that a position is always between two characters;
55679the position returned by these functions is between two characters with
55680different properties.
55681
55682 -- Function: next-property-change pos &optional object limit
55683     The function scans the text forward from position POS in the string
55684     or buffer OBJECT until it finds a change in some text property,
55685     then returns the position of the change.  In other words, it
55686     returns the position of the first character beyond POS whose
55687     properties are not identical to those of the character just after
55688     POS.
55689
55690     If LIMIT is non-‘nil’, then the scan ends at position LIMIT.  If
55691     there is no property change before that point, this function
55692     returns LIMIT.
55693
55694     The value is ‘nil’ if the properties remain unchanged all the way
55695     to the end of OBJECT and LIMIT is ‘nil’.  If the value is
55696     non-‘nil’, it is a position greater than or equal to POS.  The
55697     value equals POS only when LIMIT equals POS.
55698
55699     Here is an example of how to scan the buffer by chunks of text
55700     within which all properties are constant:
55701
55702          (while (not (eobp))
55703            (let ((plist (text-properties-at (point)))
55704                  (next-change
55705                   (or (next-property-change (point) (current-buffer))
55706                       (point-max))))
55707              Process text from point to NEXT-CHANGE...
55708              (goto-char next-change)))
55709
55710 -- Function: previous-property-change pos &optional object limit
55711     This is like ‘next-property-change’, but scans back from POS
55712     instead of forward.  If the value is non-‘nil’, it is a position
55713     less than or equal to POS; it equals POS only if LIMIT equals POS.
55714
55715 -- Function: next-single-property-change pos prop &optional object
55716          limit
55717     The function scans text for a change in the PROP property, then
55718     returns the position of the change.  The scan goes forward from
55719     position POS in the string or buffer OBJECT.  In other words, this
55720     function returns the position of the first character beyond POS
55721     whose PROP property differs from that of the character just after
55722     POS.
55723
55724     If LIMIT is non-‘nil’, then the scan ends at position LIMIT.  If
55725     there is no property change before that point,
55726     ‘next-single-property-change’ returns LIMIT.
55727
55728     The value is ‘nil’ if the property remains unchanged all the way to
55729     the end of OBJECT and LIMIT is ‘nil’.  If the value is non-‘nil’,
55730     it is a position greater than or equal to POS; it equals POS only
55731     if LIMIT equals POS.
55732
55733 -- Function: previous-single-property-change pos prop &optional object
55734          limit
55735     This is like ‘next-single-property-change’, but scans back from POS
55736     instead of forward.  If the value is non-‘nil’, it is a position
55737     less than or equal to POS; it equals POS only if LIMIT equals POS.
55738
55739 -- Function: next-char-property-change pos &optional limit
55740     This is like ‘next-property-change’ except that it considers
55741     overlay properties as well as text properties, and if no change is
55742     found before the end of the buffer, it returns the maximum buffer
55743     position rather than ‘nil’ (in this sense, it resembles the
55744     corresponding overlay function ‘next-overlay-change’, rather than
55745     ‘next-property-change’).  There is no OBJECT operand because this
55746     function operates only on the current buffer.  It returns the next
55747     address at which either kind of property changes.
55748
55749 -- Function: previous-char-property-change pos &optional limit
55750     This is like ‘next-char-property-change’, but scans back from POS
55751     instead of forward, and returns the minimum buffer position if no
55752     change is found.
55753
55754 -- Function: next-single-char-property-change pos prop &optional object
55755          limit
55756     This is like ‘next-single-property-change’ except that it considers
55757     overlay properties as well as text properties, and if no change is
55758     found before the end of the OBJECT, it returns the maximum valid
55759     position in OBJECT rather than ‘nil’.  Unlike
55760     ‘next-char-property-change’, this function _does_ have an OBJECT
55761     operand; if OBJECT is not a buffer, only text-properties are
55762     considered.
55763
55764 -- Function: previous-single-char-property-change pos prop &optional
55765          object limit
55766     This is like ‘next-single-char-property-change’, but scans back
55767     from POS instead of forward, and returns the minimum valid position
55768     in OBJECT if no change is found.
55769
55770 -- Function: text-property-any start end prop value &optional object
55771     This function returns non-‘nil’ if at least one character between
55772     START and END has a property PROP whose value is VALUE.  More
55773     precisely, it returns the position of the first such character.
55774     Otherwise, it returns ‘nil’.
55775
55776     The optional fifth argument, OBJECT, specifies the string or buffer
55777     to scan.  Positions are relative to OBJECT.  The default for OBJECT
55778     is the current buffer.
55779
55780 -- Function: text-property-not-all start end prop value &optional
55781          object
55782     This function returns non-‘nil’ if at least one character between
55783     START and END does not have a property PROP with value VALUE.  More
55784     precisely, it returns the position of the first such character.
55785     Otherwise, it returns ‘nil’.
55786
55787     The optional fifth argument, OBJECT, specifies the string or buffer
55788     to scan.  Positions are relative to OBJECT.  The default for OBJECT
55789     is the current buffer.
55790
55791 -- Function: text-property-search-forward prop &optional value
55792          predicate not-current
55793     Search for the next region that has text property PROP set to VALUE
55794     according to PREDICATE.
55795
55796     This function is modelled after ‘search-forward’ and friends in
55797     that it moves point, but it returns a structure that describes the
55798     match instead of returning it in ‘match-beginning’ and friends.
55799
55800     If the text property can’t be found, the function returns ‘nil’.
55801     If it’s found, point is placed at the end of the region that has
55802     this text property match, and a ‘prop-match’ structure is returned.
55803
55804     PREDICATE can either be ‘t’ (which is a synonym for ‘equal’), ‘nil’
55805     (which means “not equal”), or a predicate that will be called with
55806     two parameters: The first is VALUE, and the second is the value of
55807     the text property we’re inspecting.
55808
55809     If NOT-CURRENT, if point is in a region where we have a match, then
55810     skip past that and find the next instance instead.
55811
55812     The ‘prop-match’ structure has the following accessors:
55813     ‘prop-match-beginning’ (the start of the match), ‘prop-match-end’
55814     (the end of the match), and ‘prop-match-value’ (the value of
55815     PROPERTY at the start of the match).
55816
55817     In the examples below, imagine that you’re in a buffer that looks
55818     like this:
55819
55820          This is a bold and here's bolditalic and this is the end.
55821
55822     That is, the “bold” words are the ‘bold’ face, and the “italic”
55823     word is in the ‘italic’ face.
55824
55825     With point at the start:
55826
55827          (while (setq match (text-property-search-forward 'face 'bold t))
55828            (push (buffer-substring (prop-match-beginning match)
55829                                    (prop-match-end match))
55830                  words))
55831
55832     This will pick out all the words that use the ‘bold’ face.
55833
55834          (while (setq match (text-property-search-forward 'face nil t))
55835            (push (buffer-substring (prop-match-beginning match)
55836                                    (prop-match-end match))
55837                  words))
55838
55839     This will pick out all the bits that have no face properties, which
55840     will result in the list ‘("This is a " "and here's " "and this is
55841     the end")’ (only reversed, since we used ‘push’).
55842
55843          (while (setq match (text-property-search-forward 'face nil nil))
55844            (push (buffer-substring (prop-match-beginning match)
55845                                    (prop-match-end match))
55846                  words))
55847
55848     This will pick out all the regions where ‘face’ is set to
55849     something, but this is split up into where the properties change,
55850     so the result here will be ‘("bold" "bold" "italic")’.
55851
55852     For a more realistic example where you might use this, consider
55853     that you have a buffer where certain sections represent URLs, and
55854     these are tagged with ‘shr-url’.
55855
55856          (while (setq match (text-property-search-forward 'shr-url nil nil))
55857            (push (prop-match-value match) urls))
55858
55859     This will give you a list of all those URLs.
55860
55861 -- Function: text-property-search-backward prop &optional value
55862          predicate not-current
55863     This is just like ‘text-property-search-backward’, but searches
55864     backward instead.  Point is placed at the beginning of the matched
55865     region instead of the end, though.
55866
55867
55868File: elisp.info,  Node: Special Properties,  Next: Format Properties,  Prev: Property Search,  Up: Text Properties
55869
5587032.19.4 Properties with Special Meanings
55871----------------------------------------
55872
55873Here is a table of text property names that have special built-in
55874meanings.  The following sections list a few additional special property
55875names that control filling and property inheritance.  All other names
55876have no standard meaning, and you can use them as you like.
55877
55878   Note: the properties ‘composition’, ‘display’, ‘invisible’ and
55879‘intangible’ can also cause point to move to an acceptable place, after
55880each Emacs command.  *Note Adjusting Point::.
55881
55882‘category’
55883     If a character has a ‘category’ property, we call it the “property
55884     category” of the character.  It should be a symbol.  The properties
55885     of this symbol serve as defaults for the properties of the
55886     character.
55887
55888‘face’
55889     The ‘face’ property controls the appearance of the character (*note
55890     Faces::).  The value of the property can be the following:
55891
55892        • A face name (a symbol or string).
55893
55894        • An anonymous face: a property list of the form ‘(KEYWORD VALUE
55895          ...)’, where each KEYWORD is a face attribute name and VALUE
55896          is a value for that attribute.
55897
55898        • A list of faces.  Each list element should be either a face
55899          name or an anonymous face.  This specifies a face which is an
55900          aggregate of the attributes of each of the listed faces.
55901          Faces occurring earlier in the list have higher priority.
55902
55903        • A cons cell of the form ‘(foreground-color . COLOR-NAME)’ or
55904          ‘(background-color . COLOR-NAME)’.  This specifies the
55905          foreground or background color, similar to ‘(:foreground
55906          COLOR-NAME)’ or ‘(:background COLOR-NAME)’.  This form is
55907          supported for backward compatibility only, and should be
55908          avoided.
55909
55910        • A cons cell of the form ‘(:filtered FILTER FACE-SPEC)’, that
55911          specifies the face given by FACE-SPEC, but only if FILTER
55912          matches when the face is used for display.  The FACE-SPEC can
55913          use any of the forms mentioned above.  The FILTER should be of
55914          the form ‘(:window PARAM VALUE)’, which matches for windows
55915          whose parameter PARAM is ‘eq’ to VALUE.  If the variable
55916          ‘face-filters-always-match’ is non-‘nil’, all face filters are
55917          deemed to have matched.
55918
55919     Font Lock mode (*note Font Lock Mode::) works in most buffers by
55920     dynamically updating the ‘face’ property of characters based on the
55921     context.
55922
55923     The ‘add-face-text-property’ function provides a convenient way to
55924     set this text property.  *Note Changing Properties::.
55925
55926‘font-lock-face’
55927     This property specifies a value for the ‘face’ property that Font
55928     Lock mode should apply to the underlying text.  It is one of the
55929     fontification methods used by Font Lock mode, and is useful for
55930     special modes that implement their own highlighting.  *Note
55931     Precalculated Fontification::.  When Font Lock mode is disabled,
55932     ‘font-lock-face’ has no effect.
55933
55934‘mouse-face’
55935     This property is used instead of ‘face’ when the mouse is on or
55936     near the character.  For this purpose, “near” means that all text
55937     between the character and where the mouse is have the same
55938     ‘mouse-face’ property value.
55939
55940     Emacs ignores all face attributes from the ‘mouse-face’ property
55941     that alter the text size (e.g., ‘:height’, ‘:weight’, and
55942     ‘:slant’).  Those attributes are always the same as for the
55943     unhighlighted text.
55944
55945‘fontified’
55946     This property says whether the text is ready for display.  If
55947     ‘nil’, Emacs’s redisplay routine calls the functions in
55948     ‘fontification-functions’ (*note Auto Faces::) to prepare this part
55949     of the buffer before it is displayed.  It is used internally by the
55950     just-in-time font locking code.
55951
55952‘display’
55953     This property activates various features that change the way text
55954     is displayed.  For example, it can make text appear taller or
55955     shorter, higher or lower, wider or narrow, or replaced with an
55956     image.  *Note Display Property::.
55957
55958‘help-echo’
55959     If text has a string as its ‘help-echo’ property, then when you
55960     move the mouse onto that text, Emacs displays that string in the
55961     echo area, or in the tooltip window (*note Tooltips::), after
55962     passing it through ‘substitute-command-keys’.
55963
55964     If the value of the ‘help-echo’ property is a function, that
55965     function is called with three arguments, WINDOW, OBJECT and POS and
55966     should return a help string or ‘nil’ for none.  The first argument,
55967     WINDOW is the window in which the help was found.  The second,
55968     OBJECT, is the buffer, overlay or string which had the ‘help-echo’
55969     property.  The POS argument is as follows:
55970
55971        • If OBJECT is a buffer, POS is the position in the buffer.
55972        • If OBJECT is an overlay, that overlay has a ‘help-echo’
55973          property, and POS is the position in the overlay’s buffer.
55974        • If OBJECT is a string (an overlay string or a string displayed
55975          with the ‘display’ property), POS is the position in that
55976          string.
55977
55978     If the value of the ‘help-echo’ property is neither a function nor
55979     a string, it is evaluated to obtain a help string.
55980
55981     You can alter the way help text is displayed by setting the
55982     variable ‘show-help-function’ (*note Help display::).
55983
55984     This feature is used in the mode line and for other active text.
55985
55986‘help-echo-inhibit-substitution’
55987     If the first character of a ‘help-echo’ string has a non-‘nil’
55988     ‘help-echo-inhibit-substitution’ property, then it is displayed
55989     as-is by ‘show-help-function’, without being passed through
55990     ‘substitute-command-keys’.
55991
55992‘keymap’
55993     The ‘keymap’ property specifies an additional keymap for commands.
55994     When this keymap applies, it is used for key lookup before the
55995     minor mode keymaps and before the buffer’s local map.  *Note Active
55996     Keymaps::.  If the property value is a symbol, the symbol’s
55997     function definition is used as the keymap.
55998
55999     The property’s value for the character before point applies if it
56000     is non-‘nil’ and rear-sticky, and the property’s value for the
56001     character after point applies if it is non-‘nil’ and front-sticky.
56002     (For mouse clicks, the position of the click is used instead of the
56003     position of point.)
56004
56005‘local-map’
56006     This property works like ‘keymap’ except that it specifies a keymap
56007     to use _instead of_ the buffer’s local map.  For most purposes
56008     (perhaps all purposes), it is better to use the ‘keymap’ property.
56009
56010‘syntax-table’
56011     The ‘syntax-table’ property overrides what the syntax table says
56012     about this particular character.  *Note Syntax Properties::.
56013
56014‘read-only’
56015     If a character has the property ‘read-only’, then modifying that
56016     character is not allowed.  Any command that would do so gets an
56017     error, ‘text-read-only’.  If the property value is a string, that
56018     string is used as the error message.
56019
56020     Insertion next to a read-only character is an error if inserting
56021     ordinary text there would inherit the ‘read-only’ property due to
56022     stickiness.  Thus, you can control permission to insert next to
56023     read-only text by controlling the stickiness.  *Note Sticky
56024     Properties::.
56025
56026     Since changing properties counts as modifying the buffer, it is not
56027     possible to remove a ‘read-only’ property unless you know the
56028     special trick: bind ‘inhibit-read-only’ to a non-‘nil’ value and
56029     then remove the property.  *Note Read Only Buffers::.
56030
56031‘inhibit-read-only’
56032     Characters that have the property ‘inhibit-read-only’ can be edited
56033     even in read-only buffers.  *Note Read Only Buffers::.
56034
56035‘invisible’
56036     A non-‘nil’ ‘invisible’ property can make a character invisible on
56037     the screen.  *Note Invisible Text::, for details.
56038
56039‘intangible’
56040     If a group of consecutive characters have equal and non-‘nil’
56041     ‘intangible’ properties, then you cannot place point between them.
56042     If you try to move point forward into the group, point actually
56043     moves to the end of the group.  If you try to move point backward
56044     into the group, point actually moves to the start of the group.
56045
56046     If consecutive characters have unequal non-‘nil’ ‘intangible’
56047     properties, they belong to separate groups; each group is
56048     separately treated as described above.
56049
56050     When the variable ‘inhibit-point-motion-hooks’ is non-‘nil’ (as it
56051     is by default), the ‘intangible’ property is ignored.
56052
56053     Beware: this property operates at a very low level, and affects a
56054     lot of code in unexpected ways.  So use it with extreme caution.  A
56055     common misuse is to put an intangible property on invisible text,
56056     which is actually unnecessary since the command loop will move
56057     point outside of the invisible text at the end of each command
56058     anyway.  *Note Adjusting Point::.  For these reasons, this property
56059     is obsolete; use the ‘cursor-intangible’ property instead.
56060
56061‘cursor-intangible’
56062     When the minor mode ‘cursor-intangible-mode’ is turned on, point is
56063     moved away from any position that has a non-‘nil’
56064     ‘cursor-intangible’ property, just before redisplay happens.
56065
56066     When the variable ‘cursor-sensor-inhibit’ is non-‘nil’, the
56067     ‘cursor-intangible’ property and the ‘cursor-sensor-functions’
56068     property (described below) are ignored.
56069
56070‘field’
56071     Consecutive characters with the same ‘field’ property constitute a
56072     “field”.  Some motion functions including ‘forward-word’ and
56073     ‘beginning-of-line’ stop moving at a field boundary.  *Note
56074     Fields::.
56075
56076‘cursor’
56077     Normally, the cursor is displayed at the beginning or the end of
56078     any overlay and text property strings present at the current buffer
56079     position.  You can place the cursor on any desired character of
56080     these strings by giving that character a non-‘nil’ ‘cursor’ text
56081     property.  In addition, if the value of the ‘cursor’ property is an
56082     integer, it specifies the number of buffer’s character positions,
56083     starting with the position where the overlay or the ‘display’
56084     property begins, for which the cursor should be displayed on that
56085     character.  Specifically, if the value of the ‘cursor’ property of
56086     a character is the number N, the cursor will be displayed on this
56087     character for any buffer position in the range ‘[OVPOS..OVPOS+N)’,
56088     where OVPOS is the overlay’s starting position given by
56089     ‘overlay-start’ (*note Managing Overlays::), or the position where
56090     the ‘display’ text property begins in the buffer.
56091
56092     In other words, the string character with the ‘cursor’ property of
56093     any non-‘nil’ value is the character where to display the cursor.
56094     The value of the property says for which buffer positions to
56095     display the cursor there.  If the value is an integer N, the cursor
56096     is displayed there when point is anywhere between the beginning of
56097     the overlay or ‘display’ property and N positions after that.  If
56098     the value is anything else and non-‘nil’, the cursor is displayed
56099     there only when point is at the beginning of the ‘display’ property
56100     or at ‘overlay-start’.
56101
56102     When the buffer has many overlay strings (e.g., *note
56103     before-string: Overlay Properties.) that conceal some of the buffer
56104     text or ‘display’ properties that are strings, it is a good idea to
56105     use the ‘cursor’ property on these strings to cue the Emacs display
56106     about the places where to put the cursor while traversing these
56107     strings.  This directly communicates to the display engine where
56108     the Lisp program wants to put the cursor, or where the user would
56109     expect the cursor, when point is located on some buffer position
56110     that is “covered” by the display or overlay string.
56111
56112‘pointer’
56113     This specifies a specific pointer shape when the mouse pointer is
56114     over this text or image.  *Note Pointer Shape::, for possible
56115     pointer shapes.
56116
56117‘line-spacing’
56118     A newline can have a ‘line-spacing’ text or overlay property that
56119     controls the height of the display line ending with that newline.
56120     The property value overrides the default frame line spacing and the
56121     buffer local ‘line-spacing’ variable.  *Note Line Height::.
56122
56123‘line-height’
56124     A newline can have a ‘line-height’ text or overlay property that
56125     controls the total height of the display line ending in that
56126     newline.  *Note Line Height::.
56127
56128‘wrap-prefix’
56129     If text has a ‘wrap-prefix’ property, the prefix it defines will be
56130     added at display time to the beginning of every continuation line
56131     due to text wrapping (so if lines are truncated, the wrap-prefix is
56132     never used).  It may be a string or an image (*note Other Display
56133     Specs::), or a stretch of whitespace such as specified by the
56134     ‘:width’ or ‘:align-to’ display properties (*note Specified
56135     Space::).
56136
56137     A wrap-prefix may also be specified for an entire buffer using the
56138     ‘wrap-prefix’ buffer-local variable (however, a ‘wrap-prefix’
56139     text-property takes precedence over the value of the ‘wrap-prefix’
56140     variable).  *Note Truncation::.
56141
56142‘line-prefix’
56143     If text has a ‘line-prefix’ property, the prefix it defines will be
56144     added at display time to the beginning of every non-continuation
56145     line.  It may be a string or an image (*note Other Display
56146     Specs::), or a stretch of whitespace such as specified by the
56147     ‘:width’ or ‘:align-to’ display properties (*note Specified
56148     Space::).
56149
56150     A line-prefix may also be specified for an entire buffer using the
56151     ‘line-prefix’ buffer-local variable (however, a ‘line-prefix’
56152     text-property takes precedence over the value of the ‘line-prefix’
56153     variable).  *Note Truncation::.
56154
56155‘modification-hooks’
56156     If a character has the property ‘modification-hooks’, then its
56157     value should be a list of functions; modifying that character calls
56158     all of those functions before the actual modification.  Each
56159     function receives two arguments: the beginning and end of the part
56160     of the buffer being modified.  Note that if a particular
56161     modification hook function appears on several characters being
56162     modified by a single primitive, you can’t predict how many times
56163     the function will be called.  Furthermore, insertion will not
56164     modify any existing character, so this hook will only be run when
56165     removing some characters, replacing them with others, or changing
56166     their text-properties.
56167
56168     Unlike with other similar hooks, when Emacs calls these functions,
56169     ‘inhibit-modification-hooks’ does _not_ get bound to non-‘nil’.  If
56170     the functions modify the buffer, you should consider binding this
56171     variable to non-‘nil’ to prevent any buffer changes running the
56172     change hooks.  Otherwise, you must be prepared for recursive calls.
56173     *Note Change Hooks::.
56174
56175     Overlays also support the ‘modification-hooks’ property, but the
56176     details are somewhat different (*note Overlay Properties::).
56177
56178‘insert-in-front-hooks’
56179‘insert-behind-hooks’
56180     The operation of inserting text in a buffer also calls the
56181     functions listed in the ‘insert-in-front-hooks’ property of the
56182     following character and in the ‘insert-behind-hooks’ property of
56183     the preceding character.  These functions receive two arguments,
56184     the beginning and end of the inserted text.  The functions are
56185     called _after_ the actual insertion takes place.
56186
56187     When these functions are called, ‘inhibit-modification-hooks’ is
56188     bound to non-‘nil’.  If the functions modify the buffer, you might
56189     want to bind ‘inhibit-modification-hooks’ to ‘nil’, so as to cause
56190     the change hooks to run for these modifications.  However, doing
56191     this may call your own change hook recursively, so be sure to
56192     prepare for that.
56193
56194     See also *note Change Hooks::, for other hooks that are called when
56195     you change text in a buffer.
56196
56197‘point-entered’
56198‘point-left’
56199     The special properties ‘point-entered’ and ‘point-left’ record hook
56200     functions that report motion of point.  Each time point moves,
56201     Emacs compares these two property values:
56202
56203        • the ‘point-left’ property of the character after the old
56204          location, and
56205        • the ‘point-entered’ property of the character after the new
56206          location.
56207
56208     If these two values differ, each of them is called (if not ‘nil’)
56209     with two arguments: the old value of point, and the new one.
56210
56211     The same comparison is made for the characters before the old and
56212     new locations.  The result may be to execute two ‘point-left’
56213     functions (which may be the same function) and/or two
56214     ‘point-entered’ functions (which may be the same function).  In any
56215     case, all the ‘point-left’ functions are called first, followed by
56216     all the ‘point-entered’ functions.
56217
56218     It is possible to use ‘char-after’ to examine characters at various
56219     buffer positions without moving point to those positions.  Only an
56220     actual change in the value of point runs these hook functions.
56221
56222     The variable ‘inhibit-point-motion-hooks’ by default inhibits
56223     running the ‘point-left’ and ‘point-entered’ hooks, see *note
56224     Inhibit point motion hooks::.
56225
56226     These properties are obsolete; please use ‘cursor-sensor-functions’
56227     instead.
56228
56229‘cursor-sensor-functions’
56230     This special property records a list of functions that react to
56231     cursor motion.  Each function in the list is called, just before
56232     redisplay, with 3 arguments: the affected window, the previous
56233     known position of the cursor, and one of the symbols ‘entered’ or
56234     ‘left’, depending on whether the cursor is entering the text that
56235     has this property or leaving it.  The functions are called only
56236     when the minor mode ‘cursor-sensor-mode’ is turned on.
56237
56238     When the variable ‘cursor-sensor-inhibit’ is non-‘nil’, the
56239     ‘cursor-sensor-functions’ property is ignored.
56240
56241‘composition’
56242     This text property is used to display a sequence of characters as a
56243     single glyph composed from components.  But the value of the
56244     property itself is completely internal to Emacs and should not be
56245     manipulated directly by, for instance, ‘put-text-property’.
56246
56247‘minibuffer-message’
56248     This text property tells where to display temporary messages in an
56249     active minibuffer.  Specifically, the first character of the
56250     minibuffer text which has this property will have the temporary
56251     message displayed before it.  The default is to display temporary
56252     messages at the end of the minibuffer text.  This text property is
56253     used by the function that is the default value of
56254     ‘set-message-function’ (*note Displaying Messages::).
56255
56256 -- Variable: inhibit-point-motion-hooks
56257     When this obsolete variable is non-‘nil’, ‘point-left’ and
56258     ‘point-entered’ hooks are not run, and the ‘intangible’ property
56259     has no effect.  Do not set this variable globally; bind it with
56260     ‘let’.  Since the affected properties are obsolete, this variable’s
56261     default value is ‘t’, to effectively disable them.
56262
56263 -- Variable: show-help-function
56264     If this variable is non-‘nil’, it specifies a function called to
56265     display help strings.  These may be ‘help-echo’ properties, menu
56266     help strings (*note Simple Menu Items::, *note Extended Menu
56267     Items::), or tool bar help strings (*note Tool Bar::).  The
56268     specified function is called with one argument, the help string to
56269     display, which is passed through ‘substitute-command-keys’ before
56270     being given to the function, unless the help string has a non-‘nil’
56271     ‘help-echo-inhibit-substitution’ property on its first character;
56272     see *note Keys in Documentation::.  See the code of Tooltip mode
56273     (*note (emacs)Tooltips::) for an example of a mode that uses
56274     ‘show-help-function’.
56275
56276 -- Variable: face-filters-always-match
56277     If this variable is non-‘nil’, face filters that specify attributes
56278     applied only when certain conditions are met will be deemed to
56279     match always.
56280
56281
56282File: elisp.info,  Node: Format Properties,  Next: Sticky Properties,  Prev: Special Properties,  Up: Text Properties
56283
5628432.19.5 Formatted Text Properties
56285---------------------------------
56286
56287These text properties affect the behavior of the fill commands.  They
56288are used for representing formatted text.  *Note Filling::, and *note
56289Margins::.
56290
56291‘hard’
56292     If a newline character has this property, it is a “hard” newline.
56293     The fill commands do not alter hard newlines and do not move words
56294     across them.  However, this property takes effect only if the
56295     ‘use-hard-newlines’ minor mode is enabled.  *Note Hard and Soft
56296     Newlines: (emacs)Hard and Soft Newlines.
56297
56298‘right-margin’
56299     This property specifies an extra right margin for filling this part
56300     of the text.
56301
56302‘left-margin’
56303     This property specifies an extra left margin for filling this part
56304     of the text.
56305
56306‘justification’
56307     This property specifies the style of justification for filling this
56308     part of the text.
56309
56310
56311File: elisp.info,  Node: Sticky Properties,  Next: Lazy Properties,  Prev: Format Properties,  Up: Text Properties
56312
5631332.19.6 Stickiness of Text Properties
56314-------------------------------------
56315
56316Self-inserting characters, the ones that get inserted into a buffer when
56317the user types them (*note Commands for Insertion::), normally take on
56318the same properties as the preceding character.  This is called
56319“inheritance” of properties.
56320
56321   By contrast, a Lisp program can do insertion with inheritance or
56322without, depending on the choice of insertion primitive.  The ordinary
56323text insertion functions, such as ‘insert’, do not inherit any
56324properties.  They insert text with precisely the properties of the
56325string being inserted, and no others.  This is correct for programs that
56326copy text from one context to another—for example, into or out of the
56327kill ring.  To insert with inheritance, use the special primitives
56328described in this section.  Self-inserting characters inherit properties
56329because they work using these primitives.
56330
56331   When you do insertion with inheritance, _which_ properties are
56332inherited, and from where, depends on which properties are “sticky”.
56333Insertion after a character inherits those of its properties that are
56334“rear-sticky”.  Insertion before a character inherits those of its
56335properties that are “front-sticky”.  When both sides offer different
56336sticky values for the same property, the previous character’s value
56337takes precedence.
56338
56339   By default, a text property is rear-sticky but not front-sticky;
56340thus, the default is to inherit all the properties of the preceding
56341character, and nothing from the following character.
56342
56343   You can control the stickiness of various text properties with two
56344specific text properties, ‘front-sticky’ and ‘rear-nonsticky’, and with
56345the variable ‘text-property-default-nonsticky’.  You can use the
56346variable to specify a different default for a given property.  You can
56347use those two text properties to make any specific properties sticky or
56348nonsticky in any particular part of the text.
56349
56350   If a character’s ‘front-sticky’ property is ‘t’, then all its
56351properties are front-sticky.  If the ‘front-sticky’ property is a list,
56352then the sticky properties of the character are those whose names are in
56353the list.  For example, if a character has a ‘front-sticky’ property
56354whose value is ‘(face read-only)’, then insertion before the character
56355can inherit its ‘face’ property and its ‘read-only’ property, but no
56356others.
56357
56358   The ‘rear-nonsticky’ property works the opposite way.  Most
56359properties are rear-sticky by default, so the ‘rear-nonsticky’ property
56360says which properties are _not_ rear-sticky.  If a character’s
56361‘rear-nonsticky’ property is ‘t’, then none of its properties are
56362rear-sticky.  If the ‘rear-nonsticky’ property is a list, properties are
56363rear-sticky _unless_ their names are in the list.
56364
56365 -- Variable: text-property-default-nonsticky
56366     This variable holds an alist which defines the default
56367     rear-stickiness of various text properties.  Each element has the
56368     form ‘(PROPERTY . NONSTICKINESS)’, and it defines the stickiness of
56369     a particular text property, PROPERTY.
56370
56371     If NONSTICKINESS is non-‘nil’, this means that the property
56372     PROPERTY is rear-nonsticky by default.  Since all properties are
56373     front-nonsticky by default, this makes PROPERTY nonsticky in both
56374     directions by default.
56375
56376     The text properties ‘front-sticky’ and ‘rear-nonsticky’, when used,
56377     take precedence over the default NONSTICKINESS specified in
56378     ‘text-property-default-nonsticky’.
56379
56380   Here are the functions that insert text with inheritance of
56381properties:
56382
56383 -- Function: insert-and-inherit &rest strings
56384     Insert the strings STRINGS, just like the function ‘insert’, but
56385     inherit any sticky properties from the adjoining text.
56386
56387 -- Function: insert-before-markers-and-inherit &rest strings
56388     Insert the strings STRINGS, just like the function
56389     ‘insert-before-markers’, but inherit any sticky properties from the
56390     adjoining text.
56391
56392   *Note Insertion::, for the ordinary insertion functions which do not
56393inherit.
56394
56395
56396File: elisp.info,  Node: Lazy Properties,  Next: Clickable Text,  Prev: Sticky Properties,  Up: Text Properties
56397
5639832.19.7 Lazy Computation of Text Properties
56399-------------------------------------------
56400
56401Instead of computing text properties for all the text in the buffer, you
56402can arrange to compute the text properties for parts of the text when
56403and if something depends on them.
56404
56405   The primitive that extracts text from the buffer along with its
56406properties is ‘buffer-substring’.  Before examining the properties, this
56407function runs the abnormal hook ‘buffer-access-fontify-functions’.
56408
56409 -- Variable: buffer-access-fontify-functions
56410     This variable holds a list of functions for computing text
56411     properties.  Before ‘buffer-substring’ copies the text and text
56412     properties for a portion of the buffer, it calls all the functions
56413     in this list.  Each of the functions receives two arguments that
56414     specify the range of the buffer being accessed.  (The buffer itself
56415     is always the current buffer.)
56416
56417   The function ‘buffer-substring-no-properties’ does not call these
56418functions, since it ignores text properties anyway.
56419
56420   In order to prevent the hook functions from being called more than
56421once for the same part of the buffer, you can use the variable
56422‘buffer-access-fontified-property’.
56423
56424 -- Variable: buffer-access-fontified-property
56425     If this variable’s value is non-‘nil’, it is a symbol which is used
56426     as a text property name.  A non-‘nil’ value for that text property
56427     means the other text properties for this character have already
56428     been computed.
56429
56430     If all the characters in the range specified for ‘buffer-substring’
56431     have a non-‘nil’ value for this property, ‘buffer-substring’ does
56432     not call the ‘buffer-access-fontify-functions’ functions.  It
56433     assumes these characters already have the right text properties,
56434     and just copies the properties they already have.
56435
56436     The normal way to use this feature is that the
56437     ‘buffer-access-fontify-functions’ functions add this property, as
56438     well as others, to the characters they operate on.  That way, they
56439     avoid being called over and over for the same text.
56440
56441
56442File: elisp.info,  Node: Clickable Text,  Next: Fields,  Prev: Lazy Properties,  Up: Text Properties
56443
5644432.19.8 Defining Clickable Text
56445-------------------------------
56446
56447“Clickable text” is text that can be clicked, with either the mouse or
56448via a keyboard command, to produce some result.  Many major modes use
56449clickable text to implement textual hyper-links, or “links” for short.
56450
56451   The easiest way to insert and manipulate links is to use the ‘button’
56452package.  *Note Buttons::.  In this section, we will explain how to
56453manually set up clickable text in a buffer, using text properties.  For
56454simplicity, we will refer to the clickable text as a “link”.
56455
56456   Implementing a link involves three separate steps: (1) indicating
56457clickability when the mouse moves over the link; (2) making <RET> or
56458‘mouse-2’ on that link do something; and (3) setting up a ‘follow-link’
56459condition so that the link obeys ‘mouse-1-click-follows-link’.
56460
56461   To indicate clickability, add the ‘mouse-face’ text property to the
56462text of the link; then Emacs will highlight the link when the mouse
56463moves over it.  In addition, you should define a tooltip or echo area
56464message, using the ‘help-echo’ text property.  *Note Special
56465Properties::.  For instance, here is how Dired indicates that file names
56466are clickable:
56467
56468      (if (dired-move-to-filename)
56469          (add-text-properties
56470            (point)
56471            (save-excursion
56472              (dired-move-to-end-of-filename)
56473              (point))
56474            '(mouse-face highlight
56475              help-echo "mouse-2: visit this file in other window")))
56476
56477   To make the link clickable, bind <RET> and ‘mouse-2’ to commands that
56478perform the desired action.  Each command should check to see whether it
56479was called on a link, and act accordingly.  For instance, Dired’s major
56480mode keymap binds ‘mouse-2’ to the following command:
56481
56482     (defun dired-mouse-find-file-other-window (event)
56483       "In Dired, visit the file or directory name you click on."
56484       (interactive "e")
56485       (let ((window (posn-window (event-end event)))
56486             (pos (posn-point (event-end event)))
56487             file)
56488         (if (not (windowp window))
56489             (error "No file chosen"))
56490         (with-current-buffer (window-buffer window)
56491           (goto-char pos)
56492           (setq file (dired-get-file-for-visit)))
56493         (if (file-directory-p file)
56494             (or (and (cdr dired-subdir-alist)
56495                      (dired-goto-subdir file))
56496                 (progn
56497                   (select-window window)
56498                   (dired-other-window file)))
56499           (select-window window)
56500           (find-file-other-window (file-name-sans-versions file t)))))
56501
56502This command uses the functions ‘posn-window’ and ‘posn-point’ to
56503determine where the click occurred, and ‘dired-get-file-for-visit’ to
56504determine which file to visit.
56505
56506   Instead of binding the mouse command in a major mode keymap, you can
56507bind it within the link text, using the ‘keymap’ text property (*note
56508Special Properties::).  For instance:
56509
56510     (let ((map (make-sparse-keymap)))
56511       (define-key map [mouse-2] 'operate-this-button)
56512       (put-text-property link-start link-end 'keymap map))
56513
56514With this method, you can easily define different commands for different
56515links.  Furthermore, the global definition of <RET> and ‘mouse-2’ remain
56516available for the rest of the text in the buffer.
56517
56518   The basic Emacs command for clicking on links is ‘mouse-2’.  However,
56519for compatibility with other graphical applications, Emacs also
56520recognizes ‘mouse-1’ clicks on links, provided the user clicks on the
56521link quickly without moving the mouse.  This behavior is controlled by
56522the user option ‘mouse-1-click-follows-link’.  *Note (emacs)Mouse
56523References::.
56524
56525   To set up the link so that it obeys ‘mouse-1-click-follows-link’, you
56526must either (1) apply a ‘follow-link’ text or overlay property to the
56527link text, or (2) bind the ‘follow-link’ event to a keymap (which can be
56528a major mode keymap or a local keymap specified via the ‘keymap’ text
56529property).  The value of the ‘follow-link’ property, or the binding for
56530the ‘follow-link’ event, acts as a condition for the link action.  This
56531condition tells Emacs two things: the circumstances under which a
56532‘mouse-1’ click should be regarded as occurring inside the link, and how
56533to compute an action code that says what to translate the ‘mouse-1’
56534click into.  The link action condition can be one of the following:
56535
56536‘mouse-face’
56537     If the condition is the symbol ‘mouse-face’, a position is inside a
56538     link if there is a non-‘nil’ ‘mouse-face’ property at that
56539     position.  The action code is always ‘t’.
56540
56541     For example, here is how Info mode handles <mouse-1>:
56542
56543          (define-key Info-mode-map [follow-link] 'mouse-face)
56544
56545a function
56546     If the condition is a function, FUNC, then a position POS is inside
56547     a link if ‘(FUNC POS)’ evaluates to non-‘nil’.  The value returned
56548     by FUNC serves as the action code.
56549
56550     For example, here is how pcvs enables ‘mouse-1’ to follow links on
56551     file names only:
56552
56553          (define-key map [follow-link]
56554            (lambda (pos)
56555              (eq (get-char-property pos 'face) 'cvs-filename-face)))
56556
56557anything else
56558     If the condition value is anything else, then the position is
56559     inside a link and the condition itself is the action code.
56560     Clearly, you should specify this kind of condition only when
56561     applying the condition via a text or property overlay on the link
56562     text (so that it does not apply to the entire buffer).
56563
56564The action code tells ‘mouse-1’ how to follow the link:
56565
56566a string or vector
56567     If the action code is a string or vector, the ‘mouse-1’ event is
56568     translated into the first element of the string or vector; i.e.,
56569     the action of the ‘mouse-1’ click is the local or global binding of
56570     that character or symbol.  Thus, if the action code is ‘"foo"’,
56571     ‘mouse-1’ translates into ‘f’.  If it is ‘[foo]’, ‘mouse-1’
56572     translates into <foo>.
56573
56574anything else
56575     For any other non-‘nil’ action code, the ‘mouse-1’ event is
56576     translated into a ‘mouse-2’ event at the same position.
56577
56578   To define ‘mouse-1’ to activate a button defined with
56579‘define-button-type’, give the button a ‘follow-link’ property.  The
56580property value should be a link action condition, as described above.
56581*Note Buttons::.  For example, here is how Help mode handles ‘mouse-1’:
56582
56583     (define-button-type 'help-xref
56584       'follow-link t
56585       'action #'help-button-action)
56586
56587   To define ‘mouse-1’ on a widget defined with ‘define-widget’, give
56588the widget a ‘:follow-link’ property.  The property value should be a
56589link action condition, as described above.  For example, here is how the
56590‘link’ widget specifies that a <mouse-1> click shall be translated to
56591<RET>:
56592
56593     (define-widget 'link 'item
56594       "An embedded link."
56595       :button-prefix 'widget-link-prefix
56596       :button-suffix 'widget-link-suffix
56597       :follow-link "\C-m"
56598       :help-echo "Follow the link."
56599       :format "%[%t%]")
56600
56601 -- Function: mouse-on-link-p pos
56602     This function returns non-‘nil’ if position POS in the current
56603     buffer is on a link.  POS can also be a mouse event location, as
56604     returned by ‘event-start’ (*note Accessing Mouse::).
56605
56606
56607File: elisp.info,  Node: Fields,  Next: Not Intervals,  Prev: Clickable Text,  Up: Text Properties
56608
5660932.19.9 Defining and Using Fields
56610---------------------------------
56611
56612A field is a range of consecutive characters in the buffer that are
56613identified by having the same value (comparing with ‘eq’) of the ‘field’
56614property (either a text-property or an overlay property).  This section
56615describes special functions that are available for operating on fields.
56616
56617   You specify a field with a buffer position, POS.  We think of each
56618field as containing a range of buffer positions, so the position you
56619specify stands for the field containing that position.
56620
56621   When the characters before and after POS are part of the same field,
56622there is no doubt which field contains POS: the one those characters
56623both belong to.  When POS is at a boundary between fields, which field
56624it belongs to depends on the stickiness of the ‘field’ properties of the
56625two surrounding characters (*note Sticky Properties::).  The field whose
56626property would be inherited by text inserted at POS is the field that
56627contains POS.
56628
56629   There is an anomalous case where newly inserted text at POS would not
56630inherit the ‘field’ property from either side.  This happens if the
56631previous character’s ‘field’ property is not rear-sticky, and the
56632following character’s ‘field’ property is not front-sticky.  In this
56633case, POS belongs to neither the preceding field nor the following
56634field; the field functions treat it as belonging to an empty field whose
56635beginning and end are both at POS.
56636
56637   In all of these functions, if POS is omitted or ‘nil’, the value of
56638point is used by default.  If narrowing is in effect, then POS should
56639fall within the accessible portion.  *Note Narrowing::.
56640
56641 -- Function: field-beginning &optional pos escape-from-edge limit
56642     This function returns the beginning of the field specified by POS.
56643
56644     If POS is at the beginning of its field, and ESCAPE-FROM-EDGE is
56645     non-‘nil’, then the return value is always the beginning of the
56646     preceding field that _ends_ at POS, regardless of the stickiness of
56647     the ‘field’ properties around POS.
56648
56649     If LIMIT is non-‘nil’, it is a buffer position; if the beginning of
56650     the field is before LIMIT, then LIMIT will be returned instead.
56651
56652 -- Function: field-end &optional pos escape-from-edge limit
56653     This function returns the end of the field specified by POS.
56654
56655     If POS is at the end of its field, and ESCAPE-FROM-EDGE is
56656     non-‘nil’, then the return value is always the end of the following
56657     field that _begins_ at POS, regardless of the stickiness of the
56658     ‘field’ properties around POS.
56659
56660     If LIMIT is non-‘nil’, it is a buffer position; if the end of the
56661     field is after LIMIT, then LIMIT will be returned instead.
56662
56663 -- Function: field-string &optional pos
56664     This function returns the contents of the field specified by POS,
56665     as a string.
56666
56667 -- Function: field-string-no-properties &optional pos
56668     This function returns the contents of the field specified by POS,
56669     as a string, discarding text properties.
56670
56671 -- Function: delete-field &optional pos
56672     This function deletes the text of the field specified by POS.
56673
56674 -- Function: constrain-to-field new-pos old-pos &optional
56675          escape-from-edge only-in-line inhibit-capture-property
56676     This function constrains NEW-POS to the field that OLD-POS belongs
56677     to—in other words, it returns the position closest to NEW-POS that
56678     is in the same field as OLD-POS.
56679
56680     If NEW-POS is ‘nil’, then ‘constrain-to-field’ uses the value of
56681     point instead, and moves point to the resulting position in
56682     addition to returning that position.
56683
56684     If OLD-POS is at the boundary of two fields, then the acceptable
56685     final positions depend on the argument ESCAPE-FROM-EDGE.  If
56686     ESCAPE-FROM-EDGE is ‘nil’, then NEW-POS must be in the field whose
56687     ‘field’ property equals what new characters inserted at OLD-POS
56688     would inherit.  (This depends on the stickiness of the ‘field’
56689     property for the characters before and after OLD-POS.)  If
56690     ESCAPE-FROM-EDGE is non-‘nil’, NEW-POS can be anywhere in the two
56691     adjacent fields.  Additionally, if two fields are separated by
56692     another field with the special value ‘boundary’, then any point
56693     within this special field is also considered to be on the boundary.
56694
56695     Commands like ‘C-a’ with no argument, that normally move backward
56696     to a specific kind of location and stay there once there, probably
56697     should specify ‘nil’ for ESCAPE-FROM-EDGE.  Other motion commands
56698     that check fields should probably pass ‘t’.
56699
56700     If the optional argument ONLY-IN-LINE is non-‘nil’, and
56701     constraining NEW-POS in the usual way would move it to a different
56702     line, NEW-POS is returned unconstrained.  This used in commands
56703     that move by line, such as ‘next-line’ and ‘beginning-of-line’, so
56704     that they respect field boundaries only in the case where they can
56705     still move to the right line.
56706
56707     If the optional argument INHIBIT-CAPTURE-PROPERTY is non-‘nil’, and
56708     OLD-POS has a non-‘nil’ property of that name, then any field
56709     boundaries are ignored.
56710
56711     You can cause ‘constrain-to-field’ to ignore all field boundaries
56712     (and so never constrain anything) by binding the variable
56713     ‘inhibit-field-text-motion’ to a non-‘nil’ value.
56714
56715
56716File: elisp.info,  Node: Not Intervals,  Prev: Fields,  Up: Text Properties
56717
5671832.19.10 Why Text Properties are not Intervals
56719----------------------------------------------
56720
56721Some editors that support adding attributes to text in the buffer do so
56722by letting the user specify intervals within the text, and adding the
56723properties to the intervals.  Those editors permit the user or the
56724programmer to determine where individual intervals start and end.  We
56725deliberately provided a different sort of interface in Emacs Lisp to
56726avoid certain paradoxical behavior associated with text modification.
56727
56728   If the actual subdivision into intervals is meaningful, that means
56729you can distinguish between a buffer that is just one interval with a
56730certain property, and a buffer containing the same text subdivided into
56731two intervals, both of which have that property.
56732
56733   Suppose you take the buffer with just one interval and kill part of
56734the text.  The text remaining in the buffer is one interval, and the
56735copy in the kill ring (and the undo list) becomes a separate interval.
56736Then if you yank back the killed text, you get two intervals with the
56737same properties.  Thus, editing does not preserve the distinction
56738between one interval and two.
56739
56740   Suppose we attempt to fix this problem by coalescing the two
56741intervals when the text is inserted.  That works fine if the buffer
56742originally was a single interval.  But suppose instead that we have two
56743adjacent intervals with the same properties, and we kill the text of one
56744interval and yank it back.  The same interval-coalescence feature that
56745rescues the other case causes trouble in this one: after yanking, we
56746have just one interval.  Once again, editing does not preserve the
56747distinction between one interval and two.
56748
56749   Insertion of text at the border between intervals also raises
56750questions that have no satisfactory answer.
56751
56752   However, it is easy to arrange for editing to behave consistently for
56753questions of the form, “What are the properties of text at this buffer
56754or string position?” So we have decided these are the only questions
56755that make sense; we have not implemented asking questions about where
56756intervals start or end.
56757
56758   In practice, you can usually use the text property search functions
56759in place of explicit interval boundaries.  You can think of them as
56760finding the boundaries of intervals, assuming that intervals are always
56761coalesced whenever possible.  *Note Property Search::.
56762
56763   Emacs also provides explicit intervals as a presentation feature; see
56764*note Overlays::.
56765
56766
56767File: elisp.info,  Node: Substitution,  Next: Registers,  Prev: Text Properties,  Up: Text
56768
5676932.20 Substituting for a Character Code
56770=======================================
56771
56772The following functions replace characters within a specified region
56773based on their character codes.
56774
56775 -- Function: subst-char-in-region start end old-char new-char &optional
56776          noundo
56777     This function replaces all occurrences of the character OLD-CHAR
56778     with the character NEW-CHAR in the region of the current buffer
56779     defined by START and END.
56780
56781     If NOUNDO is non-‘nil’, then ‘subst-char-in-region’ does not record
56782     the change for undo and does not mark the buffer as modified.  This
56783     was useful for controlling the old selective display feature (*note
56784     Selective Display::).
56785
56786     ‘subst-char-in-region’ does not move point and returns ‘nil’.
56787
56788          ---------- Buffer: foo ----------
56789          This is the contents of the buffer before.
56790          ---------- Buffer: foo ----------
56791
56792          (subst-char-in-region 1 20 ?i ?X)
56793               ⇒ nil
56794
56795          ---------- Buffer: foo ----------
56796          ThXs Xs the contents of the buffer before.
56797          ---------- Buffer: foo ----------
56798
56799 -- Command: translate-region start end table
56800     This function applies a translation table to the characters in the
56801     buffer between positions START and END.
56802
56803     The translation table TABLE is a string or a char-table; ‘(aref
56804     TABLE OCHAR)’ gives the translated character corresponding to
56805     OCHAR.  If TABLE is a string, any characters with codes larger than
56806     the length of TABLE are not altered by the translation.
56807
56808     The return value of ‘translate-region’ is the number of characters
56809     that were actually changed by the translation.  This does not count
56810     characters that were mapped into themselves in the translation
56811     table.
56812
56813
56814File: elisp.info,  Node: Registers,  Next: Transposition,  Prev: Substitution,  Up: Text
56815
5681632.21 Registers
56817===============
56818
56819A register is a sort of variable used in Emacs editing that can hold a
56820variety of different kinds of values.  Each register is named by a
56821single character.  All ASCII characters and their meta variants (but
56822with the exception of ‘C-g’) can be used to name registers.  Thus, there
56823are 255 possible registers.  A register is designated in Emacs Lisp by
56824the character that is its name.
56825
56826 -- Variable: register-alist
56827     This variable is an alist of elements of the form ‘(NAME .
56828     CONTENTS)’.  Normally, there is one element for each Emacs register
56829     that has been used.
56830
56831     The object NAME is a character (an integer) identifying the
56832     register.
56833
56834   The CONTENTS of a register can have several possible types:
56835
56836a number
56837     A number stands for itself.  If ‘insert-register’ finds a number in
56838     the register, it converts the number to decimal.
56839
56840a marker
56841     A marker represents a buffer position to jump to.
56842
56843a string
56844     A string is text saved in the register.
56845
56846a rectangle
56847     A rectangle is represented by a list of strings.
56848
56849‘(WINDOW-CONFIGURATION POSITION)’
56850     This represents a window configuration to restore in one frame, and
56851     a position to jump to in the current buffer.
56852
56853‘(FRAME-CONFIGURATION POSITION)’
56854     This represents a frame configuration to restore, and a position to
56855     jump to in the current buffer.
56856
56857(file FILENAME)
56858     This represents a file to visit; jumping to this value visits file
56859     FILENAME.
56860
56861(file-query FILENAME POSITION)
56862     This represents a file to visit and a position in it; jumping to
56863     this value visits file FILENAME and goes to buffer position
56864     POSITION.  Restoring this type of position asks the user for
56865     confirmation first.
56866
56867   The functions in this section return unpredictable values unless
56868otherwise stated.
56869
56870 -- Function: get-register reg
56871     This function returns the contents of the register REG, or ‘nil’ if
56872     it has no contents.
56873
56874 -- Function: set-register reg value
56875     This function sets the contents of register REG to VALUE.  A
56876     register can be set to any value, but the other register functions
56877     expect only certain data types.  The return value is VALUE.
56878
56879 -- Command: view-register reg
56880     This command displays what is contained in register REG.
56881
56882 -- Command: insert-register reg &optional beforep
56883     This command inserts contents of register REG into the current
56884     buffer.
56885
56886     Normally, this command puts point before the inserted text, and the
56887     mark after it.  However, if the optional second argument BEFOREP is
56888     non-‘nil’, it puts the mark before and point after.
56889
56890     When called interactively, the command defaults to putting point
56891     after text, and a prefix argument inverts this behavior.
56892
56893     If the register contains a rectangle, then the rectangle is
56894     inserted with its upper left corner at point.  This means that text
56895     is inserted in the current line and underneath it on successive
56896     lines.
56897
56898     If the register contains something other than saved text (a string)
56899     or a rectangle (a list), currently useless things happen.  This may
56900     be changed in the future.
56901
56902 -- Function: register-read-with-preview prompt
56903     This function reads and returns a register name, prompting with
56904     PROMPT and possibly showing a preview of the existing registers and
56905     their contents.  The preview is shown in a temporary window, after
56906     the delay specified by the user option ‘register-preview-delay’, if
56907     its value and ‘register-alist’ are both non-‘nil’.  The preview is
56908     also shown if the user requests help (e.g., by typing the help
56909     character).  We recommend that all interactive commands which read
56910     register names use this function.
56911
56912
56913File: elisp.info,  Node: Transposition,  Next: Replacing,  Prev: Registers,  Up: Text
56914
5691532.22 Transposition of Text
56916===========================
56917
56918This function can be used to transpose stretches of text:
56919
56920 -- Function: transpose-regions start1 end1 start2 end2 &optional
56921          leave-markers
56922     This function exchanges two nonoverlapping portions of the buffer
56923     (if they overlap, the function signals an error).  Arguments START1
56924     and END1 specify the bounds of one portion and arguments START2 and
56925     END2 specify the bounds of the other portion.
56926
56927     Normally, ‘transpose-regions’ relocates markers with the transposed
56928     text; a marker previously positioned within one of the two
56929     transposed portions moves along with that portion, thus remaining
56930     between the same two characters in their new position.  However, if
56931     LEAVE-MARKERS is non-‘nil’, ‘transpose-regions’ does not do this—it
56932     leaves all markers unrelocated.
56933
56934
56935File: elisp.info,  Node: Replacing,  Next: Decompression,  Prev: Transposition,  Up: Text
56936
5693732.23 Replacing Buffer Text
56938===========================
56939
56940You can use the following function to replace the text of one buffer
56941with the text of another buffer:
56942
56943 -- Command: replace-buffer-contents source &optional max-secs max-costs
56944     This function replaces the accessible portion of the current buffer
56945     with the accessible portion of the buffer SOURCE.  SOURCE may
56946     either be a buffer object or the name of a buffer.  When
56947     ‘replace-buffer-contents’ succeeds, the text of the accessible
56948     portion of the current buffer will be equal to the text of the
56949     accessible portion of the SOURCE buffer.
56950
56951     This function attempts to keep point, markers, text properties, and
56952     overlays in the current buffer intact.  One potential case where
56953     this behavior is useful is external code formatting programs: they
56954     typically write the reformatted text into a temporary buffer or
56955     file, and using ‘delete-region’ and ‘insert-buffer-substring’ would
56956     destroy these properties.  However, the latter combination is
56957     typically faster (*Note Deletion::, and *note Insertion::).
56958
56959     For its working, ‘replace-buffer-contents’ needs to compare the
56960     contents of the original buffer with that of SOURCE which is a
56961     costly operation if the buffers are huge and there is a high number
56962     of differences between them.  In order to keep
56963     ‘replace-buffer-contents’’s runtime in bounds, it has two optional
56964     arguments.
56965
56966     MAX-SECS defines a hard boundary in terms of seconds.  If given and
56967     exceeded, it will fall back to ‘delete-region’ and
56968     ‘insert-buffer-substring’.
56969
56970     MAX-COSTS defines the quality of the difference computation.  If
56971     the actual costs exceed this limit, heuristics are used to provide
56972     a faster but suboptimal solution.  The default value is 1000000.
56973
56974     ‘replace-buffer-contents’ returns t if a non-destructive
56975     replacement could be performed.  Otherwise, i.e., if MAX-SECS was
56976     exceeded, it returns nil.
56977
56978 -- Function: replace-region-contents beg end replace-fn &optional
56979          max-secs max-costs
56980     This function replaces the region between BEG and END using the
56981     given REPLACE-FN.  The function REPLACE-FN is run in the current
56982     buffer narrowed to the specified region and it should return either
56983     a string or a buffer replacing the region.
56984
56985     The replacement is performed using ‘replace-buffer-contents’ (see
56986     above) which also describes the MAX-SECS and MAX-COSTS arguments
56987     and the return value.
56988
56989     Note: If the replacement is a string, it will be placed in a
56990     temporary buffer so that ‘replace-buffer-contents’ can operate on
56991     it.  Therefore, if you already have the replacement in a buffer, it
56992     makes no sense to convert it to a string using ‘buffer-substring’
56993     or similar.
56994
56995
56996File: elisp.info,  Node: Decompression,  Next: Base 64,  Prev: Replacing,  Up: Text
56997
5699832.24 Dealing With Compressed Data
56999==================================
57000
57001When ‘auto-compression-mode’ is enabled, Emacs automatically
57002uncompresses compressed files when you visit them, and automatically
57003recompresses them if you alter and save them.  *Note (emacs)Compressed
57004Files::.
57005
57006   The above feature works by calling an external executable (e.g.,
57007‘gzip’).  Emacs can also be compiled with support for built-in
57008decompression using the zlib library, which is faster than calling an
57009external program.
57010
57011 -- Function: zlib-available-p
57012     This function returns non-‘nil’ if built-in zlib decompression is
57013     available.
57014
57015 -- Function: zlib-decompress-region start end &optional allow-partial
57016     This function decompresses the region between START and END, using
57017     built-in zlib decompression.  The region should contain data that
57018     were compressed with gzip or zlib.  On success, the function
57019     replaces the contents of the region with the decompressed data.  If
57020     ALLOW-PARTIAL is ‘nil’ or omitted, then on failure, the function
57021     leaves the region unchanged and returns ‘nil’.  Otherwise, it
57022     returns the number of bytes that were not decompressed and replaces
57023     the region text by whatever data was successfully decompressed.
57024     This function can be called only in unibyte buffers.
57025
57026
57027File: elisp.info,  Node: Base 64,  Next: Checksum/Hash,  Prev: Decompression,  Up: Text
57028
5702932.25 Base 64 Encoding
57030======================
57031
57032Base 64 code is used in email to encode a sequence of 8-bit bytes as a
57033longer sequence of ASCII graphic characters.  It is defined in Internet
57034RFC(1)2045 and also in RFC 4648.  This section describes the functions
57035for converting to and from this code.
57036
57037 -- Command: base64-encode-region beg end &optional no-line-break
57038     This function converts the region from BEG to END into base 64
57039     code.  It returns the length of the encoded text.  An error is
57040     signaled if a character in the region is multibyte, i.e., in a
57041     multibyte buffer the region must contain only characters from the
57042     charsets ‘ascii’, ‘eight-bit-control’ and ‘eight-bit-graphic’.
57043
57044     Normally, this function inserts newline characters into the encoded
57045     text, to avoid overlong lines.  However, if the optional argument
57046     NO-LINE-BREAK is non-‘nil’, these newlines are not added, so the
57047     output is just one long line.
57048
57049 -- Command: base64url-encode-region beg end &optional no-pad
57050     This function is like ‘base64-encode-region’, but it implements the
57051     URL variant of base 64 encoding, per RFC 4648, and it doesn’t
57052     insert newline characters into the encoded text, so the output is
57053     just one long line.
57054
57055     If the optional argument NO-PAD is non-‘nil’ then this function
57056     doesn’t generate the padding (‘=’).
57057
57058 -- Function: base64-encode-string string &optional no-line-break
57059     This function converts the string STRING into base 64 code.  It
57060     returns a string containing the encoded text.  As for
57061     ‘base64-encode-region’, an error is signaled if a character in the
57062     string is multibyte.
57063
57064     Normally, this function inserts newline characters into the encoded
57065     text, to avoid overlong lines.  However, if the optional argument
57066     NO-LINE-BREAK is non-‘nil’, these newlines are not added, so the
57067     result string is just one long line.
57068
57069 -- Function: base64url-encode-string string &optional no-pad
57070     Like ‘base64-encode-string’, but generates the URL variant of base
57071     64, and doesn’t insert newline characters into the encoded text, so
57072     the result is just one long line.
57073
57074     If the optional argument NO-PAD is non-‘nil’ then this function
57075     doesn’t generate the padding.
57076
57077 -- Command: base64-decode-region beg end &optional base64url
57078     This function converts the region from BEG to END from base 64 code
57079     into the corresponding decoded text.  It returns the length of the
57080     decoded text.
57081
57082     The decoding functions ignore newline characters in the encoded
57083     text.
57084
57085     If optional argument BASE64URL is non-‘nil’, then padding is
57086     optional, and the URL variant of base 64 encoding is used.
57087
57088 -- Function: base64-decode-string string &optional base64url
57089     This function converts the string STRING from base 64 code into the
57090     corresponding decoded text.  It returns a unibyte string containing
57091     the decoded text.
57092
57093     The decoding functions ignore newline characters in the encoded
57094     text.
57095
57096     If optional argument BASE64URL is non-‘nil’, then padding is
57097     optional, and the URL variant of base 64 encoding is used.
57098
57099   ---------- Footnotes ----------
57100
57101   (1) An RFC, an acronym for “Request for Comments”, is a numbered
57102Internet informational document describing a standard.  RFCs are usually
57103written by technical experts acting on their own initiative, and are
57104traditionally written in a pragmatic, experience-driven manner.
57105
57106
57107File: elisp.info,  Node: Checksum/Hash,  Next: GnuTLS Cryptography,  Prev: Base 64,  Up: Text
57108
5710932.26 Checksum/Hash
57110===================
57111
57112Emacs has built-in support for computing “cryptographic hashes”.  A
57113cryptographic hash, or “checksum”, is a digital fingerprint of a piece
57114of data (e.g., a block of text) which can be used to check that you have
57115an unaltered copy of that data.
57116
57117   Emacs supports several common cryptographic hash algorithms: MD5,
57118SHA-1, SHA-2, SHA-224, SHA-256, SHA-384 and SHA-512.  MD5 is the oldest
57119of these algorithms, and is commonly used in “message digests” to check
57120the integrity of messages transmitted over a network.  MD5 and SHA-1 are
57121not collision resistant (i.e., it is possible to deliberately design
57122different pieces of data which have the same MD5 or SHA-1 hash), so you
57123should not use them for anything security-related.  For security-related
57124applications you should use the other hash types, such as SHA-2 (e.g.
57125‘sha256’ or ‘sha512’).
57126
57127 -- Function: secure-hash-algorithms
57128     This function returns a list of symbols representing algorithms
57129     that ‘secure-hash’ can use.
57130
57131 -- Function: secure-hash algorithm object &optional start end binary
57132     This function returns a hash for OBJECT.  The argument ALGORITHM is
57133     a symbol stating which hash to compute: one of ‘md5’, ‘sha1’,
57134     ‘sha224’, ‘sha256’, ‘sha384’ or ‘sha512’.  The argument OBJECT
57135     should be a buffer or a string.
57136
57137     The optional arguments START and END are character positions
57138     specifying the portion of OBJECT to compute the message digest for.
57139     If they are ‘nil’ or omitted, the hash is computed for the whole of
57140     OBJECT.
57141
57142     If the argument BINARY is omitted or ‘nil’, the function returns
57143     the “text form” of the hash, as an ordinary Lisp string.  If BINARY
57144     is non-‘nil’, it returns the hash in “binary form”, as a sequence
57145     of bytes stored in a unibyte string.
57146
57147     This function does not compute the hash directly from the internal
57148     representation of OBJECT’s text (*note Text Representations::).
57149     Instead, it encodes the text using a coding system (*note Coding
57150     Systems::), and computes the hash from that encoded text.  If
57151     OBJECT is a buffer, the coding system used is the one which would
57152     be chosen by default for writing the text into a file.  If OBJECT
57153     is a string, the user’s preferred coding system is used (*note
57154     (emacs)Recognize Coding::).
57155
57156 -- Function: md5 object &optional start end coding-system noerror
57157     This function returns an MD5 hash.  It is semi-obsolete, since for
57158     most purposes it is equivalent to calling ‘secure-hash’ with ‘md5’
57159     as the ALGORITHM argument.  The OBJECT, START and END arguments
57160     have the same meanings as in ‘secure-hash’.
57161
57162     If CODING-SYSTEM is non-‘nil’, it specifies a coding system to use
57163     to encode the text; if omitted or ‘nil’, the default coding system
57164     is used, like in ‘secure-hash’.
57165
57166     Normally, ‘md5’ signals an error if the text can’t be encoded using
57167     the specified or chosen coding system.  However, if NOERROR is
57168     non-‘nil’, it silently uses ‘raw-text’ coding instead.
57169
57170 -- Function: buffer-hash &optional buffer-or-name
57171     Return a hash of BUFFER-OR-NAME.  If ‘nil’, this defaults to the
57172     current buffer.  As opposed to ‘secure-hash’, this function
57173     computes the hash based on the internal representation of the
57174     buffer, disregarding any coding systems.  It’s therefore only
57175     useful when comparing two buffers running in the same Emacs, and is
57176     not guaranteed to return the same hash between different Emacs
57177     versions.  It should be somewhat more efficient on larger buffers
57178     than ‘secure-hash’ is, and should not allocate more memory.
57179
57180
57181File: elisp.info,  Node: GnuTLS Cryptography,  Next: Parsing HTML/XML,  Prev: Checksum/Hash,  Up: Text
57182
5718332.27 GnuTLS Cryptography
57184=========================
57185
57186If compiled with GnuTLS, Emacs offers built-in cryptographic support.
57187Following the GnuTLS API terminology, the available tools are digests,
57188MACs, symmetric ciphers, and AEAD ciphers.
57189
57190   The terms used herein, such as IV (Initialization Vector), require
57191some familiarity with cryptography and will not be defined in detail.
57192Please consult <https://www.gnutls.org/> for specific documentation
57193which may help you understand the terminology and structure of the
57194GnuTLS library.
57195
57196* Menu:
57197
57198* Format of GnuTLS Cryptography Inputs::
57199* GnuTLS Cryptographic Functions::
57200
57201
57202File: elisp.info,  Node: Format of GnuTLS Cryptography Inputs,  Next: GnuTLS Cryptographic Functions,  Up: GnuTLS Cryptography
57203
5720432.27.1 Format of GnuTLS Cryptography Inputs
57205--------------------------------------------
57206
57207The inputs to GnuTLS cryptographic functions can be specified in several
57208ways, both as primitive Emacs Lisp types or as lists.
57209
57210   The list form is currently similar to how ‘md5’ and ‘secure-hash’
57211operate.
57212
57213‘BUFFER’
57214     Simply passing a buffer as input means the whole buffer should be
57215     used.
57216
57217‘STRING’
57218     A string as input will be used directly.  It may be modified by the
57219     function (unlike most other Emacs Lisp functions) to reduce the
57220     chance of exposing sensitive data after the function does its work.
57221
57222‘(BUFFER-OR-STRING START END CODING-SYSTEM NOERROR)’
57223     This specifies a buffer or a string as described above, but an
57224     optional range can be specified with START and END.
57225
57226     In addition an optional CODING-SYSTEM can be specified if needed.
57227
57228     The last optional item, NOERROR, overrides the normal error when
57229     the text can’t be encoded using the specified or chosen coding
57230     system.  When NOERROR is non-‘nil’, this function silently uses
57231     ‘raw-text’ coding instead.
57232
57233‘(iv-auto LENGTH)’
57234     This will generate an IV (Initialization Vector) of the specified
57235     length using the GnuTLS ‘GNUTLS_RND_NONCE’ generator and pass it to
57236     the function.  This ensures that the IV is unpredictable and
57237     unlikely to be reused in the same session.  The actual value of the
57238     IV is returned by the function as described below.
57239
57240
57241File: elisp.info,  Node: GnuTLS Cryptographic Functions,  Prev: Format of GnuTLS Cryptography Inputs,  Up: GnuTLS Cryptography
57242
5724332.27.2 GnuTLS Cryptographic Functions
57244--------------------------------------
57245
57246 -- Function: gnutls-digests
57247     This function returns the alist of the GnuTLS digest algorithms.
57248
57249     Each entry has a key which represents the algorithm, followed by a
57250     plist with internal details about the algorithm.  The plist will
57251     have ‘:type gnutls-digest-algorithm’ and also will have the key
57252     ‘:digest-algorithm-length 64’ to indicate the size, in bytes, of
57253     the resulting digest.
57254
57255     There is a name parallel between GnuTLS MAC and digest algorithms
57256     but they are separate things internally and should not be mixed.
57257
57258 -- Function: gnutls-hash-digest digest-method input
57259     The DIGEST-METHOD can be the whole plist from ‘gnutls-digests’, or
57260     just the symbol key, or a string with the name of that symbol.
57261
57262     The INPUT can be specified as a buffer or string or in other ways
57263     (*note Format of GnuTLS Cryptography Inputs::).
57264
57265     This function returns ‘nil’ on error, and signals a Lisp error if
57266     the DIGEST-METHOD or INPUT are invalid.  On success, it returns a
57267     list of a binary string (the output) and the IV used.
57268
57269 -- Function: gnutls-macs
57270     This function returns the alist of the GnuTLS MAC algorithms.
57271
57272     Each entry has a key which represents the algorithm, followed by a
57273     plist with internal details about the algorithm.  The plist will
57274     have ‘:type gnutls-mac-algorithm’ and also will have the keys
57275     ‘:mac-algorithm-length’ ‘:mac-algorithm-keysize’
57276     ‘:mac-algorithm-noncesize’ to indicate the size, in bytes, of the
57277     resulting hash, the key, and the nonce respectively.
57278
57279     The nonce is currently unused and only some MACs support it.
57280
57281     There is a name parallel between GnuTLS MAC and digest algorithms
57282     but they are separate things internally and should not be mixed.
57283
57284 -- Function: gnutls-hash-mac hash-method key input
57285     The HASH-METHOD can be the whole plist from ‘gnutls-macs’, or just
57286     the symbol key, or a string with the name of that symbol.
57287
57288     The KEY can be specified as a buffer or string or in other ways
57289     (*note Format of GnuTLS Cryptography Inputs::).  The KEY will be
57290     wiped after use if it’s a string.
57291
57292     The INPUT can be specified as a buffer or string or in other ways
57293     (*note Format of GnuTLS Cryptography Inputs::).
57294
57295     This function returns ‘nil’ on error, and signals a Lisp error if
57296     the HASH-METHOD or KEY or INPUT are invalid.
57297
57298     On success, it returns a list of a binary string (the output) and
57299     the IV used.
57300
57301 -- Function: gnutls-ciphers
57302     This function returns the alist of the GnuTLS ciphers.
57303
57304     Each entry has a key which represents the cipher, followed by a
57305     plist with internal details about the algorithm.  The plist will
57306     have ‘:type gnutls-symmetric-cipher’ and also will have the keys
57307     ‘:cipher-aead-capable’ set to ‘nil’ or ‘t’ to indicate AEAD
57308     capability; and ‘:cipher-tagsize’ ‘:cipher-blocksize’
57309     ‘:cipher-keysize’ ‘:cipher-ivsize’ to indicate the size, in bytes,
57310     of the tag, block size of the resulting data, the key, and the IV
57311     respectively.
57312
57313 -- Function: gnutls-symmetric-encrypt cipher key iv input &optional
57314          aead_auth
57315     The CIPHER can be the whole plist from ‘gnutls-ciphers’, or just
57316     the symbol key, or a string with the name of that symbol.
57317
57318     The KEY can be specified as a buffer or string or in other ways
57319     (*note Format of GnuTLS Cryptography Inputs::).  The KEY will be
57320     wiped after use if it’s a string.
57321
57322     The IV and INPUT and the optional AEAD_AUTH can be specified as a
57323     buffer or string or in other ways (*note Format of GnuTLS
57324     Cryptography Inputs::).
57325
57326     AEAD_AUTH is only checked with AEAD ciphers, that is, ciphers whose
57327     plist has ‘:cipher-aead-capable t’.  Otherwise it’s ignored.
57328
57329     This function returns ‘nil’ on error, and signals a Lisp error if
57330     the CIPHER or KEY, IV, or INPUT are invalid, or if AEAD_AUTH was
57331     specified with an AEAD cipher and was invalid.
57332
57333     On success, it returns a list of a binary string (the output) and
57334     the IV used.
57335
57336 -- Function: gnutls-symmetric-decrypt cipher key iv input &optional
57337          aead_auth
57338     The CIPHER can be the whole plist from ‘gnutls-ciphers’, or just
57339     the symbol key, or a string with the name of that symbol.
57340
57341     The KEY can be specified as a buffer or string or in other ways
57342     (*note Format of GnuTLS Cryptography Inputs::).  The KEY will be
57343     wiped after use if it’s a string.
57344
57345     The IV and INPUT and the optional AEAD_AUTH can be specified as a
57346     buffer or string or in other ways (*note Format of GnuTLS
57347     Cryptography Inputs::).
57348
57349     AEAD_AUTH is only checked with AEAD ciphers, that is, ciphers whose
57350     plist has ‘:cipher-aead-capable t’.  Otherwise it’s ignored.
57351
57352     This function returns ‘nil’ on decryption error, and signals a Lisp
57353     error if the CIPHER or KEY, IV, or INPUT are invalid, or if
57354     AEAD_AUTH was specified with an AEAD cipher and was invalid.
57355
57356     On success, it returns a list of a binary string (the output) and
57357     the IV used.
57358
57359
57360File: elisp.info,  Node: Parsing HTML/XML,  Next: Parsing JSON,  Prev: GnuTLS Cryptography,  Up: Text
57361
5736232.28 Parsing HTML and XML
57363==========================
57364
57365Emacs can be compiled with built-in libxml2 support.
57366
57367 -- Function: libxml-available-p
57368     This function returns non-‘nil’ if built-in libxml2 support is
57369     available in this Emacs session.
57370
57371   When libxml2 support is available, the following functions can be
57372used to parse HTML or XML text into Lisp object trees.
57373
57374 -- Function: libxml-parse-html-region start end &optional base-url
57375          discard-comments
57376     This function parses the text between START and END as HTML, and
57377     returns a list representing the HTML “parse tree”.  It attempts to
57378     handle real-world HTML by robustly coping with syntax mistakes.
57379
57380     The optional argument BASE-URL, if non-‘nil’, should be a string
57381     specifying the base URL for relative URLs occurring in links.
57382
57383     If the optional argument DISCARD-COMMENTS is non-‘nil’, any
57384     top-level comment is discarded.  (This argument is obsolete and
57385     will be removed in future Emacs versions.  To remove comments, use
57386     the ‘xml-remove-comments’ utility function on the data before you
57387     call the parsing function.)
57388
57389     In the parse tree, each HTML node is represented by a list in which
57390     the first element is a symbol representing the node name, the
57391     second element is an alist of node attributes, and the remaining
57392     elements are the subnodes.
57393
57394     The following example demonstrates this.  Given this (malformed)
57395     HTML document:
57396
57397          <html><head></head><body width=101><div class=thing>Foo<div>Yes
57398
57399     A call to ‘libxml-parse-html-region’ returns this DOM (document
57400     object model):
57401
57402          (html nil
57403           (head nil)
57404           (body ((width . "101"))
57405            (div ((class . "thing"))
57406             "Foo"
57407             (div nil
57408              "Yes"))))
57409
57410 -- Function: shr-insert-document dom
57411     This function renders the parsed HTML in DOM into the current
57412     buffer.  The argument DOM should be a list as generated by
57413     ‘libxml-parse-html-region’.  This function is, e.g., used by *note
57414     EWW: (eww)Top.
57415
57416 -- Function: libxml-parse-xml-region start end &optional base-url
57417          discard-comments
57418     This function is the same as ‘libxml-parse-html-region’, except
57419     that it parses the text as XML rather than HTML (so it is stricter
57420     about syntax).
57421
57422* Menu:
57423
57424* Document Object Model:: Access, manipulate and search the DOM.
57425
57426
57427File: elisp.info,  Node: Document Object Model,  Up: Parsing HTML/XML
57428
5742932.28.1 Document Object Model
57430-----------------------------
57431
57432The DOM returned by ‘libxml-parse-html-region’ (and the other XML
57433parsing functions) is a tree structure where each node has a node name
57434(called a “tag”), and optional key/value “attribute” list, and then a
57435list of “child nodes”.  The child nodes are either strings or DOM
57436objects.
57437
57438     (body ((width . "101"))
57439      (div ((class . "thing"))
57440       "Foo"
57441       (div nil
57442        "Yes")))
57443
57444 -- Function: dom-node tag &optional attributes &rest children
57445     This function creates a DOM node of type TAG.  If given, ATTRIBUTES
57446     should be a key/value pair list.  If given, CHILDREN should be DOM
57447     nodes.
57448
57449   The following functions can be used to work with this structure.
57450Each function takes a DOM node, or a list of nodes.  In the latter case,
57451only the first node in the list is used.
57452
57453   Simple accessors:
57454
57455‘dom-tag NODE’
57456     Return the “tag” (also called “node name”) of the node.
57457
57458‘dom-attr NODE ATTRIBUTE’
57459     Return the value of ATTRIBUTE in the node.  A common usage would
57460     be:
57461
57462          (dom-attr img 'href)
57463          => "https://fsf.org/logo.png"
57464
57465‘dom-children NODE’
57466     Return all the children of the node.
57467
57468‘dom-non-text-children NODE’
57469     Return all the non-string children of the node.
57470
57471‘dom-attributes NODE’
57472     Return the key/value pair list of attributes of the node.
57473
57474‘dom-text NODE’
57475     Return all the textual elements of the node as a concatenated
57476     string.
57477
57478‘dom-texts NODE’
57479     Return all the textual elements of the node, as well as the textual
57480     elements of all the children of the node, recursively, as a
57481     concatenated string.  This function also takes an optional
57482     separator to be inserted between the textual elements.
57483
57484‘dom-parent DOM NODE’
57485     Return the parent of NODE in DOM.
57486
57487‘dom-remove DOM NODE’
57488     Remove NODE from DOM.
57489
57490   The following are functions for altering the DOM.
57491
57492‘dom-set-attribute NODE ATTRIBUTE VALUE’
57493     Set the ATTRIBUTE of the node to VALUE.
57494
57495‘dom-append-child NODE CHILD’
57496     Append CHILD as the last child of NODE.
57497
57498‘dom-add-child-before NODE CHILD BEFORE’
57499     Add CHILD to NODE’s child list before the BEFORE node.  If BEFORE
57500     is ‘nil’, make CHILD the first child.
57501
57502‘dom-set-attributes NODE ATTRIBUTES’
57503     Replace all the attributes of the node with a new key/value list.
57504
57505   The following are functions for searching for elements in the DOM.
57506They all return lists of matching nodes.
57507
57508‘dom-by-tag DOM TAG’
57509     Return all nodes in DOM that are of type TAG.  A typical use would
57510     be:
57511
57512          (dom-by-tag dom 'td)
57513          => '((td ...) (td ...) (td ...))
57514
57515‘dom-by-class DOM MATCH’
57516     Return all nodes in DOM that have class names that match MATCH,
57517     which is a regular expression.
57518
57519‘dom-by-style DOM STYLE’
57520     Return all nodes in DOM that have styles that match MATCH, which is
57521     a regular expression.
57522
57523‘dom-by-id DOM STYLE’
57524     Return all nodes in DOM that have IDs that match MATCH, which is a
57525     regular expression.
57526
57527‘dom-search DOM PREDICATE’
57528     Return all nodes in DOM where PREDICATE returns a non-‘nil’ value.
57529     PREDICATE is called with the node to be tested as its parameter.
57530
57531‘dom-strings DOM’
57532     Return all strings in DOM.
57533
57534   Utility functions:
57535
57536‘dom-pp DOM &optional REMOVE-EMPTY’
57537     Pretty-print DOM at point.  If REMOVE-EMPTY, don’t print textual
57538     nodes that just contain white-space.
57539
57540
57541File: elisp.info,  Node: Parsing JSON,  Next: JSONRPC,  Prev: Parsing HTML/XML,  Up: Text
57542
5754332.29 Parsing and generating JSON values
57544========================================
57545
57546When Emacs is compiled with JSON (“JavaScript Object Notation”) support,
57547it provides several functions to convert between Lisp objects and JSON
57548values.  Any JSON value can be converted to a Lisp object, but not vice
57549versa.  Specifically:
57550
57551   • JSON uses three keywords: ‘true’, ‘null’, ‘false’.  ‘true’ is
57552     represented by the symbol ‘t’.  By default, the remaining two are
57553     represented, respectively, by the symbols ‘:null’ and ‘:false’.
57554
57555   • JSON only has floating-point numbers.  They can represent both Lisp
57556     integers and Lisp floating-point numbers.
57557
57558   • JSON strings are always Unicode strings encoded in UTF-8.  Lisp
57559     strings can contain non-Unicode characters.
57560
57561   • JSON has only one sequence type, the array.  JSON arrays are
57562     represented using Lisp vectors.
57563
57564   • JSON has only one map type, the object.  JSON objects are
57565     represented using Lisp hashtables, alists or plists.  When an alist
57566     or plist contains several elements with the same key, Emacs uses
57567     only the first element for serialization, in accordance with the
57568     behavior of ‘assq’.
57569
57570Note that ‘nil’, being both a valid alist and a valid plist, represents
57571‘{}’, the empty JSON object; not ‘null’, ‘false’, or an empty array, all
57572of which are different JSON values.
57573
57574   If some Lisp object can’t be represented in JSON, the serialization
57575functions will signal an error of type ‘wrong-type-argument’.  The
57576parsing functions can also signal the following errors:
57577
57578‘json-end-of-file’
57579     Signaled when encountering a premature end of the input text.
57580
57581‘json-trailing-content’
57582     Signaled when encountering unexpected input after the first JSON
57583     object parsed.
57584
57585‘json-parse-error’
57586     Signaled when encountering invalid JSON syntax.
57587
57588   Only top-level values (arrays and objects) can be serialized to JSON.
57589The subobjects within these top-level values can be of any type.
57590Likewise, the parsing functions will only return vectors, hashtables,
57591alists, and plists.
57592
57593 -- Function: json-serialize object &rest args
57594     This function returns a new Lisp string which contains the JSON
57595     representation of OBJECT.  The argument ARGS is a list of
57596     keyword/argument pairs.  The following keywords are accepted:
57597
57598     ‘:null-object’
57599          The value decides which Lisp object to use to represent the
57600          JSON keyword ‘null’.  It defaults to the symbol ‘:null’.
57601
57602     ‘:false-object’
57603          The value decides which Lisp object to use to represent the
57604          JSON keyword ‘false’.  It defaults to the symbol ‘:false’.
57605
57606 -- Function: json-insert object &rest args
57607     This function inserts the JSON representation of OBJECT into the
57608     current buffer before point.  The argument ARGS are interpreted as
57609     in ‘json-parse-string’.
57610
57611 -- Function: json-parse-string string &rest args
57612     This function parses the JSON value in STRING, which must be a Lisp
57613     string.  If STRING doesn’t contain a valid JSON object, this
57614     function signals the ‘json-parse-error’ error.
57615
57616     The argument ARGS is a list of keyword/argument pairs.  The
57617     following keywords are accepted:
57618
57619     ‘:object-type’
57620          The value decides which Lisp object to use for representing
57621          the key-value mappings of a JSON object.  It can be either
57622          ‘hash-table’, the default, to make hashtables with strings as
57623          keys; ‘alist’ to use alists with symbols as keys; or ‘plist’
57624          to use plists with keyword symbols as keys.
57625
57626     ‘:array-type’
57627          The value decides which Lisp object to use for representing a
57628          JSON array.  It can be either ‘array’, the default, to use
57629          Lisp arrays; or ‘list’ to use lists.
57630
57631     ‘:null-object’
57632          The value decides which Lisp object to use to represent the
57633          JSON keyword ‘null’.  It defaults to the symbol ‘:null’.
57634
57635     ‘:false-object’
57636          The value decides which Lisp object to use to represent the
57637          JSON keyword ‘false’.  It defaults to the symbol ‘:false’.
57638
57639 -- Function: json-parse-buffer &rest args
57640     This function reads the next JSON value from the current buffer,
57641     starting at point.  It moves point to the position immediately
57642     after the value if contains a valid JSON object; otherwise it
57643     signals the ‘json-parse-error’ error and doesn’t move point.  The
57644     arguments ARGS are interpreted as in ‘json-parse-string’.
57645
57646
57647File: elisp.info,  Node: JSONRPC,  Next: Atomic Changes,  Prev: Parsing JSON,  Up: Text
57648
5764932.30 JSONRPC communication
57650===========================
57651
57652The ‘jsonrpc’ library implements the JSONRPC specification, version 2.0,
57653as it is described in <https://www.jsonrpc.org/>.  As the name suggests,
57654JSONRPC is a generic “Remote Procedure Call” protocol designed around
57655JSON objects, which you can convert to and from Lisp objects (*note
57656Parsing JSON::).
57657
57658* Menu:
57659
57660* JSONRPC Overview::
57661* Process-based JSONRPC connections::
57662* JSONRPC JSON object format::
57663* JSONRPC deferred requests::
57664
57665
57666File: elisp.info,  Node: JSONRPC Overview,  Next: Process-based JSONRPC connections,  Up: JSONRPC
57667
5766832.30.1 Overview
57669----------------
57670
57671Quoting from the spec (https://www.jsonrpc.org/), JSONRPC "is transport
57672agnostic in that the concepts can be used within the same process, over
57673sockets, over http, or in many various message passing environments."
57674
57675   To model this agnosticism, the ‘jsonrpc’ library uses objects of a
57676‘jsonrpc-connection’ class, which represent a connection to a remote
57677JSON endpoint (for details on Emacs’s object system, *note EIEIO:
57678(eieio)Top.).  In modern object-oriented parlance, this class is
57679“abstract”, i.e. the actual class of a useful connection object is
57680always a subclass of ‘jsonrpc-connection’.  Nevertheless, we can define
57681two distinct APIs around the ‘jsonrpc-connection’ class:
57682
57683  1. A user interface for building JSONRPC applications
57684
57685     In this scenario, the JSONRPC application selects a concrete
57686     subclass of ‘jsonrpc-connection’, and proceeds to create objects of
57687     that subclass using ‘make-instance’.  To initiate a contact to the
57688     remote endpoint, the JSONRPC application passes this object to the
57689     functions ‘jsonrpc-notify’, ‘jsonrpc-request’, and/or
57690     ‘jsonrpc-async-request’.  For handling remotely initiated contacts,
57691     which generally come in asynchronously, the instantiation should
57692     include ‘:request-dispatcher’ and ‘:notification-dispatcher’
57693     initargs, which are both functions of 3 arguments: the connection
57694     object; a symbol naming the JSONRPC method invoked remotely; and a
57695     JSONRPC ‘params’ object.
57696
57697     The function passed as ‘:request-dispatcher’ is responsible for
57698     handling the remote endpoint’s requests, which expect a reply from
57699     the local endpoint (in this case, the program you’re building).
57700     Inside that function, you may either return locally (a normal
57701     return) or non-locally (an error return).  A local return value
57702     must be a Lisp object that can be serialized as JSON (*note Parsing
57703     JSON::).  This determines a success response, and the object is
57704     forwarded to the server as the JSONRPC ‘result’ object.  A
57705     non-local return, achieved by calling the function ‘jsonrpc-error’,
57706     causes an error response to be sent to the server.  The details of
57707     the accompanying JSONRPC ‘error’ are filled out with whatever was
57708     passed to ‘jsonrpc-error’.  A non-local return triggered by an
57709     unexpected error of any other type also causes an error response to
57710     be sent (unless you have set ‘debug-on-error’, in which case this
57711     calls the Lisp debugger, *note Error Debugging::).
57712
57713  2. A inheritance interface for building JSONRPC transport
57714     implementations
57715
57716     In this scenario, ‘jsonrpc-connection’ is subclassed to implement a
57717     different underlying transport strategy (for details on how to
57718     subclass, see *note Inheritance: (eieio)Inheritance.).  Users of
57719     the application-building interface can then instantiate objects of
57720     this concrete class (using the ‘make-instance’ function) and
57721     connect to JSONRPC endpoints using that strategy.
57722
57723     This API has mandatory and optional parts.
57724
57725     To allow its users to initiate JSONRPC contacts (notifications or
57726     requests) or reply to endpoint requests, the subclass must have an
57727     implementation of the ‘jsonrpc-connection-send’ method.
57728
57729     Likewise, for handling the three types of remote contacts
57730     (requests, notifications, and responses to local requests), the
57731     transport implementation must arrange for the function
57732     ‘jsonrpc-connection-receive’ to be called after noticing a new
57733     JSONRPC message on the wire (whatever that "wire" may be).
57734
57735     Finally, and optionally, the ‘jsonrpc-connection’ subclass should
57736     implement the ‘jsonrpc-shutdown’ and ‘jsonrpc-running-p’ methods if
57737     these concepts apply to the transport.  If they do, then any system
57738     resources (e.g. processes, timers, etc.)  used to listen for
57739     messages on the wire should be released in ‘jsonrpc-shutdown’, i.e.
57740     they should only be needed while ‘jsonrpc-running-p’ is non-nil.
57741
57742
57743File: elisp.info,  Node: Process-based JSONRPC connections,  Next: JSONRPC JSON object format,  Prev: JSONRPC Overview,  Up: JSONRPC
57744
5774532.30.2 Process-based JSONRPC connections
57746-----------------------------------------
57747
57748For convenience, the ‘jsonrpc’ library comes with a built-in
57749‘jsonrpc-process-connection’ transport implementation that can talk to
57750local subprocesses (using the standard input and standard output); or
57751TCP hosts (using sockets); or any other remote endpoint that Emacs’s
57752process object can represent (*note Processes::).
57753
57754   Using this transport, the JSONRPC messages are encoded on the wire as
57755plain text and prefaced by some basic HTTP-style enveloping headers,
57756such as “Content-Length”.
57757
57758   For an example of an application using this transport scheme on top
57759of JSONRPC, see the Language Server Protocol
57760(https://microsoft.github.io/language-server-protocol/specification).
57761
57762   Along with the mandatory ‘:request-dispatcher’ and
57763‘:notification-dispatcher’ initargs, users of the
57764‘jsonrpc-process-connection’ class should pass the following initargs as
57765keyword-value pairs to ‘make-instance’:
57766
57767‘:process’
57768     Value must be a live process object or a function of no arguments
57769     producing one such object.  If passed a process object, the object
57770     is expected to contain a pre-established connection; otherwise, the
57771     function is called immediately after the object is made.
57772
57773‘:on-shutdown’
57774     Value must be a function of a single argument, the
57775     ‘jsonrpc-process-connection’ object.  The function is called after
57776     the underlying process object has been deleted (either deliberately
57777     by ‘jsonrpc-shutdown’, or unexpectedly, because of some external
57778     cause).
57779
57780
57781File: elisp.info,  Node: JSONRPC JSON object format,  Next: JSONRPC deferred requests,  Prev: Process-based JSONRPC connections,  Up: JSONRPC
57782
5778332.30.3 JSONRPC JSON object format
57784----------------------------------
57785
57786JSONRPC JSON objects are exchanged as Lisp plists (*note Property
57787Lists::): JSON-compatible plists are handed to the dispatcher functions
57788and, likewise, JSON-compatible plists should be given to
57789‘jsonrpc-notify’, ‘jsonrpc-request’, and ‘jsonrpc-async-request’.
57790
57791   To facilitate handling plists, this library makes liberal use of
57792‘cl-lib’ library (*note cl-lib: (cl)Top.) and suggests (but doesn’t
57793force) its clients to do the same.  A macro ‘jsonrpc-lambda’ can be used
57794to create a lambda for destructuring a JSON-object like in this example:
57795
57796     (jsonrpc-async-request
57797      myproc :frobnicate `(:foo "trix")
57798      :success-fn (jsonrpc-lambda (&key bar baz &allow-other-keys)
57799                    (message "Server replied back with %s and %s!"
57800                             bar baz))
57801      :error-fn (jsonrpc-lambda (&key code message _data)
57802                  (message "Sadly, server reports %s: %s"
57803                           code message)))
57804
57805
57806File: elisp.info,  Node: JSONRPC deferred requests,  Prev: JSONRPC JSON object format,  Up: JSONRPC
57807
5780832.30.4 Deferred JSONRPC requests
57809---------------------------------
57810
57811In many RPC situations, synchronization between the two communicating
57812endpoints is a matter of correctly designing the RPC application: when
57813synchronization is needed, requests (which are blocking) should be used;
57814when it isn’t, notifications should suffice.  However, when Emacs acts
57815as one of these endpoints, asynchronous events (e.g.  timer- or
57816process-related) may be triggered while there is still uncertainty about
57817the state of the remote endpoint.  Furthermore, acting on these events
57818may only sometimes demand synchronization, depending on the event’s
57819specific nature.
57820
57821   The ‘:deferred’ keyword argument to ‘jsonrpc-request’ and
57822‘jsonrpc-async-request’ is designed to let the caller indicate that the
57823specific request needs synchronization and its actual issuance may be
57824delayed to the future, until some condition is satisfied.  Specifying
57825‘:deferred’ for a request doesn’t mean it _will_ be delayed, only that
57826it _can_ be.  If the request isn’t sent immediately, ‘jsonrpc’ will make
57827renewed efforts to send it at certain key times during communication,
57828such as when receiving or sending other messages to the endpoint.
57829
57830   Before any attempt to send the request, the application-specific
57831conditions are checked.  Since the ‘jsonrpc’ library can’t know what
57832these conditions are, the program can use the
57833‘jsonrpc-connection-ready-p’ generic function (*note Generic
57834Functions::) to specify them.  The default method for this function
57835returns ‘t’, but you can add overriding methods that return ‘nil’ in
57836some situations, based on the arguments passed to it, which are the
57837‘jsonrpc-connection’ object (*note JSONRPC Overview::) and whichever
57838value you passed as the ‘:deferred’ keyword argument.
57839
57840
57841File: elisp.info,  Node: Atomic Changes,  Next: Change Hooks,  Prev: JSONRPC,  Up: Text
57842
5784332.31 Atomic Change Groups
57844==========================
57845
57846In database terminology, an “atomic” change is an indivisible change—it
57847can succeed entirely or it can fail entirely, but it cannot partly
57848succeed.  A Lisp program can make a series of changes to one or several
57849buffers as an “atomic change group”, meaning that either the entire
57850series of changes will be installed in their buffers or, in case of an
57851error, none of them will be.
57852
57853   To do this for one buffer, the one already current, simply write a
57854call to ‘atomic-change-group’ around the code that makes the changes,
57855like this:
57856
57857     (atomic-change-group
57858       (insert foo)
57859       (delete-region x y))
57860
57861If an error (or other nonlocal exit) occurs inside the body of
57862‘atomic-change-group’, it unmakes all the changes in that buffer that
57863were during the execution of the body.  This kind of change group has no
57864effect on any other buffers—any such changes remain.
57865
57866   If you need something more sophisticated, such as to make changes in
57867various buffers constitute one atomic group, you must directly call
57868lower-level functions that ‘atomic-change-group’ uses.
57869
57870 -- Function: prepare-change-group &optional buffer
57871     This function sets up a change group for buffer BUFFER, which
57872     defaults to the current buffer.  It returns a handle that
57873     represents the change group.  You must use this handle to activate
57874     the change group and subsequently to finish it.
57875
57876   To use the change group, you must “activate” it.  You must do this
57877before making any changes in the text of BUFFER.
57878
57879 -- Function: activate-change-group handle
57880     This function activates the change group that HANDLE designates.
57881
57882   After you activate the change group, any changes you make in that
57883buffer become part of it.  Once you have made all the desired changes in
57884the buffer, you must “finish” the change group.  There are two ways to
57885do this: you can either accept (and finalize) all the changes, or cancel
57886them all.
57887
57888 -- Function: accept-change-group handle
57889     This function accepts all the changes in the change group specified
57890     by HANDLE, making them final.
57891
57892 -- Function: cancel-change-group handle
57893     This function cancels and undoes all the changes in the change
57894     group specified by HANDLE.
57895
57896   You can cause some or all of the changes in a change group to be
57897considered as a single unit for the purposes of the ‘undo’ commands
57898(*note Undo::) by using ‘undo-amalgamate-change-group’.
57899
57900 -- Function: undo-amalgamate-change-group
57901     Amalgamate all the changes made in the change-group since the state
57902     identified by HANDLE.  This function removes all undo boundaries
57903     between undo records of changes since the state described by
57904     HANDLE.  Usually, HANDLE is the handle returned by
57905     ‘prepare-change-group’, in which case all the changes since the
57906     beginning of the change-group are amalgamated into a single undo
57907     unit.
57908
57909   Your code should use ‘unwind-protect’ to make sure the group is
57910always finished.  The call to ‘activate-change-group’ should be inside
57911the ‘unwind-protect’, in case the user types ‘C-g’ just after it runs.
57912(This is one reason why ‘prepare-change-group’ and
57913‘activate-change-group’ are separate functions, because normally you
57914would call ‘prepare-change-group’ before the start of that
57915‘unwind-protect’.)  Once you finish the group, don’t use the handle
57916again—in particular, don’t try to finish the same group twice.
57917
57918   To make a multibuffer change group, call ‘prepare-change-group’ once
57919for each buffer you want to cover, then use ‘nconc’ to combine the
57920returned values, like this:
57921
57922     (nconc (prepare-change-group buffer-1)
57923            (prepare-change-group buffer-2))
57924
57925   You can then activate the multibuffer change group with a single call
57926to ‘activate-change-group’, and finish it with a single call to
57927‘accept-change-group’ or ‘cancel-change-group’.
57928
57929   Nested use of several change groups for the same buffer works as you
57930would expect.  Non-nested use of change groups for the same buffer will
57931get Emacs confused, so don’t let it happen; the first change group you
57932start for any given buffer should be the last one finished.
57933
57934
57935File: elisp.info,  Node: Change Hooks,  Prev: Atomic Changes,  Up: Text
57936
5793732.32 Change Hooks
57938==================
57939
57940These hook variables let you arrange to take notice of changes in
57941buffers (or in a particular buffer, if you make them buffer-local).  See
57942also *note Special Properties::, for how to detect changes to specific
57943parts of the text.
57944
57945   The functions you use in these hooks should save and restore the
57946match data if they do anything that uses regular expressions; otherwise,
57947they will interfere in bizarre ways with the editing operations that
57948call them.
57949
57950 -- Variable: before-change-functions
57951     This variable holds a list of functions to call when Emacs is about
57952     to modify a buffer.  Each function gets two arguments, the
57953     beginning and end of the region that is about to change,
57954     represented as integers.  The buffer that is about to change is
57955     always the current buffer when the function is called.
57956
57957 -- Variable: after-change-functions
57958     This variable holds a list of functions to call after Emacs
57959     modifies a buffer.  Each function receives three arguments: the
57960     beginning and end of the region just changed, and the length of the
57961     text that existed before the change.  All three arguments are
57962     integers.  The buffer that has been changed is always the current
57963     buffer when the function is called.
57964
57965     The length of the old text is the difference between the buffer
57966     positions before and after that text as it was before the change.
57967     As for the changed text, its length is simply the difference
57968     between the first two arguments.
57969
57970   Output of messages into the ‘*Messages*’ buffer does not call these
57971functions, and neither do certain internal buffer changes, such as
57972changes in buffers created by Emacs internally for certain jobs, that
57973should not be visible to Lisp programs.
57974
57975   The vast majority of buffer changing primitives will call
57976‘before-change-functions’ and ‘after-change-functions’ in balanced
57977pairs, once for each change, where the arguments to these hooks exactly
57978delimit the change being made.  Yet, hook functions should not rely on
57979this always being the case, because some complex primitives call
57980‘before-change-functions’ once before making changes, and then call
57981‘after-change-functions’ zero or more times, depending on how many
57982individual changes the primitive is making.  When that happens, the
57983arguments to ‘before-change-functions’ will enclose a region in which
57984the individual changes are made, but won’t necessarily be the minimal
57985such region, and the arguments to each successive call of
57986‘after-change-functions’ will then delimit the part of text being
57987changed exactly.  In general, we advise using either the before- or the
57988after-change hook, but not both.
57989
57990 -- Macro: combine-after-change-calls body...
57991     The macro executes BODY normally, but arranges to call the
57992     after-change functions just once for a series of several changes—if
57993     that seems safe.
57994
57995     If a program makes several text changes in the same area of the
57996     buffer, using the macro ‘combine-after-change-calls’ around that
57997     part of the program can make it run considerably faster when
57998     after-change hooks are in use.  When the after-change hooks are
57999     ultimately called, the arguments specify a portion of the buffer
58000     including all of the changes made within the
58001     ‘combine-after-change-calls’ body.
58002
58003     *Warning:* You must not alter the values of
58004     ‘after-change-functions’ within the body of a
58005     ‘combine-after-change-calls’ form.
58006
58007     *Warning:* If the changes you combine occur in widely scattered
58008     parts of the buffer, this will still work, but it is not advisable,
58009     because it may lead to inefficient behavior for some change hook
58010     functions.
58011
58012 -- Macro: combine-change-calls beg end body...
58013     This executes BODY normally, except any buffer changes it makes do
58014     not trigger the calls to ‘before-change-functions’ and
58015     ‘after-change-functions’.  Instead there is a single call of each
58016     of these hooks for the region enclosed by BEG and END, the
58017     parameters supplied to ‘after-change-functions’ reflecting the
58018     changes made to the size of the region by BODY.
58019
58020     The result of this macro is the result returned by BODY.
58021
58022     This macro is useful when a function makes a possibly large number
58023     of repetitive changes to the buffer, and the change hooks would
58024     otherwise take a long time to run, were they to be run for each
58025     individual buffer modification.  Emacs itself uses this macro, for
58026     example, in the commands ‘comment-region’ and ‘uncomment-region’.
58027
58028     *Warning:* You must not alter the values of
58029     ‘before-change-functions’ or ‘after-change-function’ within BODY.
58030
58031     *Warning:* You must not make any buffer changes outside of the
58032     region specified by BEG and END.
58033
58034 -- Variable: first-change-hook
58035     This variable is a normal hook that is run whenever a buffer is
58036     changed that was previously in the unmodified state.
58037
58038 -- Variable: inhibit-modification-hooks
58039     If this variable is non-‘nil’, all of the change hooks are
58040     disabled; none of them run.  This affects all the hook variables
58041     described above in this section, as well as the hooks attached to
58042     certain special text properties (*note Special Properties::) and
58043     overlay properties (*note Overlay Properties::).
58044
58045     Also, this variable is bound to non-‘nil’ while running those same
58046     hook variables, so that by default modifying the buffer from a
58047     modification hook does not cause other modification hooks to be
58048     run.  If you do want modification hooks to be run in a particular
58049     piece of code that is itself run from a modification hook, then
58050     rebind locally ‘inhibit-modification-hooks’ to ‘nil’.  However,
58051     doing this may cause recursive calls to the modification hooks, so
58052     be sure to prepare for that (for example, by binding some variable
58053     which tells your hook to do nothing).
58054
58055     We recommend that you only bind this variable for modifications
58056     that do not result in lasting changes to buffer text contents (for
58057     example face changes or temporary modifications).  If you need to
58058     delay change hooks during a series of changes (typically for
58059     performance reasons), use ‘combine-change-calls’ or
58060     ‘combine-after-change-calls’ instead.
58061
58062
58063File: elisp.info,  Node: Non-ASCII Characters,  Next: Searching and Matching,  Prev: Text,  Up: Top
58064
5806533 Non-ASCII Characters
58066***********************
58067
58068This chapter covers the special issues relating to characters and how
58069they are stored in strings and buffers.
58070
58071* Menu:
58072
58073* Text Representations::    How Emacs represents text.
58074* Disabling Multibyte::     Controlling whether to use multibyte characters.
58075* Converting Representations::  Converting unibyte to multibyte and vice versa.
58076* Selecting a Representation::  Treating a byte sequence as unibyte or multi.
58077* Character Codes::         How unibyte and multibyte relate to
58078                                codes of individual characters.
58079* Character Properties::    Character attributes that define their
58080                                behavior and handling.
58081* Character Sets::          The space of possible character codes
58082                                is divided into various character sets.
58083* Scanning Charsets::       Which character sets are used in a buffer?
58084* Translation of Characters::   Translation tables are used for conversion.
58085* Coding Systems::          Coding systems are conversions for saving files.
58086* Input Methods::           Input methods allow users to enter various
58087                                non-ASCII characters without special keyboards.
58088* Locales::                 Interacting with the POSIX locale.
58089
58090
58091File: elisp.info,  Node: Text Representations,  Next: Disabling Multibyte,  Up: Non-ASCII Characters
58092
5809333.1 Text Representations
58094=========================
58095
58096Emacs buffers and strings support a large repertoire of characters from
58097many different scripts, allowing users to type and display text in
58098almost any known written language.
58099
58100   To support this multitude of characters and scripts, Emacs closely
58101follows the “Unicode Standard”.  The Unicode Standard assigns a unique
58102number, called a “codepoint”, to each and every character.  The range of
58103codepoints defined by Unicode, or the Unicode “codespace”, is
58104‘0..#x10FFFF’ (in hexadecimal notation), inclusive.  Emacs extends this
58105range with codepoints in the range ‘#x110000..#x3FFFFF’, which it uses
58106for representing characters that are not unified with Unicode and “raw
581078-bit bytes” that cannot be interpreted as characters.  Thus, a
58108character codepoint in Emacs is a 22-bit integer.
58109
58110   To conserve memory, Emacs does not hold fixed-length 22-bit numbers
58111that are codepoints of text characters within buffers and strings.
58112Rather, Emacs uses a variable-length internal representation of
58113characters, that stores each character as a sequence of 1 to 5 8-bit
58114bytes, depending on the magnitude of its codepoint(1).  For example, any
58115ASCII character takes up only 1 byte, a Latin-1 character takes up 2
58116bytes, etc.  We call this representation of text “multibyte”.
58117
58118   Outside Emacs, characters can be represented in many different
58119encodings, such as ISO-8859-1, GB-2312, Big-5, etc.  Emacs converts
58120between these external encodings and its internal representation, as
58121appropriate, when it reads text into a buffer or a string, or when it
58122writes text to a disk file or passes it to some other process.
58123
58124   Occasionally, Emacs needs to hold and manipulate encoded text or
58125binary non-text data in its buffers or strings.  For example, when Emacs
58126visits a file, it first reads the file’s text verbatim into a buffer,
58127and only then converts it to the internal representation.  Before the
58128conversion, the buffer holds encoded text.
58129
58130   Encoded text is not really text, as far as Emacs is concerned, but
58131rather a sequence of raw 8-bit bytes.  We call buffers and strings that
58132hold encoded text “unibyte” buffers and strings, because Emacs treats
58133them as a sequence of individual bytes.  Usually, Emacs displays unibyte
58134buffers and strings as octal codes such as ‘\237’.  We recommend that
58135you never use unibyte buffers and strings except for manipulating
58136encoded text or binary non-text data.
58137
58138   In a buffer, the buffer-local value of the variable
58139‘enable-multibyte-characters’ specifies the representation used.  The
58140representation for a string is determined and recorded in the string
58141when the string is constructed.
58142
58143 -- Variable: enable-multibyte-characters
58144     This variable specifies the current buffer’s text representation.
58145     If it is non-‘nil’, the buffer contains multibyte text; otherwise,
58146     it contains unibyte encoded text or binary non-text data.
58147
58148     You cannot set this variable directly; instead, use the function
58149     ‘set-buffer-multibyte’ to change a buffer’s representation.
58150
58151 -- Function: position-bytes position
58152     Buffer positions are measured in character units.  This function
58153     returns the byte-position corresponding to buffer position POSITION
58154     in the current buffer.  This is 1 at the start of the buffer, and
58155     counts upward in bytes.  If POSITION is out of range, the value is
58156     ‘nil’.
58157
58158 -- Function: byte-to-position byte-position
58159     Return the buffer position, in character units, corresponding to
58160     given BYTE-POSITION in the current buffer.  If BYTE-POSITION is out
58161     of range, the value is ‘nil’.  In a multibyte buffer, an arbitrary
58162     value of BYTE-POSITION can be not at character boundary, but inside
58163     a multibyte sequence representing a single character; in this case,
58164     this function returns the buffer position of the character whose
58165     multibyte sequence includes BYTE-POSITION.  In other words, the
58166     value does not change for all byte positions that belong to the
58167     same character.
58168
58169   The following two functions are useful when a Lisp program needs to
58170map buffer positions to byte offsets in a file visited by the buffer.
58171
58172 -- Function: bufferpos-to-filepos position &optional quality
58173          coding-system
58174     This function is similar to ‘position-bytes’, but instead of byte
58175     position in the current buffer it returns the offset from the
58176     beginning of the current buffer’s file of the byte that corresponds
58177     to the given character POSITION in the buffer.  The conversion
58178     requires to know how the text is encoded in the buffer’s file; this
58179     is what the CODING-SYSTEM argument is for, defaulting to the value
58180     of ‘buffer-file-coding-system’.  The optional argument QUALITY
58181     specifies how accurate the result should be; it should be one of
58182     the following:
58183
58184     ‘exact’
58185          The result must be accurate.  The function may need to encode
58186          and decode a large part of the buffer, which is expensive and
58187          can be slow.
58188     ‘approximate’
58189          The value can be an approximation.  The function may avoid
58190          expensive processing and return an inexact result.
58191     ‘nil’
58192          If the exact result needs expensive processing, the function
58193          will return ‘nil’ rather than an approximation.  This is the
58194          default if the argument is omitted.
58195
58196 -- Function: filepos-to-bufferpos byte &optional quality coding-system
58197     This function returns the buffer position corresponding to a file
58198     position specified by BYTE, a zero-base byte offset from the file’s
58199     beginning.  The function performs the conversion opposite to what
58200     ‘bufferpos-to-filepos’ does.  Optional arguments QUALITY and
58201     CODING-SYSTEM have the same meaning and values as for
58202     ‘bufferpos-to-filepos’.
58203
58204 -- Function: multibyte-string-p string
58205     Return ‘t’ if STRING is a multibyte string, ‘nil’ otherwise.  This
58206     function also returns ‘nil’ if STRING is some object other than a
58207     string.
58208
58209 -- Function: string-bytes string
58210     This function returns the number of bytes in STRING.  If STRING is
58211     a multibyte string, this can be greater than ‘(length STRING)’.
58212
58213 -- Function: unibyte-string &rest bytes
58214     This function concatenates all its argument BYTES and makes the
58215     result a unibyte string.
58216
58217   ---------- Footnotes ----------
58218
58219   (1) This internal representation is based on one of the encodings
58220defined by the Unicode Standard, called “UTF-8”, for representing any
58221Unicode codepoint, but Emacs extends UTF-8 to represent the additional
58222codepoints it uses for raw 8-bit bytes and characters not unified with
58223Unicode.
58224
58225
58226File: elisp.info,  Node: Disabling Multibyte,  Next: Converting Representations,  Prev: Text Representations,  Up: Non-ASCII Characters
58227
5822833.2 Disabling Multibyte Characters
58229===================================
58230
58231By default, Emacs starts in multibyte mode: it stores the contents of
58232buffers and strings using an internal encoding that represents non-ASCII
58233characters using multi-byte sequences.  Multibyte mode allows you to use
58234all the supported languages and scripts without limitations.
58235
58236   Under very special circumstances, you may want to disable multibyte
58237character support, for a specific buffer.  When multibyte characters are
58238disabled in a buffer, we call that “unibyte mode”.  In unibyte mode,
58239each character in the buffer has a character code ranging from 0 through
58240255 (0377 octal); 0 through 127 (0177 octal) represent ASCII characters,
58241and 128 (0200 octal) through 255 (0377 octal) represent non-ASCII
58242characters.
58243
58244   To edit a particular file in unibyte representation, visit it using
58245‘find-file-literally’.  *Note Visiting Functions::.  You can convert a
58246multibyte buffer to unibyte by saving it to a file, killing the buffer,
58247and visiting the file again with ‘find-file-literally’.  Alternatively,
58248you can use ‘C-x <RET> c’ (‘universal-coding-system-argument’) and
58249specify ‘raw-text’ as the coding system with which to visit or save a
58250file.  *Note Specifying a Coding System for File Text: (emacs)Text
58251Coding.  Unlike ‘find-file-literally’, finding a file as ‘raw-text’
58252doesn’t disable format conversion, uncompression, or auto mode
58253selection.
58254
58255   The buffer-local variable ‘enable-multibyte-characters’ is non-‘nil’
58256in multibyte buffers, and ‘nil’ in unibyte ones.  The mode line also
58257indicates whether a buffer is multibyte or not.  With a graphical
58258display, in a multibyte buffer, the portion of the mode line that
58259indicates the character set has a tooltip that (amongst other things)
58260says that the buffer is multibyte.  In a unibyte buffer, the character
58261set indicator is absent.  Thus, in a unibyte buffer (when using a
58262graphical display) there is normally nothing before the indication of
58263the visited file’s end-of-line convention (colon, backslash, etc.),
58264unless you are using an input method.
58265
58266   You can turn off multibyte support in a specific buffer by invoking
58267the command ‘toggle-enable-multibyte-characters’ in that buffer.
58268
58269
58270File: elisp.info,  Node: Converting Representations,  Next: Selecting a Representation,  Prev: Disabling Multibyte,  Up: Non-ASCII Characters
58271
5827233.3 Converting Text Representations
58273====================================
58274
58275Emacs can convert unibyte text to multibyte; it can also convert
58276multibyte text to unibyte, provided that the multibyte text contains
58277only ASCII and 8-bit raw bytes.  In general, these conversions happen
58278when inserting text into a buffer, or when putting text from several
58279strings together in one string.  You can also explicitly convert a
58280string’s contents to either representation.
58281
58282   Emacs chooses the representation for a string based on the text from
58283which it is constructed.  The general rule is to convert unibyte text to
58284multibyte text when combining it with other multibyte text, because the
58285multibyte representation is more general and can hold whatever
58286characters the unibyte text has.
58287
58288   When inserting text into a buffer, Emacs converts the text to the
58289buffer’s representation, as specified by ‘enable-multibyte-characters’
58290in that buffer.  In particular, when you insert multibyte text into a
58291unibyte buffer, Emacs converts the text to unibyte, even though this
58292conversion cannot in general preserve all the characters that might be
58293in the multibyte text.  The other natural alternative, to convert the
58294buffer contents to multibyte, is not acceptable because the buffer’s
58295representation is a choice made by the user that cannot be overridden
58296automatically.
58297
58298   Converting unibyte text to multibyte text leaves ASCII characters
58299unchanged, and converts bytes with codes 128 through 255 to the
58300multibyte representation of raw eight-bit bytes.
58301
58302   Converting multibyte text to unibyte converts all ASCII and eight-bit
58303characters to their single-byte form, but loses information for
58304non-ASCII characters by discarding all but the low 8 bits of each
58305character’s codepoint.  Converting unibyte text to multibyte and back to
58306unibyte reproduces the original unibyte text.
58307
58308   The next two functions either return the argument STRING, or a newly
58309created string with no text properties.
58310
58311 -- Function: string-to-multibyte string
58312     This function returns a multibyte string containing the same
58313     sequence of characters as STRING.  If STRING is a multibyte string,
58314     it is returned unchanged.  The function assumes that STRING
58315     includes only ASCII characters and raw 8-bit bytes; the latter are
58316     converted to their multibyte representation corresponding to the
58317     codepoints ‘#x3FFF80’ through ‘#x3FFFFF’, inclusive (*note
58318     codepoints: Text Representations.).
58319
58320 -- Function: string-to-unibyte string
58321     This function returns a unibyte string containing the same sequence
58322     of characters as STRING.  It signals an error if STRING contains a
58323     non-ASCII character.  If STRING is a unibyte string, it is returned
58324     unchanged.  Use this function for STRING arguments that contain
58325     only ASCII and eight-bit characters.
58326
58327 -- Function: byte-to-string byte
58328     This function returns a unibyte string containing a single byte of
58329     character data, BYTE.  It signals an error if BYTE is not an
58330     integer between 0 and 255.
58331
58332 -- Function: multibyte-char-to-unibyte char
58333     This converts the multibyte character CHAR to a unibyte character,
58334     and returns that character.  If CHAR is neither ASCII nor
58335     eight-bit, the function returns −1.
58336
58337 -- Function: unibyte-char-to-multibyte char
58338     This convert the unibyte character CHAR to a multibyte character,
58339     assuming CHAR is either ASCII or raw 8-bit byte.
58340
58341
58342File: elisp.info,  Node: Selecting a Representation,  Next: Character Codes,  Prev: Converting Representations,  Up: Non-ASCII Characters
58343
5834433.4 Selecting a Representation
58345===============================
58346
58347Sometimes it is useful to examine an existing buffer or string as
58348multibyte when it was unibyte, or vice versa.
58349
58350 -- Function: set-buffer-multibyte multibyte
58351     Set the representation type of the current buffer.  If MULTIBYTE is
58352     non-‘nil’, the buffer becomes multibyte.  If MULTIBYTE is ‘nil’,
58353     the buffer becomes unibyte.
58354
58355     This function leaves the buffer contents unchanged when viewed as a
58356     sequence of bytes.  As a consequence, it can change the contents
58357     viewed as characters; for instance, a sequence of three bytes which
58358     is treated as one character in multibyte representation will count
58359     as three characters in unibyte representation.  Eight-bit
58360     characters representing raw bytes are an exception.  They are
58361     represented by one byte in a unibyte buffer, but when the buffer is
58362     set to multibyte, they are converted to two-byte sequences, and
58363     vice versa.
58364
58365     This function sets ‘enable-multibyte-characters’ to record which
58366     representation is in use.  It also adjusts various data in the
58367     buffer (including overlays, text properties and markers) so that
58368     they cover the same text as they did before.
58369
58370     This function signals an error if the buffer is narrowed, since the
58371     narrowing might have occurred in the middle of multibyte character
58372     sequences.
58373
58374     This function also signals an error if the buffer is an indirect
58375     buffer.  An indirect buffer always inherits the representation of
58376     its base buffer.
58377
58378 -- Function: string-as-unibyte string
58379     If STRING is already a unibyte string, this function returns STRING
58380     itself.  Otherwise, it returns a new string with the same bytes as
58381     STRING, but treating each byte as a separate character (so that the
58382     value may have more characters than STRING); as an exception, each
58383     eight-bit character representing a raw byte is converted into a
58384     single byte.  The newly-created string contains no text properties.
58385
58386 -- Function: string-as-multibyte string
58387     If STRING is a multibyte string, this function returns STRING
58388     itself.  Otherwise, it returns a new string with the same bytes as
58389     STRING, but treating each multibyte sequence as one character.
58390     This means that the value may have fewer characters than STRING
58391     has.  If a byte sequence in STRING is invalid as a multibyte
58392     representation of a single character, each byte in the sequence is
58393     treated as a raw 8-bit byte.  The newly-created string contains no
58394     text properties.
58395
58396
58397File: elisp.info,  Node: Character Codes,  Next: Character Properties,  Prev: Selecting a Representation,  Up: Non-ASCII Characters
58398
5839933.5 Character Codes
58400====================
58401
58402The unibyte and multibyte text representations use different character
58403codes.  The valid character codes for unibyte representation range from
584040 to ‘#xFF’ (255)—the values that can fit in one byte.  The valid
58405character codes for multibyte representation range from 0 to ‘#x3FFFFF’.
58406In this code space, values 0 through ‘#x7F’ (127) are for ASCII
58407characters, and values ‘#x80’ (128) through ‘#x3FFF7F’ (4194175) are for
58408non-ASCII characters.
58409
58410   Emacs character codes are a superset of the Unicode standard.  Values
584110 through ‘#x10FFFF’ (1114111) correspond to Unicode characters of the
58412same codepoint; values ‘#x110000’ (1114112) through ‘#x3FFF7F’ (4194175)
58413represent characters that are not unified with Unicode; and values
58414‘#x3FFF80’ (4194176) through ‘#x3FFFFF’ (4194303) represent eight-bit
58415raw bytes.
58416
58417 -- Function: characterp charcode
58418     This returns ‘t’ if CHARCODE is a valid character, and ‘nil’
58419     otherwise.
58420
58421          (characterp 65)
58422               ⇒ t
58423          (characterp 4194303)
58424               ⇒ t
58425          (characterp 4194304)
58426               ⇒ nil
58427
58428 -- Function: max-char
58429     This function returns the largest value that a valid character
58430     codepoint can have.
58431
58432          (characterp (max-char))
58433               ⇒ t
58434          (characterp (1+ (max-char)))
58435               ⇒ nil
58436
58437 -- Function: char-from-name string &optional ignore-case
58438     This function returns the character whose Unicode name is STRING.
58439     If IGNORE-CASE is non-‘nil’, case is ignored in STRING.  This
58440     function returns ‘nil’ if STRING does not name a character.
58441
58442          ;; U+03A3
58443          (= (char-from-name "GREEK CAPITAL LETTER SIGMA") #x03A3)
58444               ⇒ t
58445
58446 -- Function: get-byte &optional pos string
58447     This function returns the byte at character position POS in the
58448     current buffer.  If the current buffer is unibyte, this is
58449     literally the byte at that position.  If the buffer is multibyte,
58450     byte values of ASCII characters are the same as character
58451     codepoints, whereas eight-bit raw bytes are converted to their
58452     8-bit codes.  The function signals an error if the character at POS
58453     is non-ASCII.
58454
58455     The optional argument STRING means to get a byte value from that
58456     string instead of the current buffer.
58457
58458
58459File: elisp.info,  Node: Character Properties,  Next: Character Sets,  Prev: Character Codes,  Up: Non-ASCII Characters
58460
5846133.6 Character Properties
58462=========================
58463
58464A “character property” is a named attribute of a character that
58465specifies how the character behaves and how it should be handled during
58466text processing and display.  Thus, character properties are an
58467important part of specifying the character’s semantics.
58468
58469   On the whole, Emacs follows the Unicode Standard in its
58470implementation of character properties.  In particular, Emacs supports
58471the Unicode Character Property Model
58472(https://www.unicode.org/reports/tr23/), and the Emacs character
58473property database is derived from the Unicode Character Database (UCD).
58474See the Character Properties chapter of the Unicode Standard
58475(https://www.unicode.org/versions/Unicode12.1.0/ch04.pdf), for a
58476detailed description of Unicode character properties and their meaning.
58477This section assumes you are already familiar with that chapter of the
58478Unicode Standard, and want to apply that knowledge to Emacs Lisp
58479programs.
58480
58481   In Emacs, each property has a name, which is a symbol, and a set of
58482possible values, whose types depend on the property; if a character does
58483not have a certain property, the value is ‘nil’.  As a general rule, the
58484names of character properties in Emacs are produced from the
58485corresponding Unicode properties by downcasing them and replacing each
58486‘_’ character with a dash ‘-’.  For example, ‘Canonical_Combining_Class’
58487becomes ‘canonical-combining-class’.  However, sometimes we shorten the
58488names to make their use easier.
58489
58490   Some codepoints are left “unassigned” by the UCD—they don’t
58491correspond to any character.  The Unicode Standard defines default
58492values of properties for such codepoints; they are mentioned below for
58493each property.
58494
58495   Here is the full list of value types for all the character properties
58496that Emacs knows about:
58497
58498‘name’
58499     Corresponds to the ‘Name’ Unicode property.  The value is a string
58500     consisting of upper-case Latin letters A to Z, digits, spaces, and
58501     hyphen ‘-’ characters.  For unassigned codepoints, the value is
58502     ‘nil’.
58503
58504‘general-category’
58505     Corresponds to the ‘General_Category’ Unicode property.  The value
58506     is a symbol whose name is a 2-letter abbreviation of the
58507     character’s classification.  For unassigned codepoints, the value
58508     is ‘Cn’.
58509
58510‘canonical-combining-class’
58511     Corresponds to the ‘Canonical_Combining_Class’ Unicode property.
58512     The value is an integer.  For unassigned codepoints, the value is
58513     zero.
58514
58515‘bidi-class’
58516     Corresponds to the Unicode ‘Bidi_Class’ property.  The value is a
58517     symbol whose name is the Unicode “directional type” of the
58518     character.  Emacs uses this property when it reorders bidirectional
58519     text for display (*note Bidirectional Display::).  For unassigned
58520     codepoints, the value depends on the code blocks to which the
58521     codepoint belongs: most unassigned codepoints get the value of ‘L’
58522     (strong L), but some get values of ‘AL’ (Arabic letter) or ‘R’
58523     (strong R).
58524
58525‘decomposition’
58526     Corresponds to the Unicode properties ‘Decomposition_Type’ and
58527     ‘Decomposition_Value’.  The value is a list, whose first element
58528     may be a symbol representing a compatibility formatting tag, such
58529     as ‘small’(1); the other elements are characters that give the
58530     compatibility decomposition sequence of this character.  For
58531     characters that don’t have decomposition sequences, and for
58532     unassigned codepoints, the value is a list with a single member,
58533     the character itself.
58534
58535‘decimal-digit-value’
58536     Corresponds to the Unicode ‘Numeric_Value’ property for characters
58537     whose ‘Numeric_Type’ is ‘Decimal’.  The value is an integer, or
58538     ‘nil’ if the character has no decimal digit value.  For unassigned
58539     codepoints, the value is ‘nil’, which means NaN, or “not a number”.
58540
58541‘digit-value’
58542     Corresponds to the Unicode ‘Numeric_Value’ property for characters
58543     whose ‘Numeric_Type’ is ‘Digit’.  The value is an integer.
58544     Examples of such characters include compatibility subscript and
58545     superscript digits, for which the value is the corresponding
58546     number.  For characters that don’t have any numeric value, and for
58547     unassigned codepoints, the value is ‘nil’, which means NaN.
58548
58549‘numeric-value’
58550     Corresponds to the Unicode ‘Numeric_Value’ property for characters
58551     whose ‘Numeric_Type’ is ‘Numeric’.  The value of this property is a
58552     number.  Examples of characters that have this property include
58553     fractions, subscripts, superscripts, Roman numerals, currency
58554     numerators, and encircled numbers.  For example, the value of this
58555     property for the character U+2155 VULGAR FRACTION ONE FIFTH is
58556     ‘0.2’.  For characters that don’t have any numeric value, and for
58557     unassigned codepoints, the value is ‘nil’, which means NaN.
58558
58559‘mirrored’
58560     Corresponds to the Unicode ‘Bidi_Mirrored’ property.  The value of
58561     this property is a symbol, either ‘Y’ or ‘N’.  For unassigned
58562     codepoints, the value is ‘N’.
58563
58564‘mirroring’
58565     Corresponds to the Unicode ‘Bidi_Mirroring_Glyph’ property.  The
58566     value of this property is a character whose glyph represents the
58567     mirror image of the character’s glyph, or ‘nil’ if there’s no
58568     defined mirroring glyph.  All the characters whose ‘mirrored’
58569     property is ‘N’ have ‘nil’ as their ‘mirroring’ property; however,
58570     some characters whose ‘mirrored’ property is ‘Y’ also have ‘nil’
58571     for ‘mirroring’, because no appropriate characters exist with
58572     mirrored glyphs.  Emacs uses this property to display mirror images
58573     of characters when appropriate (*note Bidirectional Display::).
58574     For unassigned codepoints, the value is ‘nil’.
58575
58576‘paired-bracket’
58577     Corresponds to the Unicode ‘Bidi_Paired_Bracket’ property.  The
58578     value of this property is the codepoint of a character’s “paired
58579     bracket”, or ‘nil’ if the character is not a bracket character.
58580     This establishes a mapping between characters that are treated as
58581     bracket pairs by the Unicode Bidirectional Algorithm; Emacs uses
58582     this property when it decides how to reorder for display
58583     parentheses, braces, and other similar characters (*note
58584     Bidirectional Display::).
58585
58586‘bracket-type’
58587     Corresponds to the Unicode ‘Bidi_Paired_Bracket_Type’ property.
58588     For characters whose ‘paired-bracket’ property is non-‘nil’, the
58589     value of this property is a symbol, either ‘o’ (for opening bracket
58590     characters) or ‘c’ (for closing bracket characters).  For
58591     characters whose ‘paired-bracket’ property is ‘nil’, the value is
58592     the symbol ‘n’ (None).  Like ‘paired-bracket’, this property is
58593     used for bidirectional display.
58594
58595‘old-name’
58596     Corresponds to the Unicode ‘Unicode_1_Name’ property.  The value is
58597     a string.  For unassigned codepoints, and characters that have no
58598     value for this property, the value is ‘nil’.
58599
58600‘iso-10646-comment’
58601     Corresponds to the Unicode ‘ISO_Comment’ property.  The value is
58602     either a string or ‘nil’.  For unassigned codepoints, the value is
58603     ‘nil’.
58604
58605‘uppercase’
58606     Corresponds to the Unicode ‘Simple_Uppercase_Mapping’ property.
58607     The value of this property is a single character.  For unassigned
58608     codepoints, the value is ‘nil’, which means the character itself.
58609
58610‘lowercase’
58611     Corresponds to the Unicode ‘Simple_Lowercase_Mapping’ property.
58612     The value of this property is a single character.  For unassigned
58613     codepoints, the value is ‘nil’, which means the character itself.
58614
58615‘titlecase’
58616     Corresponds to the Unicode ‘Simple_Titlecase_Mapping’ property.
58617     “Title case” is a special form of a character used when the first
58618     character of a word needs to be capitalized.  The value of this
58619     property is a single character.  For unassigned codepoints, the
58620     value is ‘nil’, which means the character itself.
58621
58622‘special-uppercase’
58623     Corresponds to Unicode language- and context-independent special
58624     upper-casing rules.  The value of this property is a string (which
58625     may be empty).  For example mapping for U+00DF LATIN SMALL LETTER
58626     SHARP S is ‘"SS"’.  For characters with no special mapping, the
58627     value is ‘nil’ which means ‘uppercase’ property needs to be
58628     consulted instead.
58629
58630‘special-lowercase’
58631     Corresponds to Unicode language- and context-independent special
58632     lower-casing rules.  The value of this property is a string (which
58633     may be empty).  For example mapping for U+0130 LATIN CAPITAL LETTER
58634     I WITH DOT ABOVE the value is ‘"i\u0307"’ (i.e.  2-character string
58635     consisting of LATIN SMALL LETTER I followed by U+0307 COMBINING DOT
58636     ABOVE).  For characters with no special mapping, the value is ‘nil’
58637     which means ‘lowercase’ property needs to be consulted instead.
58638
58639‘special-titlecase’
58640     Corresponds to Unicode unconditional special title-casing rules.
58641     The value of this property is a string (which may be empty).  For
58642     example mapping for U+FB01 LATIN SMALL LIGATURE FI the value is
58643     ‘"Fi"’.  For characters with no special mapping, the value is ‘nil’
58644     which means ‘titlecase’ property needs to be consulted instead.
58645
58646 -- Function: get-char-code-property char propname
58647     This function returns the value of CHAR’s PROPNAME property.
58648
58649          (get-char-code-property ?\s 'general-category)
58650               ⇒ Zs
58651          (get-char-code-property ?1 'general-category)
58652               ⇒ Nd
58653          ;; U+2084
58654          (get-char-code-property ?\N{SUBSCRIPT FOUR}
58655                                  'digit-value)
58656               ⇒ 4
58657          ;; U+2155
58658          (get-char-code-property ?\N{VULGAR FRACTION ONE FIFTH}
58659                                  'numeric-value)
58660               ⇒ 0.2
58661          ;; U+2163
58662          (get-char-code-property ?\N{ROMAN NUMERAL FOUR}
58663                                  'numeric-value)
58664               ⇒ 4
58665          (get-char-code-property ?\( 'paired-bracket)
58666               ⇒ 41  ;; closing parenthesis
58667          (get-char-code-property ?\) 'bracket-type)
58668               ⇒ c
58669
58670 -- Function: char-code-property-description prop value
58671     This function returns the description string of property PROP’s
58672     VALUE, or ‘nil’ if VALUE has no description.
58673
58674          (char-code-property-description 'general-category 'Zs)
58675               ⇒ "Separator, Space"
58676          (char-code-property-description 'general-category 'Nd)
58677               ⇒ "Number, Decimal Digit"
58678          (char-code-property-description 'numeric-value '1/5)
58679               ⇒ nil
58680
58681 -- Function: put-char-code-property char propname value
58682     This function stores VALUE as the value of the property PROPNAME
58683     for the character CHAR.
58684
58685 -- Variable: unicode-category-table
58686     The value of this variable is a char-table (*note Char-Tables::)
58687     that specifies, for each character, its Unicode ‘General_Category’
58688     property as a symbol.
58689
58690 -- Variable: char-script-table
58691     The value of this variable is a char-table that specifies, for each
58692     character, a symbol whose name is the script to which the character
58693     belongs, according to the Unicode Standard classification of the
58694     Unicode code space into script-specific blocks.  This char-table
58695     has a single extra slot whose value is the list of all script
58696     symbols.
58697
58698 -- Variable: char-width-table
58699     The value of this variable is a char-table that specifies the width
58700     of each character in columns that it will occupy on the screen.
58701
58702 -- Variable: printable-chars
58703     The value of this variable is a char-table that specifies, for each
58704     character, whether it is printable or not.  That is, if evaluating
58705     ‘(aref printable-chars char)’ results in ‘t’, the character is
58706     printable, and if it results in ‘nil’, it is not.
58707
58708   ---------- Footnotes ----------
58709
58710   (1) The Unicode specification writes these tag names inside ‘<..>’
58711brackets, but the tag names in Emacs do not include the brackets; e.g.,
58712Unicode specifies ‘<small>’ where Emacs uses ‘small’.
58713
58714
58715File: elisp.info,  Node: Character Sets,  Next: Scanning Charsets,  Prev: Character Properties,  Up: Non-ASCII Characters
58716
5871733.7 Character Sets
58718===================
58719
58720An Emacs “character set”, or “charset”, is a set of characters in which
58721each character is assigned a numeric code point.  (The Unicode Standard
58722calls this a “coded character set”.)  Each Emacs charset has a name
58723which is a symbol.  A single character can belong to any number of
58724different character sets, but it will generally have a different code
58725point in each charset.  Examples of character sets include ‘ascii’,
58726‘iso-8859-1’, ‘greek-iso8859-7’, and ‘windows-1255’.  The code point
58727assigned to a character in a charset is usually different from its code
58728point used in Emacs buffers and strings.
58729
58730   Emacs defines several special character sets.  The character set
58731‘unicode’ includes all the characters whose Emacs code points are in the
58732range ‘0..#x10FFFF’.  The character set ‘emacs’ includes all ASCII and
58733non-ASCII characters.  Finally, the ‘eight-bit’ charset includes the
587348-bit raw bytes; Emacs uses it to represent raw bytes encountered in
58735text.
58736
58737 -- Function: charsetp object
58738     Returns ‘t’ if OBJECT is a symbol that names a character set, ‘nil’
58739     otherwise.
58740
58741 -- Variable: charset-list
58742     The value is a list of all defined character set names.
58743
58744 -- Function: charset-priority-list &optional highestp
58745     This function returns a list of all defined character sets ordered
58746     by their priority.  If HIGHESTP is non-‘nil’, the function returns
58747     a single character set of the highest priority.
58748
58749 -- Function: set-charset-priority &rest charsets
58750     This function makes CHARSETS the highest priority character sets.
58751
58752 -- Function: char-charset character &optional restriction
58753     This function returns the name of the character set of highest
58754     priority that CHARACTER belongs to.  ASCII characters are an
58755     exception: for them, this function always returns ‘ascii’.
58756
58757     If RESTRICTION is non-‘nil’, it should be a list of charsets to
58758     search.  Alternatively, it can be a coding system, in which case
58759     the returned charset must be supported by that coding system (*note
58760     Coding Systems::).
58761
58762 -- Function: charset-plist charset
58763     This function returns the property list of the character set
58764     CHARSET.  Although CHARSET is a symbol, this is not the same as the
58765     property list of that symbol.  Charset properties include important
58766     information about the charset, such as its documentation string,
58767     short name, etc.
58768
58769 -- Function: put-charset-property charset propname value
58770     This function sets the PROPNAME property of CHARSET to the given
58771     VALUE.
58772
58773 -- Function: get-charset-property charset propname
58774     This function returns the value of CHARSETs property PROPNAME.
58775
58776 -- Command: list-charset-chars charset
58777     This command displays a list of characters in the character set
58778     CHARSET.
58779
58780   Emacs can convert between its internal representation of a character
58781and the character’s codepoint in a specific charset.  The following two
58782functions support these conversions.
58783
58784 -- Function: decode-char charset code-point
58785     This function decodes a character that is assigned a CODE-POINT in
58786     CHARSET, to the corresponding Emacs character, and returns it.  If
58787     CHARSET doesn’t contain a character of that code point, the value
58788     is ‘nil’.
58789
58790     For backward compatibility, if CODE-POINT doesn’t fit in a Lisp
58791     fixnum (*note most-positive-fixnum: Integer Basics.), it can be
58792     specified as a cons cell ‘(HIGH . LOW)’, where LOW are the lower 16
58793     bits of the value and HIGH are the high 16 bits.  This usage is
58794     obsolescent.
58795
58796 -- Function: encode-char char charset
58797     This function returns the code point assigned to the character CHAR
58798     in CHARSET.  If CHARSET doesn’t have a codepoint for CHAR, the
58799     value is ‘nil’.
58800
58801   The following function comes in handy for applying a certain function
58802to all or part of the characters in a charset:
58803
58804 -- Function: map-charset-chars function charset &optional arg from-code
58805          to-code
58806     Call FUNCTION for characters in CHARSET.  FUNCTION is called with
58807     two arguments.  The first one is a cons cell ‘(FROM . TO)’, where
58808     FROM and TO indicate a range of characters contained in charset.
58809     The second argument passed to FUNCTION is ARG.
58810
58811     By default, the range of codepoints passed to FUNCTION includes all
58812     the characters in CHARSET, but optional arguments FROM-CODE and
58813     TO-CODE limit that to the range of characters between these two
58814     codepoints of CHARSET.  If either of them is ‘nil’, it defaults to
58815     the first or last codepoint of CHARSET, respectively.
58816
58817
58818File: elisp.info,  Node: Scanning Charsets,  Next: Translation of Characters,  Prev: Character Sets,  Up: Non-ASCII Characters
58819
5882033.8 Scanning for Character Sets
58821================================
58822
58823Sometimes it is useful to find out which character set a particular
58824character belongs to.  One use for this is in determining which coding
58825systems (*note Coding Systems::) are capable of representing all of the
58826text in question; another is to determine the font(s) for displaying
58827that text.
58828
58829 -- Function: charset-after &optional pos
58830     This function returns the charset of highest priority containing
58831     the character at position POS in the current buffer.  If POS is
58832     omitted or ‘nil’, it defaults to the current value of point.  If
58833     POS is out of range, the value is ‘nil’.
58834
58835 -- Function: find-charset-region beg end &optional translation
58836     This function returns a list of the character sets of highest
58837     priority that contain characters in the current buffer between
58838     positions BEG and END.
58839
58840     The optional argument TRANSLATION specifies a translation table to
58841     use for scanning the text (*note Translation of Characters::).  If
58842     it is non-‘nil’, then each character in the region is translated
58843     through this table, and the value returned describes the translated
58844     characters instead of the characters actually in the buffer.
58845
58846 -- Function: find-charset-string string &optional translation
58847     This function returns a list of character sets of highest priority
58848     that contain characters in STRING.  It is just like
58849     ‘find-charset-region’, except that it applies to the contents of
58850     STRING instead of part of the current buffer.
58851
58852
58853File: elisp.info,  Node: Translation of Characters,  Next: Coding Systems,  Prev: Scanning Charsets,  Up: Non-ASCII Characters
58854
5885533.9 Translation of Characters
58856==============================
58857
58858A “translation table” is a char-table (*note Char-Tables::) that
58859specifies a mapping of characters into characters.  These tables are
58860used in encoding and decoding, and for other purposes.  Some coding
58861systems specify their own particular translation tables; there are also
58862default translation tables which apply to all other coding systems.
58863
58864   A translation table has two extra slots.  The first is either ‘nil’
58865or a translation table that performs the reverse translation; the second
58866is the maximum number of characters to look up for translating sequences
58867of characters (see the description of
58868‘make-translation-table-from-alist’ below).
58869
58870 -- Function: make-translation-table &rest translations
58871     This function returns a translation table based on the argument
58872     TRANSLATIONS.  Each element of TRANSLATIONS should be a list of
58873     elements of the form ‘(FROM . TO)’; this says to translate the
58874     character FROM into TO.
58875
58876     The arguments and the forms in each argument are processed in
58877     order, and if a previous form already translates TO to some other
58878     character, say TO-ALT, FROM is also translated to TO-ALT.
58879
58880   During decoding, the translation table’s translations are applied to
58881the characters that result from ordinary decoding.  If a coding system
58882has the property ‘:decode-translation-table’, that specifies the
58883translation table to use, or a list of translation tables to apply in
58884sequence.  (This is a property of the coding system, as returned by
58885‘coding-system-get’, not a property of the symbol that is the coding
58886system’s name.  *Note Basic Concepts of Coding Systems: Coding System
58887Basics.)  Finally, if ‘standard-translation-table-for-decode’ is
58888non-‘nil’, the resulting characters are translated by that table.
58889
58890   During encoding, the translation table’s translations are applied to
58891the characters in the buffer, and the result of translation is actually
58892encoded.  If a coding system has property ‘:encode-translation-table’,
58893that specifies the translation table to use, or a list of translation
58894tables to apply in sequence.  In addition, if the variable
58895‘standard-translation-table-for-encode’ is non-‘nil’, it specifies the
58896translation table to use for translating the result.
58897
58898 -- Variable: standard-translation-table-for-decode
58899     This is the default translation table for decoding.  If a coding
58900     systems specifies its own translation tables, the table that is the
58901     value of this variable, if non-‘nil’, is applied after them.
58902
58903 -- Variable: standard-translation-table-for-encode
58904     This is the default translation table for encoding.  If a coding
58905     systems specifies its own translation tables, the table that is the
58906     value of this variable, if non-‘nil’, is applied after them.
58907
58908 -- Variable: translation-table-for-input
58909     Self-inserting characters are translated through this translation
58910     table before they are inserted.  Search commands also translate
58911     their input through this table, so they can compare more reliably
58912     with what’s in the buffer.
58913
58914     This variable automatically becomes buffer-local when set.
58915
58916 -- Function: make-translation-table-from-vector vec
58917     This function returns a translation table made from VEC that is an
58918     array of 256 elements to map bytes (values 0 through #xFF) to
58919     characters.  Elements may be ‘nil’ for untranslated bytes.  The
58920     returned table has a translation table for reverse mapping in the
58921     first extra slot, and the value ‘1’ in the second extra slot.
58922
58923     This function provides an easy way to make a private coding system
58924     that maps each byte to a specific character.  You can specify the
58925     returned table and the reverse translation table using the
58926     properties ‘:decode-translation-table’ and
58927     ‘:encode-translation-table’ respectively in the PROPS argument to
58928     ‘define-coding-system’.
58929
58930 -- Function: make-translation-table-from-alist alist
58931     This function is similar to ‘make-translation-table’ but returns a
58932     complex translation table rather than a simple one-to-one mapping.
58933     Each element of ALIST is of the form ‘(FROM . TO)’, where FROM and
58934     TO are either characters or vectors specifying a sequence of
58935     characters.  If FROM is a character, that character is translated
58936     to TO (i.e., to a character or a character sequence).  If FROM is a
58937     vector of characters, that sequence is translated to TO.  The
58938     returned table has a translation table for reverse mapping in the
58939     first extra slot, and the maximum length of all the FROM character
58940     sequences in the second extra slot.
58941
58942
58943File: elisp.info,  Node: Coding Systems,  Next: Input Methods,  Prev: Translation of Characters,  Up: Non-ASCII Characters
58944
5894533.10 Coding Systems
58946====================
58947
58948When Emacs reads or writes a file, and when Emacs sends text to a
58949subprocess or receives text from a subprocess, it normally performs
58950character code conversion and end-of-line conversion as specified by a
58951particular “coding system”.
58952
58953   How to define a coding system is an arcane matter, and is not
58954documented here.
58955
58956* Menu:
58957
58958* Coding System Basics::        Basic concepts.
58959* Encoding and I/O::            How file I/O functions handle coding systems.
58960* Lisp and Coding Systems::     Functions to operate on coding system names.
58961* User-Chosen Coding Systems::  Asking the user to choose a coding system.
58962* Default Coding Systems::      Controlling the default choices.
58963* Specifying Coding Systems::   Requesting a particular coding system
58964                                    for a single file operation.
58965* Explicit Encoding::           Encoding or decoding text without doing I/O.
58966* Terminal I/O Encoding::       Use of encoding for terminal I/O.
58967
58968
58969File: elisp.info,  Node: Coding System Basics,  Next: Encoding and I/O,  Up: Coding Systems
58970
5897133.10.1 Basic Concepts of Coding Systems
58972----------------------------------------
58973
58974“Character code conversion” involves conversion between the internal
58975representation of characters used inside Emacs and some other encoding.
58976Emacs supports many different encodings, in that it can convert to and
58977from them.  For example, it can convert text to or from encodings such
58978as Latin 1, Latin 2, Latin 3, Latin 4, Latin 5, and several variants of
58979ISO 2022.  In some cases, Emacs supports several alternative encodings
58980for the same characters; for example, there are three coding systems for
58981the Cyrillic (Russian) alphabet: ISO, Alternativnyj, and KOI8.
58982
58983   Every coding system specifies a particular set of character code
58984conversions, but the coding system ‘undecided’ is special: it leaves the
58985choice unspecified, to be chosen heuristically for each file, based on
58986the file’s data.  The coding system ‘prefer-utf-8’ is like ‘undecided’,
58987but it prefers to choose ‘utf-8’ when possible.
58988
58989   In general, a coding system doesn’t guarantee roundtrip identity:
58990decoding a byte sequence using a coding system, then encoding the
58991resulting text in the same coding system, can produce a different byte
58992sequence.  But some coding systems do guarantee that the byte sequence
58993will be the same as what you originally decoded.  Here are a few
58994examples:
58995
58996     iso-8859-1, utf-8, big5, shift_jis, euc-jp
58997
58998   Encoding buffer text and then decoding the result can also fail to
58999reproduce the original text.  For instance, if you encode a character
59000with a coding system which does not support that character, the result
59001is unpredictable, and thus decoding it using the same coding system may
59002produce a different text.  Currently, Emacs can’t report errors that
59003result from encoding unsupported characters.
59004
59005   “End of line conversion” handles three different conventions used on
59006various systems for representing end of line in files.  The Unix
59007convention, used on GNU and Unix systems, is to use the linefeed
59008character (also called newline).  The DOS convention, used on MS-Windows
59009and MS-DOS systems, is to use a carriage return and a linefeed at the
59010end of a line.  The Mac convention is to use just carriage return.
59011(This was the convention used in Classic Mac OS.)
59012
59013   “Base coding systems” such as ‘latin-1’ leave the end-of-line
59014conversion unspecified, to be chosen based on the data.  “Variant coding
59015systems” such as ‘latin-1-unix’, ‘latin-1-dos’ and ‘latin-1-mac’ specify
59016the end-of-line conversion explicitly as well.  Most base coding systems
59017have three corresponding variants whose names are formed by adding
59018‘-unix’, ‘-dos’ and ‘-mac’.
59019
59020   The coding system ‘raw-text’ is special in that it prevents character
59021code conversion, and causes the buffer visited with this coding system
59022to be a unibyte buffer.  For historical reasons, you can save both
59023unibyte and multibyte text with this coding system.  When you use
59024‘raw-text’ to encode multibyte text, it does perform one character code
59025conversion: it converts eight-bit characters to their single-byte
59026external representation.  ‘raw-text’ does not specify the end-of-line
59027conversion, allowing that to be determined as usual by the data, and has
59028the usual three variants which specify the end-of-line conversion.
59029
59030   ‘no-conversion’ (and its alias ‘binary’) is equivalent to
59031‘raw-text-unix’: it specifies no conversion of either character codes or
59032end-of-line.
59033
59034   The coding system ‘utf-8-emacs’ specifies that the data is
59035represented in the internal Emacs encoding (*note Text
59036Representations::).  This is like ‘raw-text’ in that no code conversion
59037happens, but different in that the result is multibyte data.  The name
59038‘emacs-internal’ is an alias for ‘utf-8-emacs-unix’ (so it forces no
59039conversion of end-of-line, unlike ‘utf-8-emacs’, which can decode all 3
59040kinds of end-of-line conventions).
59041
59042 -- Function: coding-system-get coding-system property
59043     This function returns the specified property of the coding system
59044     CODING-SYSTEM.  Most coding system properties exist for internal
59045     purposes, but one that you might find useful is ‘:mime-charset’.
59046     That property’s value is the name used in MIME for the character
59047     coding which this coding system can read and write.  Examples:
59048
59049          (coding-system-get 'iso-latin-1 :mime-charset)
59050               ⇒ iso-8859-1
59051          (coding-system-get 'iso-2022-cn :mime-charset)
59052               ⇒ iso-2022-cn
59053          (coding-system-get 'cyrillic-koi8 :mime-charset)
59054               ⇒ koi8-r
59055
59056     The value of the ‘:mime-charset’ property is also defined as an
59057     alias for the coding system.
59058
59059 -- Function: coding-system-aliases coding-system
59060     This function returns the list of aliases of CODING-SYSTEM.
59061
59062
59063File: elisp.info,  Node: Encoding and I/O,  Next: Lisp and Coding Systems,  Prev: Coding System Basics,  Up: Coding Systems
59064
5906533.10.2 Encoding and I/O
59066------------------------
59067
59068The principal purpose of coding systems is for use in reading and
59069writing files.  The function ‘insert-file-contents’ uses a coding system
59070to decode the file data, and ‘write-region’ uses one to encode the
59071buffer contents.
59072
59073   You can specify the coding system to use either explicitly (*note
59074Specifying Coding Systems::), or implicitly using a default mechanism
59075(*note Default Coding Systems::).  But these methods may not completely
59076specify what to do.  For example, they may choose a coding system such
59077as ‘undecided’ which leaves the character code conversion to be
59078determined from the data.  In these cases, the I/O operation finishes
59079the job of choosing a coding system.  Very often you will want to find
59080out afterwards which coding system was chosen.
59081
59082 -- Variable: buffer-file-coding-system
59083     This buffer-local variable records the coding system used for
59084     saving the buffer and for writing part of the buffer with
59085     ‘write-region’.  If the text to be written cannot be safely encoded
59086     using the coding system specified by this variable, these
59087     operations select an alternative encoding by calling the function
59088     ‘select-safe-coding-system’ (*note User-Chosen Coding Systems::).
59089     If selecting a different encoding requires to ask the user to
59090     specify a coding system, ‘buffer-file-coding-system’ is updated to
59091     the newly selected coding system.
59092
59093     ‘buffer-file-coding-system’ does _not_ affect sending text to a
59094     subprocess.
59095
59096 -- Variable: save-buffer-coding-system
59097     This variable specifies the coding system for saving the buffer (by
59098     overriding ‘buffer-file-coding-system’).  Note that it is not used
59099     for ‘write-region’.
59100
59101     When a command to save the buffer starts out to use
59102     ‘buffer-file-coding-system’ (or ‘save-buffer-coding-system’), and
59103     that coding system cannot handle the actual text in the buffer, the
59104     command asks the user to choose another coding system (by calling
59105     ‘select-safe-coding-system’).  After that happens, the command also
59106     updates ‘buffer-file-coding-system’ to represent the coding system
59107     that the user specified.
59108
59109 -- Variable: last-coding-system-used
59110     I/O operations for files and subprocesses set this variable to the
59111     coding system name that was used.  The explicit encoding and
59112     decoding functions (*note Explicit Encoding::) set it too.
59113
59114     *Warning:* Since receiving subprocess output sets this variable, it
59115     can change whenever Emacs waits; therefore, you should copy the
59116     value shortly after the function call that stores the value you are
59117     interested in.
59118
59119   The variable ‘selection-coding-system’ specifies how to encode
59120selections for the window system.  *Note Window System Selections::.
59121
59122 -- Variable: file-name-coding-system
59123     The variable ‘file-name-coding-system’ specifies the coding system
59124     to use for encoding file names.  Emacs encodes file names using
59125     that coding system for all file operations.  If
59126     ‘file-name-coding-system’ is ‘nil’, Emacs uses a default coding
59127     system determined by the selected language environment.  In the
59128     default language environment, any non-ASCII characters in file
59129     names are not encoded specially; they appear in the file system
59130     using the internal Emacs representation.
59131
59132   *Warning:* if you change ‘file-name-coding-system’ (or the language
59133environment) in the middle of an Emacs session, problems can result if
59134you have already visited files whose names were encoded using the
59135earlier coding system and are handled differently under the new coding
59136system.  If you try to save one of these buffers under the visited file
59137name, saving may use the wrong file name, or it may get an error.  If
59138such a problem happens, use ‘C-x C-w’ to specify a new file name for
59139that buffer.
59140
59141   On Windows 2000 and later, Emacs by default uses Unicode APIs to pass
59142file names to the OS, so the value of ‘file-name-coding-system’ is
59143largely ignored.  Lisp applications that need to encode or decode file
59144names on the Lisp level should use ‘utf-8’ coding-system when
59145‘system-type’ is ‘windows-nt’; the conversion of UTF-8 encoded file
59146names to the encoding appropriate for communicating with the OS is
59147performed internally by Emacs.
59148
59149
59150File: elisp.info,  Node: Lisp and Coding Systems,  Next: User-Chosen Coding Systems,  Prev: Encoding and I/O,  Up: Coding Systems
59151
5915233.10.3 Coding Systems in Lisp
59153------------------------------
59154
59155Here are the Lisp facilities for working with coding systems:
59156
59157 -- Function: coding-system-list &optional base-only
59158     This function returns a list of all coding system names (symbols).
59159     If BASE-ONLY is non-‘nil’, the value includes only the base coding
59160     systems.  Otherwise, it includes alias and variant coding systems
59161     as well.
59162
59163 -- Function: coding-system-p object
59164     This function returns ‘t’ if OBJECT is a coding system name or
59165     ‘nil’.
59166
59167 -- Function: check-coding-system coding-system
59168     This function checks the validity of CODING-SYSTEM.  If that is
59169     valid, it returns CODING-SYSTEM.  If CODING-SYSTEM is ‘nil’, the
59170     function return ‘nil’.  For any other values, it signals an error
59171     whose ‘error-symbol’ is ‘coding-system-error’ (*note signal:
59172     Signaling Errors.).
59173
59174 -- Function: coding-system-eol-type coding-system
59175     This function returns the type of end-of-line (a.k.a. “eol”)
59176     conversion used by CODING-SYSTEM.  If CODING-SYSTEM specifies a
59177     certain eol conversion, the return value is an integer 0, 1, or 2,
59178     standing for ‘unix’, ‘dos’, and ‘mac’, respectively.  If
59179     CODING-SYSTEM doesn’t specify eol conversion explicitly, the return
59180     value is a vector of coding systems, each one with one of the
59181     possible eol conversion types, like this:
59182
59183          (coding-system-eol-type 'latin-1)
59184               ⇒ [latin-1-unix latin-1-dos latin-1-mac]
59185
59186     If this function returns a vector, Emacs will decide, as part of
59187     the text encoding or decoding process, what eol conversion to use.
59188     For decoding, the end-of-line format of the text is auto-detected,
59189     and the eol conversion is set to match it (e.g., DOS-style CRLF
59190     format will imply ‘dos’ eol conversion).  For encoding, the eol
59191     conversion is taken from the appropriate default coding system
59192     (e.g., default value of ‘buffer-file-coding-system’ for
59193     ‘buffer-file-coding-system’), or from the default eol conversion
59194     appropriate for the underlying platform.
59195
59196 -- Function: coding-system-change-eol-conversion coding-system eol-type
59197     This function returns a coding system which is like CODING-SYSTEM
59198     except for its eol conversion, which is specified by ‘eol-type’.
59199     EOL-TYPE should be ‘unix’, ‘dos’, ‘mac’, or ‘nil’.  If it is ‘nil’,
59200     the returned coding system determines the end-of-line conversion
59201     from the data.
59202
59203     EOL-TYPE may also be 0, 1 or 2, standing for ‘unix’, ‘dos’ and
59204     ‘mac’, respectively.
59205
59206 -- Function: coding-system-change-text-conversion eol-coding
59207          text-coding
59208     This function returns a coding system which uses the end-of-line
59209     conversion of EOL-CODING, and the text conversion of TEXT-CODING.
59210     If TEXT-CODING is ‘nil’, it returns ‘undecided’, or one of its
59211     variants according to EOL-CODING.
59212
59213 -- Function: find-coding-systems-region from to
59214     This function returns a list of coding systems that could be used
59215     to encode a text between FROM and TO.  All coding systems in the
59216     list can safely encode any multibyte characters in that portion of
59217     the text.
59218
59219     If the text contains no multibyte characters, the function returns
59220     the list ‘(undecided)’.
59221
59222 -- Function: find-coding-systems-string string
59223     This function returns a list of coding systems that could be used
59224     to encode the text of STRING.  All coding systems in the list can
59225     safely encode any multibyte characters in STRING.  If the text
59226     contains no multibyte characters, this returns the list
59227     ‘(undecided)’.
59228
59229 -- Function: find-coding-systems-for-charsets charsets
59230     This function returns a list of coding systems that could be used
59231     to encode all the character sets in the list CHARSETS.
59232
59233 -- Function: check-coding-systems-region start end coding-system-list
59234     This function checks whether coding systems in the list
59235     ‘coding-system-list’ can encode all the characters in the region
59236     between START and END.  If all of the coding systems in the list
59237     can encode the specified text, the function returns ‘nil’.  If some
59238     coding systems cannot encode some of the characters, the value is
59239     an alist, each element of which has the form ‘(CODING-SYSTEM1 POS1
59240     POS2 ...)’, meaning that CODING-SYSTEM1 cannot encode characters at
59241     buffer positions POS1, POS2, ....
59242
59243     START may be a string, in which case END is ignored and the
59244     returned value references string indices instead of buffer
59245     positions.
59246
59247 -- Function: detect-coding-region start end &optional highest
59248     This function chooses a plausible coding system for decoding the
59249     text from START to END.  This text should be a byte sequence, i.e.,
59250     unibyte text or multibyte text with only ASCII and eight-bit
59251     characters (*note Explicit Encoding::).
59252
59253     Normally this function returns a list of coding systems that could
59254     handle decoding the text that was scanned.  They are listed in
59255     order of decreasing priority.  But if HIGHEST is non-‘nil’, then
59256     the return value is just one coding system, the one that is highest
59257     in priority.
59258
59259     If the region contains only ASCII characters except for such
59260     ISO-2022 control characters ISO-2022 as ‘ESC’, the value is
59261     ‘undecided’ or ‘(undecided)’, or a variant specifying end-of-line
59262     conversion, if that can be deduced from the text.
59263
59264     If the region contains null bytes, the value is ‘no-conversion’,
59265     even if the region contains text encoded in some coding system.
59266
59267 -- Function: detect-coding-string string &optional highest
59268     This function is like ‘detect-coding-region’ except that it
59269     operates on the contents of STRING instead of bytes in the buffer.
59270
59271 -- Variable: inhibit-nul-byte-detection
59272     If this variable has a non-‘nil’ value, null bytes are ignored when
59273     detecting the encoding of a region or a string.  This allows the
59274     encoding of text that contains null bytes to be correctly detected,
59275     such as Info files with Index nodes.
59276
59277 -- Variable: inhibit-iso-escape-detection
59278     If this variable has a non-‘nil’ value, ISO-2022 escape sequences
59279     are ignored when detecting the encoding of a region or a string.
59280     The result is that no text is ever detected as encoded in some
59281     ISO-2022 encoding, and all escape sequences become visible in a
59282     buffer.  *Warning:* _Use this variable with extreme caution,
59283     because many files in the Emacs distribution use ISO-2022
59284     encoding._
59285
59286 -- Function: coding-system-charset-list coding-system
59287     This function returns the list of character sets (*note Character
59288     Sets::) supported by CODING-SYSTEM.  Some coding systems that
59289     support too many character sets to list them all yield special
59290     values:
59291        • If CODING-SYSTEM supports all Emacs characters, the value is
59292          ‘(emacs)’.
59293        • If CODING-SYSTEM supports all Unicode characters, the value is
59294          ‘(unicode)’.
59295        • If CODING-SYSTEM supports all ISO-2022 charsets, the value is
59296          ‘iso-2022’.
59297        • If CODING-SYSTEM supports all the characters in the internal
59298          coding system used by Emacs version 21 (prior to the
59299          implementation of internal Unicode support), the value is
59300          ‘emacs-mule’.
59301
59302   *Note Process Information: Coding systems for a subprocess, in
59303particular the description of the functions ‘process-coding-system’ and
59304‘set-process-coding-system’, for how to examine or set the coding
59305systems used for I/O to a subprocess.
59306
59307
59308File: elisp.info,  Node: User-Chosen Coding Systems,  Next: Default Coding Systems,  Prev: Lisp and Coding Systems,  Up: Coding Systems
59309
5931033.10.4 User-Chosen Coding Systems
59311----------------------------------
59312
59313 -- Function: select-safe-coding-system from to &optional
59314          default-coding-system accept-default-p file
59315     This function selects a coding system for encoding specified text,
59316     asking the user to choose if necessary.  Normally the specified
59317     text is the text in the current buffer between FROM and TO.  If
59318     FROM is a string, the string specifies the text to encode, and TO
59319     is ignored.
59320
59321     If the specified text includes raw bytes (*note Text
59322     Representations::), ‘select-safe-coding-system’ suggests ‘raw-text’
59323     for its encoding.
59324
59325     If DEFAULT-CODING-SYSTEM is non-‘nil’, that is the first coding
59326     system to try; if that can handle the text,
59327     ‘select-safe-coding-system’ returns that coding system.  It can
59328     also be a list of coding systems; then the function tries each of
59329     them one by one.  After trying all of them, it next tries the
59330     current buffer’s value of ‘buffer-file-coding-system’ (if it is not
59331     ‘undecided’), then the default value of ‘buffer-file-coding-system’
59332     and finally the user’s most preferred coding system, which the user
59333     can set using the command ‘prefer-coding-system’ (*note Recognizing
59334     Coding Systems: (emacs)Recognize Coding.).
59335
59336     If one of those coding systems can safely encode all the specified
59337     text, ‘select-safe-coding-system’ chooses it and returns it.
59338     Otherwise, it asks the user to choose from a list of coding systems
59339     which can encode all the text, and returns the user’s choice.
59340
59341     DEFAULT-CODING-SYSTEM can also be a list whose first element is ‘t’
59342     and whose other elements are coding systems.  Then, if no coding
59343     system in the list can handle the text, ‘select-safe-coding-system’
59344     queries the user immediately, without trying any of the three
59345     alternatives described above.  This is handy for checking only the
59346     coding systems in the list.
59347
59348     The optional argument ACCEPT-DEFAULT-P determines whether a coding
59349     system selected without user interaction is acceptable.  If it’s
59350     omitted or ‘nil’, such a silent selection is always acceptable.  If
59351     it is non-‘nil’, it should be a function;
59352     ‘select-safe-coding-system’ calls this function with one argument,
59353     the base coding system of the selected coding system.  If the
59354     function returns ‘nil’, ‘select-safe-coding-system’ rejects the
59355     silently selected coding system, and asks the user to select a
59356     coding system from a list of possible candidates.
59357
59358     If the variable ‘select-safe-coding-system-accept-default-p’ is
59359     non-‘nil’, it should be a function taking a single argument.  It is
59360     used in place of ACCEPT-DEFAULT-P, overriding any value supplied
59361     for this argument.
59362
59363     As a final step, before returning the chosen coding system,
59364     ‘select-safe-coding-system’ checks whether that coding system is
59365     consistent with what would be selected if the contents of the
59366     region were read from a file.  (If not, this could lead to data
59367     corruption in a file subsequently re-visited and edited.)
59368     Normally, ‘select-safe-coding-system’ uses ‘buffer-file-name’ as
59369     the file for this purpose, but if FILE is non-‘nil’, it uses that
59370     file instead (this can be relevant for ‘write-region’ and similar
59371     functions).  If it detects an apparent inconsistency,
59372     ‘select-safe-coding-system’ queries the user before selecting the
59373     coding system.
59374
59375 -- Variable: select-safe-coding-system-function
59376     This variable names the function to be called to request the user
59377     to select a proper coding system for encoding text when the default
59378     coding system for an output operation cannot safely encode that
59379     text.  The default value of this variable is
59380     ‘select-safe-coding-system’.  Emacs primitives that write text to
59381     files, such as ‘write-region’, or send text to other processes,
59382     such as ‘process-send-region’, normally call the value of this
59383     variable, unless ‘coding-system-for-write’ is bound to a non-‘nil’
59384     value (*note Specifying Coding Systems::).
59385
59386   Here are two functions you can use to let the user specify a coding
59387system, with completion.  *Note Completion::.
59388
59389 -- Function: read-coding-system prompt &optional default
59390     This function reads a coding system using the minibuffer, prompting
59391     with string PROMPT, and returns the coding system name as a symbol.
59392     If the user enters null input, DEFAULT specifies which coding
59393     system to return.  It should be a symbol or a string.
59394
59395 -- Function: read-non-nil-coding-system prompt
59396     This function reads a coding system using the minibuffer, prompting
59397     with string PROMPT, and returns the coding system name as a symbol.
59398     If the user tries to enter null input, it asks the user to try
59399     again.  *Note Coding Systems::.
59400
59401
59402File: elisp.info,  Node: Default Coding Systems,  Next: Specifying Coding Systems,  Prev: User-Chosen Coding Systems,  Up: Coding Systems
59403
5940433.10.5 Default Coding Systems
59405------------------------------
59406
59407This section describes variables that specify the default coding system
59408for certain files or when running certain subprograms, and the function
59409that I/O operations use to access them.
59410
59411   The idea of these variables is that you set them once and for all to
59412the defaults you want, and then do not change them again.  To specify a
59413particular coding system for a particular operation in a Lisp program,
59414don’t change these variables; instead, override them using
59415‘coding-system-for-read’ and ‘coding-system-for-write’ (*note Specifying
59416Coding Systems::).
59417
59418 -- User Option: auto-coding-regexp-alist
59419     This variable is an alist of text patterns and corresponding coding
59420     systems.  Each element has the form ‘(REGEXP . CODING-SYSTEM)’; a
59421     file whose first few kilobytes match REGEXP is decoded with
59422     CODING-SYSTEM when its contents are read into a buffer.  The
59423     settings in this alist take priority over ‘coding:’ tags in the
59424     files and the contents of ‘file-coding-system-alist’ (see below).
59425     The default value is set so that Emacs automatically recognizes
59426     mail files in Babyl format and reads them with no code conversions.
59427
59428 -- User Option: file-coding-system-alist
59429     This variable is an alist that specifies the coding systems to use
59430     for reading and writing particular files.  Each element has the
59431     form ‘(PATTERN . CODING)’, where PATTERN is a regular expression
59432     that matches certain file names.  The element applies to file names
59433     that match PATTERN.
59434
59435     The CDR of the element, CODING, should be either a coding system, a
59436     cons cell containing two coding systems, or a function name (a
59437     symbol with a function definition).  If CODING is a coding system,
59438     that coding system is used for both reading the file and writing
59439     it.  If CODING is a cons cell containing two coding systems, its
59440     CAR specifies the coding system for decoding, and its CDR specifies
59441     the coding system for encoding.
59442
59443     If CODING is a function name, the function should take one
59444     argument, a list of all arguments passed to
59445     ‘find-operation-coding-system’.  It must return a coding system or
59446     a cons cell containing two coding systems.  This value has the same
59447     meaning as described above.
59448
59449     If CODING (or what returned by the above function) is ‘undecided’,
59450     the normal code-detection is performed.
59451
59452 -- User Option: auto-coding-alist
59453     This variable is an alist that specifies the coding systems to use
59454     for reading and writing particular files.  Its form is like that of
59455     ‘file-coding-system-alist’, but, unlike the latter, this variable
59456     takes priority over any ‘coding:’ tags in the file.
59457
59458 -- Variable: process-coding-system-alist
59459     This variable is an alist specifying which coding systems to use
59460     for a subprocess, depending on which program is running in the
59461     subprocess.  It works like ‘file-coding-system-alist’, except that
59462     PATTERN is matched against the program name used to start the
59463     subprocess.  The coding system or systems specified in this alist
59464     are used to initialize the coding systems used for I/O to the
59465     subprocess, but you can specify other coding systems later using
59466     ‘set-process-coding-system’.
59467
59468   *Warning:* Coding systems such as ‘undecided’, which determine the
59469coding system from the data, do not work entirely reliably with
59470asynchronous subprocess output.  This is because Emacs handles
59471asynchronous subprocess output in batches, as it arrives.  If the coding
59472system leaves the character code conversion unspecified, or leaves the
59473end-of-line conversion unspecified, Emacs must try to detect the proper
59474conversion from one batch at a time, and this does not always work.
59475
59476   Therefore, with an asynchronous subprocess, if at all possible, use a
59477coding system which determines both the character code conversion and
59478the end of line conversion—that is, one like ‘latin-1-unix’, rather than
59479‘undecided’ or ‘latin-1’.
59480
59481 -- Variable: network-coding-system-alist
59482     This variable is an alist that specifies the coding system to use
59483     for network streams.  It works much like
59484     ‘file-coding-system-alist’, with the difference that the PATTERN in
59485     an element may be either a port number or a regular expression.  If
59486     it is a regular expression, it is matched against the network
59487     service name used to open the network stream.
59488
59489 -- Variable: default-process-coding-system
59490     This variable specifies the coding systems to use for subprocess
59491     (and network stream) input and output, when nothing else specifies
59492     what to do.
59493
59494     The value should be a cons cell of the form ‘(INPUT-CODING .
59495     OUTPUT-CODING)’.  Here INPUT-CODING applies to input from the
59496     subprocess, and OUTPUT-CODING applies to output to it.
59497
59498 -- User Option: auto-coding-functions
59499     This variable holds a list of functions that try to determine a
59500     coding system for a file based on its undecoded contents.
59501
59502     Each function in this list should be written to look at text in the
59503     current buffer, but should not modify it in any way.  The buffer
59504     will contain the text of parts of the file.  Each function should
59505     take one argument, SIZE, which tells it how many characters to look
59506     at, starting from point.  If the function succeeds in determining a
59507     coding system for the file, it should return that coding system.
59508     Otherwise, it should return ‘nil’.
59509
59510     The functions in this list could be called either when the file is
59511     visited and Emacs wants to decode its contents, and/or when the
59512     file’s buffer is about to be saved and Emacs wants to determine how
59513     to encode its contents.
59514
59515     If a file has a ‘coding:’ tag, that takes precedence, so these
59516     functions won’t be called.
59517
59518 -- Function: find-auto-coding filename size
59519     This function tries to determine a suitable coding system for
59520     FILENAME.  It examines the buffer visiting the named file, using
59521     the variables documented above in sequence, until it finds a match
59522     for one of the rules specified by these variables.  It then returns
59523     a cons cell of the form ‘(CODING . SOURCE)’, where CODING is the
59524     coding system to use and SOURCE is a symbol, one of
59525     ‘auto-coding-alist’, ‘auto-coding-regexp-alist’, ‘:coding’, or
59526     ‘auto-coding-functions’, indicating which one supplied the matching
59527     rule.  The value ‘:coding’ means the coding system was specified by
59528     the ‘coding:’ tag in the file (*note coding tag: (emacs)Specify
59529     Coding.).  The order of looking for a matching rule is
59530     ‘auto-coding-alist’ first, then ‘auto-coding-regexp-alist’, then
59531     the ‘coding:’ tag, and lastly ‘auto-coding-functions’.  If no
59532     matching rule was found, the function returns ‘nil’.
59533
59534     The second argument SIZE is the size of text, in characters,
59535     following point.  The function examines text only within SIZE
59536     characters after point.  Normally, the buffer should be positioned
59537     at the beginning when this function is called, because one of the
59538     places for the ‘coding:’ tag is the first one or two lines of the
59539     file; in that case, SIZE should be the size of the buffer.
59540
59541 -- Function: set-auto-coding filename size
59542     This function returns a suitable coding system for file FILENAME.
59543     It uses ‘find-auto-coding’ to find the coding system.  If no coding
59544     system could be determined, the function returns ‘nil’.  The
59545     meaning of the argument SIZE is like in ‘find-auto-coding’.
59546
59547 -- Function: find-operation-coding-system operation &rest arguments
59548     This function returns the coding system to use (by default) for
59549     performing OPERATION with ARGUMENTS.  The value has this form:
59550
59551          (DECODING-SYSTEM . ENCODING-SYSTEM)
59552
59553     The first element, DECODING-SYSTEM, is the coding system to use for
59554     decoding (in case OPERATION does decoding), and ENCODING-SYSTEM is
59555     the coding system for encoding (in case OPERATION does encoding).
59556
59557     The argument OPERATION is a symbol; it should be one of
59558     ‘write-region’, ‘start-process’, ‘call-process’,
59559     ‘call-process-region’, ‘insert-file-contents’, or
59560     ‘open-network-stream’.  These are the names of the Emacs I/O
59561     primitives that can do character code and eol conversion.
59562
59563     The remaining arguments should be the same arguments that might be
59564     given to the corresponding I/O primitive.  Depending on the
59565     primitive, one of those arguments is selected as the “target”.  For
59566     example, if OPERATION does file I/O, whichever argument specifies
59567     the file name is the target.  For subprocess primitives, the
59568     process name is the target.  For ‘open-network-stream’, the target
59569     is the service name or port number.
59570
59571     Depending on OPERATION, this function looks up the target in
59572     ‘file-coding-system-alist’, ‘process-coding-system-alist’, or
59573     ‘network-coding-system-alist’.  If the target is found in the
59574     alist, ‘find-operation-coding-system’ returns its association in
59575     the alist; otherwise it returns ‘nil’.
59576
59577     If OPERATION is ‘insert-file-contents’, the argument corresponding
59578     to the target may be a cons cell of the form ‘(FILENAME . BUFFER)’.
59579     In that case, FILENAME is a file name to look up in
59580     ‘file-coding-system-alist’, and BUFFER is a buffer that contains
59581     the file’s contents (not yet decoded).  If
59582     ‘file-coding-system-alist’ specifies a function to call for this
59583     file, and that function needs to examine the file’s contents (as it
59584     usually does), it should examine the contents of BUFFER instead of
59585     reading the file.
59586
59587
59588File: elisp.info,  Node: Specifying Coding Systems,  Next: Explicit Encoding,  Prev: Default Coding Systems,  Up: Coding Systems
59589
5959033.10.6 Specifying a Coding System for One Operation
59591----------------------------------------------------
59592
59593You can specify the coding system for a specific operation by binding
59594the variables ‘coding-system-for-read’ and/or ‘coding-system-for-write’.
59595
59596 -- Variable: coding-system-for-read
59597     If this variable is non-‘nil’, it specifies the coding system to
59598     use for reading a file, or for input from a synchronous subprocess.
59599
59600     It also applies to any asynchronous subprocess or network stream,
59601     but in a different way: the value of ‘coding-system-for-read’ when
59602     you start the subprocess or open the network stream specifies the
59603     input decoding method for that subprocess or network stream.  It
59604     remains in use for that subprocess or network stream unless and
59605     until overridden.
59606
59607     The right way to use this variable is to bind it with ‘let’ for a
59608     specific I/O operation.  Its global value is normally ‘nil’, and
59609     you should not globally set it to any other value.  Here is an
59610     example of the right way to use the variable:
59611
59612          ;; Read the file with no character code conversion.
59613          (let ((coding-system-for-read 'no-conversion))
59614            (insert-file-contents filename))
59615
59616     When its value is non-‘nil’, this variable takes precedence over
59617     all other methods of specifying a coding system to use for input,
59618     including ‘file-coding-system-alist’, ‘process-coding-system-alist’
59619     and ‘network-coding-system-alist’.
59620
59621 -- Variable: coding-system-for-write
59622     This works much like ‘coding-system-for-read’, except that it
59623     applies to output rather than input.  It affects writing to files,
59624     as well as sending output to subprocesses and net connections.  It
59625     also applies to encoding command-line arguments with which Emacs
59626     invokes subprocesses.
59627
59628     When a single operation does both input and output, as do
59629     ‘call-process-region’ and ‘start-process’, both
59630     ‘coding-system-for-read’ and ‘coding-system-for-write’ affect it.
59631
59632 -- Variable: coding-system-require-warning
59633     Binding ‘coding-system-for-write’ to a non-‘nil’ value prevents
59634     output primitives from calling the function specified by
59635     ‘select-safe-coding-system-function’ (*note User-Chosen Coding
59636     Systems::).  This is because ‘C-x <RET> c’
59637     (‘universal-coding-system-argument’) works by binding
59638     ‘coding-system-for-write’, and Emacs should obey user selection.
59639     If a Lisp program binds ‘coding-system-for-write’ to a value that
59640     might not be safe for encoding the text to be written, it can also
59641     bind ‘coding-system-require-warning’ to a non-‘nil’ value, which
59642     will force the output primitives to check the encoding by calling
59643     the value of ‘select-safe-coding-system-function’ even though
59644     ‘coding-system-for-write’ is non-‘nil’.  Alternatively, call
59645     ‘select-safe-coding-system’ explicitly before using the specified
59646     encoding.
59647
59648 -- User Option: inhibit-eol-conversion
59649     When this variable is non-‘nil’, no end-of-line conversion is done,
59650     no matter which coding system is specified.  This applies to all
59651     the Emacs I/O and subprocess primitives, and to the explicit
59652     encoding and decoding functions (*note Explicit Encoding::).
59653
59654   Sometimes, you need to prefer several coding systems for some
59655operation, rather than fix a single one.  Emacs lets you specify a
59656priority order for using coding systems.  This ordering affects the
59657sorting of lists of coding systems returned by functions such as
59658‘find-coding-systems-region’ (*note Lisp and Coding Systems::).
59659
59660 -- Function: coding-system-priority-list &optional highestp
59661     This function returns the list of coding systems in the order of
59662     their current priorities.  Optional argument HIGHESTP, if
59663     non-‘nil’, means return only the highest priority coding system.
59664
59665 -- Function: set-coding-system-priority &rest coding-systems
59666     This function puts CODING-SYSTEMS at the beginning of the priority
59667     list for coding systems, thus making their priority higher than all
59668     the rest.
59669
59670 -- Macro: with-coding-priority coding-systems &rest body
59671     This macro executes BODY, like ‘progn’ does (*note progn:
59672     Sequencing.), with CODING-SYSTEMS at the front of the priority list
59673     for coding systems.  CODING-SYSTEMS should be a list of coding
59674     systems to prefer during execution of BODY.
59675
59676
59677File: elisp.info,  Node: Explicit Encoding,  Next: Terminal I/O Encoding,  Prev: Specifying Coding Systems,  Up: Coding Systems
59678
5967933.10.7 Explicit Encoding and Decoding
59680--------------------------------------
59681
59682All the operations that transfer text in and out of Emacs have the
59683ability to use a coding system to encode or decode the text.  You can
59684also explicitly encode and decode text using the functions in this
59685section.
59686
59687   The result of encoding, and the input to decoding, are not ordinary
59688text.  They logically consist of a series of byte values; that is, a
59689series of ASCII and eight-bit characters.  In unibyte buffers and
59690strings, these characters have codes in the range 0 through #xFF (255).
59691In a multibyte buffer or string, eight-bit characters have character
59692codes higher than #xFF (*note Text Representations::), but Emacs
59693transparently converts them to their single-byte values when you encode
59694or decode such text.
59695
59696   The usual way to read a file into a buffer as a sequence of bytes, so
59697you can decode the contents explicitly, is with
59698‘insert-file-contents-literally’ (*note Reading from Files::);
59699alternatively, specify a non-‘nil’ RAWFILE argument when visiting a file
59700with ‘find-file-noselect’.  These methods result in a unibyte buffer.
59701
59702   The usual way to use the byte sequence that results from explicitly
59703encoding text is to copy it to a file or process—for example, to write
59704it with ‘write-region’ (*note Writing to Files::), and suppress encoding
59705by binding ‘coding-system-for-write’ to ‘no-conversion’.
59706
59707   Here are the functions to perform explicit encoding or decoding.  The
59708encoding functions produce sequences of bytes; the decoding functions
59709are meant to operate on sequences of bytes.  All of these functions
59710discard text properties.  They also set ‘last-coding-system-used’ to the
59711precise coding system they used.
59712
59713 -- Command: encode-coding-region start end coding-system &optional
59714          destination
59715     This command encodes the text from START to END according to coding
59716     system CODING-SYSTEM.  Normally, the encoded text replaces the
59717     original text in the buffer, but the optional argument DESTINATION
59718     can change that.  If DESTINATION is a buffer, the encoded text is
59719     inserted in that buffer after point (point does not move); if it is
59720     ‘t’, the command returns the encoded text as a unibyte string
59721     without inserting it.
59722
59723     If encoded text is inserted in some buffer, this command returns
59724     the length of the encoded text.
59725
59726     The result of encoding is logically a sequence of bytes, but the
59727     buffer remains multibyte if it was multibyte before, and any 8-bit
59728     bytes are converted to their multibyte representation (*note Text
59729     Representations::).
59730
59731     Do _not_ use ‘undecided’ for CODING-SYSTEM when encoding text,
59732     since that may lead to unexpected results.  Instead, use
59733     ‘select-safe-coding-system’ (*note select-safe-coding-system:
59734     User-Chosen Coding Systems.) to suggest a suitable encoding, if
59735     there’s no obvious pertinent value for CODING-SYSTEM.
59736
59737 -- Function: encode-coding-string string coding-system &optional nocopy
59738          buffer
59739     This function encodes the text in STRING according to coding system
59740     CODING-SYSTEM.  It returns a new string containing the encoded
59741     text, except when NOCOPY is non-‘nil’, in which case the function
59742     may return STRING itself if the encoding operation is trivial.  The
59743     result of encoding is a unibyte string.
59744
59745 -- Command: decode-coding-region start end coding-system &optional
59746          destination
59747     This command decodes the text from START to END according to coding
59748     system CODING-SYSTEM.  To make explicit decoding useful, the text
59749     before decoding ought to be a sequence of byte values, but both
59750     multibyte and unibyte buffers are acceptable (in the multibyte
59751     case, the raw byte values should be represented as eight-bit
59752     characters).  Normally, the decoded text replaces the original text
59753     in the buffer, but the optional argument DESTINATION can change
59754     that.  If DESTINATION is a buffer, the decoded text is inserted in
59755     that buffer after point (point does not move); if it is ‘t’, the
59756     command returns the decoded text as a multibyte string without
59757     inserting it.
59758
59759     If decoded text is inserted in some buffer, this command returns
59760     the length of the decoded text.  If that buffer is a unibyte buffer
59761     (*note Selecting a Representation::), the internal representation
59762     of the decoded text (*note Text Representations::) is inserted into
59763     the buffer as individual bytes.
59764
59765     This command puts a ‘charset’ text property on the decoded text.
59766     The value of the property states the character set used to decode
59767     the original text.
59768
59769 -- Function: decode-coding-string string coding-system &optional nocopy
59770          buffer
59771     This function decodes the text in STRING according to
59772     CODING-SYSTEM.  It returns a new string containing the decoded
59773     text, except when NOCOPY is non-‘nil’, in which case the function
59774     may return STRING itself if the decoding operation is trivial.  To
59775     make explicit decoding useful, the contents of STRING ought to be a
59776     unibyte string with a sequence of byte values, but a multibyte
59777     string is also acceptable (assuming it contains 8-bit bytes in
59778     their multibyte form).
59779
59780     If optional argument BUFFER specifies a buffer, the decoded text is
59781     inserted in that buffer after point (point does not move).  In this
59782     case, the return value is the length of the decoded text.  If that
59783     buffer is a unibyte buffer, the internal representation of the
59784     decoded text is inserted into it as individual bytes.
59785
59786     This function puts a ‘charset’ text property on the decoded text.
59787     The value of the property states the character set used to decode
59788     the original text:
59789
59790          (decode-coding-string "Gr\374ss Gott" 'latin-1)
59791               ⇒ #("Grüss Gott" 0 9 (charset iso-8859-1))
59792
59793 -- Function: decode-coding-inserted-region from to filename &optional
59794          visit beg end replace
59795     This function decodes the text from FROM to TO as if it were being
59796     read from file FILENAME using ‘insert-file-contents’ using the rest
59797     of the arguments provided.
59798
59799     The normal way to use this function is after reading text from a
59800     file without decoding, if you decide you would rather have decoded
59801     it.  Instead of deleting the text and reading it again, this time
59802     with decoding, you can call this function.
59803
59804
59805File: elisp.info,  Node: Terminal I/O Encoding,  Prev: Explicit Encoding,  Up: Coding Systems
59806
5980733.10.8 Terminal I/O Encoding
59808-----------------------------
59809
59810Emacs can use coding systems to decode keyboard input and encode
59811terminal output.  This is useful for terminals that transmit or display
59812text using a particular encoding, such as Latin-1.  Emacs does not set
59813‘last-coding-system-used’ when encoding or decoding terminal I/O.
59814
59815 -- Function: keyboard-coding-system &optional terminal
59816     This function returns the coding system used for decoding keyboard
59817     input from TERMINAL.  A value of ‘no-conversion’ means no decoding
59818     is done.  If TERMINAL is omitted or ‘nil’, it means the selected
59819     frame’s terminal.  *Note Multiple Terminals::.
59820
59821 -- Command: set-keyboard-coding-system coding-system &optional terminal
59822     This command specifies CODING-SYSTEM as the coding system to use
59823     for decoding keyboard input from TERMINAL.  If CODING-SYSTEM is
59824     ‘nil’, that means not to decode keyboard input.  If TERMINAL is a
59825     frame, it means that frame’s terminal; if it is ‘nil’, that means
59826     the currently selected frame’s terminal.  *Note Multiple
59827     Terminals::.
59828
59829 -- Function: terminal-coding-system &optional terminal
59830     This function returns the coding system that is in use for encoding
59831     terminal output from TERMINAL.  A value of ‘no-conversion’ means no
59832     encoding is done.  If TERMINAL is a frame, it means that frame’s
59833     terminal; if it is ‘nil’, that means the currently selected frame’s
59834     terminal.
59835
59836 -- Command: set-terminal-coding-system coding-system &optional terminal
59837     This command specifies CODING-SYSTEM as the coding system to use
59838     for encoding terminal output from TERMINAL.  If CODING-SYSTEM is
59839     ‘nil’, that means not to encode terminal output.  If TERMINAL is a
59840     frame, it means that frame’s terminal; if it is ‘nil’, that means
59841     the currently selected frame’s terminal.
59842
59843
59844File: elisp.info,  Node: Input Methods,  Next: Locales,  Prev: Coding Systems,  Up: Non-ASCII Characters
59845
5984633.11 Input Methods
59847===================
59848
59849“Input methods” provide convenient ways of entering non-ASCII characters
59850from the keyboard.  Unlike coding systems, which translate non-ASCII
59851characters to and from encodings meant to be read by programs, input
59852methods provide human-friendly commands.  (*Note (emacs)Input Methods::,
59853for information on how users use input methods to enter text.)  How to
59854define input methods is not yet documented in this manual, but here we
59855describe how to use them.
59856
59857   Each input method has a name, which is currently a string; in the
59858future, symbols may also be usable as input method names.
59859
59860 -- Variable: current-input-method
59861     This variable holds the name of the input method now active in the
59862     current buffer.  (It automatically becomes local in each buffer
59863     when set in any fashion.)  It is ‘nil’ if no input method is active
59864     in the buffer now.
59865
59866 -- User Option: default-input-method
59867     This variable holds the default input method for commands that
59868     choose an input method.  Unlike ‘current-input-method’, this
59869     variable is normally global.
59870
59871 -- Command: set-input-method input-method
59872     This command activates input method INPUT-METHOD for the current
59873     buffer.  It also sets ‘default-input-method’ to INPUT-METHOD.  If
59874     INPUT-METHOD is ‘nil’, this command deactivates any input method
59875     for the current buffer.
59876
59877 -- Function: read-input-method-name prompt &optional default
59878          inhibit-null
59879     This function reads an input method name with the minibuffer,
59880     prompting with PROMPT.  If DEFAULT is non-‘nil’, that is returned
59881     by default, if the user enters empty input.  However, if
59882     INHIBIT-NULL is non-‘nil’, empty input signals an error.
59883
59884     The returned value is a string.
59885
59886 -- Variable: input-method-alist
59887     This variable defines all the supported input methods.  Each
59888     element defines one input method, and should have the form:
59889
59890          (INPUT-METHOD LANGUAGE-ENV ACTIVATE-FUNC
59891           TITLE DESCRIPTION ARGS...)
59892
59893     Here INPUT-METHOD is the input method name, a string; LANGUAGE-ENV
59894     is another string, the name of the language environment this input
59895     method is recommended for.  (That serves only for documentation
59896     purposes.)
59897
59898     ACTIVATE-FUNC is a function to call to activate this method.  The
59899     ARGS, if any, are passed as arguments to ACTIVATE-FUNC.  All told,
59900     the arguments to ACTIVATE-FUNC are INPUT-METHOD and the ARGS.
59901
59902     TITLE is a string to display in the mode line while this method is
59903     active.  DESCRIPTION is a string describing this method and what it
59904     is good for.
59905
59906   The fundamental interface to input methods is through the variable
59907‘input-method-function’.  *Note Reading One Event::, and *note Invoking
59908the Input Method::.
59909
59910
59911File: elisp.info,  Node: Locales,  Prev: Input Methods,  Up: Non-ASCII Characters
59912
5991333.12 Locales
59914=============
59915
59916In POSIX, locales control which language to use in language-related
59917features.  These Emacs variables control how Emacs interacts with these
59918features.
59919
59920 -- Variable: locale-coding-system
59921     This variable specifies the coding system to use for decoding
59922     system error messages and—on X Window system only—keyboard input,
59923     for sending batch output to the standard output and error streams,
59924     for encoding the format argument to ‘format-time-string’, and for
59925     decoding the return value of ‘format-time-string’.
59926
59927 -- Variable: system-messages-locale
59928     This variable specifies the locale to use for generating system
59929     error messages.  Changing the locale can cause messages to come out
59930     in a different language or in a different orthography.  If the
59931     variable is ‘nil’, the locale is specified by environment variables
59932     in the usual POSIX fashion.
59933
59934 -- Variable: system-time-locale
59935     This variable specifies the locale to use for formatting time
59936     values.  Changing the locale can cause messages to appear according
59937     to the conventions of a different language.  If the variable is
59938     ‘nil’, the locale is specified by environment variables in the
59939     usual POSIX fashion.
59940
59941 -- Function: locale-info item
59942     This function returns locale data ITEM for the current POSIX
59943     locale, if available.  ITEM should be one of these symbols:
59944
59945     ‘codeset’
59946          Return the character set as a string (locale item ‘CODESET’).
59947
59948     ‘days’
59949          Return a 7-element vector of day names (locale items ‘DAY_1’
59950          through ‘DAY_7’);
59951
59952     ‘months’
59953          Return a 12-element vector of month names (locale items
59954          ‘MON_1’ through ‘MON_12’).
59955
59956     ‘paper’
59957          Return a list ‘(WIDTH HEIGHT)’ of 2 integers, for the default
59958          paper size measured in millimeters (locale items
59959          ‘_NL_PAPER_WIDTH’ and ‘_NL_PAPER_HEIGHT’).
59960
59961     If the system can’t provide the requested information, or if ITEM
59962     is not one of those symbols, the value is ‘nil’.  All strings in
59963     the return value are decoded using ‘locale-coding-system’.  *Note
59964     (libc)Locales::, for more information about locales and locale
59965     items.
59966
59967
59968File: elisp.info,  Node: Searching and Matching,  Next: Syntax Tables,  Prev: Non-ASCII Characters,  Up: Top
59969
5997034 Searching and Matching
59971*************************
59972
59973GNU Emacs provides two ways to search through a buffer for specified
59974text: exact string searches and regular expression searches.  After a
59975regular expression search, you can examine the “match data” to determine
59976which text matched the whole regular expression or various portions of
59977it.
59978
59979* Menu:
59980
59981* String Search::         Search for an exact match.
59982* Searching and Case::    Case-independent or case-significant searching.
59983* Regular Expressions::   Describing classes of strings.
59984* Regexp Search::         Searching for a match for a regexp.
59985* POSIX Regexps::         Searching POSIX-style for the longest match.
59986* Match Data::            Finding out which part of the text matched,
59987                            after a string or regexp search.
59988* Search and Replace::    Commands that loop, searching and replacing.
59989* Standard Regexps::      Useful regexps for finding sentences, pages,...
59990
59991   The ‘skip-chars...’ functions also perform a kind of searching.
59992*Note Skipping Characters::.  To search for changes in character
59993properties, see *note Property Search::.
59994
59995
59996File: elisp.info,  Node: String Search,  Next: Searching and Case,  Up: Searching and Matching
59997
5999834.1 Searching for Strings
59999==========================
60000
60001These are the primitive functions for searching through the text in a
60002buffer.  They are meant for use in programs, but you may call them
60003interactively.  If you do so, they prompt for the search string; the
60004arguments LIMIT and NOERROR are ‘nil’, and REPEAT is 1.  For more
60005details on interactive searching, *note Searching and Replacement:
60006(emacs)Search.
60007
60008   These search functions convert the search string to multibyte if the
60009buffer is multibyte; they convert the search string to unibyte if the
60010buffer is unibyte.  *Note Text Representations::.
60011
60012 -- Command: search-forward string &optional limit noerror count
60013     This function searches forward from point for an exact match for
60014     STRING.  If successful, it sets point to the end of the occurrence
60015     found, and returns the new value of point.  If no match is found,
60016     the value and side effects depend on NOERROR (see below).
60017
60018     In the following example, point is initially at the beginning of
60019     the line.  Then ‘(search-forward "fox")’ moves point after the last
60020     letter of ‘fox’:
60021
60022          ---------- Buffer: foo ----------
60023          ★The quick brown fox jumped over the lazy dog.
60024          ---------- Buffer: foo ----------
60025
60026          (search-forward "fox")
60027               ⇒ 20
60028
60029          ---------- Buffer: foo ----------
60030          The quick brown fox★ jumped over the lazy dog.
60031          ---------- Buffer: foo ----------
60032
60033     The argument LIMIT specifies the bound to the search, and should be
60034     a position in the current buffer.  No match extending after that
60035     position is accepted.  If LIMIT is omitted or ‘nil’, it defaults to
60036     the end of the accessible portion of the buffer.
60037
60038     What happens when the search fails depends on the value of NOERROR.
60039     If NOERROR is ‘nil’, a ‘search-failed’ error is signaled.  If
60040     NOERROR is ‘t’, ‘search-forward’ returns ‘nil’ and does nothing.
60041     If NOERROR is neither ‘nil’ nor ‘t’, then ‘search-forward’ moves
60042     point to the upper bound and returns ‘nil’.
60043
60044     The argument NOERROR only affects valid searches which fail to find
60045     a match.  Invalid arguments cause errors regardless of NOERROR.
60046
60047     If COUNT is a positive number N, the search is done N times; each
60048     successive search starts at the end of the previous match.  If all
60049     these successive searches succeed, the function call succeeds,
60050     moving point and returning its new value.  Otherwise the function
60051     call fails, with results depending on the value of NOERROR, as
60052     described above.  If COUNT is a negative number −N, the search is
60053     done N times in the opposite (backward) direction.
60054
60055 -- Command: search-backward string &optional limit noerror count
60056     This function searches backward from point for STRING.  It is like
60057     ‘search-forward’, except that it searches backwards rather than
60058     forwards.  Backward searches leave point at the beginning of the
60059     match.
60060
60061 -- Command: word-search-forward string &optional limit noerror count
60062     This function searches forward from point for a word match for
60063     STRING.  If it finds a match, it sets point to the end of the match
60064     found, and returns the new value of point.
60065
60066     Word matching regards STRING as a sequence of words, disregarding
60067     punctuation that separates them.  It searches the buffer for the
60068     same sequence of words.  Each word must be distinct in the buffer
60069     (searching for the word ‘ball’ does not match the word ‘balls’),
60070     but the details of punctuation and spacing are ignored (searching
60071     for ‘ball boy’ does match ‘ball. Boy!’).
60072
60073     In this example, point is initially at the beginning of the buffer;
60074     the search leaves it between the ‘y’ and the ‘!’.
60075
60076          ---------- Buffer: foo ----------
60077          ★He said "Please!  Find
60078          the ball boy!"
60079          ---------- Buffer: foo ----------
60080
60081          (word-search-forward "Please find the ball, boy.")
60082               ⇒ 39
60083
60084          ---------- Buffer: foo ----------
60085          He said "Please!  Find
60086          the ball boy★!"
60087          ---------- Buffer: foo ----------
60088
60089     If LIMIT is non-‘nil’, it must be a position in the current buffer;
60090     it specifies the upper bound to the search.  The match found must
60091     not extend after that position.
60092
60093     If NOERROR is ‘nil’, then ‘word-search-forward’ signals an error if
60094     the search fails.  If NOERROR is ‘t’, then it returns ‘nil’ instead
60095     of signaling an error.  If NOERROR is neither ‘nil’ nor ‘t’, it
60096     moves point to LIMIT (or the end of the accessible portion of the
60097     buffer) and returns ‘nil’.
60098
60099     If COUNT is a positive number, it specifies how many successive
60100     occurrences to search for.  Point is positioned at the end of the
60101     last match.  If COUNT is a negative number, the search is backward
60102     and point is positioned at the beginning of the last match.
60103
60104     Internally, ‘word-search-forward’ and related functions use the
60105     function ‘word-search-regexp’ to convert STRING to a regular
60106     expression that ignores punctuation.
60107
60108 -- Command: word-search-forward-lax string &optional limit noerror
60109          count
60110     This command is identical to ‘word-search-forward’, except that the
60111     beginning or the end of STRING need not match a word boundary,
60112     unless STRING begins or ends in whitespace.  For instance,
60113     searching for ‘ball boy’ matches ‘ball boyee’, but does not match
60114     ‘balls boy’.
60115
60116 -- Command: word-search-backward string &optional limit noerror count
60117     This function searches backward from point for a word match to
60118     STRING.  This function is just like ‘word-search-forward’ except
60119     that it searches backward and normally leaves point at the
60120     beginning of the match.
60121
60122 -- Command: word-search-backward-lax string &optional limit noerror
60123          count
60124     This command is identical to ‘word-search-backward’, except that
60125     the beginning or the end of STRING need not match a word boundary,
60126     unless STRING begins or ends in whitespace.
60127
60128
60129File: elisp.info,  Node: Searching and Case,  Next: Regular Expressions,  Prev: String Search,  Up: Searching and Matching
60130
6013134.2 Searching and Case
60132=======================
60133
60134By default, searches in Emacs ignore the case of the text they are
60135searching through; if you specify searching for ‘FOO’, then ‘Foo’ or
60136‘foo’ is also considered a match.  This applies to regular expressions,
60137too; thus, ‘[aB]’ would match ‘a’ or ‘A’ or ‘b’ or ‘B’.
60138
60139   If you do not want this feature, set the variable ‘case-fold-search’
60140to ‘nil’.  Then all letters must match exactly, including case.  This is
60141a buffer-local variable; altering the variable affects only the current
60142buffer.  (*Note Intro to Buffer-Local::.)  Alternatively, you may change
60143the default value.  In Lisp code, you will more typically use ‘let’ to
60144bind ‘case-fold-search’ to the desired value.
60145
60146   Note that the user-level incremental search feature handles case
60147distinctions differently.  When the search string contains only lower
60148case letters, the search ignores case, but when the search string
60149contains one or more upper case letters, the search becomes
60150case-sensitive.  But this has nothing to do with the searching functions
60151used in Lisp code.  *Note (emacs)Incremental Search::.
60152
60153 -- User Option: case-fold-search
60154     This buffer-local variable determines whether searches should
60155     ignore case.  If the variable is ‘nil’ they do not ignore case;
60156     otherwise (and by default) they do ignore case.
60157
60158 -- User Option: case-replace
60159     This variable determines whether the higher-level replacement
60160     functions should preserve case.  If the variable is ‘nil’, that
60161     means to use the replacement text verbatim.  A non-‘nil’ value
60162     means to convert the case of the replacement text according to the
60163     text being replaced.
60164
60165     This variable is used by passing it as an argument to the function
60166     ‘replace-match’.  *Note Replacing Match::.
60167
60168
60169File: elisp.info,  Node: Regular Expressions,  Next: Regexp Search,  Prev: Searching and Case,  Up: Searching and Matching
60170
6017134.3 Regular Expressions
60172========================
60173
60174A “regular expression”, or “regexp” for short, is a pattern that denotes
60175a (possibly infinite) set of strings.  Searching for matches for a
60176regexp is a very powerful operation.  This section explains how to write
60177regexps; the following section says how to search for them.
60178
60179   For interactive development of regular expressions, you can use the
60180‘M-x re-builder’ command.  It provides a convenient interface for
60181creating regular expressions, by giving immediate visual feedback in a
60182separate buffer.  As you edit the regexp, all its matches in the target
60183buffer are highlighted.  Each parenthesized sub-expression of the regexp
60184is shown in a distinct face, which makes it easier to verify even very
60185complex regexps.
60186
60187* Menu:
60188
60189* Syntax of Regexps::       Rules for writing regular expressions.
60190* Regexp Example::          Illustrates regular expression syntax.
60191* Rx Notation::             An alternative, structured regexp notation.
60192* Regexp Functions::        Functions for operating on regular expressions.
60193
60194
60195File: elisp.info,  Node: Syntax of Regexps,  Next: Regexp Example,  Up: Regular Expressions
60196
6019734.3.1 Syntax of Regular Expressions
60198------------------------------------
60199
60200Regular expressions have a syntax in which a few characters are special
60201constructs and the rest are “ordinary”.  An ordinary character is a
60202simple regular expression that matches that character and nothing else.
60203The special characters are ‘.’, ‘*’, ‘+’, ‘?’, ‘[’, ‘^’, ‘$’, and ‘\’;
60204no new special characters will be defined in the future.  The character
60205‘]’ is special if it ends a character alternative (see later).  The
60206character ‘-’ is special inside a character alternative.  A ‘[:’ and
60207balancing ‘:]’ enclose a character class inside a character alternative.
60208Any other character appearing in a regular expression is ordinary,
60209unless a ‘\’ precedes it.
60210
60211   For example, ‘f’ is not a special character, so it is ordinary, and
60212therefore ‘f’ is a regular expression that matches the string ‘f’ and no
60213other string.  (It does _not_ match the string ‘fg’, but it does match a
60214_part_ of that string.)  Likewise, ‘o’ is a regular expression that
60215matches only ‘o’.
60216
60217   Any two regular expressions A and B can be concatenated.  The result
60218is a regular expression that matches a string if A matches some amount
60219of the beginning of that string and B matches the rest of the string.
60220
60221   As a simple example, we can concatenate the regular expressions ‘f’
60222and ‘o’ to get the regular expression ‘fo’, which matches only the
60223string ‘fo’.  Still trivial.  To do something more powerful, you need to
60224use one of the special regular expression constructs.
60225
60226* Menu:
60227
60228* Regexp Special::      Special characters in regular expressions.
60229* Char Classes::        Character classes used in regular expressions.
60230* Regexp Backslash::    Backslash-sequences in regular expressions.
60231
60232
60233File: elisp.info,  Node: Regexp Special,  Next: Char Classes,  Up: Syntax of Regexps
60234
6023534.3.1.1 Special Characters in Regular Expressions
60236..................................................
60237
60238Here is a list of the characters that are special in a regular
60239expression.
60240
60241‘.’ (Period)
60242     is a special character that matches any single character except a
60243     newline.  Using concatenation, we can make regular expressions like
60244a.b’, which matches any three-character string that begins with
60245     ‘a’ and ends with ‘b’.
60246
60247‘*’
60248     is not a construct by itself; it is a postfix operator that means
60249     to match the preceding regular expression repetitively as many
60250     times as possible.  Thus, ‘o*’ matches any number of ‘o’s
60251     (including no ‘o’s).
60252
60253     ‘*’ always applies to the _smallest_ possible preceding expression.
60254     Thus, ‘fo*’ has a repeating ‘o’, not a repeating ‘fo’.  It matches
60255     ‘f’, ‘fo’, ‘foo’, and so on.
60256
60257     The matcher processes a ‘*’ construct by matching, immediately, as
60258     many repetitions as can be found.  Then it continues with the rest
60259     of the pattern.  If that fails, backtracking occurs, discarding
60260     some of the matches of the ‘*’-modified construct in the hope that
60261     this will make it possible to match the rest of the pattern.  For
60262     example, in matching ‘ca*ar’ against the string ‘caaar’, the ‘a*’
60263     first tries to match all three ‘a’s; but the rest of the pattern is
60264     ‘ar’ and there is only ‘r’ left to match, so this try fails.  The
60265     next alternative is for ‘a*’ to match only two ‘a’s.  With this
60266     choice, the rest of the regexp matches successfully.
60267
60268     *Warning:* Nested repetition operators can run for a very long
60269     time, if they lead to ambiguous matching.  For example, trying to
60270     match the regular expression ‘\(x+y*\)*a’ against the string
60271     ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz’ could take hours before it
60272     ultimately fails.  Emacs must try each way of grouping the ‘x’s
60273     before concluding that none of them can work.  In general, avoid
60274     expressions that can match the same string in multiple ways.
60275
60276‘+’
60277     is a postfix operator, similar to ‘*’ except that it must match the
60278     preceding expression at least once.  So, for example, ‘ca+r’
60279     matches the strings ‘car’ and ‘caaaar’ but not the string ‘cr’,
60280     whereas ‘ca*r’ matches all three strings.
60281
60282‘?’
60283     is a postfix operator, similar to ‘*’ except that it must match the
60284     preceding expression either once or not at all.  For example,
60285     ‘ca?r’ matches ‘car’ or ‘cr’; nothing else.
60286
60287‘*?’, ‘+?’, ‘??’
60288     These are “non-greedy” variants of the operators ‘*’, ‘+’ and ‘?’.
60289     Where those operators match the largest possible substring
60290     (consistent with matching the entire containing expression), the
60291     non-greedy variants match the smallest possible substring
60292     (consistent with matching the entire containing expression).
60293
60294     For example, the regular expression ‘c[ad]*a’ when applied to the
60295     string ‘cdaaada’ matches the whole string; but the regular
60296     expression ‘c[ad]*?a’, applied to that same string, matches just
60297     ‘cda’.  (The smallest possible match here for ‘[ad]*?’ that permits
60298     the whole expression to match is ‘d’.)
60299
60300‘[ ... ]’
60301     is a “character alternative”, which begins with ‘[’ and is
60302     terminated by ‘]’.  In the simplest case, the characters between
60303     the two brackets are what this character alternative can match.
60304
60305     Thus, ‘[ad]’ matches either one ‘a’ or one ‘d’, and ‘[ad]*’ matches
60306     any string composed of just ‘a’s and ‘d’s (including the empty
60307     string).  It follows that ‘c[ad]*r’ matches ‘cr’, ‘car’, ‘cdr’,
60308     ‘caddaar’, etc.
60309
60310     You can also include character ranges in a character alternative,
60311     by writing the starting and ending characters with a ‘-’ between
60312     them.  Thus, ‘[a-z]’ matches any lower-case ASCII letter.  Ranges
60313     may be intermixed freely with individual characters, as in
60314     ‘[a-z$%.]’, which matches any lower case ASCII letter or ‘$’, ‘%’
60315     or period.  However, the ending character of one range should not
60316     be the starting point of another one; for example, ‘[a-m-z]’ should
60317     be avoided.
60318
60319     A character alternative can also specify named character classes
60320     (*note Char Classes::).  This is a POSIX feature.  For example,
60321     ‘[[:ascii:]]’ matches any ASCII character.  Using a character class
60322     is equivalent to mentioning each of the characters in that class;
60323     but the latter is not feasible in practice, since some classes
60324     include thousands of different characters.  A character class
60325     should not appear as the lower or upper bound of a range.
60326
60327     The usual regexp special characters are not special inside a
60328     character alternative.  A completely different set of characters is
60329     special: ‘]’, ‘-’ and ‘^’.  To include ‘]’ in a character
60330     alternative, put it at the beginning.  To include ‘^’, put it
60331     anywhere but at the beginning.  To include ‘-’, put it at the end.
60332     Thus, ‘[]^-]’ matches all three of these special characters.  You
60333     cannot use ‘\’ to escape these three characters, since ‘\’ is not
60334     special here.
60335
60336     The following aspects of ranges are specific to Emacs, in that
60337     POSIX allows but does not require this behavior and programs other
60338     than Emacs may behave differently:
60339
60340       1. If ‘case-fold-search’ is non-‘nil’, ‘[a-z]’ also matches
60341          upper-case letters.
60342
60343       2. A range is not affected by the locale’s collation sequence: it
60344          always represents the set of characters with codepoints
60345          ranging between those of its bounds, so that ‘[a-z]’ matches
60346          only ASCII letters, even outside the C or POSIX locale.
60347
60348       3. If the lower bound of a range is greater than its upper bound,
60349          the range is empty and represents no characters.  Thus,
60350          ‘[z-a]’ always fails to match, and ‘[^z-a]’ matches any
60351          character, including newline.  However, a reversed range
60352          should always be from the letter ‘z’ to the letter ‘a’ to make
60353          it clear that it is not a typo; for example, ‘[+-*/]’ should
60354          be avoided, because it matches only ‘/’ rather than the
60355          likely-intended four characters.
60356
60357     Some kinds of character alternatives are not the best style even
60358     though they have a well-defined meaning in Emacs.  They include:
60359
60360       1. Although a range’s bound can be almost any character, it is
60361          better style to stay within natural sequences of ASCII letters
60362          and digits because most people have not memorized character
60363          code tables.  For example, ‘[.-9]’ is less clear than
60364          ‘[./0-9]’, and ‘[`-~]’ is less clear than ‘[`a-z{|}~]’.
60365          Unicode character escapes can help here; for example, for most
60366          programmers ‘[ก-ฺ฿-๛]’ is less clear than
60367          ‘[\u0E01-\u0E3A\u0E3F-\u0E5B]’.
60368
60369       2. Although a character alternative can include duplicates, it is
60370          better style to avoid them.  For example, ‘[XYa-yYb-zX]’ is
60371          less clear than ‘[XYa-z]’.
60372
60373       3. Although a range can denote just one, two, or three
60374          characters, it is simpler to list the characters.  For
60375          example, ‘[a-a0]’ is less clear than ‘[a0]’, ‘[i-j]’ is less
60376          clear than ‘[ij]’, and ‘[i-k]’ is less clear than ‘[ijk]’.
60377
60378       4. Although a ‘-’ can appear at the beginning of a character
60379          alternative or as the upper bound of a range, it is better
60380          style to put ‘-’ by itself at the end of a character
60381          alternative.  For example, although ‘[-a-z]’ is valid,
60382          ‘[a-z-]’ is better style; and although ‘[*--]’ is valid,
60383          ‘[*+,-]’ is clearer.
60384
60385‘[^ ... ]’
60386     ‘[^’ begins a “complemented character alternative”.  This matches
60387     any character except the ones specified.  Thus, ‘[^a-z0-9A-Z]’
60388     matches all characters _except_ ASCII letters and digits.
60389
60390     ‘^’ is not special in a character alternative unless it is the
60391     first character.  The character following the ‘^’ is treated as if
60392     it were first (in other words, ‘-’ and ‘]’ are not special there).
60393
60394     A complemented character alternative can match a newline, unless
60395     newline is mentioned as one of the characters not to match.  This
60396     is in contrast to the handling of regexps in programs such as
60397     ‘grep’.
60398
60399     You can specify named character classes, just like in character
60400     alternatives.  For instance, ‘[^[:ascii:]]’ matches any non-ASCII
60401     character.  *Note Char Classes::.
60402
60403‘^’
60404     When matching a buffer, ‘^’ matches the empty string, but only at
60405     the beginning of a line in the text being matched (or the beginning
60406     of the accessible portion of the buffer).  Otherwise it fails to
60407     match anything.  Thus, ‘^foo’ matches a ‘foo’ that occurs at the
60408     beginning of a line.
60409
60410     When matching a string instead of a buffer, ‘^’ matches at the
60411     beginning of the string or after a newline character.
60412
60413     For historical compatibility reasons, ‘^’ can be used only at the
60414     beginning of the regular expression, or after ‘\(’, ‘\(?:’ or ‘\|’.
60415
60416‘$’
60417     is similar to ‘^’ but matches only at the end of a line (or the end
60418     of the accessible portion of the buffer).  Thus, ‘x+$’ matches a
60419     string of one ‘x’ or more at the end of a line.
60420
60421     When matching a string instead of a buffer, ‘$’ matches at the end
60422     of the string or before a newline character.
60423
60424     For historical compatibility reasons, ‘$’ can be used only at the
60425     end of the regular expression, or before ‘\)’ or ‘\|’.
60426
60427‘\’
60428     has two functions: it quotes the special characters (including
60429     ‘\’), and it introduces additional special constructs.
60430
60431     Because ‘\’ quotes special characters, ‘\$’ is a regular expression
60432     that matches only ‘$’, and ‘\[’ is a regular expression that
60433     matches only ‘[’, and so on.
60434
60435     Note that ‘\’ also has special meaning in the read syntax of Lisp
60436     strings (*note String Type::), and must be quoted with ‘\’.  For
60437     example, the regular expression that matches the ‘\’ character is
60438     ‘\\’.  To write a Lisp string that contains the characters ‘\\’,
60439     Lisp syntax requires you to quote each ‘\’ with another ‘\’.
60440     Therefore, the read syntax for a regular expression matching ‘\’ is
60441     ‘"\\\\"’.
60442
60443   *Please note:* For historical compatibility, special characters are
60444treated as ordinary ones if they are in contexts where their special
60445meanings make no sense.  For example, ‘*foo’ treats ‘*’ as ordinary
60446since there is no preceding expression on which the ‘*’ can act.  It is
60447poor practice to depend on this behavior; quote the special character
60448anyway, regardless of where it appears.
60449
60450   As a ‘\’ is not special inside a character alternative, it can never
60451remove the special meaning of ‘-’ or ‘]’.  So you should not quote these
60452characters when they have no special meaning either.  This would not
60453clarify anything, since backslashes can legitimately precede these
60454characters where they _have_ special meaning, as in ‘[^\]’ (‘"[^\\]"’
60455for Lisp string syntax), which matches any single character except a
60456backslash.
60457
60458   In practice, most ‘]’ that occur in regular expressions close a
60459character alternative and hence are special.  However, occasionally a
60460regular expression may try to match a complex pattern of literal ‘[’ and
60461‘]’.  In such situations, it sometimes may be necessary to carefully
60462parse the regexp from the start to determine which square brackets
60463enclose a character alternative.  For example, ‘[^][]]’ consists of the
60464complemented character alternative ‘[^][]’ (which matches any single
60465character that is not a square bracket), followed by a literal ‘]’.
60466
60467   The exact rules are that at the beginning of a regexp, ‘[’ is special
60468and ‘]’ not.  This lasts until the first unquoted ‘[’, after which we
60469are in a character alternative; ‘[’ is no longer special (except when it
60470starts a character class) but ‘]’ is special, unless it immediately
60471follows the special ‘[’ or that ‘[’ followed by a ‘^’.  This lasts until
60472the next special ‘]’ that does not end a character class.  This ends the
60473character alternative and restores the ordinary syntax of regular
60474expressions; an unquoted ‘[’ is special again and a ‘]’ not.
60475
60476
60477File: elisp.info,  Node: Char Classes,  Next: Regexp Backslash,  Prev: Regexp Special,  Up: Syntax of Regexps
60478
6047934.3.1.2 Character Classes
60480..........................
60481
60482Below is a table of the classes you can use in a character alternative,
60483and what they mean.  Note that the ‘[’ and ‘]’ characters that enclose
60484the class name are part of the name, so a regular expression using these
60485classes needs one more pair of brackets.  For example, a regular
60486expression matching a sequence of one or more letters and digits would
60487be ‘[[:alnum:]]+’, not ‘[:alnum:]+’.
60488
60489‘[:ascii:]’
60490     This matches any ASCII character (codes 0–127).
60491‘[:alnum:]’
60492     This matches any letter or digit.  For multibyte characters, it
60493     matches characters whose Unicode ‘general-category’ property (*note
60494     Character Properties::) indicates they are alphabetic or decimal
60495     number characters.
60496‘[:alpha:]’
60497     This matches any letter.  For multibyte characters, it matches
60498     characters whose Unicode ‘general-category’ property (*note
60499     Character Properties::) indicates they are alphabetic characters.
60500‘[:blank:]’
60501     This matches horizontal whitespace, as defined by Annex C of the
60502     Unicode Technical Standard #18.  In particular, it matches spaces,
60503     tabs, and other characters whose Unicode ‘general-category’
60504     property (*note Character Properties::) indicates they are spacing
60505     separators.
60506‘[:cntrl:]’
60507     This matches any character whose code is in the range 0–31.
60508‘[:digit:]’
60509     This matches ‘0’ through ‘9’.  Thus, ‘[-+[:digit:]]’ matches any
60510     digit, as well as ‘+’ and ‘-’.
60511‘[:graph:]’
60512     This matches graphic characters—everything except whitespace, ASCII
60513     and non-ASCII control characters, surrogates, and codepoints
60514     unassigned by Unicode, as indicated by the Unicode
60515     ‘general-category’ property (*note Character Properties::).
60516‘[:lower:]’
60517     This matches any lower-case letter, as determined by the current
60518     case table (*note Case Tables::).  If ‘case-fold-search’ is
60519     non-‘nil’, this also matches any upper-case letter.
60520‘[:multibyte:]’
60521     This matches any multibyte character (*note Text
60522     Representations::).
60523‘[:nonascii:]’
60524     This matches any non-ASCII character.
60525‘[:print:]’
60526     This matches any printing character—either whitespace, or a graphic
60527     character matched by ‘[:graph:]’.
60528‘[:punct:]’
60529     This matches any punctuation character.  (At present, for multibyte
60530     characters, it matches anything that has non-word syntax.)
60531‘[:space:]’
60532     This matches any character that has whitespace syntax (*note Syntax
60533     Class Table::).
60534‘[:unibyte:]’
60535     This matches any unibyte character (*note Text Representations::).
60536‘[:upper:]’
60537     This matches any upper-case letter, as determined by the current
60538     case table (*note Case Tables::).  If ‘case-fold-search’ is
60539     non-‘nil’, this also matches any lower-case letter.
60540‘[:word:]’
60541     This matches any character that has word syntax (*note Syntax Class
60542     Table::).
60543‘[:xdigit:]’
60544     This matches the hexadecimal digits: ‘0’ through ‘9’, ‘a’ through
60545     ‘f’ and ‘A’ through ‘F’.
60546
60547
60548File: elisp.info,  Node: Regexp Backslash,  Prev: Char Classes,  Up: Syntax of Regexps
60549
6055034.3.1.3 Backslash Constructs in Regular Expressions
60551....................................................
60552
60553For the most part, ‘\’ followed by any character matches only that
60554character.  However, there are several exceptions: certain sequences
60555starting with ‘\’ that have special meanings.  Here is a table of the
60556special ‘\’ constructs.
60557
60558‘\|’
60559     specifies an alternative.  Two regular expressions A and B with
60560     ‘\|’ in between form an expression that matches anything that
60561     either A or B matches.
60562
60563     Thus, ‘foo\|bar’ matches either ‘foo’ or ‘bar’ but no other string.
60564
60565     ‘\|’ applies to the largest possible surrounding expressions.  Only
60566     a surrounding ‘\( ... \)’ grouping can limit the grouping power of
60567     ‘\|’.
60568
60569     If you need full backtracking capability to handle multiple uses of
60570     ‘\|’, use the POSIX regular expression functions (*note POSIX
60571     Regexps::).
60572
60573‘\{M\}’
60574     is a postfix operator that repeats the previous pattern exactly M
60575     times.  Thus, ‘x\{5\}’ matches the string ‘xxxxx’ and nothing else.
60576     ‘c[ad]\{3\}r’ matches string such as ‘caaar’, ‘cdddr’, ‘cadar’, and
60577     so on.
60578
60579‘\{M,N\}’
60580     is a more general postfix operator that specifies repetition with a
60581     minimum of M repeats and a maximum of N repeats.  If M is omitted,
60582     the minimum is 0; if N is omitted, there is no maximum.  For both
60583     forms, M and N, if specified, may be no larger than 2**16 − 1 .
60584
60585     For example, ‘c[ad]\{1,2\}r’ matches the strings ‘car’, ‘cdr’,
60586     ‘caar’, ‘cadr’, ‘cdar’, and ‘cddr’, and nothing else.
60587     ‘\{0,1\}’ or ‘\{,1\}’ is equivalent to ‘?’.
60588     ‘\{0,\}’ or ‘\{,\}’ is equivalent to ‘*’.
60589     ‘\{1,\}’ is equivalent to ‘+’.
60590
60591‘\( ... \)’
60592     is a grouping construct that serves three purposes:
60593
60594       1. To enclose a set of ‘\|’ alternatives for other operations.
60595          Thus, the regular expression ‘\(foo\|bar\)x’ matches either
60596          ‘foox’ or ‘barx’.
60597
60598       2. To enclose a complicated expression for the postfix operators
60599          ‘*’, ‘+’ and ‘?’ to operate on.  Thus, ‘ba\(na\)*’ matches
60600          ‘ba’, ‘bana’, ‘banana’, ‘bananana’, etc., with any number
60601          (zero or more) of ‘na’ strings.
60602
60603       3. To record a matched substring for future reference with
60604          ‘\DIGIT’ (see below).
60605
60606     This last application is not a consequence of the idea of a
60607     parenthetical grouping; it is a separate feature that was assigned
60608     as a second meaning to the same ‘\( ... \)’ construct because, in
60609     practice, there was usually no conflict between the two meanings.
60610     But occasionally there is a conflict, and that led to the
60611     introduction of shy groups.
60612
60613‘\(?: ... \)’
60614     is the “shy group” construct.  A shy group serves the first two
60615     purposes of an ordinary group (controlling the nesting of other
60616     operators), but it does not get a number, so you cannot refer back
60617     to its value with ‘\DIGIT’.  Shy groups are particularly useful for
60618     mechanically-constructed regular expressions, because they can be
60619     added automatically without altering the numbering of ordinary,
60620     non-shy groups.
60621
60622     Shy groups are also called “non-capturing” or “unnumbered groups”.
60623
60624‘\(?NUM: ... \)’
60625     is the “explicitly numbered group” construct.  Normal groups get
60626     their number implicitly, based on their position, which can be
60627     inconvenient.  This construct allows you to force a particular
60628     group number.  There is no particular restriction on the numbering,
60629     e.g., you can have several groups with the same number in which
60630     case the last one to match (i.e., the rightmost match) will win.
60631     Implicitly numbered groups always get the smallest integer larger
60632     than the one of any previous group.
60633
60634‘\DIGIT’
60635     matches the same text that matched the DIGITth occurrence of a
60636     grouping (‘\( ... \)’) construct.
60637
60638     In other words, after the end of a group, the matcher remembers the
60639     beginning and end of the text matched by that group.  Later on in
60640     the regular expression you can use ‘\’ followed by DIGIT to match
60641     that same text, whatever it may have been.
60642
60643     The strings matching the first nine grouping constructs appearing
60644     in the entire regular expression passed to a search or matching
60645     function are assigned numbers 1 through 9 in the order that the
60646     open parentheses appear in the regular expression.  So you can use
60647     ‘\1’ through ‘\9’ to refer to the text matched by the corresponding
60648     grouping constructs.
60649
60650     For example, ‘\(.*\)\1’ matches any newline-free string that is
60651     composed of two identical halves.  The ‘\(.*\)’ matches the first
60652     half, which may be anything, but the ‘\1’ that follows must match
60653     the same exact text.
60654
60655     If a ‘\( ... \)’ construct matches more than once (which can
60656     happen, for instance, if it is followed by ‘*’), only the last
60657     match is recorded.
60658
60659     If a particular grouping construct in the regular expression was
60660     never matched—for instance, if it appears inside of an alternative
60661     that wasn’t used, or inside of a repetition that repeated zero
60662     times—then the corresponding ‘\DIGIT’ construct never matches
60663     anything.  To use an artificial example, ‘\(foo\(b*\)\|lose\)\2’
60664     cannot match ‘lose’: the second alternative inside the larger group
60665     matches it, but then ‘\2’ is undefined and can’t match anything.
60666     But it can match ‘foobb’, because the first alternative matches
60667     ‘foob’ and ‘\2’ matches ‘b’.
60668
60669‘\w’
60670     matches any word-constituent character.  The editor syntax table
60671     determines which characters these are.  *Note Syntax Tables::.
60672
60673‘\W’
60674     matches any character that is not a word constituent.
60675
60676‘\sCODE’
60677     matches any character whose syntax is CODE.  Here CODE is a
60678     character that represents a syntax code: thus, ‘w’ for word
60679     constituent, ‘-’ for whitespace, ‘(’ for open parenthesis, etc.  To
60680     represent whitespace syntax, use either ‘-’ or a space character.
60681     *Note Syntax Class Table::, for a list of syntax codes and the
60682     characters that stand for them.
60683
60684‘\SCODE’
60685     matches any character whose syntax is not CODE.
60686
60687‘\cC’
60688     matches any character whose category is C.  Here C is a character
60689     that represents a category: thus, ‘c’ for Chinese characters or ‘g’
60690     for Greek characters in the standard category table.  You can see
60691     the list of all the currently defined categories with ‘M-x
60692     describe-categories <RET>’.  You can also define your own
60693     categories in addition to the standard ones using the
60694     ‘define-category’ function (*note Categories::).
60695
60696‘\CC’
60697     matches any character whose category is not C.
60698
60699   The following regular expression constructs match the empty
60700string—that is, they don’t use up any characters—but whether they match
60701depends on the context.  For all, the beginning and end of the
60702accessible portion of the buffer are treated as if they were the actual
60703beginning and end of the buffer.
60704
60705‘\`’
60706     matches the empty string, but only at the beginning of the buffer
60707     or string being matched against.
60708
60709‘\'’
60710     matches the empty string, but only at the end of the buffer or
60711     string being matched against.
60712
60713‘\=’
60714     matches the empty string, but only at point.  (This construct is
60715     not defined when matching against a string.)
60716
60717‘\b’
60718     matches the empty string, but only at the beginning or end of a
60719     word.  Thus, ‘\bfoo\b’ matches any occurrence of ‘foo’ as a
60720     separate word.  ‘\bballs?\b’ matches ‘ball’ or ‘balls’ as a
60721     separate word.
60722
60723     ‘\b’ matches at the beginning or end of the buffer (or string)
60724     regardless of what text appears next to it.
60725
60726‘\B’
60727     matches the empty string, but _not_ at the beginning or end of a
60728     word, nor at the beginning or end of the buffer (or string).
60729
60730‘\<’
60731     matches the empty string, but only at the beginning of a word.
60732     ‘\<’ matches at the beginning of the buffer (or string) only if a
60733     word-constituent character follows.
60734
60735‘\>’
60736     matches the empty string, but only at the end of a word.  ‘\>’
60737     matches at the end of the buffer (or string) only if the contents
60738     end with a word-constituent character.
60739
60740‘\_<’
60741     matches the empty string, but only at the beginning of a symbol.  A
60742     symbol is a sequence of one or more word or symbol constituent
60743     characters.  ‘\_<’ matches at the beginning of the buffer (or
60744     string) only if a symbol-constituent character follows.
60745
60746‘\_>’
60747     matches the empty string, but only at the end of a symbol.  ‘\_>’
60748     matches at the end of the buffer (or string) only if the contents
60749     end with a symbol-constituent character.
60750
60751   Not every string is a valid regular expression.  For example, a
60752string that ends inside a character alternative without a terminating
60753‘]’ is invalid, and so is a string that ends with a single ‘\’.  If an
60754invalid regular expression is passed to any of the search functions, an
60755‘invalid-regexp’ error is signaled.
60756
60757
60758File: elisp.info,  Node: Regexp Example,  Next: Rx Notation,  Prev: Syntax of Regexps,  Up: Regular Expressions
60759
6076034.3.2 Complex Regexp Example
60761-----------------------------
60762
60763Here is a complicated regexp which was formerly used by Emacs to
60764recognize the end of a sentence together with any whitespace that
60765follows.  (Nowadays Emacs uses a similar but more complex default regexp
60766constructed by the function ‘sentence-end’.  *Note Standard Regexps::.)
60767
60768   Below, we show first the regexp as a string in Lisp syntax (to
60769distinguish spaces from tab characters), and then the result of
60770evaluating it.  The string constant begins and ends with a double-quote.
60771‘\"’ stands for a double-quote as part of the string, ‘\\’ for a
60772backslash as part of the string, ‘\t’ for a tab and ‘\n’ for a newline.
60773
60774     "[.?!][]\"')}]*\\($\\| $\\|\t\\|  \\)[ \t\n]*"
60775          ⇒ "[.?!][]\"')}]*\\($\\| $\\|  \\|  \\)[
60776     ]*"
60777
60778In the output, tab and newline appear as themselves.
60779
60780   This regular expression contains four parts in succession and can be
60781deciphered as follows:
60782
60783‘[.?!]’
60784     The first part of the pattern is a character alternative that
60785     matches any one of three characters: period, question mark, and
60786     exclamation mark.  The match must begin with one of these three
60787     characters.  (This is one point where the new default regexp used
60788     by Emacs differs from the old.  The new value also allows some
60789     non-ASCII characters that end a sentence without any following
60790     whitespace.)
60791
60792‘[]\"')}]*’
60793     The second part of the pattern matches any closing braces and
60794     quotation marks, zero or more of them, that may follow the period,
60795     question mark or exclamation mark.  The ‘\"’ is Lisp syntax for a
60796     double-quote in a string.  The ‘*’ at the end indicates that the
60797     immediately preceding regular expression (a character alternative,
60798     in this case) may be repeated zero or more times.
60799
60800‘\\($\\| $\\|\t\\|  \\)’
60801     The third part of the pattern matches the whitespace that follows
60802     the end of a sentence: the end of a line (optionally with a space),
60803     or a tab, or two spaces.  The double backslashes mark the
60804     parentheses and vertical bars as regular expression syntax; the
60805     parentheses delimit a group and the vertical bars separate
60806     alternatives.  The dollar sign is used to match the end of a line.
60807
60808‘[ \t\n]*’
60809     Finally, the last part of the pattern matches any additional
60810     whitespace beyond the minimum needed to end a sentence.
60811
60812   In the ‘rx’ notation (*note Rx Notation::), the regexp could be
60813written
60814
60815     (rx (any ".?!")                    ; Punctuation ending sentence.
60816         (zero-or-more (any "\"')]}"))  ; Closing quotes or brackets.
60817         (or line-end
60818             (seq " " line-end)
60819             "\t"
60820             "  ")                      ; Two spaces.
60821         (zero-or-more (any "\t\n ")))  ; Optional extra whitespace.
60822
60823   Since ‘rx’ regexps are just S-expressions, they can be formatted and
60824commented as such.
60825
60826
60827File: elisp.info,  Node: Rx Notation,  Next: Regexp Functions,  Prev: Regexp Example,  Up: Regular Expressions
60828
6082934.3.3 The ‘rx’ Structured Regexp Notation
60830------------------------------------------
60831
60832As an alternative to the string-based syntax, Emacs provides the
60833structured ‘rx’ notation based on Lisp S-expressions.  This notation is
60834usually easier to read, write and maintain than regexp strings, and can
60835be indented and commented freely.  It requires a conversion into string
60836form since that is what regexp functions expect, but that conversion
60837typically takes place during byte-compilation rather than when the Lisp
60838code using the regexp is run.
60839
60840   Here is an ‘rx’ regexp(1) that matches a block comment in the C
60841programming language:
60842
60843     (rx "/*"                          ; Initial /*
60844         (zero-or-more
60845          (or (not (any "*"))          ;  Either non-*,
60846              (seq "*"                 ;  or * followed by
60847                   (not (any "/")))))  ;  non-/
60848         (one-or-more "*")             ; At least one star,
60849         "/")                          ; and the final /
60850
60851or, using shorter synonyms and written more compactly,
60852
60853     (rx "/*"
60854         (* (| (not "*")
60855               (: "*" (not "/"))))
60856         (+ "*") "/")
60857
60858In conventional string syntax, it would be written
60859
60860     "/\\*\\(?:[^*]\\|\\*[^/]\\)*\\*+/"
60861
60862   The ‘rx’ notation is mainly useful in Lisp code; it cannot be used in
60863most interactive situations where a regexp is requested, such as when
60864running ‘query-replace-regexp’ or in variable customization.
60865
60866* Menu:
60867
60868* Rx Constructs::       Constructs valid in rx forms.
60869* Rx Functions::        Functions and macros that use rx forms.
60870* Extending Rx::        How to define your own rx forms.
60871
60872   ---------- Footnotes ----------
60873
60874   (1) It could be written much simpler with non-greedy operators
60875(how?), but that would make the example less interesting.
60876
60877
60878File: elisp.info,  Node: Rx Constructs,  Next: Rx Functions,  Up: Rx Notation
60879
6088034.3.3.1 Constructs in ‘rx’ regexps
60881...................................
60882
60883The various forms in ‘rx’ regexps are described below.  The shorthand RX
60884represents any ‘rx’ form, and RX... means zero or more ‘rx’ forms.
60885Where the corresponding string regexp syntax is given, A, B, ... are
60886string regexp subexpressions.
60887
60888Literals
60889........
60890
60891‘"some-string"’
60892     Match the string ‘some-string’ literally.  There are no characters
60893     with special meaning, unlike in string regexps.
60894
60895‘?C’
60896     Match the character ‘C’ literally.
60897
60898Sequence and alternative
60899........................
60900
60901‘(seq RX...)’
60902‘(sequence RX...)’
60903‘(: RX...)’
60904‘(and RX...)’
60905     Match the RXs in sequence.  Without arguments, the expression
60906     matches the empty string.
60907     Corresponding string regexp: ‘AB...’ (subexpressions in sequence).
60908
60909‘(or RX...)’
60910‘(| RX...)’
60911     Match exactly one of the RXs.  If all arguments are strings,
60912     characters, or ‘or’ forms so constrained, the longest possible
60913     match will always be used.  Otherwise, either the longest match or
60914     the first (in left-to-right order) will be used.  Without
60915     arguments, the expression will not match anything at all.
60916     Corresponding string regexp: ‘A\|B\|...’.
60917
60918‘unmatchable’
60919     Refuse any match.  Equivalent to ‘(or)’.  *Note
60920     regexp-unmatchable::.
60921
60922Repetition
60923..........
60924
60925Normally, repetition forms are greedy, in that they attempt to match as
60926many times as possible.  Some forms are non-greedy; they try to match as
60927few times as possible (*note Non-greedy repetition::).
60928
60929‘(zero-or-more RX...)’
60930‘(0+ RX...)’
60931     Match the RXs zero or more times.  Greedy by default.
60932     Corresponding string regexp: ‘A*’ (greedy), ‘A*?’ (non-greedy)
60933
60934‘(one-or-more RX...)’
60935‘(1+ RX...)’
60936     Match the RXs one or more times.  Greedy by default.
60937     Corresponding string regexp: ‘A+’ (greedy), ‘A+?’ (non-greedy)
60938
60939‘(zero-or-one RX...)’
60940‘(optional RX...)’
60941‘(opt RX...)’
60942     Match the RXs once or an empty string.  Greedy by default.
60943     Corresponding string regexp: ‘A?’ (greedy), ‘A??’ (non-greedy).
60944
60945‘(* RX...)’
60946     Match the RXs zero or more times.  Greedy.
60947     Corresponding string regexp: ‘A*’
60948
60949‘(+ RX...)’
60950     Match the RXs one or more times.  Greedy.
60951     Corresponding string regexp: ‘A+’
60952
60953‘(? RX...)’
60954     Match the RXs once or an empty string.  Greedy.
60955     Corresponding string regexp: ‘A?’
60956
60957‘(*? RX...)’
60958     Match the RXs zero or more times.  Non-greedy.
60959     Corresponding string regexp: ‘A*?’
60960
60961‘(+? RX...)’
60962     Match the RXs one or more times.  Non-greedy.
60963     Corresponding string regexp: ‘A+?’
60964
60965‘(?? RX...)’
60966     Match the RXs or an empty string.  Non-greedy.
60967     Corresponding string regexp: ‘A??’
60968
60969‘(= N RX...)’
60970‘(repeat N RX)’
60971     Match the RXs exactly N times.
60972     Corresponding string regexp: ‘A\{N\}’
60973
60974‘(>= N RX...)’
60975     Match the RXs N or more times.  Greedy.
60976     Corresponding string regexp: ‘A\{N,\}’
60977
60978‘(** N M RX...)’
60979‘(repeat N M RX...)’
60980     Match the RXs at least N but no more than M times.  Greedy.
60981     Corresponding string regexp: ‘A\{N,M\}’
60982
60983   The greediness of some repetition forms can be controlled using the
60984following constructs.  However, it is usually better to use the explicit
60985non-greedy forms above when such matching is required.
60986
60987‘(minimal-match RX)’
60988     Match RX, with ‘zero-or-more’, ‘0+’, ‘one-or-more’, ‘1+’,
60989     ‘zero-or-one’, ‘opt’ and ‘optional’ using non-greedy matching.
60990
60991‘(maximal-match RX)’
60992     Match RX, with ‘zero-or-more’, ‘0+’, ‘one-or-more’, ‘1+’,
60993     ‘zero-or-one’, ‘opt’ and ‘optional’ using greedy matching.  This is
60994     the default.
60995
60996Matching single characters
60997..........................
60998
60999‘(any SET...)’
61000‘(char SET...)’
61001‘(in SET...)’
61002     Match a single character from one of the SETs.  Each SET is a
61003     character, a string representing the set of its characters, a range
61004     or a character class (see below).  A range is either a
61005     hyphen-separated string like ‘"A-Z"’, or a cons of characters like
61006     ‘(?A . ?Z)’.
61007
61008     Note that hyphen (‘-’) is special in strings in this construct,
61009     since it acts as a range separator.  To include a hyphen, add it as
61010     a separate character or single-character string.
61011     Corresponding string regexp: ‘[...]’
61012
61013‘(not CHARSPEC)’
61014     Match a character not included in CHARSPEC.  CHARSPEC can be a
61015     character, a single-character string, an ‘any’, ‘not’, ‘or’,
61016     ‘intersection’, ‘syntax’ or ‘category’ form, or a character class.
61017     If CHARSPEC is an ‘or’ form, its arguments have the same
61018     restrictions as those of ‘intersection’; see below.
61019     Corresponding string regexp: ‘[^...]’, ‘\SCODE’, ‘\CCODE’
61020
61021‘(intersection CHARSET...)’
61022     Match a character included in all of the CHARSETs.  Each CHARSET
61023     can be a character, a single-character string, an ‘any’ form
61024     without character classes, or an ‘intersection’, ‘or’ or ‘not’ form
61025     whose arguments are also CHARSETs.
61026
61027‘not-newline’, ‘nonl’
61028     Match any character except a newline.
61029     Corresponding string regexp: ‘.’ (dot)
61030
61031‘anychar’, ‘anything’
61032     Match any character.
61033     Corresponding string regexp: ‘.\|\n’ (for example)
61034
61035character class
61036     Match a character from a named character class:
61037
61038     ‘alpha’, ‘alphabetic’, ‘letter’
61039          Match alphabetic characters.  More precisely, match characters
61040          whose Unicode ‘general-category’ property indicates that they
61041          are alphabetic.
61042
61043     ‘alnum’, ‘alphanumeric’
61044          Match alphabetic characters and digits.  More precisely, match
61045          characters whose Unicode ‘general-category’ property indicates
61046          that they are alphabetic or decimal digits.
61047
61048     ‘digit’, ‘numeric’, ‘num’
61049          Match the digits ‘0’–‘9’.
61050
61051     ‘xdigit’, ‘hex-digit’, ‘hex’
61052          Match the hexadecimal digits ‘0’–‘9’, ‘A’–‘F’ and ‘a’–‘f’.
61053
61054     ‘cntrl’, ‘control’
61055          Match any character whose code is in the range 0–31.
61056
61057     ‘blank’
61058          Match horizontal whitespace.  More precisely, match characters
61059          whose Unicode ‘general-category’ property indicates that they
61060          are spacing separators.
61061
61062     ‘space’, ‘whitespace’, ‘white’
61063          Match any character that has whitespace syntax (*note Syntax
61064          Class Table::).
61065
61066     ‘lower’, ‘lower-case’
61067          Match anything lower-case, as determined by the current case
61068          table.  If ‘case-fold-search’ is non-nil, this also matches
61069          any upper-case letter.
61070
61071     ‘upper’, ‘upper-case’
61072          Match anything upper-case, as determined by the current case
61073          table.  If ‘case-fold-search’ is non-nil, this also matches
61074          any lower-case letter.
61075
61076     ‘graph’, ‘graphic’
61077          Match any character except whitespace, ASCII and non-ASCII
61078          control characters, surrogates, and codepoints unassigned by
61079          Unicode, as indicated by the Unicode ‘general-category’
61080          property.
61081
61082     ‘print’, ‘printing’
61083          Match whitespace or a character matched by ‘graph’.
61084
61085     ‘punct’, ‘punctuation’
61086          Match any punctuation character.  (At present, for multibyte
61087          characters, anything that has non-word syntax.)
61088
61089     ‘word’, ‘wordchar’
61090          Match any character that has word syntax (*note Syntax Class
61091          Table::).
61092
61093     ‘ascii’
61094          Match any ASCII character (codes 0–127).
61095
61096     ‘nonascii’
61097          Match any non-ASCII character (but not raw bytes).
61098
61099     Corresponding string regexp: ‘[[:CLASS:]]’
61100
61101‘(syntax SYNTAX)’
61102     Match a character with syntax SYNTAX, being one of the following
61103     names:
61104
61105     Syntax name           Syntax character
61106     -----------------------------------------
61107     ‘whitespace’          ‘-’
61108     ‘punctuation’         ‘.’
61109     ‘word’                ‘w’
61110     ‘symbol’              ‘_’
61111     ‘open-parenthesis’    ‘(’
61112     ‘close-parenthesis’   ‘)’
61113     ‘expression-prefix’   ‘'’
61114     ‘string-quote’        ‘"’
61115     ‘paired-delimiter’    ‘$’
61116     ‘escape’              ‘\’
61117     ‘character-quote’     ‘/’
61118     ‘comment-start’       ‘<’
61119     ‘comment-end’         ‘>’
61120     ‘string-delimiter’    ‘|’
61121     ‘comment-delimiter’   ‘!’
61122
61123     For details, *note Syntax Class Table::.  Please note that ‘(syntax
61124     punctuation)’ is _not_ equivalent to the character class
61125     ‘punctuation’.
61126     Corresponding string regexp: ‘\sCODE’
61127
61128‘(category CATEGORY)’
61129     Match a character in category CATEGORY, which is either one of the
61130     names below or its category character.
61131
61132     Category name                        Category character
61133     ----------------------------------------------------------
61134     ‘space-for-indent’                   space
61135     ‘base’                               ‘.’
61136     ‘consonant’                          ‘0’
61137     ‘base-vowel’                         ‘1’
61138     ‘upper-diacritical-mark’             ‘2’
61139     ‘lower-diacritical-mark’             ‘3’
61140     ‘tone-mark’                          ‘4’
61141     ‘symbol’                             ‘5’
61142     ‘digit’                              ‘6’
61143     ‘vowel-modifying-diacritical-mark’   ‘7’
61144     ‘vowel-sign’                         ‘8’
61145     ‘semivowel-lower’                    ‘9’
61146     ‘not-at-end-of-line’                 ‘<’
61147     ‘not-at-beginning-of-line’           ‘>’
61148     ‘alpha-numeric-two-byte’             ‘A’
61149     ‘chinese-two-byte’                   ‘C’
61150     ‘greek-two-byte’                     ‘G’
61151     ‘japanese-hiragana-two-byte’         ‘H’
61152     ‘indian-two-byte’                    ‘I’
61153     ‘japanese-katakana-two-byte’         ‘K’
61154     ‘strong-left-to-right’               ‘L’
61155     ‘korean-hangul-two-byte’             ‘N’
61156     ‘strong-right-to-left’               ‘R’
61157     ‘cyrillic-two-byte’                  ‘Y’
61158     ‘combining-diacritic’                ‘^’
61159     ‘ascii’                              ‘a’
61160     ‘arabic’                             ‘b’
61161     ‘chinese’                            ‘c’
61162     ‘ethiopic’                           ‘e’
61163     ‘greek’                              ‘g’
61164     ‘korean’                             ‘h’
61165     ‘indian’                             ‘i’
61166     ‘japanese’                           ‘j’
61167     ‘japanese-katakana’                  ‘k’
61168     ‘latin’                              ‘l’
61169     ‘lao’                                ‘o’
61170     ‘tibetan’                            ‘q’
61171     ‘japanese-roman’                     ‘r’
61172     ‘thai’                               ‘t’
61173     ‘vietnamese’                         ‘v’
61174     ‘hebrew’                             ‘w’
61175     ‘cyrillic’                           ‘y’
61176     ‘can-break’                          ‘|’
61177
61178     For more information about currently defined categories, run the
61179     command ‘M-x describe-categories <RET>’.  For how to define new
61180     categories, *note Categories::.
61181     Corresponding string regexp: ‘\cCODE’
61182
61183Zero-width assertions
61184.....................
61185
61186These all match the empty string, but only in specific places.
61187
61188‘line-start’, ‘bol’
61189     Match at the beginning of a line.
61190     Corresponding string regexp: ‘^’
61191
61192‘line-end’, ‘eol’
61193     Match at the end of a line.
61194     Corresponding string regexp: ‘$’
61195
61196‘string-start’, ‘bos’, ‘buffer-start’, ‘bot’
61197     Match at the start of the string or buffer being matched against.
61198     Corresponding string regexp: ‘\`’
61199
61200‘string-end’, ‘eos’, ‘buffer-end’, ‘eot’
61201     Match at the end of the string or buffer being matched against.
61202     Corresponding string regexp: ‘\'’
61203
61204‘point’
61205     Match at point.
61206     Corresponding string regexp: ‘\=’
61207
61208‘word-start’, ‘bow’
61209     Match at the beginning of a word.
61210     Corresponding string regexp: ‘\<’
61211
61212‘word-end’, ‘eow’
61213     Match at the end of a word.
61214     Corresponding string regexp: ‘\>’
61215
61216‘word-boundary’
61217     Match at the beginning or end of a word.
61218     Corresponding string regexp: ‘\b’
61219
61220‘not-word-boundary’
61221     Match anywhere but at the beginning or end of a word.
61222     Corresponding string regexp: ‘\B’
61223
61224‘symbol-start’
61225     Match at the beginning of a symbol.
61226     Corresponding string regexp: ‘\_<’
61227
61228‘symbol-end’
61229     Match at the end of a symbol.
61230     Corresponding string regexp: ‘\_>’
61231
61232Capture groups
61233..............
61234
61235‘(group RX...)’
61236‘(submatch RX...)’
61237     Match the RXs, making the matched text and position accessible in
61238     the match data.  The first group in a regexp is numbered 1;
61239     subsequent groups will be numbered one higher than the previous
61240     group.
61241     Corresponding string regexp: ‘\(...\)’
61242
61243‘(group-n N RX...)’
61244‘(submatch-n N RX...)’
61245     Like ‘group’, but explicitly assign the group number N.  N must be
61246     positive.
61247     Corresponding string regexp: ‘\(?N:...\)’
61248
61249‘(backref N)’
61250     Match the text previously matched by group number N.  N must be in
61251     the range 1–9.
61252     Corresponding string regexp: ‘\N’
61253
61254Dynamic inclusion
61255.................
61256
61257‘(literal EXPR)’
61258     Match the literal string that is the result from evaluating the
61259     Lisp expression EXPR.  The evaluation takes place at call time, in
61260     the current lexical environment.
61261
61262‘(regexp EXPR)’
61263‘(regex EXPR)’
61264     Match the string regexp that is the result from evaluating the Lisp
61265     expression EXPR.  The evaluation takes place at call time, in the
61266     current lexical environment.
61267
61268‘(eval EXPR)’
61269     Match the rx form that is the result from evaluating the Lisp
61270     expression EXPR.  The evaluation takes place at macro-expansion
61271     time for ‘rx’, at call time for ‘rx-to-string’, in the current
61272     global environment.
61273
61274
61275File: elisp.info,  Node: Rx Functions,  Next: Extending Rx,  Prev: Rx Constructs,  Up: Rx Notation
61276
6127734.3.3.2 Functions and macros using ‘rx’ regexps
61278................................................
61279
61280 -- Macro: rx rx-expr...
61281     Translate the RX-EXPRs to a string regexp, as if they were the body
61282     of a ‘(seq ...)’ form.  The ‘rx’ macro expands to a string
61283     constant, or, if ‘literal’ or ‘regexp’ forms are used, a Lisp
61284     expression that evaluates to a string.
61285
61286 -- Function: rx-to-string rx-expr &optional no-group
61287     Translate RX-EXPR to a string regexp which is returned.  If
61288     NO-GROUP is absent or nil, bracket the result in a non-capturing
61289     group, ‘\(?:...\)’, if necessary to ensure that a postfix operator
61290     appended to it will apply to the whole expression.
61291
61292     Arguments to ‘literal’ and ‘regexp’ forms in RX-EXPR must be string
61293     literals.
61294
61295   The ‘pcase’ macro can use ‘rx’ expressions as patterns directly;
61296*note rx in pcase::.
61297
61298   For mechanisms to add user-defined extensions to the ‘rx’ notation,
61299*note Extending Rx::.
61300
61301
61302File: elisp.info,  Node: Extending Rx,  Prev: Rx Functions,  Up: Rx Notation
61303
6130434.3.3.3 Defining new ‘rx’ forms
61305................................
61306
61307The ‘rx’ notation can be extended by defining new symbols and
61308parameterized forms in terms of other ‘rx’ expressions.  This is handy
61309for sharing parts between several regexps, and for making complex ones
61310easier to build and understand by putting them together from smaller
61311pieces.
61312
61313   For example, you could define ‘name’ to mean ‘(one-or-more letter)’,
61314and ‘(quoted X)’ to mean ‘(seq ?' X ?')’ for any X.  These forms could
61315then be used in ‘rx’ expressions like any other: ‘(rx (quoted name))’
61316would match a nonempty sequence of letters inside single quotes.
61317
61318   The Lisp macros below provide different ways of binding names to
61319definitions.  Common to all of them are the following rules:
61320
61321   • Built-in ‘rx’ forms, like ‘digit’ and ‘group’, cannot be redefined.
61322
61323   • The definitions live in a name space of their own, separate from
61324     that of Lisp variables.  There is thus no need to attach a suffix
61325     like ‘-regexp’ to names; they cannot collide with anything else.
61326
61327   • Definitions cannot refer to themselves recursively, directly or
61328     indirectly.  If you find yourself needing this, you want a parser,
61329     not a regular expression.
61330
61331   • Definitions are only ever expanded in calls to ‘rx’ or
61332     ‘rx-to-string’, not merely by their presence in definition macros.
61333     This means that the order of definitions doesn’t matter, even when
61334     they refer to each other, and that syntax errors only show up when
61335     they are used, not when they are defined.
61336
61337   • User-defined forms are allowed wherever arbitrary ‘rx’ expressions
61338     are expected; for example, in the body of a ‘zero-or-one’ form, but
61339     not inside ‘any’ or ‘category’ forms.  They are also allowed inside
61340     ‘not’ and ‘intersection’ forms.
61341
61342 -- Macro: rx-define name [arglist] rx-form
61343     Define NAME globally in all subsequent calls to ‘rx’ and
61344     ‘rx-to-string’.  If ARGLIST is absent, then NAME is defined as a
61345     plain symbol to be replaced with RX-FORM.  Example:
61346
61347          (rx-define haskell-comment (seq "--" (zero-or-more nonl)))
61348          (rx haskell-comment)
61349               ⇒ "--.*"
61350
61351     If ARGLIST is present, it must be a list of zero or more argument
61352     names, and NAME is then defined as a parameterized form.  When used
61353     in an ‘rx’ expression as ‘(NAME ARG...)’, each ARG will replace the
61354     corresponding argument name inside RX-FORM.
61355
61356     ARGLIST may end in ‘&rest’ and one final argument name, denoting a
61357     rest parameter.  The rest parameter will expand to all extra actual
61358     argument values not matched by any other parameter in ARGLIST,
61359     spliced into RX-FORM where it occurs.  Example:
61360
61361          (rx-define moan (x y &rest r) (seq x (one-or-more y) r "!"))
61362          (rx (moan "MOO" "A" "MEE" "OW"))
61363               ⇒ "MOOA+MEEOW!"
61364
61365     Since the definition is global, it is recommended to give NAME a
61366     package prefix to avoid name clashes with definitions elsewhere, as
61367     is usual when naming non-local variables and functions.
61368
61369 -- Macro: rx-let (bindings...) body...
61370     Make the ‘rx’ definitions in BINDINGS available locally for ‘rx’
61371     macro invocations in BODY, which is then evaluated.
61372
61373     Each element of BINDINGS is on the form ‘(NAME [ARGLIST] RX-FORM)’,
61374     where the parts have the same meaning as in ‘rx-define’ above.
61375     Example:
61376
61377          (rx-let ((comma-separated (item) (seq item (0+ "," item)))
61378                   (number (1+ digit))
61379                   (numbers (comma-separated number)))
61380            (re-search-forward (rx "(" numbers ")")))
61381
61382     The definitions are only available during the macro-expansion of
61383     BODY, and are thus not present during execution of compiled code.
61384
61385     ‘rx-let’ can be used not only inside a function, but also at top
61386     level to include global variable and function definitions that need
61387     to share a common set of ‘rx’ forms.  Since the names are local
61388     inside BODY, there is no need for any package prefixes.  Example:
61389
61390          (rx-let ((phone-number (seq (opt ?+) (1+ (any digit ?-)))))
61391            (defun find-next-phone-number ()
61392              (re-search-forward (rx phone-number)))
61393            (defun phone-number-p (string)
61394              (string-match-p (rx bos phone-number eos) string)))
61395
61396     The scope of the ‘rx-let’ bindings is lexical, which means that
61397     they are not visible outside BODY itself, even in functions called
61398     from BODY.
61399
61400 -- Macro: rx-let-eval bindings body...
61401     Evaluate BINDINGS to a list of bindings as in ‘rx-let’, and
61402     evaluate BODY with those bindings in effect for calls to
61403     ‘rx-to-string’.
61404
61405     This macro is similar to ‘rx-let’, except that the BINDINGS
61406     argument is evaluated (and thus needs to be quoted if it is a list
61407     literal), and the definitions are substituted at run time, which is
61408     required for ‘rx-to-string’ to work.  Example:
61409
61410          (rx-let-eval
61411              '((ponder (x) (seq "Where have all the " x " gone?")))
61412            (looking-at (rx-to-string
61413                         '(ponder (or "flowers" "young girls"
61414                                      "left socks")))))
61415
61416     Another difference from ‘rx-let’ is that the BINDINGS are
61417     dynamically scoped, and thus also available in functions called
61418     from BODY.  However, they are not visible inside functions defined
61419     in BODY.
61420
61421
61422File: elisp.info,  Node: Regexp Functions,  Prev: Rx Notation,  Up: Regular Expressions
61423
6142434.3.4 Regular Expression Functions
61425-----------------------------------
61426
61427These functions operate on regular expressions.
61428
61429 -- Function: regexp-quote string
61430     This function returns a regular expression whose only exact match
61431     is STRING.  Using this regular expression in ‘looking-at’ will
61432     succeed only if the next characters in the buffer are STRING; using
61433     it in a search function will succeed if the text being searched
61434     contains STRING.  *Note Regexp Search::.
61435
61436     This allows you to request an exact string match or search when
61437     calling a function that wants a regular expression.
61438
61439          (regexp-quote "^The cat$")
61440               ⇒ "\\^The cat\\$"
61441
61442     One use of ‘regexp-quote’ is to combine an exact string match with
61443     context described as a regular expression.  For example, this
61444     searches for the string that is the value of STRING, surrounded by
61445     whitespace:
61446
61447          (re-search-forward
61448           (concat "\\s-" (regexp-quote string) "\\s-"))
61449
61450     The returned string may be STRING itself if it does not contain any
61451     special characters.
61452
61453 -- Function: regexp-opt strings &optional paren
61454     This function returns an efficient regular expression that will
61455     match any of the strings in the list STRINGS.  This is useful when
61456     you need to make matching or searching as fast as possible—for
61457     example, for Font Lock mode(1).
61458
61459     If STRINGS is the empty list, the return value is a regexp that
61460     never matches anything.
61461
61462     The optional argument PAREN can be any of the following:
61463
61464     a string
61465          The resulting regexp is preceded by PAREN and followed by
61466          ‘\)’, e.g.  use ‘"\\(?1:"’ to produce an explicitly numbered
61467          group.
61468
61469     ‘words’
61470          The resulting regexp is surrounded by ‘\<\(’ and ‘\)\>’.
61471
61472     ‘symbols’
61473          The resulting regexp is surrounded by ‘\_<\(’ and ‘\)\_>’
61474          (this is often appropriate when matching programming-language
61475          keywords and the like).
61476
61477     non-‘nil’
61478          The resulting regexp is surrounded by ‘\(’ and ‘\)’.
61479
61480     ‘nil’
61481          The resulting regexp is surrounded by ‘\(?:’ and ‘\)’, if it
61482          is necessary to ensure that a postfix operator appended to it
61483          will apply to the whole expression.
61484
61485     The returned regexp is ordered in such a way that it will always
61486     match the longest string possible.
61487
61488     Up to reordering, the resulting regexp of ‘regexp-opt’ is
61489     equivalent to but usually more efficient than that of a simplified
61490     version:
61491
61492          (defun simplified-regexp-opt (strings &optional paren)
61493           (let ((parens
61494                  (cond
61495                   ((stringp paren)       (cons paren "\\)"))
61496                   ((eq paren 'words)    '("\\<\\(" . "\\)\\>"))
61497                   ((eq paren 'symbols) '("\\_<\\(" . "\\)\\_>"))
61498                   ((null paren)          '("\\(?:" . "\\)"))
61499                   (t                       '("\\(" . "\\)")))))
61500             (concat (car parens)
61501                     (mapconcat 'regexp-quote strings "\\|")
61502                     (cdr parens))))
61503
61504 -- Function: regexp-opt-depth regexp
61505     This function returns the total number of grouping constructs
61506     (parenthesized expressions) in REGEXP.  This does not include shy
61507     groups (*note Regexp Backslash::).
61508
61509 -- Function: regexp-opt-charset chars
61510     This function returns a regular expression matching a character in
61511     the list of characters CHARS.
61512
61513          (regexp-opt-charset '(?a ?b ?c ?d ?e))
61514               ⇒ "[a-e]"
61515
61516 -- Variable: regexp-unmatchable
61517     This variable contains a regexp that is guaranteed not to match any
61518     string at all.  It is particularly useful as default value for
61519     variables that may be set to a pattern that actually matches
61520     something.
61521
61522   ---------- Footnotes ----------
61523
61524   (1) Note that ‘regexp-opt’ does not guarantee that its result is
61525absolutely the most efficient form possible.  A hand-tuned regular
61526expression can sometimes be slightly more efficient, but is almost never
61527worth the effort.
61528
61529
61530File: elisp.info,  Node: Regexp Search,  Next: POSIX Regexps,  Prev: Regular Expressions,  Up: Searching and Matching
61531
6153234.4 Regular Expression Searching
61533=================================
61534
61535In GNU Emacs, you can search for the next match for a regular expression
61536(*note Syntax of Regexps::) either incrementally or not.  For
61537incremental search commands, see *note Regular Expression Search:
61538(emacs)Regexp Search.  Here we describe only the search functions useful
61539in programs.  The principal one is ‘re-search-forward’.
61540
61541   These search functions convert the regular expression to multibyte if
61542the buffer is multibyte; they convert the regular expression to unibyte
61543if the buffer is unibyte.  *Note Text Representations::.
61544
61545 -- Command: re-search-forward regexp &optional limit noerror count
61546     This function searches forward in the current buffer for a string
61547     of text that is matched by the regular expression REGEXP.  The
61548     function skips over any amount of text that is not matched by
61549     REGEXP, and leaves point at the end of the first match found.  It
61550     returns the new value of point.
61551
61552     If LIMIT is non-‘nil’, it must be a position in the current buffer.
61553     It specifies the upper bound to the search.  No match extending
61554     after that position is accepted.  If LIMIT is omitted or ‘nil’, it
61555     defaults to the end of the accessible portion of the buffer.
61556
61557     What ‘re-search-forward’ does when the search fails depends on the
61558     value of NOERROR:
61559
61560     ‘nil’
61561          Signal a ‘search-failed’ error.
61562     ‘t’
61563          Do nothing and return ‘nil’.
61564     anything else
61565          Move point to LIMIT (or the end of the accessible portion of
61566          the buffer) and return ‘nil’.
61567
61568     The argument NOERROR only affects valid searches which fail to find
61569     a match.  Invalid arguments cause errors regardless of NOERROR.
61570
61571     If COUNT is a positive number N, the search is done N times; each
61572     successive search starts at the end of the previous match.  If all
61573     these successive searches succeed, the function call succeeds,
61574     moving point and returning its new value.  Otherwise the function
61575     call fails, with results depending on the value of NOERROR, as
61576     described above.  If COUNT is a negative number −N, the search is
61577     done N times in the opposite (backward) direction.
61578
61579     In the following example, point is initially before the ‘T’.
61580     Evaluating the search call moves point to the end of that line
61581     (between the ‘t’ of ‘hat’ and the newline).
61582
61583          ---------- Buffer: foo ----------
61584          I read "★The cat in the hat
61585          comes back" twice.
61586          ---------- Buffer: foo ----------
61587
61588          (re-search-forward "[a-z]+" nil t 5)
61589               ⇒ 27
61590
61591          ---------- Buffer: foo ----------
61592          I read "The cat in the hat★
61593          comes back" twice.
61594          ---------- Buffer: foo ----------
61595
61596 -- Command: re-search-backward regexp &optional limit noerror count
61597     This function searches backward in the current buffer for a string
61598     of text that is matched by the regular expression REGEXP, leaving
61599     point at the beginning of the first text found.
61600
61601     This function is analogous to ‘re-search-forward’, but they are not
61602     simple mirror images.  ‘re-search-forward’ finds the match whose
61603     beginning is as close as possible to the starting point.  If
61604     ‘re-search-backward’ were a perfect mirror image, it would find the
61605     match whose end is as close as possible.  However, in fact it finds
61606     the match whose beginning is as close as possible (and yet ends
61607     before the starting point).  The reason for this is that matching a
61608     regular expression at a given spot always works from beginning to
61609     end, and starts at a specified beginning position.
61610
61611     A true mirror-image of ‘re-search-forward’ would require a special
61612     feature for matching regular expressions from end to beginning.
61613     It’s not worth the trouble of implementing that.
61614
61615 -- Function: string-match regexp string &optional start
61616     This function returns the index of the start of the first match for
61617     the regular expression REGEXP in STRING, or ‘nil’ if there is no
61618     match.  If START is non-‘nil’, the search starts at that index in
61619     STRING.
61620
61621     For example,
61622
61623          (string-match
61624           "quick" "The quick brown fox jumped quickly.")
61625               ⇒ 4
61626          (string-match
61627           "quick" "The quick brown fox jumped quickly." 8)
61628               ⇒ 27
61629
61630     The index of the first character of the string is 0, the index of
61631     the second character is 1, and so on.
61632
61633     If this function finds a match, the index of the first character
61634     beyond the match is available as ‘(match-end 0)’.  *Note Match
61635     Data::.
61636
61637          (string-match
61638           "quick" "The quick brown fox jumped quickly." 8)
61639               ⇒ 27
61640
61641          (match-end 0)
61642               ⇒ 32
61643
61644 -- Function: string-match-p regexp string &optional start
61645     This predicate function does what ‘string-match’ does, but it
61646     avoids modifying the match data.
61647
61648 -- Function: looking-at regexp
61649     This function determines whether the text in the current buffer
61650     directly following point matches the regular expression REGEXP.
61651     “Directly following” means precisely that: the search is “anchored”
61652     and it can succeed only starting with the first character following
61653     point.  The result is ‘t’ if so, ‘nil’ otherwise.
61654
61655     This function does not move point, but it does update the match
61656     data.  *Note Match Data::.  If you need to test for a match without
61657     modifying the match data, use ‘looking-at-p’, described below.
61658
61659     In this example, point is located directly before the ‘T’.  If it
61660     were anywhere else, the result would be ‘nil’.
61661
61662          ---------- Buffer: foo ----------
61663          I read "★The cat in the hat
61664          comes back" twice.
61665          ---------- Buffer: foo ----------
61666
61667          (looking-at "The cat in the hat$")
61668               ⇒ t
61669
61670 -- Function: looking-back regexp limit &optional greedy
61671     This function returns ‘t’ if REGEXP matches the text immediately
61672     before point (i.e., ending at point), and ‘nil’ otherwise.
61673
61674     Because regular expression matching works only going forward, this
61675     is implemented by searching backwards from point for a match that
61676     ends at point.  That can be quite slow if it has to search a long
61677     distance.  You can bound the time required by specifying a
61678     non-‘nil’ value for LIMIT, which says not to search before LIMIT.
61679     In this case, the match that is found must begin at or after LIMIT.
61680     Here’s an example:
61681
61682          ---------- Buffer: foo ----------
61683          I read "★The cat in the hat
61684          comes back" twice.
61685          ---------- Buffer: foo ----------
61686
61687          (looking-back "read \"" 3)
61688               ⇒ t
61689          (looking-back "read \"" 4)
61690               ⇒ nil
61691
61692     If GREEDY is non-‘nil’, this function extends the match backwards
61693     as far as possible, stopping when a single additional previous
61694     character cannot be part of a match for REGEXP.  When the match is
61695     extended, its starting position is allowed to occur before LIMIT.
61696
61697     As a general recommendation, try to avoid using ‘looking-back’
61698     wherever possible, since it is slow.  For this reason, there are no
61699     plans to add a ‘looking-back-p’ function.
61700
61701 -- Function: looking-at-p regexp
61702     This predicate function works like ‘looking-at’, but without
61703     updating the match data.
61704
61705 -- Variable: search-spaces-regexp
61706     If this variable is non-‘nil’, it should be a regular expression
61707     that says how to search for whitespace.  In that case, any group of
61708     spaces in a regular expression being searched for stands for use of
61709     this regular expression.  However, spaces inside of constructs such
61710     as ‘[...]’ and ‘*’, ‘+’, ‘?’ are not affected by
61711     ‘search-spaces-regexp’.
61712
61713     Since this variable affects all regular expression search and match
61714     constructs, you should bind it temporarily for as small as possible
61715     a part of the code.
61716
61717
61718File: elisp.info,  Node: POSIX Regexps,  Next: Match Data,  Prev: Regexp Search,  Up: Searching and Matching
61719
6172034.5 POSIX Regular Expression Searching
61721=======================================
61722
61723The usual regular expression functions do backtracking when necessary to
61724handle the ‘\|’ and repetition constructs, but they continue this only
61725until they find _some_ match.  Then they succeed and report the first
61726match found.
61727
61728   This section describes alternative search functions which perform the
61729full backtracking specified by the POSIX standard for regular expression
61730matching.  They continue backtracking until they have tried all
61731possibilities and found all matches, so they can report the longest
61732match, as required by POSIX.  This is much slower, so use these
61733functions only when you really need the longest match.
61734
61735   The POSIX search and match functions do not properly support the
61736non-greedy repetition operators (*note non-greedy: Regexp Special.).
61737This is because POSIX backtracking conflicts with the semantics of
61738non-greedy repetition.
61739
61740 -- Command: posix-search-forward regexp &optional limit noerror count
61741     This is like ‘re-search-forward’ except that it performs the full
61742     backtracking specified by the POSIX standard for regular expression
61743     matching.
61744
61745 -- Command: posix-search-backward regexp &optional limit noerror count
61746     This is like ‘re-search-backward’ except that it performs the full
61747     backtracking specified by the POSIX standard for regular expression
61748     matching.
61749
61750 -- Function: posix-looking-at regexp
61751     This is like ‘looking-at’ except that it performs the full
61752     backtracking specified by the POSIX standard for regular expression
61753     matching.
61754
61755 -- Function: posix-string-match regexp string &optional start
61756     This is like ‘string-match’ except that it performs the full
61757     backtracking specified by the POSIX standard for regular expression
61758     matching.
61759
61760
61761File: elisp.info,  Node: Match Data,  Next: Search and Replace,  Prev: POSIX Regexps,  Up: Searching and Matching
61762
6176334.6 The Match Data
61764===================
61765
61766Emacs keeps track of the start and end positions of the segments of text
61767found during a search; this is called the “match data”.  Thanks to the
61768match data, you can search for a complex pattern, such as a date in a
61769mail message, and then extract parts of the match under control of the
61770pattern.
61771
61772   Because the match data normally describe the most recent search only,
61773you must be careful not to do another search inadvertently between the
61774search you wish to refer back to and the use of the match data.  If you
61775can’t avoid another intervening search, you must save and restore the
61776match data around it, to prevent it from being overwritten.
61777
61778   Notice that all functions are allowed to overwrite the match data
61779unless they’re explicitly documented not to do so.  A consequence is
61780that functions that are run implicitly in the background (*note
61781Timers::, and *note Idle Timers::) should likely save and restore the
61782match data explicitly.
61783
61784* Menu:
61785
61786* Replacing Match::       Replacing a substring that was matched.
61787* Simple Match Data::     Accessing single items of match data,
61788                            such as where a particular subexpression started.
61789* Entire Match Data::     Accessing the entire match data at once, as a list.
61790* Saving Match Data::     Saving and restoring the match data.
61791
61792
61793File: elisp.info,  Node: Replacing Match,  Next: Simple Match Data,  Up: Match Data
61794
6179534.6.1 Replacing the Text that Matched
61796--------------------------------------
61797
61798This function replaces all or part of the text matched by the last
61799search.  It works by means of the match data.
61800
61801 -- Function: replace-match replacement &optional fixedcase literal
61802          string subexp
61803     This function performs a replacement operation on a buffer or
61804     string.
61805
61806     If you did the last search in a buffer, you should omit the STRING
61807     argument or specify ‘nil’ for it, and make sure that the current
61808     buffer is the one in which you performed the last search.  Then
61809     this function edits the buffer, replacing the matched text with
61810     REPLACEMENT.  It leaves point at the end of the replacement text.
61811
61812     If you performed the last search on a string, pass the same string
61813     as STRING.  Then this function returns a new string, in which the
61814     matched text is replaced by REPLACEMENT.
61815
61816     If FIXEDCASE is non-‘nil’, then ‘replace-match’ uses the
61817     replacement text without case conversion; otherwise, it converts
61818     the replacement text depending upon the capitalization of the text
61819     to be replaced.  If the original text is all upper case, this
61820     converts the replacement text to upper case.  If all words of the
61821     original text are capitalized, this capitalizes all the words of
61822     the replacement text.  If all the words are one-letter and they are
61823     all upper case, they are treated as capitalized words rather than
61824     all-upper-case words.
61825
61826     If LITERAL is non-‘nil’, then REPLACEMENT is inserted exactly as it
61827     is, the only alterations being case changes as needed.  If it is
61828     ‘nil’ (the default), then the character ‘\’ is treated specially.
61829     If a ‘\’ appears in REPLACEMENT, then it must be part of one of the
61830     following sequences:
61831
61832     ‘\&’
61833          This stands for the entire text being replaced.
61834
61835     ‘\N’, where N is a digit
61836          This stands for the text that matched the Nth subexpression in
61837          the original regexp.  Subexpressions are those expressions
61838          grouped inside ‘\(...\)’.  If the Nth subexpression never
61839          matched, an empty string is substituted.
61840
61841     ‘\\’
61842          This stands for a single ‘\’ in the replacement text.
61843
61844     ‘\?’
61845          This stands for itself (for compatibility with
61846          ‘replace-regexp’ and related commands; *note (emacs)Regexp
61847          Replace::).
61848
61849     Any other character following ‘\’ signals an error.
61850
61851     The substitutions performed by ‘\&’ and ‘\N’ occur after case
61852     conversion, if any.  Therefore, the strings they substitute are
61853     never case-converted.
61854
61855     If SUBEXP is non-‘nil’, that says to replace just subexpression
61856     number SUBEXP of the regexp that was matched, not the entire match.
61857     For example, after matching ‘foo \(ba*r\)’, calling ‘replace-match’
61858     with 1 as SUBEXP means to replace just the text that matched
61859     ‘\(ba*r\)’.
61860
61861 -- Function: match-substitute-replacement replacement &optional
61862          fixedcase literal string subexp
61863     This function returns the text that would be inserted into the
61864     buffer by ‘replace-match’, but without modifying the buffer.  It is
61865     useful if you want to present the user with actual replacement
61866     result, with constructs like ‘\N’ or ‘\&’ substituted with matched
61867     groups.  Arguments REPLACEMENT and optional FIXEDCASE, LITERAL,
61868     STRING and SUBEXP have the same meaning as for ‘replace-match’.
61869
61870
61871File: elisp.info,  Node: Simple Match Data,  Next: Entire Match Data,  Prev: Replacing Match,  Up: Match Data
61872
6187334.6.2 Simple Match Data Access
61874-------------------------------
61875
61876This section explains how to use the match data to find out what was
61877matched by the last search or match operation, if it succeeded.
61878
61879   You can ask about the entire matching text, or about a particular
61880parenthetical subexpression of a regular expression.  The COUNT argument
61881in the functions below specifies which.  If COUNT is zero, you are
61882asking about the entire match.  If COUNT is positive, it specifies which
61883subexpression you want.
61884
61885   Recall that the subexpressions of a regular expression are those
61886expressions grouped with escaped parentheses, ‘\(...\)’.  The COUNTth
61887subexpression is found by counting occurrences of ‘\(’ from the
61888beginning of the whole regular expression.  The first subexpression is
61889numbered 1, the second 2, and so on.  Only regular expressions can have
61890subexpressions—after a simple string search, the only information
61891available is about the entire match.
61892
61893   Every successful search sets the match data.  Therefore, you should
61894query the match data immediately after searching, before calling any
61895other function that might perform another search.  Alternatively, you
61896may save and restore the match data (*note Saving Match Data::) around
61897the call to functions that could perform another search.  Or use the
61898functions that explicitly do not modify the match data; e.g.,
61899‘string-match-p’.
61900
61901   A search which fails may or may not alter the match data.  In the
61902current implementation, it does not, but we may change it in the future.
61903Don’t try to rely on the value of the match data after a failing search.
61904
61905 -- Function: match-string count &optional in-string
61906     This function returns, as a string, the text matched in the last
61907     search or match operation.  It returns the entire text if COUNT is
61908     zero, or just the portion corresponding to the COUNTth
61909     parenthetical subexpression, if COUNT is positive.
61910
61911     If the last such operation was done against a string with
61912     ‘string-match’, then you should pass the same string as the
61913     argument IN-STRING.  After a buffer search or match, you should
61914     omit IN-STRING or pass ‘nil’ for it; but you should make sure that
61915     the current buffer when you call ‘match-string’ is the one in which
61916     you did the searching or matching.  Failure to follow this advice
61917     will lead to incorrect results.
61918
61919     The value is ‘nil’ if COUNT is out of range, or for a subexpression
61920     inside a ‘\|’ alternative that wasn’t used or a repetition that
61921     repeated zero times.
61922
61923 -- Function: match-string-no-properties count &optional in-string
61924     This function is like ‘match-string’ except that the result has no
61925     text properties.
61926
61927 -- Function: match-beginning count
61928     If the last regular expression search found a match, this function
61929     returns the position of the start of the matching text or of a
61930     subexpression of it.
61931
61932     If COUNT is zero, then the value is the position of the start of
61933     the entire match.  Otherwise, COUNT specifies a subexpression in
61934     the regular expression, and the value of the function is the
61935     starting position of the match for that subexpression.
61936
61937     The value is ‘nil’ for a subexpression inside a ‘\|’ alternative
61938     that wasn’t used or a repetition that repeated zero times.
61939
61940 -- Function: match-end count
61941     This function is like ‘match-beginning’ except that it returns the
61942     position of the end of the match, rather than the position of the
61943     beginning.
61944
61945   Here is an example of using the match data, with a comment showing
61946the positions within the text:
61947
61948     (string-match "\\(qu\\)\\(ick\\)"
61949                   "The quick fox jumped quickly.")
61950                   ;0123456789
61951          ⇒ 4
61952
61953     (match-string 0 "The quick fox jumped quickly.")
61954          ⇒ "quick"
61955     (match-string 1 "The quick fox jumped quickly.")
61956          ⇒ "qu"
61957     (match-string 2 "The quick fox jumped quickly.")
61958          ⇒ "ick"
61959
61960     (match-beginning 1)       ; The beginning of the match
61961          ⇒ 4                 ;   with ‘qu’ is at index 4.
61962
61963     (match-beginning 2)       ; The beginning of the match
61964          ⇒ 6                 ;   with ‘ick’ is at index 6.
61965
61966     (match-end 1)             ; The end of the match
61967          ⇒ 6                 ;   with ‘qu’ is at index 6.
61968
61969     (match-end 2)             ; The end of the match
61970          ⇒ 9                 ;   with ‘ick’ is at index 9.
61971
61972   Here is another example.  Point is initially located at the beginning
61973of the line.  Searching moves point to between the space and the word
61974‘in’.  The beginning of the entire match is at the 9th character of the
61975buffer (‘T’), and the beginning of the match for the first subexpression
61976is at the 13th character (‘c’).
61977
61978     (list
61979       (re-search-forward "The \\(cat \\)")
61980       (match-beginning 0)
61981       (match-beginning 1))
61982         ⇒ (17 9 13)
61983
61984     ---------- Buffer: foo ----------
61985     I read "The cat ★in the hat comes back" twice.
61986             ^   ^
61987             9  13
61988     ---------- Buffer: foo ----------
61989
61990(In this case, the index returned is a buffer position; the first
61991character of the buffer counts as 1.)
61992
61993
61994File: elisp.info,  Node: Entire Match Data,  Next: Saving Match Data,  Prev: Simple Match Data,  Up: Match Data
61995
6199634.6.3 Accessing the Entire Match Data
61997--------------------------------------
61998
61999The functions ‘match-data’ and ‘set-match-data’ read or write the entire
62000match data, all at once.
62001
62002 -- Function: match-data &optional integers reuse reseat
62003     This function returns a list of positions (markers or integers)
62004     that record all the information on the text that the last search
62005     matched.  Element zero is the position of the beginning of the
62006     match for the whole expression; element one is the position of the
62007     end of the match for the expression.  The next two elements are the
62008     positions of the beginning and end of the match for the first
62009     subexpression, and so on.  In general, element number 2N
62010     corresponds to ‘(match-beginning N)’; and element number 2N + 1
62011     corresponds to ‘(match-end N)’.
62012
62013     Normally all the elements are markers or ‘nil’, but if INTEGERS is
62014     non-‘nil’, that means to use integers instead of markers.  (In that
62015     case, the buffer itself is appended as an additional element at the
62016     end of the list, to facilitate complete restoration of the match
62017     data.)  If the last match was done on a string with ‘string-match’,
62018     then integers are always used, since markers can’t point into a
62019     string.
62020
62021     If REUSE is non-‘nil’, it should be a list.  In that case,
62022     ‘match-data’ stores the match data in REUSE.  That is, REUSE is
62023     destructively modified.  REUSE does not need to have the right
62024     length.  If it is not long enough to contain the match data, it is
62025     extended.  If it is too long, the length of REUSE stays the same,
62026     but the elements that were not used are set to ‘nil’.  The purpose
62027     of this feature is to reduce the need for garbage collection.
62028
62029     If RESEAT is non-‘nil’, all markers on the REUSE list are reseated
62030     to point to nowhere.
62031
62032     As always, there must be no possibility of intervening searches
62033     between the call to a search function and the call to ‘match-data’
62034     that is intended to access the match data for that search.
62035
62036          (match-data)
62037               ⇒  (#<marker at 9 in foo>
62038                    #<marker at 17 in foo>
62039                    #<marker at 13 in foo>
62040                    #<marker at 17 in foo>)
62041
62042 -- Function: set-match-data match-list &optional reseat
62043     This function sets the match data from the elements of MATCH-LIST,
62044     which should be a list that was the value of a previous call to
62045     ‘match-data’.  (More precisely, anything that has the same format
62046     will work.)
62047
62048     If MATCH-LIST refers to a buffer that doesn’t exist, you don’t get
62049     an error; that sets the match data in a meaningless but harmless
62050     way.
62051
62052     If RESEAT is non-‘nil’, all markers on the MATCH-LIST list are
62053     reseated to point to nowhere.
62054
62055     ‘store-match-data’ is a semi-obsolete alias for ‘set-match-data’.
62056
62057
62058File: elisp.info,  Node: Saving Match Data,  Prev: Entire Match Data,  Up: Match Data
62059
6206034.6.4 Saving and Restoring the Match Data
62061------------------------------------------
62062
62063When you call a function that may search, you may need to save and
62064restore the match data around that call, if you want to preserve the
62065match data from an earlier search for later use.  Here is an example
62066that shows the problem that arises if you fail to save the match data:
62067
62068     (re-search-forward "The \\(cat \\)")
62069          ⇒ 48
62070     (foo)                   ; ‘foo’ does more searching.
62071     (match-end 0)
62072          ⇒ 61              ; Unexpected result—not 48!
62073
62074   You can save and restore the match data with ‘save-match-data’:
62075
62076 -- Macro: save-match-data body...
62077     This macro executes BODY, saving and restoring the match data
62078     around it.  The return value is the value of the last form in BODY.
62079
62080   You could use ‘set-match-data’ together with ‘match-data’ to imitate
62081the effect of the special form ‘save-match-data’.  Here is how:
62082
62083     (let ((data (match-data)))
62084       (unwind-protect
62085           ...   ; Ok to change the original match data.
62086         (set-match-data data)))
62087
62088   Emacs automatically saves and restores the match data when it runs
62089process filter functions (*note Filter Functions::) and process
62090sentinels (*note Sentinels::).
62091
62092
62093File: elisp.info,  Node: Search and Replace,  Next: Standard Regexps,  Prev: Match Data,  Up: Searching and Matching
62094
6209534.7 Search and Replace
62096=======================
62097
62098If you want to find all matches for a regexp in part of the buffer, and
62099replace them, the best way is to write an explicit loop using
62100‘re-search-forward’ and ‘replace-match’, like this:
62101
62102     (while (re-search-forward "foo[ \t]+bar" nil t)
62103       (replace-match "foobar"))
62104
62105*Note Replacing the Text that Matched: Replacing Match, for a
62106description of ‘replace-match’.
62107
62108   However, replacing matches in a string is more complex, especially if
62109you want to do it efficiently.  So Emacs provides a function to do this.
62110
62111 -- Function: replace-regexp-in-string regexp rep string &optional
62112          fixedcase literal subexp start
62113     This function copies STRING and searches it for matches for REGEXP,
62114     and replaces them with REP.  It returns the modified copy.  If
62115     START is non-‘nil’, the search for matches starts at that index in
62116     STRING, and the returned value does not include the first START
62117     characters of STRING.  To get the whole transformed string,
62118     concatenate the first START characters of STRING with the return
62119     value.
62120
62121     This function uses ‘replace-match’ to do the replacement, and it
62122     passes the optional arguments FIXEDCASE, LITERAL and SUBEXP along
62123     to ‘replace-match’.
62124
62125     Instead of a string, REP can be a function.  In that case,
62126     ‘replace-regexp-in-string’ calls REP for each match, passing the
62127     text of the match as its sole argument.  It collects the value REP
62128     returns and passes that to ‘replace-match’ as the replacement
62129     string.  The match data at this point are the result of matching
62130     REGEXP against a substring of STRING.
62131
62132   If you want to write a command along the lines of ‘query-replace’,
62133you can use ‘perform-replace’ to do the work.
62134
62135 -- Function: perform-replace from-string replacements query-flag
62136          regexp-flag delimited-flag &optional repeat-count map start
62137          end backward region-noncontiguous-p
62138     This function is the guts of ‘query-replace’ and related commands.
62139     It searches for occurrences of FROM-STRING in the text between
62140     positions START and END and replaces some or all of them.  If START
62141     is ‘nil’ (or omitted), point is used instead, and the end of the
62142     buffer’s accessible portion is used for END.  (If the optional
62143     argument BACKWARD is non-‘nil’, the search starts at END and goes
62144     backward.)
62145
62146     If QUERY-FLAG is ‘nil’, it replaces all occurrences; otherwise, it
62147     asks the user what to do about each one.
62148
62149     If REGEXP-FLAG is non-‘nil’, then FROM-STRING is considered a
62150     regular expression; otherwise, it must match literally.  If
62151     DELIMITED-FLAG is non-‘nil’, then only replacements surrounded by
62152     word boundaries are considered.
62153
62154     The argument REPLACEMENTS specifies what to replace occurrences
62155     with.  If it is a string, that string is used.  It can also be a
62156     list of strings, to be used in cyclic order.
62157
62158     If REPLACEMENTS is a cons cell, ‘(FUNCTION . DATA)’, this means to
62159     call FUNCTION after each match to get the replacement text.  This
62160     function is called with two arguments: DATA, and the number of
62161     replacements already made.
62162
62163     If REPEAT-COUNT is non-‘nil’, it should be an integer.  Then it
62164     specifies how many times to use each of the strings in the
62165     REPLACEMENTS list before advancing cyclically to the next one.
62166
62167     If FROM-STRING contains upper-case letters, then ‘perform-replace’
62168     binds ‘case-fold-search’ to ‘nil’, and it uses the REPLACEMENTS
62169     without altering their case.
62170
62171     Normally, the keymap ‘query-replace-map’ defines the possible user
62172     responses for queries.  The argument MAP, if non-‘nil’, specifies a
62173     keymap to use instead of ‘query-replace-map’.
62174
62175     Non-‘nil’ REGION-NONCONTIGUOUS-P means that the region between
62176     START and END is composed of noncontiguous pieces.  The most common
62177     example of this is a rectangular region, where the pieces are
62178     separated by newline characters.
62179
62180     This function uses one of two functions to search for the next
62181     occurrence of FROM-STRING.  These functions are specified by the
62182     values of two variables: ‘replace-re-search-function’ and
62183     ‘replace-search-function’.  The former is called when the argument
62184     REGEXP-FLAG is non-‘nil’, the latter when it is ‘nil’.
62185
62186 -- Variable: query-replace-map
62187     This variable holds a special keymap that defines the valid user
62188     responses for ‘perform-replace’ and the commands that use it, as
62189     well as ‘y-or-n-p’ and ‘map-y-or-n-p’.  This map is unusual in two
62190     ways:
62191
62192        • The key bindings are not commands, just symbols that are
62193          meaningful to the functions that use this map.
62194
62195        • Prefix keys are not supported; each key binding must be for a
62196          single-event key sequence.  This is because the functions
62197          don’t use ‘read-key-sequence’ to get the input; instead, they
62198          read a single event and look it up “by hand”.
62199
62200   Here are the meaningful bindings for ‘query-replace-map’.  Several of
62201them are meaningful only for ‘query-replace’ and friends.
62202
62203‘act’
62204     Do take the action being considered—in other words, “yes”.
62205
62206‘skip’
62207     Do not take action for this question—in other words, “no”.
62208
62209‘exit’
62210     Answer this question “no”, and give up on the entire series of
62211     questions, assuming that the answers will be “no”.
62212
62213‘exit-prefix’
62214     Like ‘exit’, but add the key that was pressed to
62215     ‘unread-command-events’ (*note Event Input Misc::).
62216
62217‘act-and-exit’
62218     Answer this question “yes”, and give up on the entire series of
62219     questions, assuming that subsequent answers will be “no”.
62220
62221‘act-and-show’
62222     Answer this question “yes”, but show the results—don’t advance yet
62223     to the next question.
62224
62225‘automatic’
62226     Answer this question and all subsequent questions in the series
62227     with “yes”, without further user interaction.
62228
62229‘backup’
62230     Move back to the previous place that a question was asked about.
62231
62232‘undo’
62233     Undo last replacement and move back to the place where that
62234     replacement was performed.
62235
62236‘undo-all’
62237     Undo all replacements and move back to the place where the first
62238     replacement was performed.
62239
62240‘edit’
62241     Enter a recursive edit to deal with this question—instead of any
62242     other action that would normally be taken.
62243
62244‘edit-replacement’
62245     Edit the replacement for this question in the minibuffer.
62246
62247‘delete-and-edit’
62248     Delete the text being considered, then enter a recursive edit to
62249     replace it.
62250
62251‘recenter’
62252‘scroll-up’
62253‘scroll-down’
62254‘scroll-other-window’
62255‘scroll-other-window-down’
62256     Perform the specified window scroll operation, then ask the same
62257     question again.  Only ‘y-or-n-p’ and related functions use this
62258     answer.
62259
62260‘quit’
62261     Perform a quit right away.  Only ‘y-or-n-p’ and related functions
62262     use this answer.
62263
62264‘help’
62265     Display some help, then ask again.
62266
62267 -- Variable: multi-query-replace-map
62268     This variable holds a keymap that extends ‘query-replace-map’ by
62269     providing additional keybindings that are useful in multi-buffer
62270     replacements.  The additional bindings are:
62271
62272     ‘automatic-all’
62273          Answer this question and all subsequent questions in the
62274          series with “yes”, without further user interaction, for all
62275          remaining buffers.
62276
62277     ‘exit-current’
62278          Answer this question “no”, and give up on the entire series of
62279          questions for the current buffer.  Continue to the next buffer
62280          in the sequence.
62281
62282 -- Variable: replace-search-function
62283     This variable specifies a function that ‘perform-replace’ calls to
62284     search for the next string to replace.  Its default value is
62285     ‘search-forward’.  Any other value should name a function of 3
62286     arguments: the first 3 arguments of ‘search-forward’ (*note String
62287     Search::).
62288
62289 -- Variable: replace-re-search-function
62290     This variable specifies a function that ‘perform-replace’ calls to
62291     search for the next regexp to replace.  Its default value is
62292     ‘re-search-forward’.  Any other value should name a function of 3
62293     arguments: the first 3 arguments of ‘re-search-forward’ (*note
62294     Regexp Search::).
62295
62296
62297File: elisp.info,  Node: Standard Regexps,  Prev: Search and Replace,  Up: Searching and Matching
62298
6229934.8 Standard Regular Expressions Used in Editing
62300=================================================
62301
62302This section describes some variables that hold regular expressions used
62303for certain purposes in editing:
62304
62305 -- User Option: page-delimiter
62306     This is the regular expression describing line-beginnings that
62307     separate pages.  The default value is ‘"^\014"’ (i.e., ‘"^^L"’ or
62308     ‘"^\C-l"’); this matches a line that starts with a formfeed
62309     character.
62310
62311   The following two regular expressions should _not_ assume the match
62312always starts at the beginning of a line; they should not use ‘^’ to
62313anchor the match.  Most often, the paragraph commands do check for a
62314match only at the beginning of a line, which means that ‘^’ would be
62315superfluous.  When there is a nonzero left margin, they accept matches
62316that start after the left margin.  In that case, a ‘^’ would be
62317incorrect.  However, a ‘^’ is harmless in modes where a left margin is
62318never used.
62319
62320 -- User Option: paragraph-separate
62321     This is the regular expression for recognizing the beginning of a
62322     line that separates paragraphs.  (If you change this, you may have
62323     to change ‘paragraph-start’ also.)  The default value is
62324     ‘"[ \t\f]*$"’, which matches a line that consists entirely of
62325     spaces, tabs, and form feeds (after its left margin).
62326
62327 -- User Option: paragraph-start
62328     This is the regular expression for recognizing the beginning of a
62329     line that starts _or_ separates paragraphs.  The default value is
62330     ‘"\f\\|[ \t]*$"’, which matches a line containing only whitespace
62331     or starting with a form feed (after its left margin).
62332
62333 -- User Option: sentence-end
62334     If non-‘nil’, the value should be a regular expression describing
62335     the end of a sentence, including the whitespace following the
62336     sentence.  (All paragraph boundaries also end sentences,
62337     regardless.)
62338
62339     If the value is ‘nil’, as it is by default, then the function
62340     ‘sentence-end’ constructs the regexp.  That is why you should
62341     always call the function ‘sentence-end’ to obtain the regexp to be
62342     used to recognize the end of a sentence.
62343
62344 -- Function: sentence-end
62345     This function returns the value of the variable ‘sentence-end’, if
62346     non-‘nil’.  Otherwise it returns a default value based on the
62347     values of the variables ‘sentence-end-double-space’ (*note
62348     Definition of sentence-end-double-space::),
62349     ‘sentence-end-without-period’, and ‘sentence-end-without-space’.
62350
62351
62352File: elisp.info,  Node: Syntax Tables,  Next: Abbrevs,  Prev: Searching and Matching,  Up: Top
62353
6235435 Syntax Tables
62355****************
62356
62357A “syntax table” specifies the syntactic role of each character in a
62358buffer.  It can be used to determine where words, symbols, and other
62359syntactic constructs begin and end.  This information is used by many
62360Emacs facilities, including Font Lock mode (*note Font Lock Mode::) and
62361the various complex movement commands (*note Motion::).
62362
62363* Menu:
62364
62365* Basics: Syntax Basics.     Basic concepts of syntax tables.
62366* Syntax Descriptors::       How characters are classified.
62367* Syntax Table Functions::   How to create, examine and alter syntax tables.
62368* Syntax Properties::        Overriding syntax with text properties.
62369* Motion and Syntax::        Moving over characters with certain syntaxes.
62370* Parsing Expressions::      Parsing balanced expressions
62371                                using the syntax table.
62372* Syntax Table Internals::   How syntax table information is stored.
62373* Categories::               Another way of classifying character syntax.
62374
62375
62376File: elisp.info,  Node: Syntax Basics,  Next: Syntax Descriptors,  Up: Syntax Tables
62377
6237835.1 Syntax Table Concepts
62379==========================
62380
62381A syntax table is a data structure which can be used to look up the
62382“syntax class” and other syntactic properties of each character.  Syntax
62383tables are used by Lisp programs for scanning and moving across text.
62384
62385   Internally, a syntax table is a char-table (*note Char-Tables::).
62386The element at index C describes the character with code C; its value is
62387a cons cell which specifies the syntax of the character in question.
62388*Note Syntax Table Internals::, for details.  However, instead of using
62389‘aset’ and ‘aref’ to modify and inspect syntax table contents, you
62390should usually use the higher-level functions ‘char-syntax’ and
62391‘modify-syntax-entry’, which are described in *note Syntax Table
62392Functions::.
62393
62394 -- Function: syntax-table-p object
62395     This function returns ‘t’ if OBJECT is a syntax table.
62396
62397   Each buffer has its own major mode, and each major mode has its own
62398idea of the syntax class of various characters.  For example, in Lisp
62399mode, the character ‘;’ begins a comment, but in C mode, it terminates a
62400statement.  To support these variations, the syntax table is local to
62401each buffer.  Typically, each major mode has its own syntax table, which
62402it installs in all buffers that use that mode.  For example, the
62403variable ‘emacs-lisp-mode-syntax-table’ holds the syntax table used by
62404Emacs Lisp mode, and ‘c-mode-syntax-table’ holds the syntax table used
62405by C mode.  Changing a major mode’s syntax table alters the syntax in
62406all of that mode’s buffers, as well as in any buffers subsequently put
62407in that mode.  Occasionally, several similar modes share one syntax
62408table.  *Note Example Major Modes::, for an example of how to set up a
62409syntax table.
62410
62411   A syntax table can “inherit” from another syntax table, which is
62412called its “parent syntax table”.  A syntax table can leave the syntax
62413class of some characters unspecified, by giving them the “inherit”
62414syntax class; such a character then acquires the syntax class specified
62415by the parent syntax table (*note Syntax Class Table::).  Emacs defines
62416a “standard syntax table”, which is the default parent syntax table, and
62417is also the syntax table used by Fundamental mode.
62418
62419 -- Function: standard-syntax-table
62420     This function returns the standard syntax table, which is the
62421     syntax table used in Fundamental mode.
62422
62423   Syntax tables are not used by the Emacs Lisp reader, which has its
62424own built-in syntactic rules which cannot be changed.  (Some Lisp
62425systems provide ways to redefine the read syntax, but we decided to
62426leave this feature out of Emacs Lisp for simplicity.)
62427
62428
62429File: elisp.info,  Node: Syntax Descriptors,  Next: Syntax Table Functions,  Prev: Syntax Basics,  Up: Syntax Tables
62430
6243135.2 Syntax Descriptors
62432=======================
62433
62434The “syntax class” of a character describes its syntactic role.  Each
62435syntax table specifies the syntax class of each character.  There is no
62436necessary relationship between the class of a character in one syntax
62437table and its class in any other table.
62438
62439   Each syntax class is designated by a mnemonic character, which serves
62440as the name of the class when you need to specify a class.  Usually,
62441this designator character is one that is often assigned that class;
62442however, its meaning as a designator is unvarying and independent of
62443what syntax that character currently has.  Thus, ‘\’ as a designator
62444character always stands for escape character syntax, regardless of
62445whether the ‘\’ character actually has that syntax in the current syntax
62446table.  *Note Syntax Class Table::, for a list of syntax classes and
62447their designator characters.
62448
62449   A “syntax descriptor” is a Lisp string that describes the syntax
62450class and other syntactic properties of a character.  When you want to
62451modify the syntax of a character, that is done by calling the function
62452‘modify-syntax-entry’ and passing a syntax descriptor as one of its
62453arguments (*note Syntax Table Functions::).
62454
62455   The first character in a syntax descriptor must be a syntax class
62456designator character.  The second character, if present, specifies a
62457matching character (e.g., in Lisp, the matching character for ‘(’ is
62458‘)’); a space specifies that there is no matching character.  Then come
62459characters specifying additional syntax properties (*note Syntax
62460Flags::).
62461
62462   If no matching character or flags are needed, only one character
62463(specifying the syntax class) is sufficient.
62464
62465   For example, the syntax descriptor for the character ‘*’ in C mode is
62466‘". 23"’ (i.e., punctuation, matching character slot unused, second
62467character of a comment-starter, first character of a comment-ender), and
62468the entry for ‘/’ is ‘. 14’ (i.e., punctuation, matching character slot
62469unused, first character of a comment-starter, second character of a
62470comment-ender).
62471
62472   Emacs also defines “raw syntax descriptors”, which are used to
62473describe syntax classes at a lower level.  *Note Syntax Table
62474Internals::.
62475
62476* Menu:
62477
62478* Syntax Class Table::      Table of syntax classes.
62479* Syntax Flags::            Additional flags each character can have.
62480
62481
62482File: elisp.info,  Node: Syntax Class Table,  Next: Syntax Flags,  Up: Syntax Descriptors
62483
6248435.2.1 Table of Syntax Classes
62485------------------------------
62486
62487Here is a table of syntax classes, the characters that designate them,
62488their meanings, and examples of their use.
62489
62490Whitespace characters: ‘ ’ or ‘-’
62491     Characters that separate symbols and words from each other.
62492     Typically, whitespace characters have no other syntactic
62493     significance, and multiple whitespace characters are syntactically
62494     equivalent to a single one.  Space, tab, and formfeed are
62495     classified as whitespace in almost all major modes.
62496
62497     This syntax class can be designated by either ‘ ’ or ‘-’.  Both
62498     designators are equivalent.
62499
62500Word constituents: ‘w’
62501     Parts of words in human languages.  These are typically used in
62502     variable and command names in programs.  All upper- and lower-case
62503     letters, and the digits, are typically word constituents.
62504
62505Symbol constituents: ‘_’
62506     Extra characters used in variable and command names along with word
62507     constituents.  Examples include the characters ‘$&*+-_<>’ in Lisp
62508     mode, which may be part of a symbol name even though they are not
62509     part of English words.  In standard C, the only
62510     non-word-constituent character that is valid in symbols is
62511     underscore (‘_’).
62512
62513Punctuation characters: ‘.’
62514     Characters used as punctuation in a human language, or used in a
62515     programming language to separate symbols from one another.  Some
62516     programming language modes, such as Emacs Lisp mode, have no
62517     characters in this class since the few characters that are not
62518     symbol or word constituents all have other uses.  Other programming
62519     language modes, such as C mode, use punctuation syntax for
62520     operators.
62521
62522Open parenthesis characters: ‘(’
62523Close parenthesis characters: ‘)’
62524     Characters used in dissimilar pairs to surround sentences or
62525     expressions.  Such a grouping is begun with an open parenthesis
62526     character and terminated with a close.  Each open parenthesis
62527     character matches a particular close parenthesis character, and
62528     vice versa.  Normally, Emacs indicates momentarily the matching
62529     open parenthesis when you insert a close parenthesis.  *Note
62530     Blinking::.
62531
62532     In human languages, and in C code, the parenthesis pairs are ‘()’,
62533     ‘[]’, and ‘{}’.  In Emacs Lisp, the delimiters for lists and
62534     vectors (‘()’ and ‘[]’) are classified as parenthesis characters.
62535
62536String quotes: ‘"’
62537     Characters used to delimit string constants.  The same string quote
62538     character appears at the beginning and the end of a string.  Such
62539     quoted strings do not nest.
62540
62541     The parsing facilities of Emacs consider a string as a single
62542     token.  The usual syntactic meanings of the characters in the
62543     string are suppressed.
62544
62545     The Lisp modes have two string quote characters: double-quote (‘"’)
62546     and vertical bar (‘|’).  ‘|’ is not used in Emacs Lisp, but it is
62547     used in Common Lisp.  C also has two string quote characters:
62548     double-quote for strings, and apostrophe (‘'’) for character
62549     constants.
62550
62551     Human text has no string quote characters.  We do not want
62552     quotation marks to turn off the usual syntactic properties of other
62553     characters in the quotation.
62554
62555Escape-syntax characters: ‘\’
62556     Characters that start an escape sequence, such as is used in string
62557     and character constants.  The character ‘\’ belongs to this class
62558     in both C and Lisp.  (In C, it is used thus only inside strings,
62559     but it turns out to cause no trouble to treat it this way
62560     throughout C code.)
62561
62562     Characters in this class count as part of words if
62563     ‘words-include-escapes’ is non-‘nil’.  *Note Word Motion::.
62564
62565Character quotes: ‘/’
62566     Characters used to quote the following character so that it loses
62567     its normal syntactic meaning.  This differs from an escape
62568     character in that only the character immediately following is ever
62569     affected.
62570
62571     Characters in this class count as part of words if
62572     ‘words-include-escapes’ is non-‘nil’.  *Note Word Motion::.
62573
62574     This class is used for backslash in TeX mode.
62575
62576Paired delimiters: ‘$’
62577     Similar to string quote characters, except that the syntactic
62578     properties of the characters between the delimiters are not
62579     suppressed.  Only TeX mode uses a paired delimiter presently—the
62580     ‘$’ that both enters and leaves math mode.
62581
62582Expression prefixes: ‘'’
62583     Characters used for syntactic operators that are considered as part
62584     of an expression if they appear next to one.  In Lisp modes, these
62585     characters include the apostrophe, ‘'’ (used for quoting), the
62586     comma, ‘,’ (used in macros), and ‘#’ (used in the read syntax for
62587     certain data types).
62588
62589Comment starters: ‘<’
62590Comment enders: ‘>’
62591     Characters used in various languages to delimit comments.  Human
62592     text has no comment characters.  In Lisp, the semicolon (‘;’)
62593     starts a comment and a newline or formfeed ends one.
62594
62595Inherit standard syntax: ‘@’
62596     This syntax class does not specify a particular syntax.  It says to
62597     look in the standard syntax table to find the syntax of this
62598     character.
62599
62600Generic comment delimiters: ‘!’
62601     (This syntax class is also known as “comment-fence”.)  Characters
62602     that start or end a special kind of comment.  _Any_ generic comment
62603     delimiter matches _any_ generic comment delimiter, but they cannot
62604     match a comment starter or comment ender; generic comment
62605     delimiters can only match each other.
62606
62607     This syntax class is primarily meant for use with the
62608     ‘syntax-table’ text property (*note Syntax Properties::).  You can
62609     mark any range of characters as forming a comment, by giving the
62610     first and last characters of the range ‘syntax-table’ properties
62611     identifying them as generic comment delimiters.
62612
62613Generic string delimiters: ‘|’
62614     (This syntax class is also known as “string-fence”.)  Characters
62615     that start or end a string.  This class differs from the string
62616     quote class in that _any_ generic string delimiter can match any
62617     other generic string delimiter; but they do not match ordinary
62618     string quote characters.
62619
62620     This syntax class is primarily meant for use with the
62621     ‘syntax-table’ text property (*note Syntax Properties::).  You can
62622     mark any range of characters as forming a string constant, by
62623     giving the first and last characters of the range ‘syntax-table’
62624     properties identifying them as generic string delimiters.
62625
62626
62627File: elisp.info,  Node: Syntax Flags,  Prev: Syntax Class Table,  Up: Syntax Descriptors
62628
6262935.2.2 Syntax Flags
62630-------------------
62631
62632In addition to the classes, entries for characters in a syntax table can
62633specify flags.  There are eight possible flags, represented by the
62634characters ‘1’, ‘2’, ‘3’, ‘4’, ‘b’, ‘c’, ‘n’, and ‘p’.
62635
62636   All the flags except ‘p’ are used to describe comment delimiters.
62637The digit flags are used for comment delimiters made up of 2 characters.
62638They indicate that a character can _also_ be part of a comment sequence,
62639in addition to the syntactic properties associated with its character
62640class.  The flags are independent of the class and each other for the
62641sake of characters such as ‘*’ in C mode, which is a punctuation
62642character, _and_ the second character of a start-of-comment sequence
62643(‘/*’), _and_ the first character of an end-of-comment sequence (‘*/’).
62644The flags ‘b’, ‘c’, and ‘n’ are used to qualify the corresponding
62645comment delimiter.
62646
62647   Here is a table of the possible flags for a character C, and what
62648they mean:
62649
62650   • ‘1’ means C is the start of a two-character comment-start sequence.
62651
62652   • ‘2’ means C is the second character of such a sequence.
62653
62654   • ‘3’ means C is the start of a two-character comment-end sequence.
62655
62656   • ‘4’ means C is the second character of such a sequence.
62657
62658   • ‘b’ means that C as a comment delimiter belongs to the alternative
62659     “b” comment style.  For a two-character comment starter, this flag
62660     is only significant on the second char, and for a 2-character
62661     comment ender it is only significant on the first char.
62662
62663   • ‘c’ means that C as a comment delimiter belongs to the alternative
62664     “c” comment style.  For a two-character comment delimiter, ‘c’ on
62665     either character makes it of style “c”.
62666
62667   • ‘n’ on a comment delimiter character specifies that this kind of
62668     comment can be nested.  Inside such a comment, only comments of the
62669     same style will be recognized.  For a two-character comment
62670     delimiter, ‘n’ on either character makes it nestable.
62671
62672     Emacs supports several comment styles simultaneously in any one
62673     syntax table.  A comment style is a set of flags ‘b’, ‘c’, and ‘n’,
62674     so there can be up to 8 different comment styles, each one named by
62675     the set of its flags.  Each comment delimiter has a style and only
62676     matches comment delimiters of the same style.  Thus if a comment
62677     starts with the comment-start sequence of style “bn”, it will
62678     extend until the next matching comment-end sequence of style “bn”.
62679     When the set of flags has neither flag ‘b’ nor flag ‘c’ set, the
62680     resulting style is called the “a” style.
62681
62682     The appropriate comment syntax settings for C++ can be as follows:
62683
62684     ‘/’
62685          ‘124’
62686     ‘*’
62687          ‘23b’
62688     newline
62689          ‘>’
62690
62691     This defines four comment-delimiting sequences:
62692
62693     ‘/*’
62694          This is a comment-start sequence for “b” style because the
62695          second character, ‘*’, has the ‘b’ flag.
62696
62697     ‘//’
62698          This is a comment-start sequence for “a” style because the
62699          second character, ‘/’, does not have the ‘b’ flag.
62700
62701     ‘*/’
62702          This is a comment-end sequence for “b” style because the first
62703          character, ‘*’, has the ‘b’ flag.
62704
62705     newline
62706          This is a comment-end sequence for “a” style, because the
62707          newline character does not have the ‘b’ flag.
62708
62709   • ‘p’ identifies an additional prefix character for Lisp syntax.
62710     These characters are treated as whitespace when they appear between
62711     expressions.  When they appear within an expression, they are
62712     handled according to their usual syntax classes.
62713
62714     The function ‘backward-prefix-chars’ moves back over these
62715     characters, as well as over characters whose primary syntax class
62716     is prefix (‘'’).  *Note Motion and Syntax::.
62717
62718
62719File: elisp.info,  Node: Syntax Table Functions,  Next: Syntax Properties,  Prev: Syntax Descriptors,  Up: Syntax Tables
62720
6272135.3 Syntax Table Functions
62722===========================
62723
62724In this section we describe functions for creating, accessing and
62725altering syntax tables.
62726
62727 -- Function: make-syntax-table &optional table
62728     This function creates a new syntax table.  If TABLE is non-‘nil’,
62729     the parent of the new syntax table is TABLE; otherwise, the parent
62730     is the standard syntax table.
62731
62732     In the new syntax table, all characters are initially given the
62733     “inherit” (‘@’) syntax class, i.e., their syntax is inherited from
62734     the parent table (*note Syntax Class Table::).
62735
62736 -- Function: copy-syntax-table &optional table
62737     This function constructs a copy of TABLE and returns it.  If TABLE
62738     is omitted or ‘nil’, it returns a copy of the standard syntax
62739     table.  Otherwise, an error is signaled if TABLE is not a syntax
62740     table.
62741
62742 -- Command: modify-syntax-entry char syntax-descriptor &optional table
62743     This function sets the syntax entry for CHAR according to
62744     SYNTAX-DESCRIPTOR.  CHAR must be a character, or a cons cell of the
62745     form ‘(MIN . MAX)’; in the latter case, the function sets the
62746     syntax entries for all characters in the range between MIN and MAX,
62747     inclusive.
62748
62749     The syntax is changed only for TABLE, which defaults to the current
62750     buffer’s syntax table, and not in any other syntax table.
62751
62752     The argument SYNTAX-DESCRIPTOR is a syntax descriptor, i.e., a
62753     string whose first character is a syntax class designator and whose
62754     second and subsequent characters optionally specify a matching
62755     character and syntax flags.  *Note Syntax Descriptors::.  An error
62756     is signaled if SYNTAX-DESCRIPTOR is not a valid syntax descriptor.
62757
62758     This function always returns ‘nil’.  The old syntax information in
62759     the table for this character is discarded.
62760
62761     Examples:
62762
62763          ;; Put the space character in class whitespace.
62764          (modify-syntax-entry ?\s " ")
62765               ⇒ nil
62766
62767          ;; Make ‘$’ an open parenthesis character,
62768          ;;   with ‘^’ as its matching close.
62769          (modify-syntax-entry ?$ "(^")
62770               ⇒ nil
62771
62772          ;; Make ‘^’ a close parenthesis character,
62773          ;;   with ‘$’ as its matching open.
62774          (modify-syntax-entry ?^ ")$")
62775               ⇒ nil
62776
62777          ;; Make ‘/’ a punctuation character,
62778          ;;   the first character of a start-comment sequence,
62779          ;;   and the second character of an end-comment sequence.
62780          ;;   This is used in C mode.
62781          (modify-syntax-entry ?/ ". 14")
62782               ⇒ nil
62783
62784 -- Function: char-syntax character
62785     This function returns the syntax class of CHARACTER, represented by
62786     its designator character (*note Syntax Class Table::).  This
62787     returns _only_ the class, not its matching character or syntax
62788     flags.
62789
62790     The following examples apply to C mode.  (We use ‘string’ to make
62791     it easier to see the character returned by ‘char-syntax’.)
62792
62793          ;; Space characters have whitespace syntax class.
62794          (string (char-syntax ?\s))
62795               ⇒ " "
62796
62797          ;; Forward slash characters have punctuation syntax.
62798          ;; Note that this char-syntax call does not reveal
62799          ;; that it is also part of comment-start and -end sequences.
62800          (string (char-syntax ?/))
62801               ⇒ "."
62802
62803          ;; Open parenthesis characters have open parenthesis syntax.
62804          ;; Note that this char-syntax call does not reveal that
62805          ;; it has a matching character, ‘)’.
62806          (string (char-syntax ?\())
62807               ⇒ "("
62808
62809 -- Function: set-syntax-table table
62810     This function makes TABLE the syntax table for the current buffer.
62811     It returns TABLE.
62812
62813 -- Function: syntax-table
62814     This function returns the current syntax table, which is the table
62815     for the current buffer.
62816
62817 -- Command: describe-syntax &optional buffer
62818     This command displays the contents of the syntax table of BUFFER
62819     (by default, the current buffer) in a help buffer.
62820
62821 -- Macro: with-syntax-table table body...
62822     This macro executes BODY using TABLE as the current syntax table.
62823     It returns the value of the last form in BODY, after restoring the
62824     old current syntax table.
62825
62826     Since each buffer has its own current syntax table, we should make
62827     that more precise: ‘with-syntax-table’ temporarily alters the
62828     current syntax table of whichever buffer is current at the time the
62829     macro execution starts.  Other buffers are not affected.
62830
62831
62832File: elisp.info,  Node: Syntax Properties,  Next: Motion and Syntax,  Prev: Syntax Table Functions,  Up: Syntax Tables
62833
6283435.4 Syntax Properties
62835======================
62836
62837When the syntax table is not flexible enough to specify the syntax of a
62838language, you can override the syntax table for specific character
62839occurrences in the buffer, by applying a ‘syntax-table’ text property.
62840*Note Text Properties::, for how to apply text properties.
62841
62842   The valid values of ‘syntax-table’ text property are:
62843
62844SYNTAX-TABLE
62845     If the property value is a syntax table, that table is used instead
62846     of the current buffer’s syntax table to determine the syntax for
62847     the underlying text character.
62848
62849‘(SYNTAX-CODE . MATCHING-CHAR)’
62850     A cons cell of this format is a raw syntax descriptor (*note Syntax
62851     Table Internals::), which directly specifies a syntax class for the
62852     underlying text character.
62853
62854‘nil’
62855     If the property is ‘nil’, the character’s syntax is determined from
62856     the current syntax table in the usual way.
62857
62858 -- Variable: parse-sexp-lookup-properties
62859     If this is non-‘nil’, the syntax scanning functions, like
62860     ‘forward-sexp’, pay attention to ‘syntax-table’ text properties.
62861     Otherwise they use only the current syntax table.
62862
62863 -- Variable: syntax-propertize-function
62864     This variable, if non-‘nil’, should store a function for applying
62865     ‘syntax-table’ properties to a specified stretch of text.  It is
62866     intended to be used by major modes to install a function which
62867     applies ‘syntax-table’ properties in some mode-appropriate way.
62868
62869     The function is called by ‘syntax-ppss’ (*note Position Parse::),
62870     and by Font Lock mode during syntactic fontification (*note
62871     Syntactic Font Lock::).  It is called with two arguments, START and
62872     END, which are the starting and ending positions of the text on
62873     which it should act.  It is allowed to call ‘syntax-ppss’ on any
62874     position before END, but if a Lisp program calls ‘syntax-ppss’ on
62875     some position and later modifies the buffer at some earlier
62876     position, then it is that program’s responsibility to call
62877     ‘syntax-ppss-flush-cache’ to flush the now obsolete info from the
62878     cache.
62879
62880     *Caution:* When this variable is non-‘nil’, Emacs removes
62881     ‘syntax-table’ text properties arbitrarily and relies on
62882     ‘syntax-propertize-function’ to reapply them.  Thus if this
62883     facility is used at all, the function must apply *all*
62884     ‘syntax-table’ text properties used by the major mode.  In
62885     particular, Modes derived from a CC Mode mode must not use this
62886     variable, since CC Mode uses other means to apply and remove these
62887     text properties.
62888
62889 -- Variable: syntax-propertize-extend-region-functions
62890     This abnormal hook is run by the syntax parsing code prior to
62891     calling ‘syntax-propertize-function’.  Its role is to help locate
62892     safe starting and ending buffer positions for passing to
62893     ‘syntax-propertize-function’.  For example, a major mode can add a
62894     function to this hook to identify multi-line syntactic constructs,
62895     and ensure that the boundaries do not fall in the middle of one.
62896
62897     Each function in this hook should accept two arguments, START and
62898     END.  It should return either a cons cell of two adjusted buffer
62899     positions, ‘(NEW-START . NEW-END)’, or ‘nil’ if no adjustment is
62900     necessary.  The hook functions are run in turn, repeatedly, until
62901     they all return ‘nil’.
62902
62903
62904File: elisp.info,  Node: Motion and Syntax,  Next: Parsing Expressions,  Prev: Syntax Properties,  Up: Syntax Tables
62905
6290635.5 Motion and Syntax
62907======================
62908
62909This section describes functions for moving across characters that have
62910certain syntax classes.
62911
62912 -- Function: skip-syntax-forward syntaxes &optional limit
62913     This function moves point forward across characters having syntax
62914     classes mentioned in SYNTAXES (a string of syntax class
62915     characters).  It stops when it encounters the end of the buffer, or
62916     position LIMIT (if specified), or a character it is not supposed to
62917     skip.
62918
62919     If SYNTAXES starts with ‘^’, then the function skips characters
62920     whose syntax is _not_ in SYNTAXES.
62921
62922     The return value is the distance traveled, which is a nonnegative
62923     integer.
62924
62925 -- Function: skip-syntax-backward syntaxes &optional limit
62926     This function moves point backward across characters whose syntax
62927     classes are mentioned in SYNTAXES.  It stops when it encounters the
62928     beginning of the buffer, or position LIMIT (if specified), or a
62929     character it is not supposed to skip.
62930
62931     If SYNTAXES starts with ‘^’, then the function skips characters
62932     whose syntax is _not_ in SYNTAXES.
62933
62934     The return value indicates the distance traveled.  It is an integer
62935     that is zero or less.
62936
62937 -- Function: backward-prefix-chars
62938     This function moves point backward over any number of characters
62939     with expression prefix syntax.  This includes both characters in
62940     the expression prefix syntax class, and characters with the ‘p’
62941     flag.
62942
62943
62944File: elisp.info,  Node: Parsing Expressions,  Next: Syntax Table Internals,  Prev: Motion and Syntax,  Up: Syntax Tables
62945
6294635.6 Parsing Expressions
62947========================
62948
62949This section describes functions for parsing and scanning balanced
62950expressions.  We will refer to such expressions as “sexps”, following
62951the terminology of Lisp, even though these functions can act on
62952languages other than Lisp.  Basically, a sexp is either a balanced
62953parenthetical grouping, a string, or a symbol (i.e., a sequence of
62954characters whose syntax is either word constituent or symbol
62955constituent).  However, characters in the expression prefix syntax class
62956(*note Syntax Class Table::) are treated as part of the sexp if they
62957appear next to it.
62958
62959   The syntax table controls the interpretation of characters, so these
62960functions can be used for Lisp expressions when in Lisp mode and for C
62961expressions when in C mode.  *Note List Motion::, for convenient
62962higher-level functions for moving over balanced expressions.
62963
62964   A character’s syntax controls how it changes the state of the parser,
62965rather than describing the state itself.  For example, a string
62966delimiter character toggles the parser state between in-string and
62967in-code, but the syntax of characters does not directly say whether they
62968are inside a string.  For example (note that 15 is the syntax code for
62969generic string delimiters),
62970
62971     (put-text-property 1 9 'syntax-table '(15 . nil))
62972
62973does not tell Emacs that the first eight chars of the current buffer are
62974a string, but rather that they are all string delimiters.  As a result,
62975Emacs treats them as four consecutive empty string constants.
62976
62977* Menu:
62978
62979* Motion via Parsing::       Motion functions that work by parsing.
62980* Position Parse::           Determining the syntactic state of a position.
62981* Parser State::             How Emacs represents a syntactic state.
62982* Low-Level Parsing::        Parsing across a specified region.
62983* Control Parsing::          Parameters that affect parsing.
62984
62985
62986File: elisp.info,  Node: Motion via Parsing,  Next: Position Parse,  Up: Parsing Expressions
62987
6298835.6.1 Motion Commands Based on Parsing
62989---------------------------------------
62990
62991This section describes simple point-motion functions that operate based
62992on parsing expressions.
62993
62994 -- Function: scan-lists from count depth
62995     This function scans forward COUNT balanced parenthetical groupings
62996     from position FROM.  It returns the position where the scan stops.
62997     If COUNT is negative, the scan moves backwards.
62998
62999     If DEPTH is nonzero, treat the starting position as being DEPTH
63000     parentheses deep.  The scanner moves forward or backward through
63001     the buffer until the depth changes to zero COUNT times.  Hence, a
63002     positive value for DEPTH has the effect of moving out DEPTH levels
63003     of parenthesis from the starting position, while a negative DEPTH
63004     has the effect of moving deeper by -DEPTH levels of parenthesis.
63005
63006     Scanning ignores comments if ‘parse-sexp-ignore-comments’ is
63007     non-‘nil’.
63008
63009     If the scan reaches the beginning or end of the accessible part of
63010     the buffer before it has scanned over COUNT parenthetical
63011     groupings, the return value is ‘nil’ if the depth at that point is
63012     zero; if the depth is non-zero, a ‘scan-error’ error is signaled.
63013
63014 -- Function: scan-sexps from count
63015     This function scans forward COUNT sexps from position FROM.  It
63016     returns the position where the scan stops.  If COUNT is negative,
63017     the scan moves backwards.
63018
63019     Scanning ignores comments if ‘parse-sexp-ignore-comments’ is
63020     non-‘nil’.
63021
63022     If the scan reaches the beginning or end of (the accessible part
63023     of) the buffer while in the middle of a parenthetical grouping, an
63024     error is signaled.  If it reaches the beginning or end between
63025     groupings but before count is used up, ‘nil’ is returned.
63026
63027 -- Function: forward-comment count
63028     This function moves point forward across COUNT complete comments
63029     (that is, including the starting delimiter and the terminating
63030     delimiter if any), plus any whitespace encountered on the way.  It
63031     moves backward if COUNT is negative.  If it encounters anything
63032     other than a comment or whitespace, it stops, leaving point at the
63033     place where it stopped.  This includes (for instance) finding the
63034     end of a comment when moving forward and expecting the beginning of
63035     one.  The function also stops immediately after moving over the
63036     specified number of complete comments.  If COUNT comments are found
63037     as expected, with nothing except whitespace between them, it
63038     returns ‘t’; otherwise it returns ‘nil’.
63039
63040     This function cannot tell whether the comments it traverses are
63041     embedded within a string.  If they look like comments, it treats
63042     them as comments.
63043
63044     To move forward over all comments and whitespace following point,
63045     use ‘(forward-comment (buffer-size))’.  ‘(buffer-size)’ is a good
63046     argument to use, because the number of comments in the buffer
63047     cannot exceed that many.
63048
63049
63050File: elisp.info,  Node: Position Parse,  Next: Parser State,  Prev: Motion via Parsing,  Up: Parsing Expressions
63051
6305235.6.2 Finding the Parse State for a Position
63053---------------------------------------------
63054
63055For syntactic analysis, such as in indentation, often the useful thing
63056is to compute the syntactic state corresponding to a given buffer
63057position.  This function does that conveniently.
63058
63059 -- Function: syntax-ppss &optional pos
63060     This function returns the parser state that the parser would reach
63061     at position POS starting from the beginning of the visible portion
63062     of the buffer.  *Note Parser State::, for a description of the
63063     parser state.
63064
63065     The return value is the same as if you call the low-level parsing
63066     function ‘parse-partial-sexp’ to parse from the beginning of the
63067     visible portion of the buffer to POS (*note Low-Level Parsing::).
63068     However, ‘syntax-ppss’ uses caches to speed up the computation.
63069     Due to this optimization, the second value (previous complete
63070     subexpression) and sixth value (minimum parenthesis depth) in the
63071     returned parser state are not meaningful.
63072
63073     This function has a side effect: it adds a buffer-local entry to
63074     ‘before-change-functions’ (*note Change Hooks::) for
63075     ‘syntax-ppss-flush-cache’ (see below).  This entry keeps the cache
63076     consistent as the buffer is modified.  However, the cache might not
63077     be updated if ‘syntax-ppss’ is called while
63078     ‘before-change-functions’ is temporarily let-bound, or if the
63079     buffer is modified without running the hook, such as when using
63080     ‘inhibit-modification-hooks’.  In those cases, it is necessary to
63081     call ‘syntax-ppss-flush-cache’ explicitly.
63082
63083 -- Function: syntax-ppss-flush-cache beg &rest ignored-args
63084     This function flushes the cache used by ‘syntax-ppss’, starting at
63085     position BEG.  The remaining arguments, IGNORED-ARGS, are ignored;
63086     this function accepts them so that it can be directly used on hooks
63087     such as ‘before-change-functions’ (*note Change Hooks::).
63088
63089
63090File: elisp.info,  Node: Parser State,  Next: Low-Level Parsing,  Prev: Position Parse,  Up: Parsing Expressions
63091
6309235.6.3 Parser State
63093-------------------
63094
63095A “parser state” is a list of (currently) eleven elements describing the
63096state of the syntactic parser, after it parses the text between a
63097specified starting point and a specified end point in the buffer using
63098‘parse-partial-sexp’ (*note Low-Level Parsing::).  Parsing functions
63099such as ‘syntax-ppss’ (*note Position Parse::) also return a parser
63100state as the value.  ‘parse-partial-sexp’ can accept a parser state as
63101an argument, for resuming parsing.
63102
63103   Here are the meanings of the elements of the parser state:
63104
63105  0. The depth in parentheses, counting from 0.  *Warning:* this can be
63106     negative if there are more close parens than open parens between
63107     the parser’s starting point and end point.
63108
63109  1. The character position of the start of the innermost parenthetical
63110     grouping containing the stopping point; ‘nil’ if none.
63111
63112  2. The character position of the start of the last complete
63113     subexpression terminated; ‘nil’ if none.
63114
63115  3. Non-‘nil’ if inside a string.  More precisely, this is the
63116     character that will terminate the string, or ‘t’ if a generic
63117     string delimiter character should terminate it.
63118
63119  4. ‘t’ if inside a non-nestable comment (of any comment style; *note
63120     Syntax Flags::); or the comment nesting level if inside a comment
63121     that can be nested.
63122
63123  5. ‘t’ if the end point is just after a quote character.
63124
63125  6. The minimum parenthesis depth encountered during this scan.
63126
63127  7. What kind of comment is active: ‘nil’ if not in a comment or in a
63128     comment of style ‘a’; 1 for a comment of style ‘b’; 2 for a comment
63129     of style ‘c’; and ‘syntax-table’ for a comment that should be ended
63130     by a generic comment delimiter character.
63131
63132  8. The string or comment start position.  While inside a comment, this
63133     is the position where the comment began; while inside a string,
63134     this is the position where the string began.  When outside of
63135     strings and comments, this element is ‘nil’.
63136
63137  9. The list of the positions of the currently open parentheses,
63138     starting with the outermost.
63139
63140  10. When the last buffer position scanned was the (potential) first
63141     character of a two character construct (comment delimiter or
63142     escaped/char-quoted character pair), the SYNTAX-CODE (*note Syntax
63143     Table Internals::) of that position.  Otherwise ‘nil’.
63144
63145   Elements 1, 2, and 6 are ignored in a state which you pass as an
63146argument to ‘parse-partial-sexp’ to continue parsing.  Elements 9 and 10
63147are mainly used internally by the parser code.
63148
63149   Some additional useful information is available from a parser state
63150using these functions:
63151
63152 -- Function: syntax-ppss-toplevel-pos state
63153     This function extracts, from parser state STATE, the last position
63154     scanned in the parse which was at top level in grammatical
63155     structure.  “At top level” means outside of any parentheses,
63156     comments, or strings.
63157
63158     The value is ‘nil’ if STATE represents a parse which has arrived at
63159     a top level position.
63160
63161 -- Function: syntax-ppss-context state
63162     Return ‘string’ if the end position of the scan returning STATE is
63163     in a string, and ‘comment’ if it’s in a comment.
63164
63165
63166File: elisp.info,  Node: Low-Level Parsing,  Next: Control Parsing,  Prev: Parser State,  Up: Parsing Expressions
63167
6316835.6.4 Low-Level Parsing
63169------------------------
63170
63171The most basic way to use the expression parser is to tell it to start
63172at a given position with a certain state, and parse up to a specified
63173end position.
63174
63175 -- Function: parse-partial-sexp start limit &optional target-depth
63176          stop-before state stop-comment
63177     This function parses a sexp in the current buffer starting at
63178     START, not scanning past LIMIT.  It stops at position LIMIT or when
63179     certain criteria described below are met, and sets point to the
63180     location where parsing stops.  It returns a parser state (*note
63181     Parser State::) describing the status of the parse at the point
63182     where it stops.
63183
63184     If the third argument TARGET-DEPTH is non-‘nil’, parsing stops if
63185     the depth in parentheses becomes equal to TARGET-DEPTH.  The depth
63186     starts at 0, or at whatever is given in STATE.
63187
63188     If the fourth argument STOP-BEFORE is non-‘nil’, parsing stops when
63189     it comes to any character that starts a sexp.  If STOP-COMMENT is
63190     non-‘nil’, parsing stops after the start of an unnested comment.
63191     If STOP-COMMENT is the symbol ‘syntax-table’, parsing stops after
63192     the start of an unnested comment or a string, or after the end of
63193     an unnested comment or a string, whichever comes first.
63194
63195     If STATE is ‘nil’, START is assumed to be at the top level of
63196     parenthesis structure, such as the beginning of a function
63197     definition.  Alternatively, you might wish to resume parsing in the
63198     middle of the structure.  To do this, you must provide a STATE
63199     argument that describes the initial status of parsing.  The value
63200     returned by a previous call to ‘parse-partial-sexp’ will do nicely.
63201
63202
63203File: elisp.info,  Node: Control Parsing,  Prev: Low-Level Parsing,  Up: Parsing Expressions
63204
6320535.6.5 Parameters to Control Parsing
63206------------------------------------
63207
63208 -- Variable: multibyte-syntax-as-symbol
63209     If this variable is non-‘nil’, ‘scan-sexps’ treats all non-ASCII
63210     characters as symbol constituents regardless of what the syntax
63211     table says about them.  (However, ‘syntax-table ’text properties
63212     can still override the syntax.)
63213
63214 -- User Option: parse-sexp-ignore-comments
63215     If the value is non-‘nil’, then comments are treated as whitespace
63216     by the functions in this section and by ‘forward-sexp’,
63217     ‘scan-lists’ and ‘scan-sexps’.
63218
63219   The behavior of ‘parse-partial-sexp’ is also affected by
63220‘parse-sexp-lookup-properties’ (*note Syntax Properties::).
63221
63222 -- Variable: comment-end-can-be-escaped
63223     If this buffer local variable is non-‘nil’, a single character
63224     which usually terminates a comment doesn’t do so when that
63225     character is escaped.  This is used in C and C++ Modes, where line
63226     comments starting with ‘//’ can be continued onto the next line by
63227     escaping the newline with ‘\’.
63228
63229   You can use ‘forward-comment’ to move forward or backward over one
63230comment or several comments.
63231
63232
63233File: elisp.info,  Node: Syntax Table Internals,  Next: Categories,  Prev: Parsing Expressions,  Up: Syntax Tables
63234
6323535.7 Syntax Table Internals
63236===========================
63237
63238Syntax tables are implemented as char-tables (*note Char-Tables::), but
63239most Lisp programs don’t work directly with their elements.  Syntax
63240tables do not store syntax data as syntax descriptors (*note Syntax
63241Descriptors::); they use an internal format, which is documented in this
63242section.  This internal format can also be assigned as syntax properties
63243(*note Syntax Properties::).
63244
63245   Each entry in a syntax table is a “raw syntax descriptor”: a cons
63246cell of the form ‘(SYNTAX-CODE . MATCHING-CHAR)’.  SYNTAX-CODE is an
63247integer which encodes the syntax class and syntax flags, according to
63248the table below.  MATCHING-CHAR, if non-‘nil’, specifies a matching
63249character (similar to the second character in a syntax descriptor).
63250
63251   Use ‘aref’ (*note Array Functions::) to get the raw syntax descriptor
63252of a character, e.g. ‘(aref (syntax-table) ch)’.
63253
63254   Here are the syntax codes corresponding to the various syntax
63255classes:
63256
63257Code           Class                  Code           Class
632580              whitespace             8              paired delimiter
632591              punctuation            9              escape
632602              word                   10             character quote
632613              symbol                 11             comment-start
632624              open parenthesis       12             comment-end
632635              close parenthesis      13             inherit
632646              expression prefix      14             generic comment
632657              string quote           15             generic string
63266
63267For example, in the standard syntax table, the entry for ‘(’ is ‘(4 .
6326841)’.  41 is the character code for ‘)’.
63269
63270   Syntax flags are encoded in higher order bits, starting 16 bits from
63271the least significant bit.  This table gives the power of two which
63272corresponds to each syntax flag.
63273
63274Prefix      Flag                   Prefix      Flag
63275‘1’         ‘(ash 1 16)’           ‘p’         ‘(ash 1 20)’
63276‘2’         ‘(ash 1 17)’           ‘b’         ‘(ash 1 21)’
63277‘3’         ‘(ash 1 18)’           ‘n’         ‘(ash 1 22)’
63278‘4’         ‘(ash 1 19)’           ‘c’         ‘(ash 1 23)’
63279
63280 -- Function: string-to-syntax desc
63281     Given a syntax descriptor DESC (a string), this function returns
63282     the corresponding raw syntax descriptor.
63283
63284 -- Function: syntax-after pos
63285     This function returns the raw syntax descriptor for the character
63286     in the buffer after position POS, taking account of syntax
63287     properties as well as the syntax table.  If POS is outside the
63288     buffer’s accessible portion (*note accessible portion: Narrowing.),
63289     the return value is ‘nil’.
63290
63291 -- Function: syntax-class syntax
63292     This function returns the syntax code for the raw syntax descriptor
63293     SYNTAX.  More precisely, it takes the raw syntax descriptor’s
63294     SYNTAX-CODE component, masks off the high 16 bits which record the
63295     syntax flags, and returns the resulting integer.
63296
63297     If SYNTAX is ‘nil’, the return value is ‘nil’.  This is so that the
63298     expression
63299
63300          (syntax-class (syntax-after pos))
63301
63302     evaluates to ‘nil’ if ‘pos’ is outside the buffer’s accessible
63303     portion, without throwing errors or returning an incorrect code.
63304
63305
63306File: elisp.info,  Node: Categories,  Prev: Syntax Table Internals,  Up: Syntax Tables
63307
6330835.8 Categories
63309===============
63310
63311“Categories” provide an alternate way of classifying characters
63312syntactically.  You can define several categories as needed, then
63313independently assign each character to one or more categories.  Unlike
63314syntax classes, categories are not mutually exclusive; it is normal for
63315one character to belong to several categories.
63316
63317   Each buffer has a “category table” which records which categories are
63318defined and also which characters belong to each category.  Each
63319category table defines its own categories, but normally these are
63320initialized by copying from the standard categories table, so that the
63321standard categories are available in all modes.
63322
63323   Each category has a name, which is an ASCII printing character in the
63324range ‘ ’ to ‘~’.  You specify the name of a category when you define it
63325with ‘define-category’.
63326
63327   The category table is actually a char-table (*note Char-Tables::).
63328The element of the category table at index C is a “category set”—a
63329bool-vector—that indicates which categories character C belongs to.  In
63330this category set, if the element at index CAT is ‘t’, that means
63331category CAT is a member of the set, and that character C belongs to
63332category CAT.
63333
63334   For the next three functions, the optional argument TABLE defaults to
63335the current buffer’s category table.
63336
63337 -- Function: define-category char docstring &optional table
63338     This function defines a new category, with name CHAR and
63339     documentation DOCSTRING, for the category table TABLE.
63340
63341     Here’s an example of defining a new category for characters that
63342     have strong right-to-left directionality (*note Bidirectional
63343     Display::) and using it in a special category table.  To obtain the
63344     information about the directionality of characters, the example
63345     code uses the ‘bidi-class’ Unicode property (*note bidi-class:
63346     Character Properties.).
63347
63348          (defvar special-category-table-for-bidi
63349            ;;     Make an empty category-table.
63350            (let ((category-table (make-category-table))
63351                  ;; Create a char-table which gives the 'bidi-class' Unicode
63352                  ;; property for each character.
63353                  (uniprop-table
63354                   (unicode-property-table-internal 'bidi-class)))
63355              (define-category ?R "Characters of bidi-class R, AL, or RLO"
63356                               category-table)
63357              ;; Modify the category entry of each character whose
63358              ;; 'bidi-class' Unicode property is R, AL, or RLO --
63359              ;; these have a right-to-left directionality.
63360              (map-char-table
63361               (lambda (key val)
63362                 (if (memq val '(R AL RLO))
63363                     (modify-category-entry key ?R category-table)))
63364               uniprop-table)
63365              category-table))
63366
63367 -- Function: category-docstring category &optional table
63368     This function returns the documentation string of category CATEGORY
63369     in category table TABLE.
63370
63371          (category-docstring ?a)
63372               ⇒ "ASCII"
63373          (category-docstring ?l)
63374               ⇒ "Latin"
63375
63376 -- Function: get-unused-category &optional table
63377     This function returns a category name (a character) which is not
63378     currently defined in TABLE.  If all possible categories are in use
63379     in TABLE, it returns ‘nil’.
63380
63381 -- Function: category-table
63382     This function returns the current buffer’s category table.
63383
63384 -- Function: category-table-p object
63385     This function returns ‘t’ if OBJECT is a category table, otherwise
63386     ‘nil’.
63387
63388 -- Function: standard-category-table
63389     This function returns the standard category table.
63390
63391 -- Function: copy-category-table &optional table
63392     This function constructs a copy of TABLE and returns it.  If TABLE
63393     is not supplied (or is ‘nil’), it returns a copy of the standard
63394     category table.  Otherwise, an error is signaled if TABLE is not a
63395     category table.
63396
63397 -- Function: set-category-table table
63398     This function makes TABLE the category table for the current
63399     buffer.  It returns TABLE.
63400
63401 -- Function: make-category-table
63402     This creates and returns an empty category table.  In an empty
63403     category table, no categories have been allocated, and no
63404     characters belong to any categories.
63405
63406 -- Function: make-category-set categories
63407     This function returns a new category set—a bool-vector—whose
63408     initial contents are the categories listed in the string
63409     CATEGORIES.  The elements of CATEGORIES should be category names;
63410     the new category set has ‘t’ for each of those categories, and
63411     ‘nil’ for all other categories.
63412
63413          (make-category-set "al")
63414               ⇒ #&128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
63415
63416 -- Function: char-category-set char
63417     This function returns the category set for character CHAR in the
63418     current buffer’s category table.  This is the bool-vector which
63419     records which categories the character CHAR belongs to.  The
63420     function ‘char-category-set’ does not allocate storage, because it
63421     returns the same bool-vector that exists in the category table.
63422
63423          (char-category-set ?a)
63424               ⇒ #&128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
63425
63426 -- Function: category-set-mnemonics category-set
63427     This function converts the category set CATEGORY-SET into a string
63428     containing the characters that designate the categories that are
63429     members of the set.
63430
63431          (category-set-mnemonics (char-category-set ?a))
63432               ⇒ "al"
63433
63434 -- Function: modify-category-entry char category &optional table reset
63435     This function modifies the category set of CHAR in category table
63436     TABLE (which defaults to the current buffer’s category table).
63437     CHAR can be a character, or a cons cell of the form ‘(MIN . MAX)’;
63438     in the latter case, the function modifies the category sets of all
63439     characters in the range between MIN and MAX, inclusive.
63440
63441     Normally, it modifies a category set by adding CATEGORY to it.  But
63442     if RESET is non-‘nil’, then it deletes CATEGORY instead.
63443
63444 -- Command: describe-categories &optional buffer-or-name
63445     This function describes the category specifications in the current
63446     category table.  It inserts the descriptions in a buffer, and then
63447     displays that buffer.  If BUFFER-OR-NAME is non-‘nil’, it describes
63448     the category table of that buffer instead.
63449
63450
63451File: elisp.info,  Node: Abbrevs,  Next: Threads,  Prev: Syntax Tables,  Up: Top
63452
6345336 Abbrevs and Abbrev Expansion
63454*******************************
63455
63456An abbreviation or “abbrev” is a string of characters that may be
63457expanded to a longer string.  The user can insert the abbrev string and
63458find it replaced automatically with the expansion of the abbrev.  This
63459saves typing.
63460
63461   The set of abbrevs currently in effect is recorded in an “abbrev
63462table”.  Each buffer has a local abbrev table, but normally all buffers
63463in the same major mode share one abbrev table.  There is also a global
63464abbrev table.  Normally both are used.
63465
63466   An abbrev table is represented as an obarray.  *Note Creating
63467Symbols::, for information about obarrays.  Each abbreviation is
63468represented by a symbol in the obarray.  The symbol’s name is the
63469abbreviation; its value is the expansion; its function definition is the
63470hook function for performing the expansion (*note Defining Abbrevs::);
63471and its property list cell contains various additional properties,
63472including the use count and the number of times the abbreviation has
63473been expanded (*note Abbrev Properties::).
63474
63475   Certain abbrevs, called “system abbrevs”, are defined by a major mode
63476instead of the user.  A system abbrev is identified by its non-‘nil’
63477‘:system’ property (*note Abbrev Properties::).  When abbrevs are saved
63478to an abbrev file, system abbrevs are omitted.  *Note Abbrev Files::.
63479
63480   Because the symbols used for abbrevs are not interned in the usual
63481obarray, they will never appear as the result of reading a Lisp
63482expression; in fact, normally they are never used except by the code
63483that handles abbrevs.  Therefore, it is safe to use them in a
63484nonstandard way.
63485
63486   If the minor mode Abbrev mode is enabled, the buffer-local variable
63487‘abbrev-mode’ is non-‘nil’, and abbrevs are automatically expanded in
63488the buffer.  For the user-level commands for abbrevs, see *note Abbrev
63489Mode: (emacs)Abbrevs.
63490
63491* Menu:
63492
63493* Tables: Abbrev Tables.        Creating and working with abbrev tables.
63494* Defining Abbrevs::            Specifying abbreviations and their expansions.
63495* Files: Abbrev Files.          Saving abbrevs in files.
63496* Expansion: Abbrev Expansion.  Controlling expansion; expansion subroutines.
63497* Standard Abbrev Tables::      Abbrev tables used by various major modes.
63498* Abbrev Properties::           How to read and set abbrev properties.
63499                                Which properties have which effect.
63500* Abbrev Table Properties::     How to read and set abbrev table properties.
63501                                Which properties have which effect.
63502
63503
63504File: elisp.info,  Node: Abbrev Tables,  Next: Defining Abbrevs,  Up: Abbrevs
63505
6350636.1 Abbrev Tables
63507==================
63508
63509This section describes how to create and manipulate abbrev tables.
63510
63511 -- Function: make-abbrev-table &optional props
63512     This function creates and returns a new, empty abbrev table—an
63513     obarray containing no symbols.  It is a vector filled with zeros.
63514     PROPS is a property list that is applied to the new table (*note
63515     Abbrev Table Properties::).
63516
63517 -- Function: abbrev-table-p object
63518     This function returns a non-‘nil’ value if OBJECT is an abbrev
63519     table.
63520
63521 -- Function: clear-abbrev-table abbrev-table
63522     This function undefines all the abbrevs in ABBREV-TABLE, leaving it
63523     empty.
63524
63525 -- Function: copy-abbrev-table abbrev-table
63526     This function returns a copy of ABBREV-TABLE—a new abbrev table
63527     containing the same abbrev definitions.  It does _not_ copy any
63528     property lists; only the names, values, and functions.
63529
63530 -- Function: define-abbrev-table tabname definitions &optional
63531          docstring &rest props
63532     This function defines TABNAME (a symbol) as an abbrev table name,
63533     i.e., as a variable whose value is an abbrev table.  It defines
63534     abbrevs in the table according to DEFINITIONS, a list of elements
63535     of the form ‘(ABBREVNAME EXPANSION [HOOK] [PROPS...])’.  These
63536     elements are passed as arguments to ‘define-abbrev’.
63537
63538     The optional string DOCSTRING is the documentation string of the
63539     variable TABNAME.  The property list PROPS is applied to the abbrev
63540     table (*note Abbrev Table Properties::).
63541
63542     If this function is called more than once for the same TABNAME,
63543     subsequent calls add the definitions in DEFINITIONS to TABNAME,
63544     rather than overwriting the entire original contents.  (A
63545     subsequent call only overrides abbrevs explicitly redefined or
63546     undefined in DEFINITIONS.)
63547
63548 -- Variable: abbrev-table-name-list
63549     This is a list of symbols whose values are abbrev tables.
63550     ‘define-abbrev-table’ adds the new abbrev table name to this list.
63551
63552 -- Function: insert-abbrev-table-description name &optional human
63553     This function inserts before point a description of the abbrev
63554     table named NAME.  The argument NAME is a symbol whose value is an
63555     abbrev table.
63556
63557     If HUMAN is non-‘nil’, the description is human-oriented.  System
63558     abbrevs are listed and identified as such.  Otherwise the
63559     description is a Lisp expression—a call to ‘define-abbrev-table’
63560     that would define NAME as it is currently defined, but without the
63561     system abbrevs.  (The mode or package using NAME is supposed to add
63562     these to NAME separately.)
63563
63564
63565File: elisp.info,  Node: Defining Abbrevs,  Next: Abbrev Files,  Prev: Abbrev Tables,  Up: Abbrevs
63566
6356736.2 Defining Abbrevs
63568=====================
63569
63570‘define-abbrev’ is the low-level basic function for defining an abbrev
63571in an abbrev table.
63572
63573   When a major mode defines a system abbrev, it should call
63574‘define-abbrev’ and specify ‘t’ for the ‘:system’ property.  Be aware
63575that any saved non-system abbrevs are restored at startup, i.e., before
63576some major modes are loaded.  Therefore, major modes should not assume
63577that their abbrev tables are empty when they are first loaded.
63578
63579 -- Function: define-abbrev abbrev-table name expansion &optional hook
63580          &rest props
63581     This function defines an abbrev named NAME, in ABBREV-TABLE, to
63582     expand to EXPANSION and call HOOK, with properties PROPS (*note
63583     Abbrev Properties::).  The return value is NAME.  The ‘:system’
63584     property in PROPS is treated specially here: if it has the value
63585     ‘force’, then it will overwrite an existing definition even for a
63586     non-system abbrev of the same name.
63587
63588     NAME should be a string.  The argument EXPANSION is normally the
63589     desired expansion (a string), or ‘nil’ to undefine the abbrev.  If
63590     it is anything but a string or ‘nil’, then the abbreviation expands
63591     solely by running HOOK.
63592
63593     The argument HOOK is a function or ‘nil’.  If HOOK is non-‘nil’,
63594     then it is called with no arguments after the abbrev is replaced
63595     with EXPANSION; point is located at the end of EXPANSION when HOOK
63596     is called.
63597
63598     If HOOK is a non-‘nil’ symbol whose ‘no-self-insert’ property is
63599     non-‘nil’, HOOK can explicitly control whether to insert the
63600     self-inserting input character that triggered the expansion.  If
63601     HOOK returns non-‘nil’ in this case, that inhibits insertion of the
63602     character.  By contrast, if HOOK returns ‘nil’, ‘expand-abbrev’ (or
63603     ‘abbrev-insert’) also returns ‘nil’, as if expansion had not really
63604     occurred.
63605
63606     Normally, ‘define-abbrev’ sets the variable ‘abbrevs-changed’ to
63607     ‘t’, if it actually changes the abbrev.  This is so that some
63608     commands will offer to save the abbrevs.  It does not do this for a
63609     system abbrev, since those aren’t saved anyway.
63610
63611 -- User Option: only-global-abbrevs
63612     If this variable is non-‘nil’, it means that the user plans to use
63613     global abbrevs only.  This tells the commands that define
63614     mode-specific abbrevs to define global ones instead.  This variable
63615     does not alter the behavior of the functions in this section; it is
63616     examined by their callers.
63617
63618
63619File: elisp.info,  Node: Abbrev Files,  Next: Abbrev Expansion,  Prev: Defining Abbrevs,  Up: Abbrevs
63620
6362136.3 Saving Abbrevs in Files
63622============================
63623
63624A file of saved abbrev definitions is actually a file of Lisp code.  The
63625abbrevs are saved in the form of a Lisp program to define the same
63626abbrev tables with the same contents.  Therefore, you can load the file
63627with ‘load’ (*note How Programs Do Loading::).  However, the function
63628‘quietly-read-abbrev-file’ is provided as a more convenient interface.
63629Emacs automatically calls this function at startup.
63630
63631   User-level facilities such as ‘save-some-buffers’ can save abbrevs in
63632a file automatically, under the control of variables described here.
63633
63634 -- User Option: abbrev-file-name
63635     This is the default file name for reading and saving abbrevs.  By
63636     default, Emacs will look for ‘~/.emacs.d/abbrev_defs’, and, if not
63637     found, for ‘~/.abbrev_defs’; if neither file exists, Emacs will
63638     create ‘~/.emacs.d/abbrev_defs’.
63639
63640 -- Function: quietly-read-abbrev-file &optional filename
63641     This function reads abbrev definitions from a file named FILENAME,
63642     previously written with ‘write-abbrev-file’.  If FILENAME is
63643     omitted or ‘nil’, the file specified in ‘abbrev-file-name’ is used.
63644
63645     As the name implies, this function does not display any messages.
63646
63647 -- User Option: save-abbrevs
63648     A non-‘nil’ value for ‘save-abbrevs’ means that Emacs should offer
63649     to save abbrevs (if any have changed) when files are saved.  If the
63650     value is ‘silently’, Emacs saves the abbrevs without asking the
63651     user.  ‘abbrev-file-name’ specifies the file to save the abbrevs
63652     in.  The default value is ‘t’.
63653
63654 -- Variable: abbrevs-changed
63655     This variable is set non-‘nil’ by defining or altering any abbrevs
63656     (except system abbrevs).  This serves as a flag for various Emacs
63657     commands to offer to save your abbrevs.
63658
63659 -- Command: write-abbrev-file &optional filename
63660     Save all abbrev definitions (except system abbrevs), for all abbrev
63661     tables listed in ‘abbrev-table-name-list’, in the file FILENAME, in
63662     the form of a Lisp program that when loaded will define the same
63663     abbrevs.  Tables that do not have any abbrevs to save are omitted.
63664     If FILENAME is ‘nil’ or omitted, ‘abbrev-file-name’ is used.  This
63665     function returns ‘nil’.
63666
63667
63668File: elisp.info,  Node: Abbrev Expansion,  Next: Standard Abbrev Tables,  Prev: Abbrev Files,  Up: Abbrevs
63669
6367036.4 Looking Up and Expanding Abbreviations
63671===========================================
63672
63673Abbrevs are usually expanded by certain interactive commands, including
63674‘self-insert-command’.  This section describes the subroutines used in
63675writing such commands, as well as the variables they use for
63676communication.
63677
63678 -- Function: abbrev-symbol abbrev &optional table
63679     This function returns the symbol representing the abbrev named
63680     ABBREV.  It returns ‘nil’ if that abbrev is not defined.  The
63681     optional second argument TABLE is the abbrev table in which to look
63682     it up.  If TABLE is ‘nil’, this function tries first the current
63683     buffer’s local abbrev table, and second the global abbrev table.
63684
63685 -- Function: abbrev-expansion abbrev &optional table
63686     This function returns the string that ABBREV would expand into (as
63687     defined by the abbrev tables used for the current buffer).  It
63688     returns ‘nil’ if ABBREV is not a valid abbrev.  The optional
63689     argument TABLE specifies the abbrev table to use, as in
63690     ‘abbrev-symbol’.
63691
63692 -- Command: expand-abbrev
63693     This command expands the abbrev before point, if any.  If point
63694     does not follow an abbrev, this command does nothing.  To do the
63695     expansion, it calls the function that is the value of the
63696     ‘abbrev-expand-function’ variable, with no arguments, and returns
63697     whatever that function does.
63698
63699     The default expansion function returns the abbrev symbol if it did
63700     expansion, and ‘nil’ otherwise.  If the abbrev symbol has a hook
63701     function that is a symbol whose ‘no-self-insert’ property is
63702     non-‘nil’, and if the hook function returns ‘nil’ as its value,
63703     then the default expansion function returns ‘nil’, even though
63704     expansion did occur.
63705
63706 -- Function: abbrev-insert abbrev &optional name start end
63707     This function inserts the abbrev expansion of ‘abbrev’, replacing
63708     the text between ‘start’ and ‘end’.  If ‘start’ is omitted, it
63709     defaults to point.  ‘name’, if non-‘nil’, should be the name by
63710     which this abbrev was found (a string); it is used to figure out
63711     whether to adjust the capitalization of the expansion.  The
63712     function returns ‘abbrev’ if the abbrev was successfully inserted,
63713     otherwise it returns ‘nil’.
63714
63715 -- Command: abbrev-prefix-mark &optional arg
63716     This command marks the current location of point as the beginning
63717     of an abbrev.  The next call to ‘expand-abbrev’ will use the text
63718     from here to point (where it is then) as the abbrev to expand,
63719     rather than using the previous word as usual.
63720
63721     First, this command expands any abbrev before point, unless ARG is
63722     non-‘nil’.  (Interactively, ARG is the prefix argument.)  Then it
63723     inserts a hyphen before point, to indicate the start of the next
63724     abbrev to be expanded.  The actual expansion removes the hyphen.
63725
63726 -- User Option: abbrev-all-caps
63727     When this is set non-‘nil’, an abbrev entered entirely in upper
63728     case is expanded using all upper case.  Otherwise, an abbrev
63729     entered entirely in upper case is expanded by capitalizing each
63730     word of the expansion.
63731
63732 -- Variable: abbrev-start-location
63733     The value of this variable is a buffer position (an integer or a
63734     marker) for ‘expand-abbrev’ to use as the start of the next abbrev
63735     to be expanded.  The value can also be ‘nil’, which means to use
63736     the word before point instead.  ‘abbrev-start-location’ is set to
63737     ‘nil’ each time ‘expand-abbrev’ is called.  This variable is also
63738     set by ‘abbrev-prefix-mark’.
63739
63740 -- Variable: abbrev-start-location-buffer
63741     The value of this variable is the buffer for which
63742     ‘abbrev-start-location’ has been set.  Trying to expand an abbrev
63743     in any other buffer clears ‘abbrev-start-location’.  This variable
63744     is set by ‘abbrev-prefix-mark’.
63745
63746 -- Variable: last-abbrev
63747     This is the ‘abbrev-symbol’ of the most recent abbrev expanded.
63748     This information is left by ‘expand-abbrev’ for the sake of the
63749     ‘unexpand-abbrev’ command (*note Expanding Abbrevs:
63750     (emacs)Expanding Abbrevs.).
63751
63752 -- Variable: last-abbrev-location
63753     This is the location of the most recent abbrev expanded.  This
63754     contains information left by ‘expand-abbrev’ for the sake of the
63755     ‘unexpand-abbrev’ command.
63756
63757 -- Variable: last-abbrev-text
63758     This is the exact expansion text of the most recent abbrev
63759     expanded, after case conversion (if any).  Its value is ‘nil’ if
63760     the abbrev has already been unexpanded.  This contains information
63761     left by ‘expand-abbrev’ for the sake of the ‘unexpand-abbrev’
63762     command.
63763
63764 -- Variable: abbrev-expand-function
63765     The value of this variable is a function that ‘expand-abbrev’ will
63766     call with no arguments to do the expansion.  The function can do
63767     anything it wants before and after performing the expansion.  It
63768     should return the abbrev symbol if expansion took place.
63769
63770   The following sample code shows a simple use of
63771‘abbrev-expand-function’.  It assumes that ‘foo-mode’ is a mode for
63772editing certain files in which lines that start with ‘#’ are comments.
63773You want to use Text mode abbrevs for those lines.  The regular local
63774abbrev table, ‘foo-mode-abbrev-table’ is appropriate for all other
63775lines.  *Note Standard Abbrev Tables::, for the definitions of
63776‘local-abbrev-table’ and ‘text-mode-abbrev-table’.  *Note Advising
63777Functions::, for details of ‘add-function’.
63778
63779     (defun foo-mode-abbrev-expand-function (expand)
63780       (if (not (save-excursion (forward-line 0) (eq (char-after) ?#)))
63781           ;; Performs normal expansion.
63782           (funcall expand)
63783         ;; We're inside a comment: use the text-mode abbrevs.
63784         (let ((local-abbrev-table text-mode-abbrev-table))
63785           (funcall expand))))
63786
63787     (add-hook 'foo-mode-hook
63788               (lambda ()
63789                 (add-function :around (local 'abbrev-expand-function)
63790                               #'foo-mode-abbrev-expand-function)))
63791
63792
63793File: elisp.info,  Node: Standard Abbrev Tables,  Next: Abbrev Properties,  Prev: Abbrev Expansion,  Up: Abbrevs
63794
6379536.5 Standard Abbrev Tables
63796===========================
63797
63798Here we list the variables that hold the abbrev tables for the preloaded
63799major modes of Emacs.
63800
63801 -- Variable: global-abbrev-table
63802     This is the abbrev table for mode-independent abbrevs.  The abbrevs
63803     defined in it apply to all buffers.  Each buffer may also have a
63804     local abbrev table, whose abbrev definitions take precedence over
63805     those in the global table.
63806
63807 -- Variable: local-abbrev-table
63808     The value of this buffer-local variable is the (mode-specific)
63809     abbreviation table of the current buffer.  It can also be a list of
63810     such tables.
63811
63812 -- Variable: abbrev-minor-mode-table-alist
63813     The value of this variable is a list of elements of the form ‘(MODE
63814     . ABBREV-TABLE)’ where MODE is the name of a variable: if the
63815     variable is bound to a non-‘nil’ value, then the ABBREV-TABLE is
63816     active, otherwise it is ignored.  ABBREV-TABLE can also be a list
63817     of abbrev tables.
63818
63819 -- Variable: fundamental-mode-abbrev-table
63820     This is the local abbrev table used in Fundamental mode; in other
63821     words, it is the local abbrev table in all buffers in Fundamental
63822     mode.
63823
63824 -- Variable: text-mode-abbrev-table
63825     This is the local abbrev table used in Text mode.
63826
63827 -- Variable: lisp-mode-abbrev-table
63828     This is the local abbrev table used in Lisp mode.  It is the parent
63829     of the local abbrev table used in Emacs Lisp mode.  *Note Abbrev
63830     Table Properties::.
63831
63832
63833File: elisp.info,  Node: Abbrev Properties,  Next: Abbrev Table Properties,  Prev: Standard Abbrev Tables,  Up: Abbrevs
63834
6383536.6 Abbrev Properties
63836======================
63837
63838Abbrevs have properties, some of which influence the way they work.  You
63839can provide them as arguments to ‘define-abbrev’, and manipulate them
63840with the following functions:
63841
63842 -- Function: abbrev-put abbrev prop val
63843     Set the property PROP of ABBREV to value VAL.
63844
63845 -- Function: abbrev-get abbrev prop
63846     Return the property PROP of ABBREV, or ‘nil’ if the abbrev has no
63847     such property.
63848
63849   The following properties have special meanings:
63850
63851‘:count’
63852     This property counts the number of times the abbrev has been
63853     expanded.  If not explicitly set, it is initialized to 0 by
63854     ‘define-abbrev’.
63855
63856‘:system’
63857     If non-‘nil’, this property marks the abbrev as a system abbrev.
63858     Such abbrevs are not saved (*note Abbrev Files::).
63859
63860‘:enable-function’
63861     If non-‘nil’, this property should be a function of no arguments
63862     which returns ‘nil’ if the abbrev should not be used and ‘t’
63863     otherwise.
63864
63865‘:case-fixed’
63866     If non-‘nil’, this property indicates that the case of the abbrev’s
63867     name is significant and should only match a text with the same
63868     pattern of capitalization.  It also disables the code that modifies
63869     the capitalization of the expansion.
63870
63871
63872File: elisp.info,  Node: Abbrev Table Properties,  Prev: Abbrev Properties,  Up: Abbrevs
63873
6387436.7 Abbrev Table Properties
63875============================
63876
63877Like abbrevs, abbrev tables have properties, some of which influence the
63878way they work.  You can provide them as arguments to
63879‘define-abbrev-table’, and manipulate them with the functions:
63880
63881 -- Function: abbrev-table-put table prop val
63882     Set the property PROP of abbrev table TABLE to value VAL.
63883
63884 -- Function: abbrev-table-get table prop
63885     Return the property PROP of abbrev table TABLE, or ‘nil’ if TABLE
63886     has no such property.
63887
63888   The following properties have special meaning:
63889
63890‘:enable-function’
63891     This is like the ‘:enable-function’ abbrev property except that it
63892     applies to all abbrevs in the table.  It is used before even trying
63893     to find the abbrev before point, so it can dynamically modify the
63894     abbrev table.
63895
63896‘:case-fixed’
63897     This is like the ‘:case-fixed’ abbrev property except that it
63898     applies to all abbrevs in the table.
63899
63900‘:regexp’
63901     If non-‘nil’, this property is a regular expression that indicates
63902     how to extract the name of the abbrev before point, before looking
63903     it up in the table.  When the regular expression matches before
63904     point, the abbrev name is expected to be in submatch 1.  If this
63905     property is ‘nil’, the default is to use ‘backward-word’ and
63906     ‘forward-word’ to find the name.  This property allows the use of
63907     abbrevs whose name contains characters of non-word syntax.
63908
63909‘:parents’
63910     This property holds a list of tables from which to inherit other
63911     abbrevs.
63912
63913‘:abbrev-table-modiff’
63914     This property holds a counter incremented each time a new abbrev is
63915     added to the table.
63916
63917
63918File: elisp.info,  Node: Threads,  Next: Processes,  Prev: Abbrevs,  Up: Top
63919
6392037 Threads
63921**********
63922
63923Emacs Lisp provides a limited form of concurrency, called “threads”.
63924All the threads in a given instance of Emacs share the same memory.
63925Concurrency in Emacs Lisp is “mostly cooperative”, meaning that Emacs
63926will only switch execution between threads at well-defined times.
63927However, the Emacs thread support has been designed in a way to later
63928allow more fine-grained concurrency, and correct programs should not
63929rely on cooperative threading.
63930
63931   Currently, thread switching will occur upon explicit request via
63932‘thread-yield’, when waiting for keyboard input or for process output
63933from asynchronous processes (e.g., during ‘accept-process-output’), or
63934during blocking operations relating to threads, such as mutex locking or
63935‘thread-join’.
63936
63937   Emacs Lisp provides primitives to create and control threads, and
63938also to create and control mutexes and condition variables, useful for
63939thread synchronization.
63940
63941   While global variables are shared among all Emacs Lisp threads, local
63942variables are not—a dynamic ‘let’ binding is local.  Each thread also
63943has its own current buffer (*note Current Buffer::) and its own match
63944data (*note Match Data::).
63945
63946   Note that ‘let’ bindings are treated specially by the Emacs Lisp
63947implementation.  There is no way to duplicate this unwinding and
63948rewinding behavior other than by using ‘let’.  For example, a manual
63949implementation of ‘let’ written using ‘unwind-protect’ cannot arrange
63950for variable values to be thread-specific.
63951
63952   In the case of lexical bindings (*note Variable Scoping::), a closure
63953is an object like any other in Emacs Lisp, and bindings in a closure are
63954shared by any threads invoking the closure.
63955
63956* Menu:
63957
63958* Basic Thread Functions::      Basic thread functions.
63959* Mutexes::                     Mutexes allow exclusive access to data.
63960* Condition Variables::         Inter-thread events.
63961* The Thread List::             Show the active threads.
63962
63963
63964File: elisp.info,  Node: Basic Thread Functions,  Next: Mutexes,  Up: Threads
63965
6396637.1 Basic Thread Functions
63967===========================
63968
63969Threads can be created and waited for.  A thread cannot be exited
63970directly, but the current thread can be exited implicitly, and other
63971threads can be signaled.
63972
63973 -- Function: make-thread function &optional name
63974     Create a new thread of execution which invokes FUNCTION.  When
63975     FUNCTION returns, the thread exits.
63976
63977     The new thread is created with no local variable bindings in
63978     effect.  The new thread’s current buffer is inherited from the
63979     current thread.
63980
63981     NAME can be supplied to give a name to the thread.  The name is
63982     used for debugging and informational purposes only; it has no
63983     meaning to Emacs.  If NAME is provided, it must be a string.
63984
63985     This function returns the new thread.
63986
63987 -- Function: threadp object
63988     This function returns ‘t’ if OBJECT represents an Emacs thread,
63989     ‘nil’ otherwise.
63990
63991 -- Function: thread-join thread
63992     Block until THREAD exits, or until the current thread is signaled.
63993     It returns the result of the THREAD function.  If THREAD has
63994     already exited, this returns immediately.
63995
63996 -- Function: thread-signal thread error-symbol data
63997     Like ‘signal’ (*note Signaling Errors::), but the signal is
63998     delivered in the thread THREAD.  If THREAD is the current thread,
63999     then this just calls ‘signal’ immediately.  Otherwise, THREAD will
64000     receive the signal as soon as it becomes current.  If THREAD was
64001     blocked by a call to ‘mutex-lock’, ‘condition-wait’, or
64002     ‘thread-join’; ‘thread-signal’ will unblock it.
64003
64004     If THREAD is the main thread, the signal is not propagated there.
64005     Instead, it is shown as message in the main thread.
64006
64007 -- Function: thread-yield
64008     Yield execution to the next runnable thread.
64009
64010 -- Function: thread-name thread
64011     Return the name of THREAD, as specified to ‘make-thread’.
64012
64013 -- Function: thread-live-p thread
64014     Return ‘t’ if THREAD is alive, or ‘nil’ if it is not.  A thread is
64015     alive as long as its function is still executing.
64016
64017 -- Function: thread--blocker thread
64018     Return the object that THREAD is waiting on.  This function is
64019     primarily intended for debugging, and is given a “double hyphen”
64020     name to indicate that.
64021
64022     If THREAD is blocked in ‘thread-join’, this returns the thread for
64023     which it is waiting.
64024
64025     If THREAD is blocked in ‘mutex-lock’, this returns the mutex.
64026
64027     If THREAD is blocked in ‘condition-wait’, this returns the
64028     condition variable.
64029
64030     Otherwise, this returns ‘nil’.
64031
64032 -- Function: current-thread
64033     Return the current thread.
64034
64035 -- Function: all-threads
64036     Return a list of all the live thread objects.  A new list is
64037     returned by each invocation.
64038
64039 -- Variable: main-thread
64040     This variable keeps the main thread Emacs is running, or ‘nil’ if
64041     Emacs is compiled without thread support.
64042
64043   When code run by a thread signals an error that is unhandled, the
64044thread exits.  Other threads can access the error form which caused the
64045thread to exit using the following function.
64046
64047 -- Function: thread-last-error &optional cleanup
64048     This function returns the last error form recorded when a thread
64049     exited due to an error.  Each thread that exits abnormally
64050     overwrites the form stored by the previous thread’s error with a
64051     new value, so only the last one can be accessed.  If CLEANUP is
64052     non-‘nil’, the stored form is reset to ‘nil’.
64053
64054
64055File: elisp.info,  Node: Mutexes,  Next: Condition Variables,  Prev: Basic Thread Functions,  Up: Threads
64056
6405737.2 Mutexes
64058============
64059
64060A “mutex” is an exclusive lock.  At any moment, zero or one threads may
64061own a mutex.  If a thread attempts to acquire a mutex, and the mutex is
64062already owned by some other thread, then the acquiring thread will block
64063until the mutex becomes available.
64064
64065   Emacs Lisp mutexes are of a type called “recursive”, which means that
64066a thread can re-acquire a mutex it owns any number of times.  A mutex
64067keeps a count of how many times it has been acquired, and each
64068acquisition of a mutex must be paired with a release.  The last release
64069by a thread of a mutex reverts it to the unowned state, potentially
64070allowing another thread to acquire the mutex.
64071
64072 -- Function: mutexp object
64073     This function returns ‘t’ if OBJECT represents an Emacs mutex,
64074     ‘nil’ otherwise.
64075
64076 -- Function: make-mutex &optional name
64077     Create a new mutex and return it.  If NAME is specified, it is a
64078     name given to the mutex.  It must be a string.  The name is for
64079     debugging purposes only; it has no meaning to Emacs.
64080
64081 -- Function: mutex-name mutex
64082     Return the name of MUTEX, as specified to ‘make-mutex’.
64083
64084 -- Function: mutex-lock mutex
64085     This will block until this thread acquires MUTEX, or until this
64086     thread is signaled using ‘thread-signal’.  If MUTEX is already
64087     owned by this thread, this simply returns.
64088
64089 -- Function: mutex-unlock mutex
64090     Release MUTEX.  If MUTEX is not owned by this thread, this will
64091     signal an error.
64092
64093 -- Macro: with-mutex mutex body...
64094     This macro is the simplest and safest way to evaluate forms while
64095     holding a mutex.  It acquires MUTEX, invokes BODY, and then
64096     releases MUTEX.  It returns the result of BODY.
64097
64098
64099File: elisp.info,  Node: Condition Variables,  Next: The Thread List,  Prev: Mutexes,  Up: Threads
64100
6410137.3 Condition Variables
64102========================
64103
64104A “condition variable” is a way for a thread to block until some event
64105occurs.  A thread can wait on a condition variable, to be woken up when
64106some other thread notifies the condition.
64107
64108   A condition variable is associated with a mutex and, conceptually,
64109with some condition.  For proper operation, the mutex must be acquired,
64110and then a waiting thread must loop, testing the condition and waiting
64111on the condition variable.  For example:
64112
64113     (with-mutex mutex
64114       (while (not global-variable)
64115         (condition-wait cond-var)))
64116
64117   The mutex ensures atomicity, and the loop is for robustness—there may
64118be spurious notifications.
64119
64120   Similarly, the mutex must be held before notifying the condition.
64121The typical, and best, approach is to acquire the mutex, make the
64122changes associated with this condition, and then notify it:
64123
64124     (with-mutex mutex
64125       (setq global-variable (some-computation))
64126       (condition-notify cond-var))
64127
64128 -- Function: make-condition-variable mutex &optional name
64129     Make a new condition variable associated with MUTEX.  If NAME is
64130     specified, it is a name given to the condition variable.  It must
64131     be a string.  The name is for debugging purposes only; it has no
64132     meaning to Emacs.
64133
64134 -- Function: condition-variable-p object
64135     This function returns ‘t’ if OBJECT represents a condition
64136     variable, ‘nil’ otherwise.
64137
64138 -- Function: condition-wait cond
64139     Wait for another thread to notify COND, a condition variable.  This
64140     function will block until the condition is notified, or until a
64141     signal is delivered to this thread using ‘thread-signal’.
64142
64143     It is an error to call ‘condition-wait’ without holding the
64144     condition’s associated mutex.
64145
64146     ‘condition-wait’ releases the associated mutex while waiting.  This
64147     allows other threads to acquire the mutex in order to notify the
64148     condition.
64149
64150 -- Function: condition-notify cond &optional all
64151     Notify COND.  The mutex with COND must be held before calling this.
64152     Ordinarily a single waiting thread is woken by ‘condition-notify’;
64153     but if ALL is not ‘nil’, then all threads waiting on COND are
64154     notified.
64155
64156     ‘condition-notify’ releases the associated mutex while waiting.
64157     This allows other threads to acquire the mutex in order to wait on
64158     the condition.
64159
64160 -- Function: condition-name cond
64161     Return the name of COND, as passed to ‘make-condition-variable’.
64162
64163 -- Function: condition-mutex cond
64164     Return the mutex associated with COND.  Note that the associated
64165     mutex cannot be changed.
64166
64167
64168File: elisp.info,  Node: The Thread List,  Prev: Condition Variables,  Up: Threads
64169
6417037.4 The Thread List
64171====================
64172
64173The ‘list-threads’ command lists all the currently alive threads.  In
64174the resulting buffer, each thread is identified either by the name
64175passed to ‘make-thread’ (*note Basic Thread Functions::), or by its
64176unique internal identifier if it was not created with a name.  The
64177status of each thread at the time of the creation or last update of the
64178buffer is shown, in addition to the object the thread was blocked on at
64179the time, if it was blocked.
64180
64181 -- Variable: thread-list-refresh-seconds
64182     The ‘*Threads*’ buffer will automatically update twice per second.
64183     You can make the refresh rate faster or slower by customizing this
64184     variable.
64185
64186   Here are the commands available in the thread list buffer:
64187
64188‘b’
64189     Show a backtrace of the thread at point.  This will show where in
64190     its code the thread had yielded or was blocked at the moment you
64191     pressed ‘b’.  Be aware that the backtrace is a snapshot; the thread
64192     could have meanwhile resumed execution, and be in a different
64193     state, or could have exited.
64194
64195     You may use ‘g’ in the thread’s backtrace buffer to get an updated
64196     backtrace, as backtrace buffers do not automatically update.  *Note
64197     Backtraces::, for a description of backtraces and the other
64198     commands which work on them.
64199
64200‘s’
64201     Signal the thread at point.  After ‘s’, type ‘q’ to send a quit
64202     signal or ‘e’ to send an error signal.  Threads may implement
64203     handling of signals, but the default behavior is to exit on any
64204     signal.  Therefore you should only use this command if you
64205     understand how to restart the target thread, because your Emacs
64206     session may behave incorrectly if necessary threads are killed.
64207
64208‘g’
64209     Update the list of threads and their statuses.
64210
64211
64212File: elisp.info,  Node: Processes,  Next: Display,  Prev: Threads,  Up: Top
64213
6421438 Processes
64215************
64216
64217In the terminology of operating systems, a “process” is a space in which
64218a program can execute.  Emacs runs in a process.  Emacs Lisp programs
64219can invoke other programs in processes of their own.  These are called
64220“subprocesses” or “child processes” of the Emacs process, which is their
64221“parent process”.
64222
64223   A subprocess of Emacs may be “synchronous” or “asynchronous”,
64224depending on how it is created.  When you create a synchronous
64225subprocess, the Lisp program waits for the subprocess to terminate
64226before continuing execution.  When you create an asynchronous
64227subprocess, it can run in parallel with the Lisp program.  This kind of
64228subprocess is represented within Emacs by a Lisp object which is also
64229called a “process”.  Lisp programs can use this object to communicate
64230with the subprocess or to control it.  For example, you can send
64231signals, obtain status information, receive output from the process, or
64232send input to it.
64233
64234   In addition to processes that run programs, Lisp programs can open
64235connections of several types to devices or processes running on the same
64236machine or on other machines.  The supported connection types are: TCP
64237and UDP network connections, serial port connections, and pipe
64238connections.  Each such connection is also represented by a process
64239object.
64240
64241 -- Function: processp object
64242     This function returns ‘t’ if OBJECT represents an Emacs process
64243     object, ‘nil’ otherwise.  The process object can represent a
64244     subprocess running a program or a connection of any supported type.
64245
64246   In addition to subprocesses of the current Emacs session, you can
64247also access other processes running on your machine.  *Note System
64248Processes::.
64249
64250* Menu:
64251
64252* Subprocess Creation::      Functions that start subprocesses.
64253* Shell Arguments::          Quoting an argument to pass it to a shell.
64254* Synchronous Processes::    Details of using synchronous subprocesses.
64255* Asynchronous Processes::   Starting up an asynchronous subprocess.
64256* Deleting Processes::       Eliminating an asynchronous subprocess.
64257* Process Information::      Accessing run-status and other attributes.
64258* Input to Processes::       Sending input to an asynchronous subprocess.
64259* Signals to Processes::     Stopping, continuing or interrupting
64260                               an asynchronous subprocess.
64261* Output from Processes::    Collecting output from an asynchronous subprocess.
64262* Sentinels::                Sentinels run when process run-status changes.
64263* Query Before Exit::        Whether to query if exiting will kill a process.
64264* System Processes::         Accessing other processes running on your system.
64265* Transaction Queues::       Transaction-based communication with subprocesses.
64266* Network::                  Opening network connections.
64267* Network Servers::          Network servers let Emacs accept net connections.
64268* Datagrams::                UDP network connections.
64269* Low-Level Network::        Lower-level but more general function
64270                               to create connections and servers.
64271* Misc Network::             Additional relevant functions for net connections.
64272* Serial Ports::             Communicating with serial ports.
64273* Byte Packing::             Using bindat to pack and unpack binary data.
64274
64275
64276File: elisp.info,  Node: Subprocess Creation,  Next: Shell Arguments,  Up: Processes
64277
6427838.1 Functions that Create Subprocesses
64279=======================================
64280
64281There are three primitives that create a new subprocess in which to run
64282a program.  One of them, ‘make-process’, creates an asynchronous process
64283and returns a process object (*note Asynchronous Processes::).  The
64284other two, ‘call-process’ and ‘call-process-region’, create a
64285synchronous process and do not return a process object (*note
64286Synchronous Processes::).  There are various higher-level functions that
64287make use of these primitives to run particular types of process.
64288
64289   Synchronous and asynchronous processes are explained in the following
64290sections.  Since the three functions are all called in a similar
64291fashion, their common arguments are described here.
64292
64293   In all cases, the functions specify the program to be run.  An error
64294is signaled if the file is not found or cannot be executed.  If the file
64295name is relative, the variable ‘exec-path’ contains a list of
64296directories to search.  Emacs initializes ‘exec-path’ when it starts up,
64297based on the value of the environment variable ‘PATH’.  The standard
64298file name constructs, ‘~’, ‘.’, and ‘..’, are interpreted as usual in
64299‘exec-path’, but environment variable substitutions (‘$HOME’, etc.) are
64300not recognized; use ‘substitute-in-file-name’ to perform them (*note
64301File Name Expansion::).  ‘nil’ in this list refers to
64302‘default-directory’.
64303
64304   Executing a program can also try adding suffixes to the specified
64305name:
64306
64307 -- User Option: exec-suffixes
64308     This variable is a list of suffixes (strings) to try adding to the
64309     specified program file name.  The list should include ‘""’ if you
64310     want the name to be tried exactly as specified.  The default value
64311     is system-dependent.
64312
64313   *Please note:* The argument PROGRAM contains only the name of the
64314program file; it may not contain any command-line arguments.  You must
64315use a separate argument, ARGS, to provide those, as described below.
64316
64317   Each of the subprocess-creating functions has a BUFFER-OR-NAME
64318argument that specifies where the output from the program will go.  It
64319should be a buffer or a buffer name; if it is a buffer name, that will
64320create the buffer if it does not already exist.  It can also be ‘nil’,
64321which says to discard the output, unless a custom filter function
64322handles it.  (*Note Filter Functions::, and *note Read and Print::.)
64323Normally, you should avoid having multiple processes send output to the
64324same buffer because their output would be intermixed randomly.  For
64325synchronous processes, you can send the output to a file instead of a
64326buffer (and the corresponding argument is therefore more appropriately
64327called DESTINATION).  By default, both standard output and standard
64328error streams go to the same destination, but all the 3 primitives allow
64329optionally to direct the standard error stream to a different
64330destination.
64331
64332   All three of the subprocess-creating functions allow to specify
64333command-line arguments for the process to run.  For ‘call-process’ and
64334‘call-process-region’, these come in the form of a ‘&rest’ argument,
64335ARGS.  For ‘make-process’, both the program to run and its command-line
64336arguments are specified as a list of strings.  The command-line
64337arguments must all be strings, and they are supplied to the program as
64338separate argument strings.  Wildcard characters and other shell
64339constructs have no special meanings in these strings, since the strings
64340are passed directly to the specified program.
64341
64342   The subprocess inherits its environment from Emacs, but you can
64343specify overrides for it with ‘process-environment’.  *Note System
64344Environment::.  The subprocess gets its current directory from the value
64345of ‘default-directory’.
64346
64347 -- Variable: exec-directory
64348     The value of this variable is a string, the name of a directory
64349     that contains programs that come with GNU Emacs and are intended
64350     for Emacs to invoke.  The program ‘movemail’ is an example of such
64351     a program; Rmail uses it to fetch new mail from an inbox.
64352
64353 -- User Option: exec-path
64354     The value of this variable is a list of directories to search for
64355     programs to run in subprocesses.  Each element is either the name
64356     of a directory (i.e., a string), or ‘nil’, which stands for the
64357     default directory (which is the value of ‘default-directory’).
64358     *Note executable-find: Locating Files, for the details of this
64359     search.
64360
64361     The value of ‘exec-path’ is used by ‘call-process’ and
64362     ‘start-process’ when the PROGRAM argument is not an absolute file
64363     name.
64364
64365     Generally, you should not modify ‘exec-path’ directly.  Instead,
64366     ensure that your ‘PATH’ environment variable is set appropriately
64367     before starting Emacs.  Trying to modify ‘exec-path’ independently
64368     of ‘PATH’ can lead to confusing results.
64369
64370 -- Function: exec-path
64371     This function is an extension of the variable ‘exec-path’.  If
64372     ‘default-directory’ indicates a remote directory, this function
64373     returns a list of directories used for searching programs on the
64374     respective remote host.  In case of a local ‘default-directory’,
64375     the function returns just the value of the variable ‘exec-path’.
64376
64377
64378File: elisp.info,  Node: Shell Arguments,  Next: Synchronous Processes,  Prev: Subprocess Creation,  Up: Processes
64379
6438038.2 Shell Arguments
64381====================
64382
64383Lisp programs sometimes need to run a shell and give it a command that
64384contains file names that were specified by the user.  These programs
64385ought to be able to support any valid file name.  But the shell gives
64386special treatment to certain characters, and if these characters occur
64387in the file name, they will confuse the shell.  To handle these
64388characters, use the function ‘shell-quote-argument’:
64389
64390 -- Function: shell-quote-argument argument
64391     This function returns a string that represents, in shell syntax, an
64392     argument whose actual contents are ARGUMENT.  It should work
64393     reliably to concatenate the return value into a shell command and
64394     then pass it to a shell for execution.
64395
64396     Precisely what this function does depends on your operating system.
64397     The function is designed to work with the syntax of your system’s
64398     standard shell; if you use an unusual shell, you will need to
64399     redefine this function.  *Note Security Considerations::.
64400
64401          ;; This example shows the behavior on GNU and Unix systems.
64402          (shell-quote-argument "foo > bar")
64403               ⇒ "foo\\ \\>\\ bar"
64404
64405          ;; This example shows the behavior on MS-DOS and MS-Windows.
64406          (shell-quote-argument "foo > bar")
64407               ⇒ "\"foo > bar\""
64408
64409     Here’s an example of using ‘shell-quote-argument’ to construct a
64410     shell command:
64411
64412          (concat "diff -u "
64413                  (shell-quote-argument oldfile)
64414                  " "
64415                  (shell-quote-argument newfile))
64416
64417   The following two functions are useful for combining a list of
64418individual command-line argument strings into a single string, and
64419taking a string apart into a list of individual command-line arguments.
64420These functions are mainly intended for converting user input in the
64421minibuffer, a Lisp string, into a list of string arguments to be passed
64422to ‘make-process’, ‘call-process’ or ‘start-process’, or for converting
64423such lists of arguments into a single Lisp string to be presented in the
64424minibuffer or echo area.  Note that if a shell is involved (e.g., if
64425using ‘call-process-shell-command’), arguments should still be protected
64426by ‘shell-quote-argument’; ‘combine-and-quote-strings’ is _not_ intended
64427to protect special characters from shell evaluation.
64428
64429 -- Function: split-string-and-unquote string &optional separators
64430     This function splits STRING into substrings at matches for the
64431     regular expression SEPARATORS, like ‘split-string’ does (*note
64432     Creating Strings::); in addition, it removes quoting from the
64433     substrings.  It then makes a list of the substrings and returns it.
64434
64435     If SEPARATORS is omitted or ‘nil’, it defaults to ‘"\\s-+"’, which
64436     is a regular expression that matches one or more characters with
64437     whitespace syntax (*note Syntax Class Table::).
64438
64439     This function supports two types of quoting: enclosing a whole
64440     string in double quotes ‘"..."’, and quoting individual characters
64441     with a backslash escape ‘\’.  The latter is also used in Lisp
64442     strings, so this function can handle those as well.
64443
64444 -- Function: combine-and-quote-strings list-of-strings &optional
64445          separator
64446     This function concatenates LIST-OF-STRINGS into a single string,
64447     quoting each string as necessary.  It also sticks the SEPARATOR
64448     string between each pair of strings; if SEPARATOR is omitted or
64449     ‘nil’, it defaults to ‘" "’.  The return value is the resulting
64450     string.
64451
64452     The strings in LIST-OF-STRINGS that need quoting are those that
64453     include SEPARATOR as their substring.  Quoting a string encloses it
64454     in double quotes ‘"..."’.  In the simplest case, if you are consing
64455     a command from the individual command-line arguments, every
64456     argument that includes embedded blanks will be quoted.
64457
64458
64459File: elisp.info,  Node: Synchronous Processes,  Next: Asynchronous Processes,  Prev: Shell Arguments,  Up: Processes
64460
6446138.3 Creating a Synchronous Process
64462===================================
64463
64464After a “synchronous process” is created, Emacs waits for the process to
64465terminate before continuing.  Starting Dired on GNU or Unix(1) is an
64466example of this: it runs ‘ls’ in a synchronous process, then modifies
64467the output slightly.  Because the process is synchronous, the entire
64468directory listing arrives in the buffer before Emacs tries to do
64469anything with it.
64470
64471   While Emacs waits for the synchronous subprocess to terminate, the
64472user can quit by typing ‘C-g’.  The first ‘C-g’ tries to kill the
64473subprocess with a ‘SIGINT’ signal; but it waits until the subprocess
64474actually terminates before quitting.  If during that time the user types
64475another ‘C-g’, that kills the subprocess instantly with ‘SIGKILL’ and
64476quits immediately (except on MS-DOS, where killing other processes
64477doesn’t work).  *Note Quitting::.
64478
64479   The synchronous subprocess functions return an indication of how the
64480process terminated.
64481
64482   The output from a synchronous subprocess is generally decoded using a
64483coding system, much like text read from a file.  The input sent to a
64484subprocess by ‘call-process-region’ is encoded using a coding system,
64485much like text written into a file.  *Note Coding Systems::.
64486
64487 -- Function: call-process program &optional infile destination display
64488          &rest args
64489     This function calls PROGRAM and waits for it to finish.
64490
64491     The current working directory of the subprocess is set to the
64492     current buffer’s value of ‘default-directory’ if that is local (as
64493     determined by ‘unhandled-file-name-directory’), or "~" otherwise.
64494     If you want to run a process in a remote directory use
64495     ‘process-file’.
64496
64497     The standard input for the new process comes from file INFILE if
64498     INFILE is not ‘nil’, and from the null device otherwise.  The
64499     argument DESTINATION says where to put the process output.  Here
64500     are the possibilities:
64501
64502     a buffer
64503          Insert the output in that buffer, before point.  This includes
64504          both the standard output stream and the standard error stream
64505          of the process.
64506
64507     a buffer name (a string)
64508          Insert the output in a buffer with that name, before point.
64509
64510     ‘t’
64511          Insert the output in the current buffer, before point.
64512
64513     ‘nil’
64514          Discard the output.
64515
64516     0
64517          Discard the output, and return ‘nil’ immediately without
64518          waiting for the subprocess to finish.
64519
64520          In this case, the process is not truly synchronous, since it
64521          can run in parallel with Emacs; but you can think of it as
64522          synchronous in that Emacs is essentially finished with the
64523          subprocess as soon as this function returns.
64524
64525          MS-DOS doesn’t support asynchronous subprocesses, so this
64526          option doesn’t work there.
64527
64528     ‘(:file FILE-NAME)’
64529          Send the output to the file name specified, overwriting it if
64530          it already exists.
64531
64532     ‘(REAL-DESTINATION ERROR-DESTINATION)’
64533          Keep the standard output stream separate from the standard
64534          error stream; deal with the ordinary output as specified by
64535          REAL-DESTINATION, and dispose of the error output according to
64536          ERROR-DESTINATION.  If ERROR-DESTINATION is ‘nil’, that means
64537          to discard the error output, ‘t’ means mix it with the
64538          ordinary output, and a string specifies a file name to
64539          redirect error output into.
64540
64541          You can’t directly specify a buffer to put the error output
64542          in; that is too difficult to implement.  But you can achieve
64543          this result by sending the error output to a temporary file
64544          and then inserting the file into a buffer when the subprocess
64545          finishes.
64546
64547     If DISPLAY is non-‘nil’, then ‘call-process’ redisplays the buffer
64548     as output is inserted.  (However, if the coding system chosen for
64549     decoding output is ‘undecided’, meaning deduce the encoding from
64550     the actual data, then redisplay sometimes cannot continue once
64551     non-ASCII characters are encountered.  There are fundamental
64552     reasons why it is hard to fix this; see *note Output from
64553     Processes::.)
64554
64555     Otherwise the function ‘call-process’ does no redisplay, and the
64556     results become visible on the screen only when Emacs redisplays
64557     that buffer in the normal course of events.
64558
64559     The remaining arguments, ARGS, are strings that specify command
64560     line arguments for the program.  Each string is passed to PROGRAM
64561     as a separate argument.
64562
64563     The value returned by ‘call-process’ (unless you told it not to
64564     wait) indicates the reason for process termination.  A number gives
64565     the exit status of the subprocess; 0 means success, and any other
64566     value means failure.  If the process terminated with a signal,
64567     ‘call-process’ returns a string describing the signal.  If you told
64568     ‘call-process’ not to wait, it returns ‘nil’.
64569
64570     In the examples below, the buffer ‘foo’ is current.
64571
64572          (call-process "pwd" nil t)
64573               ⇒ 0
64574
64575          ---------- Buffer: foo ----------
64576          /home/lewis/manual
64577          ---------- Buffer: foo ----------
64578
64579          (call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
64580               ⇒ 0
64581
64582          ---------- Buffer: bar ----------
64583          lewis:x:1001:1001:Bil Lewis,,,,:/home/lewis:/bin/bash
64584
64585          ---------- Buffer: bar ----------
64586
64587     Here is an example of the use of ‘call-process’, as used to be
64588     found in the definition of the ‘insert-directory’ function:
64589
64590          (call-process insert-directory-program nil t nil switches
64591                        (if full-directory-p
64592                            (concat (file-name-as-directory file) ".")
64593                          file))
64594
64595 -- Function: process-file program &optional infile buffer display &rest
64596          args
64597     This function processes files synchronously in a separate process.
64598     It is similar to ‘call-process’, but may invoke a file name handler
64599     based on the value of the variable ‘default-directory’, which
64600     specifies the current working directory of the subprocess.
64601
64602     The arguments are handled in almost the same way as for
64603     ‘call-process’, with the following differences:
64604
64605     Some file name handlers may not support all combinations and forms
64606     of the arguments INFILE, BUFFER, and DISPLAY.  For example, some
64607     file name handlers might behave as if DISPLAY were ‘nil’,
64608     regardless of the value actually passed.  As another example, some
64609     file name handlers might not support separating standard output and
64610     error output by way of the BUFFER argument.
64611
64612     If a file name handler is invoked, it determines the program to run
64613     based on the first argument PROGRAM.  For instance, suppose that a
64614     handler for remote files is invoked.  Then the path that is used
64615     for searching for the program might be different from ‘exec-path’.
64616
64617     The second argument INFILE may invoke a file name handler.  The
64618     file name handler could be different from the handler chosen for
64619     the ‘process-file’ function itself.  (For example,
64620     ‘default-directory’ could be on one remote host, and INFILE on a
64621     different remote host.  Or ‘default-directory’ could be
64622     non-special, whereas INFILE is on a remote host.)
64623
64624     If BUFFER is a list of the form ‘(REAL-DESTINATION
64625     ERROR-DESTINATION)’, and ERROR-DESTINATION names a file, then the
64626     same remarks as for INFILE apply.
64627
64628     The remaining arguments (ARGS) will be passed to the process
64629     verbatim.  Emacs is not involved in processing file names that are
64630     present in ARGS.  To avoid confusion, it may be best to avoid
64631     absolute file names in ARGS, but rather to specify all file names
64632     as relative to ‘default-directory’.  The function
64633     ‘file-relative-name’ is useful for constructing such relative file
64634     names.  Alternatively, you can use ‘file-local-name’ (*note Magic
64635     File Names::) to obtain an absolute file name as seen from the
64636     remote host’s perspective.
64637
64638 -- Variable: process-file-side-effects
64639     This variable indicates whether a call of ‘process-file’ changes
64640     remote files.
64641
64642     By default, this variable is always set to ‘t’, meaning that a call
64643     of ‘process-file’ could potentially change any file on a remote
64644     host.  When set to ‘nil’, a file name handler could optimize its
64645     behavior with respect to remote file attribute caching.
64646
64647     You should only ever change this variable with a let-binding; never
64648     with ‘setq’.
64649
64650 -- Function: call-process-region start end program &optional delete
64651          destination display &rest args
64652     This function sends the text from START to END as standard input to
64653     a process running PROGRAM.  It deletes the text sent if DELETE is
64654     non-‘nil’; this is useful when DESTINATION is ‘t’, to insert the
64655     output in the current buffer in place of the input.
64656
64657     The arguments DESTINATION and DISPLAY control what to do with the
64658     output from the subprocess, and whether to update the display as it
64659     comes in.  For details, see the description of ‘call-process’,
64660     above.  If DESTINATION is the integer 0, ‘call-process-region’
64661     discards the output and returns ‘nil’ immediately, without waiting
64662     for the subprocess to finish (this only works if asynchronous
64663     subprocesses are supported; i.e., not on MS-DOS).
64664
64665     The remaining arguments, ARGS, are strings that specify command
64666     line arguments for the program.
64667
64668     The return value of ‘call-process-region’ is just like that of
64669     ‘call-process’: ‘nil’ if you told it to return without waiting;
64670     otherwise, a number or string which indicates how the subprocess
64671     terminated.
64672
64673     In the following example, we use ‘call-process-region’ to run the
64674     ‘cat’ utility, with standard input being the first five characters
64675     in buffer ‘foo’ (the word ‘input’).  ‘cat’ copies its standard
64676     input into its standard output.  Since the argument DESTINATION is
64677     ‘t’, this output is inserted in the current buffer.
64678
64679          ---------- Buffer: foo ----------
64680          input★
64681          ---------- Buffer: foo ----------
64682
64683          (call-process-region 1 6 "cat" nil t)
64684               ⇒ 0
64685
64686          ---------- Buffer: foo ----------
64687          inputinput★
64688          ---------- Buffer: foo ----------
64689
64690     For example, the ‘shell-command-on-region’ command uses
64691     ‘call-shell-region’ in a manner similar to this:
64692
64693          (call-shell-region
64694           start end
64695           command              ; shell command
64696           nil                  ; do not delete region
64697           buffer)              ; send output to ‘buffer’
64698
64699 -- Function: call-process-shell-command command &optional infile
64700          destination display
64701     This function executes the shell command COMMAND synchronously.
64702     The other arguments are handled as in ‘call-process’.  An old
64703     calling convention allowed passing any number of additional
64704     arguments after DISPLAY, which were concatenated to COMMAND; this
64705     is still supported, but strongly discouraged.
64706
64707 -- Function: process-file-shell-command command &optional infile
64708          destination display
64709     This function is like ‘call-process-shell-command’, but uses
64710     ‘process-file’ internally.  Depending on ‘default-directory’,
64711     COMMAND can be executed also on remote hosts.  An old calling
64712     convention allowed passing any number of additional arguments after
64713     DISPLAY, which were concatenated to COMMAND; this is still
64714     supported, but strongly discouraged.
64715
64716 -- Function: call-shell-region start end command &optional delete
64717          destination
64718     This function sends the text from START to END as standard input to
64719     an inferior shell running COMMAND.  This function is similar than
64720     ‘call-process-region’, with process being a shell.  The arguments
64721     ‘delete’, ‘destination’ and the return value are like in
64722     ‘call-process-region’.  Note that this function doesn’t accept
64723     additional arguments.
64724
64725 -- Function: shell-command-to-string command
64726     This function executes COMMAND (a string) as a shell command, then
64727     returns the command’s output as a string.
64728
64729 -- Function: process-lines program &rest args
64730     This function runs PROGRAM, waits for it to finish, and returns its
64731     output as a list of strings.  Each string in the list holds a
64732     single line of text output by the program; the end-of-line
64733     characters are stripped from each line.  The arguments beyond
64734     PROGRAM, ARGS, are strings that specify command-line arguments with
64735     which to run the program.
64736
64737     If PROGRAM exits with a non-zero exit status, this function signals
64738     an error.
64739
64740     This function works by calling ‘call-process’, so program output is
64741     decoded in the same way as for ‘call-process’.
64742
64743   ---------- Footnotes ----------
64744
64745   (1) On other systems, Emacs uses a Lisp emulation of ‘ls’; see *note
64746Contents of Directories::.
64747
64748
64749File: elisp.info,  Node: Asynchronous Processes,  Next: Deleting Processes,  Prev: Synchronous Processes,  Up: Processes
64750
6475138.4 Creating an Asynchronous Process
64752=====================================
64753
64754In this section, we describe how to create an “asynchronous process”.
64755After an asynchronous process is created, it runs in parallel with
64756Emacs, and Emacs can communicate with it using the functions described
64757in the following sections (*note Input to Processes::, and *note Output
64758from Processes::).  Note that process communication is only partially
64759asynchronous: Emacs sends and receives data to and from a process only
64760when those functions are called.
64761
64762   An asynchronous process is controlled either via a “pty”
64763(pseudo-terminal) or a “pipe”.  The choice of pty or pipe is made when
64764creating the process, by default based on the value of the variable
64765‘process-connection-type’ (see below).  If available, ptys are usually
64766preferable for processes visible to the user, as in Shell mode, because
64767they allow for job control (‘C-c’, ‘C-z’, etc.) between the process and
64768its children, and because interactive programs treat ptys as terminal
64769devices, whereas pipes don’t support these features.  However, for
64770subprocesses used by Lisp programs for internal purposes (i.e., no user
64771interaction with the subprocess is required), where significant amounts
64772of data need to be exchanged between the subprocess and the Lisp
64773program, it is often better to use a pipe, because pipes are more
64774efficient.  Also, the total number of ptys is limited on many systems,
64775and it is good not to waste them unnecessarily.
64776
64777 -- Function: make-process &rest args
64778     This function is the basic low-level primitive for starting
64779     asynchronous subprocesses.  It returns a process object
64780     representing the subprocess.  Compared to the more high-level
64781     ‘start-process’, described below, it takes keyword arguments, is
64782     more flexible, and allows to specify process filters and sentinels
64783     in a single call.
64784
64785     The arguments ARGS are a list of keyword/argument pairs.  Omitting
64786     a keyword is always equivalent to specifying it with value ‘nil’.
64787     Here are the meaningful keywords:
64788
64789     :name NAME
64790          Use the string NAME as the process name; if a process with
64791          this name already exists, then NAME is modified (by appending
64792          ‘<1>’, etc.) to be unique.
64793
64794     :buffer BUFFER
64795          Use BUFFER as the process buffer.  If the value is ‘nil’, the
64796          subprocess is not associated with any buffer.
64797
64798     :command COMMAND
64799          Use COMMAND as the command line of the process.  The value
64800          should be a list starting with the program’s executable file
64801          name, followed by strings to give to the program as its
64802          arguments.  If the first element of the list is ‘nil’, Emacs
64803          opens a new pseudoterminal (pty) and associates its input and
64804          output with BUFFER, without actually running any program; the
64805          rest of the list elements are ignored in that case.
64806
64807     :coding CODING
64808          If CODING is a symbol, it specifies the coding system to be
64809          used for both reading and writing of data from and to the
64810          connection.  If CODING is a cons cell ‘(DECODING . ENCODING)’,
64811          then DECODING will be used for reading and ENCODING for
64812          writing.  The coding system used for encoding the data written
64813          to the program is also used for encoding the command-line
64814          arguments (but not the program itself, whose file name is
64815          encoded as any other file name; *note file-name-coding-system:
64816          Encoding and I/O.).
64817
64818          If CODING is ‘nil’, the default rules for finding the coding
64819          system will apply.  *Note Default Coding Systems::.
64820
64821     :connection-type TYPE
64822          Initialize the type of device used to communicate with the
64823          subprocess.  Possible values are ‘pty’ to use a pty, ‘pipe’ to
64824          use a pipe, or ‘nil’ to use the default derived from the value
64825          of the ‘process-connection-type’ variable.  This parameter and
64826          the value of ‘process-connection-type’ are ignored if a
64827          non-‘nil’ value is specified for the ‘:stderr’ parameter; in
64828          that case, the type will always be ‘pipe’.  On systems where
64829          ptys are not available (MS-Windows), this parameter is
64830          likewise ignored, and pipes are used unconditionally.
64831
64832     :noquery QUERY-FLAG
64833          Initialize the process query flag to QUERY-FLAG.  *Note Query
64834          Before Exit::.
64835
64836     :stop STOPPED
64837          If provided, STOPPED must be ‘nil’; it is an error to use any
64838          non-‘nil’ value.  The ‘:stop’ key is ignored otherwise and is
64839          retained for compatibility with other process types such as
64840          pipe processes.  Asynchronous subprocesses never start in the
64841          stopped state.
64842
64843     :filter FILTER
64844          Initialize the process filter to FILTER.  If not specified, a
64845          default filter will be provided, which can be overridden
64846          later.  *Note Filter Functions::.
64847
64848     :sentinel SENTINEL
64849          Initialize the process sentinel to SENTINEL.  If not
64850          specified, a default sentinel will be used, which can be
64851          overridden later.  *Note Sentinels::.
64852
64853     :stderr STDERR
64854          Associate STDERR with the standard error of the process.  A
64855          non-‘nil’ value should be either a buffer or a pipe process
64856          created with ‘make-pipe-process’, described below.  If STDERR
64857          is ‘nil’, standard error is mixed with standard output, and
64858          both are sent to BUFFER or FILTER.
64859
64860          If STDERR is a buffer, Emacs will create a pipe process, the
64861          “standard error process”.  This process will have the default
64862          filter (*note Filter Functions::), sentinel (*note
64863          Sentinels::), and coding systems (*note Default Coding
64864          Systems::).  On the other hand, it will use QUERY-FLAG as its
64865          query-on-exit flag (*note Query Before Exit::).  It will be
64866          associated with the STDERR buffer (*note Process Buffers::)
64867          and send its output (which is the standard error of the main
64868          process) there.
64869
64870          If STDERR is a pipe process, Emacs will use it as standard
64871          error process for the new process.
64872
64873     :file-handler FILE-HANDLER
64874          If FILE-HANDLER is non-‘nil’, then look for a file name
64875          handler for the current buffer’s ‘default-directory’, and
64876          invoke that file name handler to make the process.  If there
64877          is no such handler, proceed as if FILE-HANDLER were ‘nil’.
64878
64879     The original argument list, modified with the actual connection
64880     information, is available via the ‘process-contact’ function.
64881
64882     The current working directory of the subprocess is set to the
64883     current buffer’s value of ‘default-directory’ if that is local (as
64884     determined by ‘unhandled-file-name-directory’), or ‘~’ otherwise.
64885     If you want to run a process in a remote directory, pass
64886     ‘:file-handler t’ to ‘make-process’.  In that case, the current
64887     working directory is the local name component of
64888     ‘default-directory’ (as determined by ‘file-local-name’).
64889
64890     Depending on the implementation of the file name handler, it might
64891     not be possible to apply FILTER or SENTINEL to the resulting
64892     process object.  The ‘:stderr’ argument cannot be a pipe process,
64893     file name handlers do not support pipe processes for this.  A
64894     buffer as ‘:stderr’ argument is accepted, its contents is shown
64895     without the use of pipe processes.  *Note Filter Functions::, *note
64896     Sentinels::, and *note Accepting Output::.
64897
64898     Some file name handlers may not support ‘make-process’.  In such
64899     cases, this function does nothing and returns ‘nil’.
64900
64901 -- Function: make-pipe-process &rest args
64902     This function creates a bidirectional pipe which can be attached to
64903     a child process.  This is useful with the ‘:stderr’ keyword of
64904     ‘make-process’.  The function returns a process object.
64905
64906     The arguments ARGS are a list of keyword/argument pairs.  Omitting
64907     a keyword is always equivalent to specifying it with value ‘nil’.
64908
64909     Here are the meaningful keywords:
64910
64911     :name NAME
64912          Use the string NAME as the process name.  As with
64913          ‘make-process’, it is modified if necessary to make it unique.
64914
64915     :buffer BUFFER
64916          Use BUFFER as the process buffer.
64917
64918     :coding CODING
64919          If CODING is a symbol, it specifies the coding system to be
64920          used for both reading and writing of data from and to the
64921          connection.  If CODING is a cons cell ‘(DECODING . ENCODING)’,
64922          then DECODING will be used for reading and ENCODING for
64923          writing.
64924
64925          If CODING is ‘nil’, the default rules for finding the coding
64926          system will apply.  *Note Default Coding Systems::.
64927
64928     :noquery QUERY-FLAG
64929          Initialize the process query flag to QUERY-FLAG.  *Note Query
64930          Before Exit::.
64931
64932     :stop STOPPED
64933          If STOPPED is non-‘nil’, start the process in the stopped
64934          state.  In the stopped state, a pipe process does not accept
64935          incoming data, but you can send outgoing data.  The stopped
64936          state is set by ‘stop-process’ and cleared by
64937          ‘continue-process’ (*note Signals to Processes::).
64938
64939     :filter FILTER
64940          Initialize the process filter to FILTER.  If not specified, a
64941          default filter will be provided, which can be changed later.
64942          *Note Filter Functions::.
64943
64944     :sentinel SENTINEL
64945          Initialize the process sentinel to SENTINEL.  If not
64946          specified, a default sentinel will be used, which can be
64947          changed later.  *Note Sentinels::.
64948
64949     The original argument list, modified with the actual connection
64950     information, is available via the ‘process-contact’ function.
64951
64952 -- Function: start-process name buffer-or-name program &rest args
64953     This function is a higher-level wrapper around ‘make-process’,
64954     exposing an interface that is similar to ‘call-process’.  It
64955     creates a new asynchronous subprocess and starts the specified
64956     PROGRAM running in it.  It returns a process object that stands for
64957     the new subprocess in Lisp.  The argument NAME specifies the name
64958     for the process object; as with ‘make-process’, it is modified if
64959     necessary to make it unique.  The buffer BUFFER-OR-NAME is the
64960     buffer to associate with the process.
64961
64962     If PROGRAM is ‘nil’, Emacs opens a new pseudoterminal (pty) and
64963     associates its input and output with BUFFER-OR-NAME, without
64964     creating a subprocess.  In that case, the remaining arguments ARGS
64965     are ignored.
64966
64967     The rest of ARGS are strings that specify command line arguments
64968     for the subprocess.
64969
64970     In the example below, the first process is started and runs
64971     (rather, sleeps) for 100 seconds (the output buffer ‘foo’ is
64972     created immediately).  Meanwhile, the second process is started,
64973     and given the name ‘my-process<1>’ for the sake of uniqueness.  It
64974     inserts the directory listing at the end of the buffer ‘foo’,
64975     before the first process finishes.  Then it finishes, and a message
64976     to that effect is inserted in the buffer.  Much later, the first
64977     process finishes, and another message is inserted in the buffer for
64978     it.
64979
64980          (start-process "my-process" "foo" "sleep" "100")
64981               ⇒ #<process my-process>
64982
64983          (start-process "my-process" "foo" "ls" "-l" "/bin")
64984               ⇒ #<process my-process<1>>
64985
64986          ---------- Buffer: foo ----------
64987          total 8336
64988          -rwxr-xr-x 1 root root 971384 Mar 30 10:14 bash
64989          -rwxr-xr-x 1 root root 146920 Jul  5  2011 bsd-csh
64990          ...
64991          -rwxr-xr-x 1 root root 696880 Feb 28 15:55 zsh4
64992
64993          Process my-process<1> finished
64994
64995          Process my-process finished
64996          ---------- Buffer: foo ----------
64997
64998 -- Function: start-file-process name buffer-or-name program &rest args
64999     Like ‘start-process’, this function starts a new asynchronous
65000     subprocess running PROGRAM in it, and returns its process object.
65001
65002     The difference from ‘start-process’ is that this function may
65003     invoke a file name handler based on the value of
65004     ‘default-directory’.  This handler ought to run PROGRAM, perhaps on
65005     the local host, perhaps on a remote host that corresponds to
65006     ‘default-directory’.  In the latter case, the local part of
65007     ‘default-directory’ becomes the working directory of the process.
65008
65009     This function does not try to invoke file name handlers for PROGRAM
65010     or for the rest of ARGS.  For that reason, if PROGRAM or any of
65011     ARGS use the remote-file syntax (*note Magic File Names::), they
65012     must be converted either to file names relative to
65013     ‘default-directory’, or to names that identify the files locally on
65014     the remote host, by running them through ‘file-local-name’.
65015
65016     Depending on the implementation of the file name handler, it might
65017     not be possible to apply ‘process-filter’ or ‘process-sentinel’ to
65018     the resulting process object.  *Note Filter Functions::, and *note
65019     Sentinels::.
65020
65021     Some file name handlers may not support ‘start-file-process’ (for
65022     example the function ‘ange-ftp-hook-function’).  In such cases,
65023     this function does nothing and returns ‘nil’.
65024
65025 -- Function: start-process-shell-command name buffer-or-name command
65026     This function is like ‘start-process’, except that it uses a shell
65027     to execute the specified COMMAND.  The argument COMMAND is a shell
65028     command string.  The variable ‘shell-file-name’ specifies which
65029     shell to use.
65030
65031     The point of running a program through the shell, rather than
65032     directly with ‘make-process’ or ‘start-process’, is so that you can
65033     employ shell features such as wildcards in the arguments.  It
65034     follows that if you include any arbitrary user-specified arguments
65035     in the command, you should quote them with ‘shell-quote-argument’
65036     first, so that any special shell characters do _not_ have their
65037     special shell meanings.  *Note Shell Arguments::.  Of course, when
65038     executing commands based on user input you should also consider the
65039     security implications.
65040
65041 -- Function: start-file-process-shell-command name buffer-or-name
65042          command
65043     This function is like ‘start-process-shell-command’, but uses
65044     ‘start-file-process’ internally.  Because of this, COMMAND can also
65045     be executed on remote hosts, depending on ‘default-directory’.
65046
65047 -- Variable: process-connection-type
65048     This variable controls the type of device used to communicate with
65049     asynchronous subprocesses.  If it is non-‘nil’, then ptys are used,
65050     when available.  Otherwise, pipes are used.
65051
65052     The value of ‘process-connection-type’ takes effect when
65053     ‘make-process’ or ‘start-process’ is called.  So you can specify
65054     how to communicate with one subprocess by binding the variable
65055     around the call to these functions.
65056
65057     Note that the value of this variable is ignored when ‘make-process’
65058     is called with a non-‘nil’ value of the ‘:stderr’ parameter; in
65059     that case, Emacs will communicate with the process using pipes.  It
65060     is also ignored if ptys are unavailable (MS-Windows).
65061
65062          (let ((process-connection-type nil))  ; use a pipe
65063            (start-process ...))
65064
65065     To determine whether a given subprocess actually got a pipe or a
65066     pty, use the function ‘process-tty-name’ (*note Process
65067     Information::).
65068
65069
65070File: elisp.info,  Node: Deleting Processes,  Next: Process Information,  Prev: Asynchronous Processes,  Up: Processes
65071
6507238.5 Deleting Processes
65073=======================
65074
65075“Deleting a process” disconnects Emacs immediately from the subprocess.
65076Processes are deleted automatically after they terminate, but not
65077necessarily right away.  You can delete a process explicitly at any
65078time.  If you explicitly delete a terminated process before it is
65079deleted automatically, no harm results.  Deleting a running process
65080sends a signal to terminate it (and its child processes, if any), and
65081calls the process sentinel.  *Note Sentinels::.
65082
65083   When a process is deleted, the process object itself continues to
65084exist as long as other Lisp objects point to it.  All the Lisp
65085primitives that work on process objects accept deleted processes, but
65086those that do I/O or send signals will report an error.  The process
65087mark continues to point to the same place as before, usually into a
65088buffer where output from the process was being inserted.
65089
65090 -- User Option: delete-exited-processes
65091     This variable controls automatic deletion of processes that have
65092     terminated (due to calling ‘exit’ or to a signal).  If it is ‘nil’,
65093     then they continue to exist until the user runs ‘list-processes’.
65094     Otherwise, they are deleted immediately after they exit.
65095
65096 -- Function: delete-process process
65097     This function deletes a process, killing it with a ‘SIGKILL’ signal
65098     if the process was running a program.  The argument may be a
65099     process, the name of a process, a buffer, or the name of a buffer.
65100     (A buffer or buffer-name stands for the process that
65101     ‘get-buffer-process’ returns.)  Calling ‘delete-process’ on a
65102     running process terminates it, updates the process status, and runs
65103     the sentinel immediately.  If the process has already terminated,
65104     calling ‘delete-process’ has no effect on its status, or on the
65105     running of its sentinel (which will happen sooner or later).
65106
65107     If the process object represents a network, serial, or pipe
65108     connection, its status changes to ‘closed’; otherwise, it changes
65109     to ‘signal’, unless the process already exited.  *Note
65110     process-status: Process Information.
65111
65112          (delete-process "*shell*")
65113               ⇒ nil
65114
65115
65116File: elisp.info,  Node: Process Information,  Next: Input to Processes,  Prev: Deleting Processes,  Up: Processes
65117
6511838.6 Process Information
65119========================
65120
65121Several functions return information about processes.
65122
65123 -- Command: list-processes &optional query-only buffer
65124     This command displays a listing of all living processes.  In
65125     addition, it finally deletes any process whose status was ‘Exited’
65126     or ‘Signaled’.  It returns ‘nil’.
65127
65128     The processes are shown in a buffer named ‘*Process List*’ (unless
65129     you specify otherwise using the optional argument BUFFER), whose
65130     major mode is Process Menu mode.
65131
65132     If QUERY-ONLY is non-‘nil’, it only lists processes whose query
65133     flag is non-‘nil’.  *Note Query Before Exit::.
65134
65135 -- Function: process-list
65136     This function returns a list of all processes that have not been
65137     deleted.
65138
65139          (process-list)
65140               ⇒ (#<process display-time> #<process shell>)
65141
65142 -- Function: get-process name
65143     This function returns the process named NAME (a string), or ‘nil’
65144     if there is none.  The argument NAME can also be a process object,
65145     in which case it is returned.
65146
65147          (get-process "shell")
65148               ⇒ #<process shell>
65149
65150 -- Function: process-command process
65151     This function returns the command that was executed to start
65152     PROCESS.  This is a list of strings, the first string being the
65153     program executed and the rest of the strings being the arguments
65154     that were given to the program.  For a network, serial, or pipe
65155     connection, this is either ‘nil’, which means the process is
65156     running or ‘t’ (process is stopped).
65157
65158          (process-command (get-process "shell"))
65159               ⇒ ("bash" "-i")
65160
65161 -- Function: process-contact process &optional key no-block
65162     This function returns information about how a network, a serial, or
65163     a pipe connection was set up.  When KEY is ‘nil’, it returns
65164     ‘(HOSTNAME SERVICE)’ for a network connection, ‘(PORT SPEED)’ for a
65165     serial connection, and ‘t’ for a pipe connection.  For an ordinary
65166     child process, this function always returns ‘t’ when called with a
65167     ‘nil’ KEY.
65168
65169     If KEY is ‘t’, the value is the complete status information for the
65170     connection, server, serial port, or pipe; that is, the list of
65171     keywords and values specified in ‘make-network-process’,
65172     ‘make-serial-process’, or ‘make-pipe-process’, except that some of
65173     the values represent the current status instead of what you
65174     specified.
65175
65176     For a network process, the values include (see
65177     ‘make-network-process’ for a complete list):
65178
65179     ‘:buffer’
65180          The associated value is the process buffer.
65181     ‘:filter’
65182          The associated value is the process filter function.  *Note
65183          Filter Functions::.
65184     ‘:sentinel’
65185          The associated value is the process sentinel function.  *Note
65186          Sentinels::.
65187     ‘:remote’
65188          In a connection, the address in internal format of the remote
65189          peer.
65190     ‘:local’
65191          The local address, in internal format.
65192     ‘:service’
65193          In a server, if you specified ‘t’ for SERVICE, this value is
65194          the actual port number.
65195
65196     ‘:local’ and ‘:remote’ are included even if they were not specified
65197     explicitly in ‘make-network-process’.
65198
65199     For a serial connection, see ‘make-serial-process’ and
65200     ‘serial-process-configure’ for the list of keys.  For a pipe
65201     connection, see ‘make-pipe-process’ for the list of keys.
65202
65203     If KEY is a keyword, the function returns the value corresponding
65204     to that keyword.
65205
65206     If PROCESS is a non-blocking network stream that hasn’t been fully
65207     set up yet, then this function will block until that has happened.
65208     If given the optional NO-BLOCK parameter, this function will return
65209     ‘nil’ instead of blocking.
65210
65211 -- Function: process-id process
65212     This function returns the PID of PROCESS.  This is an integral
65213     number that distinguishes the process PROCESS from all other
65214     processes running on the same computer at the current time.  The
65215     PID of a process is chosen by the operating system kernel when the
65216     process is started and remains constant as long as the process
65217     exists.  For network, serial, and pipe connections, this function
65218     returns ‘nil’.
65219
65220 -- Function: process-name process
65221     This function returns the name of PROCESS, as a string.
65222
65223 -- Function: process-status process-name
65224     This function returns the status of PROCESS-NAME as a symbol.  The
65225     argument PROCESS-NAME must be a process, a buffer, or a process
65226     name (a string).
65227
65228     The possible values for an actual subprocess are:
65229
65230     ‘run’
65231          for a process that is running.
65232     ‘stop’
65233          for a process that is stopped but continuable.
65234     ‘exit’
65235          for a process that has exited.
65236     ‘signal’
65237          for a process that has received a fatal signal.
65238     ‘open’
65239          for a network, serial, or pipe connection that is open.
65240     ‘closed’
65241          for a network, serial, or pipe connection that is closed.
65242          Once a connection is closed, you cannot reopen it, though you
65243          might be able to open a new connection to the same place.
65244     ‘connect’
65245          for a non-blocking connection that is waiting to complete.
65246     ‘failed’
65247          for a non-blocking connection that has failed to complete.
65248     ‘listen’
65249          for a network server that is listening.
65250     ‘nil’
65251          if PROCESS-NAME is not the name of an existing process.
65252
65253          (process-status (get-buffer "*shell*"))
65254               ⇒ run
65255
65256     For a network, serial, or pipe connection, ‘process-status’ returns
65257     one of the symbols ‘open’, ‘stop’, or ‘closed’.  The latter means
65258     that the other side closed the connection, or Emacs did
65259     ‘delete-process’.  The value ‘stop’ means that ‘stop-process’ was
65260     called on the connection.
65261
65262 -- Function: process-live-p process
65263     This function returns non-‘nil’ if PROCESS is alive.  A process is
65264     considered alive if its status is ‘run’, ‘open’, ‘listen’,
65265     ‘connect’ or ‘stop’.
65266
65267 -- Function: process-type process
65268     This function returns the symbol ‘network’ for a network connection
65269     or server, ‘serial’ for a serial port connection, ‘pipe’ for a pipe
65270     connection, or ‘real’ for a subprocess created for running a
65271     program.
65272
65273 -- Function: process-exit-status process
65274     This function returns the exit status of PROCESS or the signal
65275     number that killed it.  (Use the result of ‘process-status’ to
65276     determine which of those it is.)  If PROCESS has not yet
65277     terminated, the value is 0.  For network, serial, and pipe
65278     connections that are already closed, the value is either 0 or 256,
65279     depending on whether the connection was closed normally or
65280     abnormally.
65281
65282 -- Function: process-tty-name process
65283     This function returns the terminal name that PROCESS is using for
65284     its communication with Emacs—or ‘nil’ if it is using pipes instead
65285     of a pty (see ‘process-connection-type’ in *note Asynchronous
65286     Processes::).  If PROCESS represents a program running on a remote
65287     host, the terminal name used by that program on the remote host is
65288     provided as process property ‘remote-tty’.  If PROCESS represents a
65289     network, serial, or pipe connection, the value is ‘nil’.
65290
65291 -- Function: process-coding-system process
65292     This function returns a cons cell ‘(DECODE . ENCODE)’, describing
65293     the coding systems in use for decoding output from, and encoding
65294     input to, PROCESS (*note Coding Systems::).
65295
65296 -- Function: set-process-coding-system process &optional
65297          decoding-system encoding-system
65298     This function specifies the coding systems to use for subsequent
65299     output from and input to PROCESS.  It will use DECODING-SYSTEM to
65300     decode subprocess output, and ENCODING-SYSTEM to encode subprocess
65301     input.
65302
65303   Every process also has a property list that you can use to store
65304miscellaneous values associated with the process.
65305
65306 -- Function: process-get process propname
65307     This function returns the value of the PROPNAME property of
65308     PROCESS.
65309
65310 -- Function: process-put process propname value
65311     This function sets the value of the PROPNAME property of PROCESS to
65312     VALUE.
65313
65314 -- Function: process-plist process
65315     This function returns the process plist of PROCESS.
65316
65317 -- Function: set-process-plist process plist
65318     This function sets the process plist of PROCESS to PLIST.
65319
65320
65321File: elisp.info,  Node: Input to Processes,  Next: Signals to Processes,  Prev: Process Information,  Up: Processes
65322
6532338.7 Sending Input to Processes
65324===============================
65325
65326Asynchronous subprocesses receive input when it is sent to them by
65327Emacs, which is done with the functions in this section.  You must
65328specify the process to send input to, and the input data to send.  If
65329the subprocess runs a program, the data appears on the standard input of
65330that program; for connections, the data is sent to the connected device
65331or program.
65332
65333   Some operating systems have limited space for buffered input in a
65334pty.  On these systems, Emacs sends an EOF periodically amidst the other
65335characters, to force them through.  For most programs, these EOFs do no
65336harm.
65337
65338   Subprocess input is normally encoded using a coding system before the
65339subprocess receives it, much like text written into a file.  You can use
65340‘set-process-coding-system’ to specify which coding system to use (*note
65341Process Information::).  Otherwise, the coding system comes from
65342‘coding-system-for-write’, if that is non-‘nil’; or else from the
65343defaulting mechanism (*note Default Coding Systems::).
65344
65345   Sometimes the system is unable to accept input for that process,
65346because the input buffer is full.  When this happens, the send functions
65347wait a short while, accepting output from subprocesses, and then try
65348again.  This gives the subprocess a chance to read more of its pending
65349input and make space in the buffer.  It also allows filters (including
65350the one currently running), sentinels and timers to run—so take account
65351of that in writing your code.
65352
65353   In these functions, the PROCESS argument can be a process or the name
65354of a process, or a buffer or buffer name (which stands for a process via
65355‘get-buffer-process’).  ‘nil’ means the current buffer’s process.
65356
65357 -- Function: process-send-string process string
65358     This function sends PROCESS the contents of STRING as standard
65359     input.  It returns ‘nil’.  For example, to make a Shell buffer list
65360     files:
65361
65362          (process-send-string "shell<1>" "ls\n")
65363               ⇒ nil
65364
65365 -- Function: process-send-region process start end
65366     This function sends the text in the region defined by START and END
65367     as standard input to PROCESS.
65368
65369     An error is signaled unless both START and END are integers or
65370     markers that indicate positions in the current buffer.  (It is
65371     unimportant which number is larger.)
65372
65373 -- Function: process-send-eof &optional process
65374     This function makes PROCESS see an end-of-file in its input.  The
65375     EOF comes after any text already sent to it.  The function returns
65376     PROCESS.
65377
65378          (process-send-eof "shell")
65379               ⇒ "shell"
65380
65381 -- Function: process-running-child-p &optional process
65382     This function will tell you whether a PROCESS, which must not be a
65383     connection but a real subprocess, has given control of its terminal
65384     to a child process of its own.  If this is true, the function
65385     returns the numeric ID of the foreground process group of PROCESS;
65386     it returns ‘nil’ if Emacs can be certain that this is not so.  The
65387     value is ‘t’ if Emacs cannot tell whether this is true.  This
65388     function signals an error if PROCESS is a network, serial, or pipe
65389     connection, or is the subprocess is not active.
65390
65391
65392File: elisp.info,  Node: Signals to Processes,  Next: Output from Processes,  Prev: Input to Processes,  Up: Processes
65393
6539438.8 Sending Signals to Processes
65395=================================
65396
65397“Sending a signal” to a subprocess is a way of interrupting its
65398activities.  There are several different signals, each with its own
65399meaning.  The set of signals and their names is defined by the operating
65400system.  For example, the signal ‘SIGINT’ means that the user has typed
65401‘C-c’, or that some analogous thing has happened.
65402
65403   Each signal has a standard effect on the subprocess.  Most signals
65404kill the subprocess, but some stop (or resume) execution instead.  Most
65405signals can optionally be handled by programs; if the program handles
65406the signal, then we can say nothing in general about its effects.
65407
65408   You can send signals explicitly by calling the functions in this
65409section.  Emacs also sends signals automatically at certain times:
65410killing a buffer sends a ‘SIGHUP’ signal to all its associated
65411processes; killing Emacs sends a ‘SIGHUP’ signal to all remaining
65412processes.  (‘SIGHUP’ is a signal that usually indicates that the user
65413“hung up the phone”, i.e., disconnected.)
65414
65415   Each of the signal-sending functions takes two optional arguments:
65416PROCESS and CURRENT-GROUP.
65417
65418   The argument PROCESS must be either a process, a process name, a
65419buffer, a buffer name, or ‘nil’.  A buffer or buffer name stands for a
65420process through ‘get-buffer-process’.  ‘nil’ stands for the process
65421associated with the current buffer.  Except with ‘stop-process’ and
65422‘continue-process’, an error is signaled if PROCESS does not identify an
65423active process, or if it represents a network, serial, or pipe
65424connection.
65425
65426   The argument CURRENT-GROUP is a flag that makes a difference when you
65427are running a job-control shell as an Emacs subprocess.  If it is
65428non-‘nil’, then the signal is sent to the current process-group of the
65429terminal that Emacs uses to communicate with the subprocess.  If the
65430process is a job-control shell, this means the shell’s current subjob.
65431If CURRENT-GROUP is ‘nil’, the signal is sent to the process group of
65432the immediate subprocess of Emacs.  If the subprocess is a job-control
65433shell, this is the shell itself.  If CURRENT-GROUP is ‘lambda’, the
65434signal is sent to the process-group that owns the terminal, but only if
65435it is not the shell itself.
65436
65437   The flag CURRENT-GROUP has no effect when a pipe is used to
65438communicate with the subprocess, because the operating system does not
65439support the distinction in the case of pipes.  For the same reason,
65440job-control shells won’t work when a pipe is used.  See
65441‘process-connection-type’ in *note Asynchronous Processes::.
65442
65443 -- Function: interrupt-process &optional process current-group
65444     This function interrupts the process PROCESS by sending the signal
65445     ‘SIGINT’.  Outside of Emacs, typing the interrupt character
65446     (normally ‘C-c’ on some systems, and <DEL> on others) sends this
65447     signal.  When the argument CURRENT-GROUP is non-‘nil’, you can
65448     think of this function as typing ‘C-c’ on the terminal by which
65449     Emacs talks to the subprocess.
65450
65451 -- Function: kill-process &optional process current-group
65452     This function kills the process PROCESS by sending the signal
65453     ‘SIGKILL’.  This signal kills the subprocess immediately, and
65454     cannot be handled by the subprocess.
65455
65456 -- Function: quit-process &optional process current-group
65457     This function sends the signal ‘SIGQUIT’ to the process PROCESS.
65458     This signal is the one sent by the quit character (usually ‘C-\’)
65459     when you are not inside Emacs.
65460
65461 -- Function: stop-process &optional process current-group
65462     This function stops the specified PROCESS.  If it is a real
65463     subprocess running a program, it sends the signal ‘SIGTSTP’ to that
65464     subprocess.  If PROCESS represents a network, serial, or pipe
65465     connection, this function inhibits handling of the incoming data
65466     from the connection; for a network server, this means not accepting
65467     new connections.  Use ‘continue-process’ to resume normal
65468     execution.
65469
65470     Outside of Emacs, on systems with job control, the stop character
65471     (usually ‘C-z’) normally sends the ‘SIGTSTP’ signal to a
65472     subprocess.  When CURRENT-GROUP is non-‘nil’, you can think of this
65473     function as typing ‘C-z’ on the terminal Emacs uses to communicate
65474     with the subprocess.
65475
65476 -- Function: continue-process &optional process current-group
65477     This function resumes execution of the process PROCESS.  If it is a
65478     real subprocess running a program, it sends the signal ‘SIGCONT’ to
65479     that subprocess; this presumes that PROCESS was stopped previously.
65480     If PROCESS represents a network, serial, or pipe connection, this
65481     function resumes handling of the incoming data from the connection.
65482     For serial connections, data that arrived during the time the
65483     process was stopped might be lost.
65484
65485 -- Command: signal-process process signal
65486     This function sends a signal to process PROCESS.  The argument
65487     SIGNAL specifies which signal to send; it should be an integer, or
65488     a symbol whose name is a signal.
65489
65490     The PROCESS argument can be a system process ID (an integer); that
65491     allows you to send signals to processes that are not children of
65492     Emacs.  *Note System Processes::.
65493
65494   Sometimes, it is necessary to send a signal to a non-local
65495asynchronous process.  This is possible by writing an own
65496‘interrupt-process’ implementation.  This function must be added then to
65497‘interrupt-process-functions’.
65498
65499 -- Variable: interrupt-process-functions
65500     This variable is a list of functions to be called for
65501     ‘interrupt-process’.  The arguments of the functions are the same
65502     as for ‘interrupt-process’.  These functions are called in the
65503     order of the list, until one of them returns non-‘nil’.  The
65504     default function, which shall always be the last in this list, is
65505     ‘internal-default-interrupt-process’.
65506
65507     This is the mechanism, how Tramp implements ‘interrupt-process’.
65508
65509
65510File: elisp.info,  Node: Output from Processes,  Next: Sentinels,  Prev: Signals to Processes,  Up: Processes
65511
6551238.9 Receiving Output from Processes
65513====================================
65514
65515The output that an asynchronous subprocess writes to its standard output
65516stream is passed to a function called the “filter function”.  The
65517default filter function simply inserts the output into a buffer, which
65518is called the associated buffer of the process (*note Process
65519Buffers::).  If the process has no buffer then the default filter
65520discards the output.
65521
65522   If the subprocess writes to its standard error stream, by default the
65523error output is also passed to the process filter function.  If Emacs
65524uses a pseudo-TTY (pty) for communication with the subprocess, then it
65525is impossible to separate the standard output and standard error streams
65526of the subprocess, because a pseudo-TTY has only one output channel.  In
65527that case, if you want to keep the output to those streams separate, you
65528should redirect one of them to a file—for example, by using an
65529appropriate shell command via ‘start-process-shell-command’ or a similar
65530function.
65531
65532   Alternatively, you could use the ‘:stderr’ parameter with a non-‘nil’
65533value in a call to ‘make-process’ (*note make-process: Asynchronous
65534Processes.) to make the destination of the error output separate from
65535the standard output; in that case, Emacs will use pipes for
65536communicating with the subprocess.
65537
65538   When a subprocess terminates, Emacs reads any pending output, then
65539stops reading output from that subprocess.  Therefore, if the subprocess
65540has children that are still live and still producing output, Emacs won’t
65541receive that output.
65542
65543   Output from a subprocess can arrive only while Emacs is waiting: when
65544reading terminal input (see the function ‘waiting-for-user-input-p’), in
65545‘sit-for’ and ‘sleep-for’ (*note Waiting::), in ‘accept-process-output’
65546(*note Accepting Output::), and in functions which send data to
65547processes (*note Input to Processes::).  This minimizes the problem of
65548timing errors that usually plague parallel programming.  For example,
65549you can safely create a process and only then specify its buffer or
65550filter function; no output can arrive before you finish, if the code in
65551between does not call any primitive that waits.
65552
65553 -- Variable: process-adaptive-read-buffering
65554     On some systems, when Emacs reads the output from a subprocess, the
65555     output data is read in very small blocks, potentially resulting in
65556     very poor performance.  This behavior can be remedied to some
65557     extent by setting the variable ‘process-adaptive-read-buffering’ to
65558     a non-‘nil’ value (the default), as it will automatically delay
65559     reading from such processes, thus allowing them to produce more
65560     output before Emacs tries to read it.
65561
65562* Menu:
65563
65564* Process Buffers::         By default, output is put in a buffer.
65565* Filter Functions::        Filter functions accept output from the process.
65566* Decoding Output::         Filters can get unibyte or multibyte strings.
65567* Accepting Output::        How to wait until process output arrives.
65568* Processes and Threads::   How processes and threads interact.
65569
65570
65571File: elisp.info,  Node: Process Buffers,  Next: Filter Functions,  Up: Output from Processes
65572
6557338.9.1 Process Buffers
65574----------------------
65575
65576A process can (and usually does) have an “associated buffer”, which is
65577an ordinary Emacs buffer that is used for two purposes: storing the
65578output from the process, and deciding when to kill the process.  You can
65579also use the buffer to identify a process to operate on, since in normal
65580practice only one process is associated with any given buffer.  Many
65581applications of processes also use the buffer for editing input to be
65582sent to the process, but this is not built into Emacs Lisp.
65583
65584   By default, process output is inserted in the associated buffer.
65585(You can change this by defining a custom filter function, *note Filter
65586Functions::.)  The position to insert the output is determined by the
65587‘process-mark’, which is then updated to point to the end of the text
65588just inserted.  Usually, but not always, the ‘process-mark’ is at the
65589end of the buffer.
65590
65591   Killing the associated buffer of a process also kills the process.
65592Emacs asks for confirmation first, if the process’s
65593‘process-query-on-exit-flag’ is non-‘nil’ (*note Query Before Exit::).
65594This confirmation is done by the function
65595‘process-kill-buffer-query-function’, which is run from
65596‘kill-buffer-query-functions’ (*note Killing Buffers::).
65597
65598 -- Function: process-buffer process
65599     This function returns the associated buffer of the specified
65600     PROCESS.
65601
65602          (process-buffer (get-process "shell"))
65603               ⇒ #<buffer *shell*>
65604
65605 -- Function: process-mark process
65606     This function returns the process marker for PROCESS, which is the
65607     marker that says where to insert output from the process.
65608
65609     If PROCESS does not have a buffer, ‘process-mark’ returns a marker
65610     that points nowhere.
65611
65612     The default filter function uses this marker to decide where to
65613     insert process output, and updates it to point after the inserted
65614     text.  That is why successive batches of output are inserted
65615     consecutively.
65616
65617     Custom filter functions normally should use this marker in the same
65618     fashion.  For an example of a filter function that uses
65619     ‘process-mark’, *note Process Filter Example::.
65620
65621     When the user is expected to enter input in the process buffer for
65622     transmission to the process, the process marker separates the new
65623     input from previous output.
65624
65625 -- Function: set-process-buffer process buffer
65626     This function sets the buffer associated with PROCESS to BUFFER.
65627     If BUFFER is ‘nil’, the process becomes associated with no buffer.
65628
65629 -- Function: get-buffer-process buffer-or-name
65630     This function returns a nondeleted process associated with the
65631     buffer specified by BUFFER-OR-NAME.  If there are several processes
65632     associated with it, this function chooses one (currently, the one
65633     most recently created, but don’t count on that).  Deletion of a
65634     process (see ‘delete-process’) makes it ineligible for this
65635     function to return.
65636
65637     It is usually a bad idea to have more than one process associated
65638     with the same buffer.
65639
65640          (get-buffer-process "*shell*")
65641               ⇒ #<process shell>
65642
65643     Killing the process’s buffer deletes the process, which kills the
65644     subprocess with a ‘SIGHUP’ signal (*note Signals to Processes::).
65645
65646   If the process’s buffer is displayed in a window, your Lisp program
65647may wish to tell the process the dimensions of that window, so that the
65648process could adapt its output to those dimensions, much as it adapts to
65649the screen dimensions.  The following functions allow communicating this
65650kind of information to processes; however, not all systems support the
65651underlying functionality, so it is best to provide fallbacks, e.g., via
65652command-line arguments or environment variables.
65653
65654 -- Function: set-process-window-size process height width
65655     Tell PROCESS that its logical window size has dimensions WIDTH by
65656     HEIGHT, in character units.  If this function succeeds in
65657     communicating this information to the process, it returns ‘t’;
65658     otherwise it returns ‘nil’.
65659
65660   When windows that display buffers associated with process change
65661their dimensions, the affected processes should be told about these
65662changes.  By default, when the window configuration changes, Emacs will
65663automatically call ‘set-process-window-size’ on behalf of every process
65664whose buffer is displayed in a window, passing it the smallest
65665dimensions of all the windows displaying the process’s buffer.  This
65666works via ‘window-configuration-change-hook’ (*note Window Hooks::),
65667which is told to invoke the function that is the value of the variable
65668‘window-adjust-process-window-size-function’ for each process whose
65669buffer is displayed in at least one window.  You can customize this
65670behavior by setting the value of that variable.
65671
65672 -- User Option: window-adjust-process-window-size-function
65673     The value of this variable should be a function of two arguments: a
65674     process and the list of windows displaying the process’s buffer.
65675     When the function is called, the process’s buffer is the current
65676     buffer.  The function should return a cons cell ‘(WIDTH . HEIGHT)’
65677     that describes the dimensions of the logical process window to be
65678     passed via a call to ‘set-process-window-size’.  The function can
65679     also return ‘nil’, in which case Emacs will not call
65680     ‘set-process-window-size’ for this process.
65681
65682     Emacs supplies two predefined values for this variable:
65683     ‘window-adjust-process-window-size-smallest’, which returns the
65684     smallest of all the dimensions of the windows that display a
65685     process’s buffer; and ‘window-adjust-process-window-size-largest’,
65686     which returns the largest dimensions.  For more complex strategies,
65687     write your own function.
65688
65689     This variable can be buffer-local.
65690
65691   If the process has the ‘adjust-window-size-function’ property (*note
65692Process Information::), its value overrides the global and buffer-local
65693values of ‘window-adjust-process-window-size-function’.
65694
65695
65696File: elisp.info,  Node: Filter Functions,  Next: Decoding Output,  Prev: Process Buffers,  Up: Output from Processes
65697
6569838.9.2 Process Filter Functions
65699-------------------------------
65700
65701A process “filter function” is a function that receives the standard
65702output from the associated process.  _All_ output from that process is
65703passed to the filter.  The default filter simply outputs directly to the
65704process buffer.
65705
65706   By default, the error output from the process, if any, is also passed
65707to the filter function, unless the destination for the standard error
65708stream of the process was separated from the standard output when the
65709process was created.  Emacs will only call the filter function during
65710certain function calls.  *Note Output from Processes::.  Note that if
65711any of those functions are called by the filter, the filter may be
65712called recursively.
65713
65714   A filter function must accept two arguments: the associated process
65715and a string, which is output just received from it.  The function is
65716then free to do whatever it chooses with the output.
65717
65718   Quitting is normally inhibited within a filter function—otherwise,
65719the effect of typing ‘C-g’ at command level or to quit a user command
65720would be unpredictable.  If you want to permit quitting inside a filter
65721function, bind ‘inhibit-quit’ to ‘nil’.  In most cases, the right way to
65722do this is with the macro ‘with-local-quit’.  *Note Quitting::.
65723
65724   If an error happens during execution of a filter function, it is
65725caught automatically, so that it doesn’t stop the execution of whatever
65726program was running when the filter function was started.  However, if
65727‘debug-on-error’ is non-‘nil’, errors are not caught.  This makes it
65728possible to use the Lisp debugger to debug filter functions.  *Note
65729Debugger::.
65730
65731   Many filter functions sometimes (or always) insert the output in the
65732process’s buffer, mimicking the actions of the default filter.  Such
65733filter functions need to make sure that they save the current buffer,
65734select the correct buffer (if different) before inserting output, and
65735then restore the original buffer.  They should also check whether the
65736buffer is still alive, update the process marker, and in some cases
65737update the value of point.  Here is how to do these things:
65738
65739     (defun ordinary-insertion-filter (proc string)
65740       (when (buffer-live-p (process-buffer proc))
65741         (with-current-buffer (process-buffer proc)
65742           (let ((moving (= (point) (process-mark proc))))
65743             (save-excursion
65744               ;; Insert the text, advancing the process marker.
65745               (goto-char (process-mark proc))
65746               (insert string)
65747               (set-marker (process-mark proc) (point)))
65748             (if moving (goto-char (process-mark proc)))))))
65749
65750   To make the filter force the process buffer to be visible whenever
65751new text arrives, you could insert a line like the following just before
65752the ‘with-current-buffer’ construct:
65753
65754     (display-buffer (process-buffer proc))
65755
65756   To force point to the end of the new output, no matter where it was
65757previously, eliminate the variable ‘moving’ from the example and call
65758‘goto-char’ unconditionally.  Note that this doesn’t necessarily move
65759the window point.  The default filter actually uses
65760‘insert-before-markers’ which moves all markers, including the window
65761point.  This may move unrelated markers, so it’s generally better to
65762move the window point explicitly, or set its insertion type to ‘t’
65763(*note Window Point::).
65764
65765   Note that Emacs automatically saves and restores the match data while
65766executing filter functions.  *Note Match Data::.
65767
65768   The output to the filter may come in chunks of any size.  A program
65769that produces the same output twice in a row may send it as one batch of
65770200 characters one time, and five batches of 40 characters the next.  If
65771the filter looks for certain text strings in the subprocess output, make
65772sure to handle the case where one of these strings is split across two
65773or more batches of output; one way to do this is to insert the received
65774text into a temporary buffer, which can then be searched.
65775
65776 -- Function: set-process-filter process filter
65777     This function gives PROCESS the filter function FILTER.  If FILTER
65778     is ‘nil’, it gives the process the default filter, which inserts
65779     the process output into the process buffer.
65780
65781 -- Function: process-filter process
65782     This function returns the filter function of PROCESS.
65783
65784   In case the process’s output needs to be passed to several filters,
65785you can use ‘add-function’ to combine an existing filter with a new one.
65786*Note Advising Functions::.
65787
65788   Here is an example of the use of a filter function:
65789
65790     (defun keep-output (process output)
65791        (setq kept (cons output kept)))
65792          ⇒ keep-output
65793     (setq kept nil)
65794          ⇒ nil
65795     (set-process-filter (get-process "shell") 'keep-output)
65796          ⇒ keep-output
65797     (process-send-string "shell" "ls ~/other\n")
65798          ⇒ nil
65799     kept
65800          ⇒ ("lewis@slug:$ "
65801     "FINAL-W87-SHORT.MSS    backup.otl              kolstad.mss~
65802     address.txt             backup.psf              kolstad.psf
65803     backup.bib~             david.mss               resume-Dec-86.mss~
65804     backup.err              david.psf               resume-Dec.psf
65805     backup.mss              dland                   syllabus.mss
65806     "
65807     "#backups.mss#          backup.mss~             kolstad.mss
65808     ")
65809
65810
65811File: elisp.info,  Node: Decoding Output,  Next: Accepting Output,  Prev: Filter Functions,  Up: Output from Processes
65812
6581338.9.3 Decoding Process Output
65814------------------------------
65815
65816When Emacs writes process output directly into a multibyte buffer, it
65817decodes the output according to the process output coding system.  If
65818the coding system is ‘raw-text’ or ‘no-conversion’, Emacs converts the
65819unibyte output to multibyte using ‘string-to-multibyte’, and inserts the
65820resulting multibyte text.
65821
65822   You can use ‘set-process-coding-system’ to specify which coding
65823system to use (*note Process Information::).  Otherwise, the coding
65824system comes from ‘coding-system-for-read’, if that is non-‘nil’; or
65825else from the defaulting mechanism (*note Default Coding Systems::).  If
65826the text output by a process contains null bytes, Emacs by default uses
65827‘no-conversion’ for it; see *note inhibit-nul-byte-detection: Lisp and
65828Coding Systems, for how to control this behavior.
65829
65830   *Warning:* Coding systems such as ‘undecided’, which determine the
65831coding system from the data, do not work entirely reliably with
65832asynchronous subprocess output.  This is because Emacs has to process
65833asynchronous subprocess output in batches, as it arrives.  Emacs must
65834try to detect the proper coding system from one batch at a time, and
65835this does not always work.  Therefore, if at all possible, specify a
65836coding system that determines both the character code conversion and the
65837end of line conversion—that is, one like ‘latin-1-unix’, rather than
65838‘undecided’ or ‘latin-1’.
65839
65840   When Emacs calls a process filter function, it provides the process
65841output as a multibyte string or as a unibyte string according to the
65842process’s filter coding system.  Emacs decodes the output according to
65843the process output coding system, which usually produces a multibyte
65844string, except for coding systems such as ‘binary’ and ‘raw-text’.
65845
65846
65847File: elisp.info,  Node: Accepting Output,  Next: Processes and Threads,  Prev: Decoding Output,  Up: Output from Processes
65848
6584938.9.4 Accepting Output from Processes
65850--------------------------------------
65851
65852Output from asynchronous subprocesses normally arrives only while Emacs
65853is waiting for some sort of external event, such as elapsed time or
65854terminal input.  Occasionally it is useful in a Lisp program to
65855explicitly permit output to arrive at a specific point, or even to wait
65856until output arrives from a process.
65857
65858 -- Function: accept-process-output &optional process seconds millisec
65859          just-this-one
65860     This function allows Emacs to read pending output from processes.
65861     The output is given to their filter functions.  If PROCESS is
65862     non-‘nil’ then this function does not return until some output has
65863     been received from PROCESS or PROCESS has closed the connection.
65864
65865     The arguments SECONDS and MILLISEC let you specify timeout periods.
65866     The former specifies a period measured in seconds and the latter
65867     specifies one measured in milliseconds.  The two time periods thus
65868     specified are added together, and ‘accept-process-output’ returns
65869     after that much time, even if there is no subprocess output.
65870
65871     The argument MILLISEC is obsolete (and should not be used), because
65872     SECONDS can be floating point to specify waiting a fractional
65873     number of seconds.  If SECONDS is 0, the function accepts whatever
65874     output is pending but does not wait.
65875
65876     If PROCESS is a process, and the argument JUST-THIS-ONE is
65877     non-‘nil’, only output from that process is handled, suspending
65878     output from other processes until some output has been received
65879     from that process or the timeout expires.  If JUST-THIS-ONE is an
65880     integer, also inhibit running timers.  This feature is generally
65881     not recommended, but may be necessary for specific applications,
65882     such as speech synthesis.
65883
65884     The function ‘accept-process-output’ returns non-‘nil’ if it got
65885     output from PROCESS, or from any process if PROCESS is ‘nil’; this
65886     can occur even after a process has exited if the corresponding
65887     connection contains buffered data.  The function returns ‘nil’ if
65888     the timeout expired or the connection was closed before output
65889     arrived.
65890
65891   If a connection from a process contains buffered data,
65892‘accept-process-output’ can return non-‘nil’ even after the process has
65893exited.  Therefore, although the following loop:
65894
65895     ;; This loop contains a bug.
65896     (while (process-live-p process)
65897       (accept-process-output process))
65898
65899will often read all output from PROCESS, it has a race condition and can
65900miss some output if ‘process-live-p’ returns ‘nil’ while the connection
65901still contains data.  Better is to write the loop like this:
65902
65903     (while (accept-process-output process))
65904
65905   If you have passed a non-‘nil’ STDERR to ‘make-process’, it will have
65906a standard error process.  *Note Asynchronous Processes::.  In that
65907case, waiting for process output from the main process doesn’t wait for
65908output from the standard error process.  To make sure you have received
65909both all of standard output and all of standard error from a process,
65910use the following code:
65911
65912     (while (accept-process-output process))
65913     (while (accept-process-output stderr-process))
65914
65915   Reading pending standard error from a process running on a remote
65916host is not possible this way.
65917
65918
65919File: elisp.info,  Node: Processes and Threads,  Prev: Accepting Output,  Up: Output from Processes
65920
6592138.9.5 Processes and Threads
65922----------------------------
65923
65924Because threads were a relatively late addition to Emacs Lisp, and due
65925to the way dynamic binding was sometimes used in conjunction with
65926‘accept-process-output’, by default a process is locked to the thread
65927that created it.  When a process is locked to a thread, output from the
65928process can only be accepted by that thread.
65929
65930   A Lisp program can specify to which thread a process is to be locked,
65931or instruct Emacs to unlock a process, in which case its output can be
65932processed by any thread.  Only a single thread will wait for output from
65933a given process at one time—once one thread begins waiting for output,
65934the process is temporarily locked until ‘accept-process-output’ or
65935‘sit-for’ returns.
65936
65937   If the thread exits, all the processes locked to it are unlocked.
65938
65939 -- Function: process-thread process
65940     Return the thread to which PROCESS is locked.  If PROCESS is
65941     unlocked, return ‘nil’.
65942
65943 -- Function: set-process-thread process thread
65944     Set the locking thread of PROCESS to THREAD.  THREAD may be ‘nil’,
65945     in which case the process is unlocked.
65946
65947
65948File: elisp.info,  Node: Sentinels,  Next: Query Before Exit,  Prev: Output from Processes,  Up: Processes
65949
6595038.10 Sentinels: Detecting Process Status Changes
65951=================================================
65952
65953A “process sentinel” is a function that is called whenever the
65954associated process changes status for any reason, including signals
65955(whether sent by Emacs or caused by the process’s own actions) that
65956terminate, stop, or continue the process.  The process sentinel is also
65957called if the process exits.  The sentinel receives two arguments: the
65958process for which the event occurred, and a string describing the type
65959of event.
65960
65961   If no sentinel function was specified for a process, it will use the
65962default sentinel function, which inserts a message in the process’s
65963buffer with the process name and the string describing the event.
65964
65965   The string describing the event looks like one of the following (but
65966this is not an exhaustive list of event strings):
65967
65968   • ‘"finished\n"’.
65969
65970   • ‘"deleted\n"’.
65971
65972   • ‘"exited abnormally with code EXITCODE (core dumped)\n"’.  The
65973     “core dumped” part is optional, and only appears if the process
65974     dumped core.
65975
65976   • ‘"failed with code FAIL-CODE\n"’.
65977
65978   • ‘"SIGNAL-DESCRIPTION (core dumped)\n"’.  The SIGNAL-DESCRIPTION is
65979     a system-dependent textual description of a signal, e.g.,
65980     ‘"killed"’ for ‘SIGKILL’.  The “core dumped” part is optional, and
65981     only appears if the process dumped core.
65982
65983   • ‘"open from HOST-NAME\n"’.
65984
65985   • ‘"open\n"’.
65986
65987   • ‘"run\n"’.
65988
65989   • ‘"connection broken by remote peer\n"’.
65990
65991   A sentinel runs only while Emacs is waiting (e.g., for terminal
65992input, or for time to elapse, or for process output).  This avoids the
65993timing errors that could result from running sentinels at random places
65994in the middle of other Lisp programs.  A program can wait, so that
65995sentinels will run, by calling ‘sit-for’ or ‘sleep-for’ (*note
65996Waiting::), or ‘accept-process-output’ (*note Accepting Output::).
65997Emacs also allows sentinels to run when the command loop is reading
65998input.  ‘delete-process’ calls the sentinel when it terminates a running
65999process.
66000
66001   Emacs does not keep a queue of multiple reasons to call the sentinel
66002of one process; it records just the current status and the fact that
66003there has been a change.  Therefore two changes in status, coming in
66004quick succession, can call the sentinel just once.  However, process
66005termination will always run the sentinel exactly once.  This is because
66006the process status can’t change again after termination.
66007
66008   Emacs explicitly checks for output from the process before running
66009the process sentinel.  Once the sentinel runs due to process
66010termination, no further output can arrive from the process.
66011
66012   A sentinel that writes the output into the buffer of the process
66013should check whether the buffer is still alive.  If it tries to insert
66014into a dead buffer, it will get an error.  If the buffer is dead,
66015‘(buffer-name (process-buffer PROCESS))’ returns ‘nil’.
66016
66017   Quitting is normally inhibited within a sentinel—otherwise, the
66018effect of typing ‘C-g’ at command level or to quit a user command would
66019be unpredictable.  If you want to permit quitting inside a sentinel,
66020bind ‘inhibit-quit’ to ‘nil’.  In most cases, the right way to do this
66021is with the macro ‘with-local-quit’.  *Note Quitting::.
66022
66023   If an error happens during execution of a sentinel, it is caught
66024automatically, so that it doesn’t stop the execution of whatever
66025programs was running when the sentinel was started.  However, if
66026‘debug-on-error’ is non-‘nil’, errors are not caught.  This makes it
66027possible to use the Lisp debugger to debug the sentinel.  *Note
66028Debugger::.
66029
66030   While a sentinel is running, the process sentinel is temporarily set
66031to ‘nil’ so that the sentinel won’t run recursively.  For this reason it
66032is not possible for a sentinel to specify a new sentinel.
66033
66034   Note that Emacs automatically saves and restores the match data while
66035executing sentinels.  *Note Match Data::.
66036
66037 -- Function: set-process-sentinel process sentinel
66038     This function associates SENTINEL with PROCESS.  If SENTINEL is
66039     ‘nil’, then the process will have the default sentinel, which
66040     inserts a message in the process’s buffer when the process status
66041     changes.
66042
66043     Changes in process sentinels take effect immediately—if the
66044     sentinel is slated to be run but has not been called yet, and you
66045     specify a new sentinel, the eventual call to the sentinel will use
66046     the new one.
66047
66048          (defun msg-me (process event)
66049             (princ
66050               (format "Process: %s had the event '%s'" process event)))
66051          (set-process-sentinel (get-process "shell") 'msg-me)
66052               ⇒ msg-me
66053          (kill-process (get-process "shell"))
66054               ⊣ Process: #<process shell> had the event 'killed'
66055               ⇒ #<process shell>
66056
66057 -- Function: process-sentinel process
66058     This function returns the sentinel of PROCESS.
66059
66060   In case a process status changes need to be passed to several
66061sentinels, you can use ‘add-function’ to combine an existing sentinel
66062with a new one.  *Note Advising Functions::.
66063
66064 -- Function: waiting-for-user-input-p
66065     While a sentinel or filter function is running, this function
66066     returns non-‘nil’ if Emacs was waiting for keyboard input from the
66067     user at the time the sentinel or filter function was called, or
66068     ‘nil’ if it was not.
66069
66070
66071File: elisp.info,  Node: Query Before Exit,  Next: System Processes,  Prev: Sentinels,  Up: Processes
66072
6607338.11 Querying Before Exit
66074==========================
66075
66076When Emacs exits, it terminates all its subprocesses.  For subprocesses
66077that run a program, it sends them the ‘SIGHUP’ signal; connections are
66078simply closed.  Because subprocesses may be doing valuable work, Emacs
66079normally asks the user to confirm that it is ok to terminate them.  Each
66080process has a query flag, which, if non-‘nil’, says that Emacs should
66081ask for confirmation before exiting and thus killing that process.  The
66082default for the query flag is ‘t’, meaning _do_ query.
66083
66084 -- Function: process-query-on-exit-flag process
66085     This returns the query flag of PROCESS.
66086
66087 -- Function: set-process-query-on-exit-flag process flag
66088     This function sets the query flag of PROCESS to FLAG.  It returns
66089     FLAG.
66090
66091     Here is an example of using ‘set-process-query-on-exit-flag’ on a
66092     shell process to avoid querying:
66093
66094          (set-process-query-on-exit-flag (get-process "shell") nil)
66095               ⇒ nil
66096
66097 -- User Option: confirm-kill-processes
66098     If this user option is set to ‘t’ (the default), then Emacs asks
66099     for confirmation before killing processes on exit.  If it is ‘nil’,
66100     Emacs kills processes without confirmation, i.e., the query flag of
66101     all processes is ignored.
66102
66103
66104File: elisp.info,  Node: System Processes,  Next: Transaction Queues,  Prev: Query Before Exit,  Up: Processes
66105
6610638.12 Accessing Other Processes
66107===============================
66108
66109In addition to accessing and manipulating processes that are
66110subprocesses of the current Emacs session, Emacs Lisp programs can also
66111access other processes running on the same machine.  We call these
66112“system processes”, to distinguish them from Emacs subprocesses.
66113
66114   Emacs provides several primitives for accessing system processes.
66115Not all platforms support these primitives; on those which don’t, these
66116primitives return ‘nil’.
66117
66118 -- Function: list-system-processes
66119     This function returns a list of all the processes running on the
66120     system.  Each process is identified by its PID, a numerical process
66121     ID that is assigned by the OS and distinguishes the process from
66122     all the other processes running on the same machine at the same
66123     time.
66124
66125 -- Function: process-attributes pid
66126     This function returns an alist of attributes for the process
66127     specified by its process ID PID.  Each association in the alist is
66128     of the form ‘(KEY . VALUE)’, where KEY designates the attribute and
66129     VALUE is the value of that attribute.  The various attribute KEYs
66130     that this function can return are listed below.  Not all platforms
66131     support all of these attributes; if an attribute is not supported,
66132     its association will not appear in the returned alist.
66133
66134     ‘euid’
66135          The effective user ID of the user who invoked the process.
66136          The corresponding VALUE is a number.  If the process was
66137          invoked by the same user who runs the current Emacs session,
66138          the value is identical to what ‘user-uid’ returns (*note User
66139          Identification::).
66140
66141     ‘user’
66142          User name corresponding to the process’s effective user ID, a
66143          string.
66144
66145     ‘egid’
66146          The group ID of the effective user ID, a number.
66147
66148     ‘group’
66149          Group name corresponding to the effective user’s group ID, a
66150          string.
66151
66152     ‘comm’
66153          The name of the command that runs in the process.  This is a
66154          string that usually specifies the name of the executable file
66155          of the process, without the leading directories.  However,
66156          some special system processes can report strings that do not
66157          correspond to an executable file of a program.
66158
66159     ‘state’
66160          The state code of the process.  This is a short string that
66161          encodes the scheduling state of the process.  Here’s a list of
66162          the most frequently seen codes:
66163
66164          ‘"D"’
66165               uninterruptible sleep (usually I/O)
66166          ‘"R"’
66167               running
66168          ‘"S"’
66169               interruptible sleep (waiting for some event)
66170          ‘"T"’
66171               stopped, e.g., by a job control signal
66172          ‘"Z"’
66173               zombie: a process that terminated, but was not reaped by
66174               its parent
66175
66176          For the full list of the possible states, see the manual page
66177          of the ‘ps’ command.
66178
66179     ‘ppid’
66180          The process ID of the parent process, a number.
66181
66182     ‘pgrp’
66183          The process group ID of the process, a number.
66184
66185     ‘sess’
66186          The session ID of the process.  This is a number that is the
66187          process ID of the process’s “session leader”.
66188
66189     ‘ttname’
66190          A string that is the name of the process’s controlling
66191          terminal.  On Unix and GNU systems, this is normally the file
66192          name of the corresponding terminal device, such as
66193/dev/pts65’.
66194
66195     ‘tpgid’
66196          The numerical process group ID of the foreground process group
66197          that uses the process’s terminal.
66198
66199     ‘minflt’
66200          The number of minor page faults caused by the process since
66201          its beginning.  (Minor page faults are those that don’t
66202          involve reading from disk.)
66203
66204     ‘majflt’
66205          The number of major page faults caused by the process since
66206          its beginning.  (Major page faults require a disk to be read,
66207          and are thus more expensive than minor page faults.)
66208
66209     ‘cminflt’
66210     ‘cmajflt’
66211          Like ‘minflt’ and ‘majflt’, but include the number of page
66212          faults for all the child processes of the given process.
66213
66214     ‘utime’
66215          Time spent by the process in the user context, for running the
66216          application’s code.  The corresponding VALUE is a Lisp
66217          timestamp (*note Time of Day::).
66218
66219     ‘stime’
66220          Time spent by the process in the system (kernel) context, for
66221          processing system calls.  The corresponding VALUE is a Lisp
66222          timestamp.
66223
66224     ‘time’
66225          The sum of ‘utime’ and ‘stime’.  The corresponding VALUE is a
66226          Lisp timestamp.
66227
66228     ‘cutime’
66229     ‘cstime’
66230     ‘ctime’
66231          Like ‘utime’, ‘stime’, and ‘time’, but include the times of
66232          all the child processes of the given process.
66233
66234     ‘pri’
66235          The numerical priority of the process.
66236
66237     ‘nice’
66238          The “nice value” of the process, a number.  (Processes with
66239          smaller nice values get scheduled more favorably.)
66240
66241     ‘thcount’
66242          The number of threads in the process.
66243
66244     ‘start’
66245          The time when the process was started, as a Lisp timestamp.
66246
66247     ‘etime’
66248          The time elapsed since the process started, as a Lisp
66249          timestamp.
66250
66251     ‘vsize’
66252          The virtual memory size of the process, measured in kilobytes.
66253
66254     ‘rss’
66255          The size of the process’s “resident set”, the number of
66256          kilobytes occupied by the process in the machine’s physical
66257          memory.
66258
66259     ‘pcpu’
66260          The percentage of the CPU time used by the process since it
66261          started.  The corresponding VALUE is a floating-point number
66262          between 0 and 100.
66263
66264     ‘pmem’
66265          The percentage of the total physical memory installed on the
66266          machine used by the process’s resident set.  The value is a
66267          floating-point number between 0 and 100.
66268
66269     ‘args’
66270          The command-line with which the process was invoked.  This is
66271          a string in which individual command-line arguments are
66272          separated by blanks; whitespace characters that are embedded
66273          in the arguments are quoted as appropriate for the system’s
66274          shell: escaped by backslash characters on GNU and Unix, and
66275          enclosed in double quote characters on Windows.  Thus, this
66276          command-line string can be directly used in primitives such as
66277          ‘shell-command’.
66278
66279
66280File: elisp.info,  Node: Transaction Queues,  Next: Network,  Prev: System Processes,  Up: Processes
66281
6628238.13 Transaction Queues
66283========================
66284
66285You can use a “transaction queue” to communicate with a subprocess using
66286transactions.  First use ‘tq-create’ to create a transaction queue
66287communicating with a specified process.  Then you can call ‘tq-enqueue’
66288to send a transaction.
66289
66290 -- Function: tq-create process
66291     This function creates and returns a transaction queue communicating
66292     with PROCESS.  The argument PROCESS should be a subprocess capable
66293     of sending and receiving streams of bytes.  It may be a child
66294     process, or it may be a TCP connection to a server, possibly on
66295     another machine.
66296
66297 -- Function: tq-enqueue queue question regexp closure fn &optional
66298          delay-question
66299     This function sends a transaction to queue QUEUE.  Specifying the
66300     queue has the effect of specifying the subprocess to talk to.
66301
66302     The argument QUESTION is the outgoing message that starts the
66303     transaction.  The argument FN is the function to call when the
66304     corresponding answer comes back; it is called with two arguments:
66305     CLOSURE, and the answer received.
66306
66307     The argument REGEXP is a regular expression that should match text
66308     at the end of the entire answer, but nothing before; that’s how
66309     ‘tq-enqueue’ determines where the answer ends.
66310
66311     If the argument DELAY-QUESTION is non-‘nil’, delay sending this
66312     question until the process has finished replying to any previous
66313     questions.  This produces more reliable results with some
66314     processes.
66315
66316 -- Function: tq-close queue
66317     Shut down transaction queue QUEUE, waiting for all pending
66318     transactions to complete, and then terminate the connection or
66319     child process.
66320
66321   Transaction queues are implemented by means of a filter function.
66322*Note Filter Functions::.
66323
66324
66325File: elisp.info,  Node: Network,  Next: Network Servers,  Prev: Transaction Queues,  Up: Processes
66326
6632738.14 Network Connections
66328=========================
66329
66330Emacs Lisp programs can open stream (TCP) and datagram (UDP) network
66331connections (*note Datagrams::) to other processes on the same machine
66332or other machines.  A network connection is handled by Lisp much like a
66333subprocess, and is represented by a process object.  However, the
66334process you are communicating with is not a child of the Emacs process,
66335has no process ID, and you can’t kill it or send it signals.  All you
66336can do is send and receive data.  ‘delete-process’ closes the
66337connection, but does not kill the program at the other end; that program
66338must decide what to do about closure of the connection.
66339
66340   Lisp programs can listen for connections by creating network servers.
66341A network server is also represented by a kind of process object, but
66342unlike a network connection, the network server never transfers data
66343itself.  When it receives a connection request, it creates a new network
66344connection to represent the connection just made.  (The network
66345connection inherits certain information, including the process plist,
66346from the server.)  The network server then goes back to listening for
66347more connection requests.
66348
66349   Network connections and servers are created by calling
66350‘make-network-process’ with an argument list consisting of
66351keyword/argument pairs, for example ‘:server t’ to create a server
66352process, or ‘:type 'datagram’ to create a datagram connection.  *Note
66353Low-Level Network::, for details.  You can also use the
66354‘open-network-stream’ function described below.
66355
66356   To distinguish the different types of processes, the ‘process-type’
66357function returns the symbol ‘network’ for a network connection or
66358server, ‘serial’ for a serial port connection, ‘pipe’ for a pipe
66359connection, or ‘real’ for a real subprocess.
66360
66361   The ‘process-status’ function returns ‘open’, ‘closed’, ‘connect’,
66362‘stop’, or ‘failed’ for network connections.  For a network server, the
66363status is always ‘listen’.  Except for ‘stop’, none of those values is
66364possible for a real subprocess.  *Note Process Information::.
66365
66366   You can stop and resume operation of a network process by calling
66367‘stop-process’ and ‘continue-process’.  For a server process, being
66368stopped means not accepting new connections.  (Up to 5 connection
66369requests will be queued for when you resume the server; you can increase
66370this limit, unless it is imposed by the operating system—see the
66371‘:server’ keyword of ‘make-network-process’, *note Network Processes::.)
66372For a network stream connection, being stopped means not processing
66373input (any arriving input waits until you resume the connection).  For a
66374datagram connection, some number of packets may be queued but input may
66375be lost.  You can use the function ‘process-command’ to determine
66376whether a network connection or server is stopped; a non-‘nil’ value
66377means yes.
66378
66379   Emacs can create encrypted network connections, using either built-in
66380or external support.  The built-in support uses the GnuTLS Transport
66381Layer Security Library; see the GnuTLS project page
66382(https://www.gnu.org/software/gnutls/).  If your Emacs was compiled with
66383GnuTLS support, the function ‘gnutls-available-p’ is defined and returns
66384non-‘nil’.  For more details, *note Overview: (emacs-gnutls)Top.  The
66385external support uses the ‘starttls.el’ library, which requires a helper
66386utility such as ‘gnutls-cli’ to be installed on the system.  The
66387‘open-network-stream’ function can transparently handle the details of
66388creating encrypted connections for you, using whatever support is
66389available.
66390
66391 -- Function: open-network-stream name buffer host service &rest
66392          parameters
66393     This function opens a TCP connection, with optional encryption, and
66394     returns a process object that represents the connection.
66395
66396     The NAME argument specifies the name for the process object.  It is
66397     modified as necessary to make it unique.
66398
66399     The BUFFER argument is the buffer to associate with the connection.
66400     Output from the connection is inserted in the buffer, unless you
66401     specify your own filter function to handle the output.  If BUFFER
66402     is ‘nil’, it means that the connection is not associated with any
66403     buffer.
66404
66405     The arguments HOST and SERVICE specify where to connect to; HOST is
66406     the host name (a string), and SERVICE is the name of a defined
66407     network service (a string) or a port number (an integer like ‘80’
66408     or an integer string like ‘"80"’).
66409
66410     The remaining arguments PARAMETERS are keyword/argument pairs that
66411     are mainly relevant to encrypted connections:
66412
66413     ‘:nowait BOOLEAN’
66414          If non-‘nil’, try to make an asynchronous connection.
66415
66416     ‘:type TYPE’
66417          The type of connection.  Options are:
66418
66419          ‘plain’
66420               An ordinary, unencrypted connection.
66421          ‘tls’
66422          ‘ssl’
66423               A TLS (Transport Layer Security) connection.
66424          ‘nil’
66425          ‘network’
66426               Start with a plain connection, and if parameters
66427               ‘:success’ and ‘:capability-command’ are supplied, try to
66428               upgrade to an encrypted connection via STARTTLS.  If that
66429               fails, retain the unencrypted connection.
66430          ‘starttls’
66431               As for ‘nil’, but if STARTTLS fails drop the connection.
66432          ‘shell’
66433               A shell connection.
66434
66435     ‘:always-query-capabilities BOOLEAN’
66436          If non-‘nil’, always ask for the server’s capabilities, even
66437          when doing a ‘plain’ connection.
66438
66439     ‘:capability-command CAPABILITY-COMMAND’
66440          Command string to query the host capabilities.
66441
66442     ‘:end-of-command REGEXP’
66443     ‘:end-of-capability REGEXP’
66444          Regular expression matching the end of a command, or the end
66445          of the command CAPABILITY-COMMAND.  The latter defaults to the
66446          former.
66447
66448     ‘:starttls-function FUNCTION’
66449          Function of one argument (the response to CAPABILITY-COMMAND),
66450          which returns either ‘nil’, or the command to activate
66451          STARTTLS if supported.
66452
66453     ‘:success REGEXP’
66454          Regular expression matching a successful STARTTLS negotiation.
66455
66456     ‘:use-starttls-if-possible BOOLEAN’
66457          If non-‘nil’, do opportunistic STARTTLS upgrades even if Emacs
66458          doesn’t have built-in TLS support.
66459
66460     ‘:warn-unless-encrypted BOOLEAN’
66461          If non-‘nil’, and ‘:return-value’ is also non-‘nil’, Emacs
66462          will warn if the connection isn’t encrypted.  This is useful
66463          for protocols like IMAP and the like, where most users would
66464          expect the network traffic to be encrypted.
66465
66466     ‘:client-certificate LIST-OR-T’
66467          Either a list of the form ‘(KEY-FILE CERT-FILE)’, naming the
66468          certificate key file and certificate file itself, or ‘t’,
66469          meaning to query ‘auth-source’ for this information (*note
66470          auth-source: (auth)Help for users.).  Only used for TLS or
66471          STARTTLS.  To enable automatic queries of ‘auth-source’ when
66472          ‘:client-certificate’ is not specified customize
66473          ‘network-stream-use-client-certificates’ to t.
66474
66475     ‘:return-list CONS-OR-NIL’
66476          The return value of this function.  If omitted or ‘nil’,
66477          return a process object.  Otherwise, a cons of the form
66478          ‘(PROCESS-OBJECT . PLIST)’, where PLIST has keywords:
66479
66480          ‘:greeting STRING-OR-NIL’
66481               If non-‘nil’, the greeting string returned by the host.
66482          ‘:capabilities STRING-OR-NIL’
66483               If non-‘nil’, the host’s capability string.
66484          ‘:type SYMBOL’
66485               The connection type: ‘plain’ or ‘tls’.
66486
66487     ‘:shell-command STRING-OR-NIL’
66488          If the connection ‘type’ is ‘shell’, this parameter will be
66489          interpreted as a format-spec string that will be executed to
66490          make the connection.  The specs available are ‘%s’ for the
66491          host name and ‘%p’ for the port number.  For instance, if you
66492          want to first ssh to ‘gateway’ before making a plain
66493          connection, then this parameter could be something like ‘ssh
66494          gateway nc %s %p’.
66495
66496
66497File: elisp.info,  Node: Network Servers,  Next: Datagrams,  Prev: Network,  Up: Processes
66498
6649938.15 Network Servers
66500=====================
66501
66502You create a server by calling ‘make-network-process’ (*note Network
66503Processes::) with ‘:server t’.  The server will listen for connection
66504requests from clients.  When it accepts a client connection request,
66505that creates a new network connection, itself a process object, with the
66506following parameters:
66507
66508   • The connection’s process name is constructed by concatenating the
66509     server process’s NAME with a client identification string.  The
66510     client identification string for an IPv4 connection looks like
66511     ‘<A.B.C.D:P>’, which represents an address and port number.
66512     Otherwise, it is a unique number in brackets, as in ‘<NNN>’.  The
66513     number is unique for each connection in the Emacs session.
66514
66515   • If the server has a non-default filter, the connection process does
66516     not get a separate process buffer; otherwise, Emacs creates a new
66517     buffer for the purpose.  The buffer name is the server’s buffer
66518     name or process name, concatenated with the client identification
66519     string.
66520
66521     The server’s process buffer value is never used directly, but the
66522     log function can retrieve it and use it to log connections by
66523     inserting text there.
66524
66525   • The communication type and the process filter and sentinel are
66526     inherited from those of the server.  The server never directly uses
66527     its filter and sentinel; their sole purpose is to initialize
66528     connections made to the server.
66529
66530   • The connection’s process contact information is set according to
66531     the client’s addressing information (typically an IP address and a
66532     port number).  This information is associated with the
66533     ‘process-contact’ keywords ‘:host’, ‘:service’, ‘:remote’.
66534
66535   • The connection’s local address is set up according to the port
66536     number used for the connection.
66537
66538   • The client process’s plist is initialized from the server’s plist.
66539
66540
66541File: elisp.info,  Node: Datagrams,  Next: Low-Level Network,  Prev: Network Servers,  Up: Processes
66542
6654338.16 Datagrams
66544===============
66545
66546A “datagram” connection communicates with individual packets rather than
66547streams of data.  Each call to ‘process-send’ sends one datagram packet
66548(*note Input to Processes::), and each datagram received results in one
66549call to the filter function.
66550
66551   The datagram connection doesn’t have to talk with the same remote
66552peer all the time.  It has a “remote peer address” which specifies where
66553to send datagrams to.  Each time an incoming datagram is passed to the
66554filter function, the peer address is set to the address that datagram
66555came from; that way, if the filter function sends a datagram, it will go
66556back to that place.  You can specify the remote peer address when you
66557create the datagram connection using the ‘:remote’ keyword.  You can
66558change it later on by calling ‘set-process-datagram-address’.
66559
66560 -- Function: process-datagram-address process
66561     If PROCESS is a datagram connection or server, this function
66562     returns its remote peer address.
66563
66564 -- Function: set-process-datagram-address process address
66565     If PROCESS is a datagram connection or server, this function sets
66566     its remote peer address to ADDRESS.
66567
66568
66569File: elisp.info,  Node: Low-Level Network,  Next: Misc Network,  Prev: Datagrams,  Up: Processes
66570
6657138.17 Low-Level Network Access
66572==============================
66573
66574You can also create network connections by operating at a lower level
66575than that of ‘open-network-stream’, using ‘make-network-process’.
66576
66577* Menu:
66578
66579* Proc: Network Processes.   Using ‘make-network-process’.
66580* Options: Network Options.  Further control over network connections.
66581* Features: Network Feature Testing.
66582                             Determining which network features work on
66583                               the machine you are using.
66584
66585
66586File: elisp.info,  Node: Network Processes,  Next: Network Options,  Up: Low-Level Network
66587
6658838.17.1 ‘make-network-process’
66589------------------------------
66590
66591The basic function for creating network connections and network servers
66592is ‘make-network-process’.  It can do either of those jobs, depending on
66593the arguments you give it.
66594
66595 -- Function: make-network-process &rest args
66596     This function creates a network connection or server and returns
66597     the process object that represents it.  The arguments ARGS are a
66598     list of keyword/argument pairs.  Omitting a keyword is always
66599     equivalent to specifying it with value ‘nil’, except for ‘:coding’,
66600     ‘:filter-multibyte’, and ‘:reuseaddr’.  Here are the meaningful
66601     keywords (those corresponding to network options are listed in the
66602     following section):
66603
66604     :name NAME
66605          Use the string NAME as the process name.  It is modified if
66606          necessary to make it unique.
66607
66608     :type TYPE
66609          Specify the communication type.  A value of ‘nil’ specifies a
66610          stream connection (the default); ‘datagram’ specifies a
66611          datagram connection; ‘seqpacket’ specifies a sequenced packet
66612          stream connection.  Both connections and servers can be of
66613          these types.
66614
66615     :server SERVER-FLAG
66616          If SERVER-FLAG is non-‘nil’, create a server.  Otherwise,
66617          create a connection.  For a stream type server, SERVER-FLAG
66618          may be an integer, which then specifies the length of the
66619          queue of pending connections to the server.  The default queue
66620          length is 5.
66621
66622     :host HOST
66623          Specify the host to connect to.  HOST should be a host name or
66624          Internet address, as a string, or the symbol ‘local’ to
66625          specify the local host.  If you specify HOST for a server, it
66626          must specify a valid address for the local host, and only
66627          clients connecting to that address will be accepted.  When
66628          using ‘local’, by default IPv4 will be used, specify a FAMILY
66629          of ‘ipv6’ to override this.  To listen on all interfaces,
66630          specify an address of ‘"0.0.0.0"’ for IPv4 or ‘"::"’ for IPv6.
66631          Note that on some operating systems, listening on ‘"::"’ will
66632          also listen on IPv4, so attempting to then listen separately
66633          on IPv4 will result in ‘EADDRINUSE’ errors (‘"Address already
66634          in use"’).
66635
66636     :service SERVICE
66637          SERVICE specifies a port number to connect to; or, for a
66638          server, the port number to listen on.  It should be a service
66639          name like ‘"https"’ that translates to a port number, or an
66640          integer like ‘443’ or an integer string like ‘"443"’ that
66641          specifies the port number directly.  For a server, it can also
66642          be ‘t’, which means to let the system select an unused port
66643          number.
66644
66645     :family FAMILY
66646          FAMILY specifies the address (and protocol) family for
66647          communication.  ‘nil’ means determine the proper address
66648          family automatically for the given HOST and SERVICE.  ‘local’
66649          specifies a Unix socket, in which case HOST is ignored.
66650          ‘ipv4’ and ‘ipv6’ specify to use IPv4 and IPv6, respectively.
66651
66652     :use-external-socket USE-EXTERNAL-SOCKET
66653          If USE-EXTERNAL-SOCKET is non-‘nil’ use any sockets passed to
66654          Emacs on invocation instead of allocating one.  This is used
66655          by the Emacs server code to allow on-demand socket activation.
66656          If Emacs wasn’t passed a socket, this option is silently
66657          ignored.
66658
66659     :local LOCAL-ADDRESS
66660          For a server process, LOCAL-ADDRESS is the address to listen
66661          on.  It overrides FAMILY, HOST and SERVICE, so you might as
66662          well not specify them.
66663
66664     :remote REMOTE-ADDRESS
66665          For a connection, REMOTE-ADDRESS is the address to connect to.
66666          It overrides FAMILY, HOST and SERVICE, so you might as well
66667          not specify them.
66668
66669          For a datagram server, REMOTE-ADDRESS specifies the initial
66670          setting of the remote datagram address.
66671
66672          The format of LOCAL-ADDRESS or REMOTE-ADDRESS depends on the
66673          address family:
66674
66675             - An IPv4 address is represented as a five-element vector
66676               of four 8-bit integers and one 16-bit integer ‘[A B C D
66677               P]’ corresponding to numeric IPv4 address A.B.C.D and
66678               port number P.
66679
66680             - An IPv6 address is represented as a nine-element vector
66681               of 16-bit integers ‘[A B C D E F G H P]’ corresponding to
66682               numeric IPv6 address A:B:C:D:E:F:G:H and port number P.
66683
66684             - A local address is represented as a string, which
66685               specifies the address in the local address space.
66686
66687             - An unsupported-family address is represented by a cons
66688               ‘(F . AV)’, where F is the family number and AV is a
66689               vector specifying the socket address using one element
66690               per address data byte.  Do not rely on this format in
66691               portable code, as it may depend on implementation defined
66692               constants, data sizes, and data structure alignment.
66693
66694     :nowait BOOL
66695          If BOOL is non-‘nil’ for a stream connection, return without
66696          waiting for the connection to complete.  When the connection
66697          succeeds or fails, Emacs will call the sentinel function, with
66698          a second argument matching ‘"open"’ (if successful) or
66699          ‘"failed"’.  The default is to block, so that
66700          ‘make-network-process’ does not return until the connection
66701          has succeeded or failed.
66702
66703          If you’re setting up an asynchronous TLS connection, you have
66704          to also provide the ‘:tls-parameters’ parameter (see below).
66705
66706          Depending on the capabilities of Emacs, how asynchronous
66707          ‘:nowait’ is may vary.  The three elements that may (or may
66708          not) be done asynchronously are domain name resolution, socket
66709          setup, and (for TLS connections) TLS negotiation.
66710
66711          Many functions that interact with process objects, (for
66712          instance, ‘process-datagram-address’) rely on them at least
66713          having a socket before they can return a useful value.  These
66714          functions will block until the socket has achieved the desired
66715          status.  The recommended way of interacting with asynchronous
66716          sockets is to place a sentinel on the process, and not try to
66717          interact with it before it has changed status to ‘"run"’.
66718          That way, none of these functions will block.
66719
66720     :tls-parameters
66721          When opening a TLS connection, this should be where the first
66722          element is the TLS type (which should either be
66723          ‘gnutls-x509pki’ or ‘gnutls-anon’, and the remaining elements
66724          should form a keyword list acceptable for ‘gnutls-boot’.
66725          (This keyword list can be obtained from the
66726          ‘gnutls-boot-parameters’ function.)  The TLS connection will
66727          then be negotiated after completing the connection to the
66728          host.
66729
66730     :stop STOPPED
66731          If STOPPED is non-‘nil’, start the network connection or
66732          server in the stopped state.
66733
66734     :buffer BUFFER
66735          Use BUFFER as the process buffer.
66736
66737     :coding CODING
66738          Use CODING as the coding system for this process.  To specify
66739          different coding systems for decoding data from the connection
66740          and for encoding data sent to it, specify ‘(DECODING .
66741          ENCODING)’ for CODING.
66742
66743          If you don’t specify this keyword at all, the default is to
66744          determine the coding systems from the data.
66745
66746     :noquery QUERY-FLAG
66747          Initialize the process query flag to QUERY-FLAG.  *Note Query
66748          Before Exit::.
66749
66750     :filter FILTER
66751          Initialize the process filter to FILTER.
66752
66753     :filter-multibyte MULTIBYTE
66754          If MULTIBYTE is non-‘nil’, strings given to the process filter
66755          are multibyte, otherwise they are unibyte.  The default is
66756          ‘t’.
66757
66758     :sentinel SENTINEL
66759          Initialize the process sentinel to SENTINEL.
66760
66761     :log LOG
66762          Initialize the log function of a server process to LOG.  The
66763          log function is called each time the server accepts a network
66764          connection from a client.  The arguments passed to the log
66765          function are SERVER, CONNECTION, and MESSAGE; where SERVER is
66766          the server process, CONNECTION is the new process for the
66767          connection, and MESSAGE is a string describing what has
66768          happened.
66769
66770     :plist PLIST
66771          Initialize the process plist to PLIST.
66772
66773     The original argument list, modified with the actual connection
66774     information, is available via the ‘process-contact’ function.
66775
66776
66777File: elisp.info,  Node: Network Options,  Next: Network Feature Testing,  Prev: Network Processes,  Up: Low-Level Network
66778
6677938.17.2 Network Options
66780-----------------------
66781
66782The following network options can be specified when you create a network
66783process.  Except for ‘:reuseaddr’, you can also set or modify these
66784options later, using ‘set-network-process-option’.
66785
66786   For a server process, the options specified with
66787‘make-network-process’ are not inherited by the client connections, so
66788you will need to set the necessary options for each child connection as
66789it is created.
66790
66791:bindtodevice DEVICE-NAME
66792     If DEVICE-NAME is a non-empty string identifying a network
66793     interface name (see ‘network-interface-list’), only handle packets
66794     received on that interface.  If DEVICE-NAME is ‘nil’ (the default),
66795     handle packets received on any interface.
66796
66797     Using this option may require special privileges on some systems.
66798
66799:broadcast BROADCAST-FLAG
66800     If BROADCAST-FLAG is non-‘nil’ for a datagram process, the process
66801     will receive datagram packet sent to a broadcast address, and be
66802     able to send packets to a broadcast address.  This is ignored for a
66803     stream connection.
66804
66805:dontroute DONTROUTE-FLAG
66806     If DONTROUTE-FLAG is non-‘nil’, the process can only send to hosts
66807     on the same network as the local host.
66808
66809:keepalive KEEPALIVE-FLAG
66810     If KEEPALIVE-FLAG is non-‘nil’ for a stream connection, enable
66811     exchange of low-level keep-alive messages.
66812
66813:linger LINGER-ARG
66814     If LINGER-ARG is non-‘nil’, wait for successful transmission of all
66815     queued packets on the connection before it is deleted (see
66816     ‘delete-process’).  If LINGER-ARG is an integer, it specifies the
66817     maximum time in seconds to wait for queued packets to be sent
66818     before closing the connection.  The default is ‘nil’, which means
66819     to discard unsent queued packets when the process is deleted.
66820
66821:oobinline OOBINLINE-FLAG
66822     If OOBINLINE-FLAG is non-‘nil’ for a stream connection, receive
66823     out-of-band data in the normal data stream.  Otherwise, ignore
66824     out-of-band data.
66825
66826:priority PRIORITY
66827     Set the priority for packets sent on this connection to the integer
66828     PRIORITY.  The interpretation of this number is protocol specific;
66829     such as setting the TOS (type of service) field on IP packets sent
66830     on this connection.  It may also have system dependent effects,
66831     such as selecting a specific output queue on the network interface.
66832
66833:reuseaddr REUSEADDR-FLAG
66834     If REUSEADDR-FLAG is non-‘nil’ (the default) for a stream server
66835     process, allow this server to reuse a specific port number (see
66836     ‘:service’), unless another process on this host is already
66837     listening on that port.  If REUSEADDR-FLAG is ‘nil’, there may be a
66838     period of time after the last use of that port (by any process on
66839     the host) where it is not possible to make a new server on that
66840     port.
66841
66842 -- Function: set-network-process-option process option value &optional
66843          no-error
66844     This function sets or modifies a network option for network process
66845     PROCESS.  The accepted options and values are as for
66846     ‘make-network-process’.  If NO-ERROR is non-‘nil’, this function
66847     returns ‘nil’ instead of signaling an error if OPTION is not a
66848     supported option.  If the function successfully completes, it
66849     returns ‘t’.
66850
66851     The current setting of an option is available via the
66852     ‘process-contact’ function.
66853
66854
66855File: elisp.info,  Node: Network Feature Testing,  Prev: Network Options,  Up: Low-Level Network
66856
6685738.17.3 Testing Availability of Network Features
66858------------------------------------------------
66859
66860To test for the availability of a given network feature, use ‘featurep’
66861like this:
66862
66863     (featurep 'make-network-process '(KEYWORD VALUE))
66864
66865The result of this form is ‘t’ if it works to specify KEYWORD with value
66866VALUE in ‘make-network-process’.  Here are some of the KEYWORD—VALUE
66867pairs you can test in this way.
66868
66869‘(:nowait t)’
66870     Non-‘nil’ if non-blocking connect is supported.
66871‘(:type datagram)’
66872     Non-‘nil’ if datagrams are supported.
66873‘(:family local)’
66874     Non-‘nil’ if local (a.k.a. “UNIX domain”) sockets are supported.
66875‘(:family ipv6)’
66876     Non-‘nil’ if IPv6 is supported.
66877‘(:service t)’
66878     Non-‘nil’ if the system can select the port for a server.
66879
66880   To test for the availability of a given network option, use
66881‘featurep’ like this:
66882
66883     (featurep 'make-network-process 'KEYWORD)
66884
66885The accepted KEYWORD values are ‘:bindtodevice’, etc.  For the complete
66886list, *note Network Options::.  This form returns non-‘nil’ if that
66887particular network option is supported by ‘make-network-process’ (or
66888‘set-network-process-option’).
66889
66890
66891File: elisp.info,  Node: Misc Network,  Next: Serial Ports,  Prev: Low-Level Network,  Up: Processes
66892
6689338.18 Misc Network Facilities
66894=============================
66895
66896These additional functions are useful for creating and operating on
66897network connections.  Note that they are supported only on some systems.
66898
66899 -- Function: network-interface-list &optional full family
66900     This function returns a list describing the network interfaces of
66901     the machine you are using.  The value is an alist whose elements
66902     have the form ‘(IFNAME . ADDRESS)’.  IFNAME is a string naming the
66903     interface, ADDRESS has the same form as the LOCAL-ADDRESS and
66904     REMOTE-ADDRESS arguments to ‘make-network-process’, i.e.  a vector
66905     of integers.  By default both IPv4 and IPv6 addresses are returned
66906     if possible.
66907
66908     Optional argument FULL non-‘nil’ means to instead return a list of
66909     one or more elements of the form ‘(IFNAME ADDR BCAST NETMASK)’.
66910     IFNAME is a non-unique string naming the interface.  ADDR, BCAST,
66911     and NETMASK are vectors of integers detailing the IP address,
66912     broadcast address, and network mask.
66913
66914     Optional argument FAMILY specified as symbol ‘ipv4’ or ‘ipv6’
66915     restricts the returned information to IPv4 and IPv6 addresses
66916     respectively, independently of the value of FULL.  Specifying
66917     ‘ipv6’ when IPv6 support is not available will result in an error
66918     being signaled.
66919
66920     Some examples:
66921
66922          (network-interface-list) ⇒
66923          (("vmnet8" .
66924            [172 16 76 1 0])
66925           ("vmnet1" .
66926            [172 16 206 1 0])
66927           ("lo0" .
66928            [65152 0 0 0 0 0 0 1 0])
66929           ("lo0" .
66930            [0 0 0 0 0 0 0 1 0])
66931           ("lo0" .
66932            [127 0 0 1 0]))
66933
66934          (network-interface-list t) ⇒
66935          (("vmnet8"
66936            [172 16 76 1 0]
66937            [172 16 76 255 0]
66938            [255 255 255 0 0])
66939           ("vmnet1"
66940            [172 16 206 1 0]
66941            [172 16 206 255 0]
66942            [255 255 255 0 0])
66943           ("lo0"
66944            [65152 0 0 0 0 0 0 1 0]
66945            [65152 0 0 0 65535 65535 65535 65535 0]
66946            [65535 65535 65535 65535 0 0 0 0 0])
66947           ("lo0"
66948            [0 0 0 0 0 0 0 1 0]
66949            [0 0 0 0 0 0 0 1 0]
66950            [65535 65535 65535 65535 65535 65535 65535 65535 0])
66951           ("lo0"
66952            [127 0 0 1 0]
66953            [127 255 255 255 0]
66954            [255 0 0 0 0]))
66955
66956 -- Function: network-interface-info ifname
66957     This function returns information about the network interface named
66958     IFNAME.  The value is a list of the form ‘(ADDR BCAST NETMASK
66959     HWADDR FLAGS)’.
66960
66961     ADDR
66962          The Internet protocol address.
66963     BCAST
66964          The broadcast address.
66965     NETMASK
66966          The network mask.
66967     HWADDR
66968          The layer 2 address (Ethernet MAC address, for instance).
66969     FLAGS
66970          The current flags of the interface.
66971
66972     Note that this function returns only IPv4 information.
66973
66974 -- Function: format-network-address address &optional omit-port
66975     This function converts the Lisp representation of a network address
66976     to a string.
66977
66978     A five-element vector ‘[A B C D P]’ represents an IPv4 address
66979     A.B.C.D and port number P.  ‘format-network-address’ converts that
66980     to the string ‘"A.B.C.D:P"’.
66981
66982     A nine-element vector ‘[A B C D E F G H P]’ represents an IPv6
66983     address along with a port number.  ‘format-network-address’
66984     converts that to the string ‘"[A:B:C:D:E:F:G:H]:P"’.
66985
66986     If the vector does not include the port number, P, or if OMIT-PORT
66987     is non-‘nil’, the result does not include the ‘:P’ suffix.
66988
66989 -- Function: network-lookup-address-info name &optional family
66990     This function is used to perform hostname lookups on NAME, which is
66991     expected to be an ASCII-only string, otherwise an error is
66992     signaled.  Call ‘puny-encode-domain’ on NAME first if you wish to
66993     lookup internationalized hostnames.
66994
66995     If successful it returns a list of Lisp representations of network
66996     addresses, otherwise it returns ‘nil’.  In the latter case, it also
66997     displays the error message hopefully explaining what went wrong.
66998
66999     By default both IPv4 and IPv6 lookups are attempted.  The optional
67000     argument FAMILY controls this behavior, specifying the symbol
67001     ‘ipv4’ or ‘ipv6’ restricts lookups to IPv4 and IPv6 respectively.
67002
67003
67004File: elisp.info,  Node: Serial Ports,  Next: Byte Packing,  Prev: Misc Network,  Up: Processes
67005
6700638.19 Communicating with Serial Ports
67007=====================================
67008
67009Emacs can communicate with serial ports.  For interactive use, ‘M-x
67010serial-term’ opens a terminal window.  In a Lisp program,
67011‘make-serial-process’ creates a process object.
67012
67013   The serial port can be configured at run-time, without having to
67014close and re-open it.  The function ‘serial-process-configure’ lets you
67015change the speed, bytesize, and other parameters.  In a terminal window
67016created by ‘serial-term’, you can click on the mode line for
67017configuration.
67018
67019   A serial connection is represented by a process object, which can be
67020used in a similar way to a subprocess or network process.  You can send
67021and receive data, and configure the serial port.  A serial process
67022object has no process ID, however, and you can’t send signals to it, and
67023the status codes are different from other types of processes.
67024‘delete-process’ on the process object or ‘kill-buffer’ on the process
67025buffer close the connection, but this does not affect the device
67026connected to the serial port.
67027
67028   The function ‘process-type’ returns the symbol ‘serial’ for a process
67029object representing a serial port connection.
67030
67031   Serial ports are available on GNU/Linux, Unix, and MS Windows
67032systems.
67033
67034 -- Command: serial-term port speed &optional line-mode
67035     Start a terminal-emulator for a serial port in a new buffer.  PORT
67036     is the name of the serial port to connect to.  For example, this
67037     could be ‘/dev/ttyS0’ on Unix.  On MS Windows, this could be
67038     ‘COM1’, or ‘\\.\COM10’ (double the backslashes in Lisp strings).
67039
67040     SPEED is the speed of the serial port in bits per second.  9600 is
67041     a common value.  The buffer is in Term mode; see *note (emacs)Term
67042     Mode::, for the commands to use in that buffer.  You can change the
67043     speed and the configuration in the mode line menu.  If LINE-MODE is
67044     non-‘nil’, ‘term-line-mode’ is used; otherwise ‘term-raw-mode’ is
67045     used.
67046
67047 -- Function: make-serial-process &rest args
67048     This function creates a process and a buffer.  Arguments are
67049     specified as keyword/argument pairs.  Here’s the list of the
67050     meaningful keywords, with the first two (PORT and SPEED) being
67051     mandatory:
67052
67053     ‘:port PORT’
67054          This is the name of the serial port.  On Unix and GNU systems,
67055          this is a file name such as ‘/dev/ttyS0’.  On Windows, this
67056          could be ‘COM1’, or ‘\\.\COM10’ for ports higher than ‘COM9’
67057          (double the backslashes in Lisp strings).
67058
67059     ‘:speed SPEED’
67060          The speed of the serial port in bits per second.  This
67061          function calls ‘serial-process-configure’ to handle the speed;
67062          see the following documentation of that function for more
67063          details.
67064
67065     ‘:name NAME’
67066          The name of the process.  If NAME is not given, PORT will
67067          serve as the process name as well.
67068
67069     ‘:buffer BUFFER’
67070          The buffer to associate with the process.  The value can be
67071          either a buffer or a string that names a buffer.  Process
67072          output goes at the end of that buffer, unless you specify an
67073          output stream or filter function to handle the output.  If
67074          BUFFER is not given, the process buffer’s name is taken from
67075          the value of the ‘:name’ keyword.
67076
67077     ‘:coding CODING’
67078          If CODING is a symbol, it specifies the coding system used for
67079          both reading and writing for this process.  If CODING is a
67080          cons ‘(DECODING . ENCODING)’, DECODING is used for reading,
67081          and ENCODING is used for writing.  If not specified, the
67082          default is to determine the coding systems from the data
67083          itself.
67084
67085     ‘:noquery QUERY-FLAG’
67086          Initialize the process query flag to QUERY-FLAG.  *Note Query
67087          Before Exit::.  The flags defaults to ‘nil’ if unspecified.
67088
67089     ‘:stop BOOL’
67090          Start process in the stopped state if BOOL is non-‘nil’.  In
67091          the stopped state, a serial process does not accept incoming
67092          data, but you can send outgoing data.  The stopped state is
67093          cleared by ‘continue-process’ and set by ‘stop-process’.
67094
67095     ‘:filter FILTER’
67096          Install FILTER as the process filter.
67097
67098     ‘:sentinel SENTINEL’
67099          Install SENTINEL as the process sentinel.
67100
67101     ‘:plist PLIST’
67102          Install PLIST as the initial plist of the process.
67103
67104     ‘:bytesize’
67105     ‘:parity’
67106     ‘:stopbits’
67107     ‘:flowcontrol’
67108          These are handled by ‘serial-process-configure’, which is
67109          called by ‘make-serial-process’.
67110
67111     The original argument list, possibly modified by later
67112     configuration, is available via the function ‘process-contact’.
67113
67114     Here is an example:
67115
67116          (make-serial-process :port "/dev/ttyS0" :speed 9600)
67117
67118 -- Function: serial-process-configure &rest args
67119
67120     This function configures a serial port connection.  Arguments are
67121     specified as keyword/argument pairs.  Attributes that are not given
67122     are re-initialized from the process’s current configuration
67123     (available via the function ‘process-contact’), or set to
67124     reasonable default values.  The following arguments are defined:
67125
67126     ‘:process PROCESS’
67127     ‘:name NAME’
67128     ‘:buffer BUFFER’
67129     ‘:port PORT’
67130          Any of these arguments can be given to identify the process
67131          that is to be configured.  If none of these arguments is
67132          given, the current buffer’s process is used.
67133
67134     ‘:speed SPEED’
67135          The speed of the serial port in bits per second, a.k.a. “baud
67136          rate”.  The value can be any number, but most serial ports
67137          work only at a few defined values between 1200 and 115200,
67138          with 9600 being the most common value.  If SPEED is ‘nil’, the
67139          function ignores all other arguments and does not configure
67140          the port.  This may be useful for special serial ports such as
67141          Bluetooth-to-serial converters, which can only be configured
67142          through ‘AT’ commands sent through the connection.  The value
67143          of ‘nil’ for SPEED is valid only for connections that were
67144          already opened by a previous call to ‘make-serial-process’ or
67145          ‘serial-term’.
67146
67147     ‘:bytesize BYTESIZE’
67148          The number of bits per byte, which can be 7 or 8.  If BYTESIZE
67149          is not given or ‘nil’, it defaults to 8.
67150
67151     ‘:parity PARITY’
67152          The value can be ‘nil’ (don’t use parity), the symbol ‘odd’
67153          (use odd parity), or the symbol ‘even’ (use even parity).  If
67154          PARITY is not given, it defaults to no parity.
67155
67156     ‘:stopbits STOPBITS’
67157          The number of stopbits used to terminate a transmission of
67158          each byte.  STOPBITS can be 1 or 2.  If STOPBITS is not given
67159          or ‘nil’, it defaults to 1.
67160
67161     ‘:flowcontrol FLOWCONTROL’
67162          The type of flow control to use for this connection, which is
67163          either ‘nil’ (don’t use flow control), the symbol ‘hw’ (use
67164          RTS/CTS hardware flow control), or the symbol ‘sw’ (use
67165          XON/XOFF software flow control).  If FLOWCONTROL is not given,
67166          it defaults to no flow control.
67167
67168     Internally, ‘make-serial-process’ calls ‘serial-process-configure’
67169     for the initial configuration of the serial port.
67170
67171
67172File: elisp.info,  Node: Byte Packing,  Prev: Serial Ports,  Up: Processes
67173
6717438.20 Packing and Unpacking Byte Arrays
67175=======================================
67176
67177This section describes how to pack and unpack arrays of bytes, usually
67178for binary network protocols.  These functions convert byte arrays to
67179alists, and vice versa.  The byte array can be represented as a unibyte
67180string or as a vector of integers, while the alist associates symbols
67181either with fixed-size objects or with recursive sub-alists.  To use the
67182functions referred to in this section, load the ‘bindat’ library.
67183
67184   Conversion from byte arrays to nested alists is also known as
67185“deserializing” or “unpacking”, while going in the opposite direction is
67186also known as “serializing” or “packing”.
67187
67188* Menu:
67189
67190* Bindat Spec::         Describing data layout.
67191* Bindat Functions::    Doing the unpacking and packing.
67192
67193
67194File: elisp.info,  Node: Bindat Spec,  Next: Bindat Functions,  Up: Byte Packing
67195
6719638.20.1 Describing Data Layout
67197------------------------------
67198
67199To control unpacking and packing, you write a “data layout
67200specification”, a special nested list describing named and typed
67201“fields”.  This specification controls the length of each field to be
67202processed, and how to pack or unpack it.  We normally keep bindat specs
67203in variables whose names end in ‘-bindat-spec’; that kind of name is
67204automatically recognized as risky.
67205
67206   A field’s “type” describes the size (in bytes) of the object that the
67207field represents and, in the case of multibyte fields, how the bytes are
67208ordered within the field.  The two possible orderings are “big endian”
67209(also known as “network byte ordering”) and “little endian”.  For
67210instance, the number ‘#x23cd’ (decimal 9165) in big endian would be the
67211two bytes ‘#x23’ ‘#xcd’; and in little endian, ‘#xcd’ ‘#x23’.  Here are
67212the possible type values:
67213
67214‘u8’
67215‘byte’
67216     Unsigned byte, with length 1.
67217
67218‘u16’
67219‘word’
67220‘short’
67221     Unsigned integer in network byte order, with length 2.
67222
67223‘u24’
67224     Unsigned integer in network byte order, with length 3.
67225
67226‘u32’
67227‘dword’
67228‘long’
67229     Unsigned integer in network byte order, with length 4.  Note: These
67230     values may be limited by Emacs’s integer implementation limits.
67231
67232‘u16r’
67233‘u24r’
67234‘u32r’
67235     Unsigned integer in little endian order, with length 2, 3 and 4,
67236     respectively.
67237
67238‘str LEN’
67239     String of length LEN.
67240
67241‘strz LEN’
67242     Zero-terminated string, in a fixed-size field with length LEN.
67243
67244‘vec LEN [TYPE]’
67245     Vector of LEN elements of type TYPE, defaulting to bytes.  The TYPE
67246     is any of the simple types above, or another vector specified as a
67247     list of the form ‘(vec LEN [TYPE])’.
67248
67249‘ip’
67250     Four-byte vector representing an Internet address.  For example:
67251     ‘[127 0 0 1]’ for localhost.
67252
67253‘bits LEN’
67254     List of set bits in LEN bytes.  The bytes are taken in big endian
67255     order and the bits are numbered starting with ‘8 * LEN − 1’ and
67256     ending with zero.  For example: ‘bits 2’ unpacks ‘#x28’ ‘#x1c’ to
67257     ‘(2 3 4 11 13)’ and ‘#x1c’ ‘#x28’ to ‘(3 5 10 11 12)’.
67258
67259‘(eval FORM)’
67260     FORM is a Lisp expression evaluated at the moment the field is
67261     unpacked or packed.  The result of the evaluation should be one of
67262     the above-listed type specifications.
67263
67264   For a fixed-size field, the length LEN is given as an integer
67265specifying the number of bytes in the field.
67266
67267   When the length of a field is not fixed, it typically depends on the
67268value of a preceding field.  In this case, the length LEN can be given
67269either as a list ‘(NAME ...)’ identifying a “field name” in the format
67270specified for ‘bindat-get-field’ below, or by an expression ‘(eval
67271FORM)’ where FORM should evaluate to an integer, specifying the field
67272length.
67273
67274   A field specification generally has the form ‘([NAME] HANDLER)’,
67275where NAME is optional.  Don’t use names that are symbols meaningful as
67276type specifications (above) or handler specifications (below), since
67277that would be ambiguous.  NAME can be a symbol or an expression ‘(eval
67278FORM)’, in which case FORM should evaluate to a symbol.
67279
67280   HANDLER describes how to unpack or pack the field and can be one of
67281the following:
67282
67283‘TYPE’
67284     Unpack/pack this field according to the type specification TYPE.
67285
67286‘eval FORM’
67287     Evaluate FORM, a Lisp expression, for side-effect only.  If the
67288     field name is specified, the value is bound to that field name.
67289
67290‘fill LEN’
67291     Skip LEN bytes.  In packing, this leaves them unchanged, which
67292     normally means they remain zero.  In unpacking, this means they are
67293     ignored.
67294
67295‘align LEN’
67296     Skip to the next multiple of LEN bytes.
67297
67298‘struct SPEC-NAME’
67299     Process SPEC-NAME as a sub-specification.  This describes a
67300     structure nested within another structure.
67301
67302‘union FORM (TAG SPEC)...’
67303     Evaluate FORM, a Lisp expression, find the first TAG that matches
67304     it, and process its associated data layout specification SPEC.
67305     Matching can occur in one of three ways:
67306
67307        • If a TAG has the form ‘(eval EXPR)’, evaluate EXPR with the
67308          variable ‘tag’ dynamically bound to the value of FORM.  A
67309          non-‘nil’ result indicates a match.
67310
67311        • TAG matches if it is ‘equal’ to the value of FORM.
67312
67313        • TAG matches unconditionally if it is ‘t’.
67314
67315‘repeat COUNT FIELD-SPECS...’
67316     Process the FIELD-SPECS recursively, in order, then repeat starting
67317     from the first one, processing all the specifications COUNT times
67318     overall.  The COUNT is given using the same formats as a field
67319     length—if an ‘eval’ form is used, it is evaluated just once.  For
67320     correct operation, each specification in FIELD-SPECS must include a
67321     name.
67322
67323   For the ‘(eval FORM)’ forms used in a bindat specification, the FORM
67324can access and update these dynamically bound variables during
67325evaluation:
67326
67327‘last’
67328     Value of the last field processed.
67329
67330‘bindat-raw’
67331     The data as a byte array.
67332
67333‘bindat-idx’
67334     Current index (within ‘bindat-raw’) for unpacking or packing.
67335
67336‘struct’
67337     The alist containing the structured data that have been unpacked so
67338     far, or the entire structure being packed.  You can use
67339     ‘bindat-get-field’ to access specific fields of this structure.
67340
67341‘count’
67342‘index’
67343     Inside a ‘repeat’ block, these contain the maximum number of
67344     repetitions (as specified by the COUNT parameter), and the current
67345     repetition number (counting from 0).  Setting ‘count’ to zero will
67346     terminate the inner-most repeat block after the current repetition
67347     has completed.
67348
67349
67350File: elisp.info,  Node: Bindat Functions,  Prev: Bindat Spec,  Up: Byte Packing
67351
6735238.20.2 Functions to Unpack and Pack Bytes
67353------------------------------------------
67354
67355In the following documentation, SPEC refers to a data layout
67356specification, ‘bindat-raw’ to a byte array, and STRUCT to an alist
67357representing unpacked field data.
67358
67359 -- Function: bindat-unpack spec bindat-raw &optional bindat-idx
67360     This function unpacks data from the unibyte string or byte array
67361     ‘bindat-raw’ according to SPEC.  Normally, this starts unpacking at
67362     the beginning of the byte array, but if BINDAT-IDX is non-‘nil’, it
67363     specifies a zero-based starting position to use instead.
67364
67365     The value is an alist or nested alist in which each element
67366     describes one unpacked field.
67367
67368 -- Function: bindat-get-field struct &rest name
67369     This function selects a field’s data from the nested alist STRUCT.
67370     Usually STRUCT was returned by ‘bindat-unpack’.  If NAME
67371     corresponds to just one argument, that means to extract a top-level
67372     field value.  Multiple NAME arguments specify repeated lookup of
67373     sub-structures.  An integer name acts as an array index.
67374
67375     For example, if NAME is ‘(a b 2 c)’, that means to find field ‘c’
67376     in the third element of subfield ‘b’ of field ‘a’.  (This
67377     corresponds to ‘struct.a.b[2].c’ in C.)
67378
67379   Although packing and unpacking operations change the organization of
67380data (in memory), they preserve the data’s “total length”, which is the
67381sum of all the fields’ lengths, in bytes.  This value is not generally
67382inherent in either the specification or alist alone; instead, both
67383pieces of information contribute to its calculation.  Likewise, the
67384length of a string or array being unpacked may be longer than the data’s
67385total length as described by the specification.
67386
67387 -- Function: bindat-length spec struct
67388     This function returns the total length of the data in STRUCT,
67389     according to SPEC.
67390
67391 -- Function: bindat-pack spec struct &optional bindat-raw bindat-idx
67392     This function returns a byte array packed according to SPEC from
67393     the data in the alist STRUCT.  It normally creates and fills a new
67394     byte array starting at the beginning.  However, if BINDAT-RAW is
67395     non-‘nil’, it specifies a pre-allocated unibyte string or vector to
67396     pack into.  If BINDAT-IDX is non-‘nil’, it specifies the starting
67397     offset for packing into ‘bindat-raw’.
67398
67399     When pre-allocating, you should make sure ‘(length BINDAT-RAW)’
67400     meets or exceeds the total length to avoid an out-of-range error.
67401
67402 -- Function: bindat-ip-to-string ip
67403     Convert the Internet address vector IP to a string in the usual
67404     dotted notation.
67405
67406          (bindat-ip-to-string [127 0 0 1])
67407               ⇒ "127.0.0.1"
67408
67409
67410File: elisp.info,  Node: Display,  Next: System Interface,  Prev: Processes,  Up: Top
67411
6741239 Emacs Display
67413****************
67414
67415This chapter describes a number of features related to the display that
67416Emacs presents to the user.
67417
67418* Menu:
67419
67420* Refresh Screen::      Clearing the screen and redrawing everything on it.
67421* Forcing Redisplay::   Forcing redisplay.
67422* Truncation::          Folding or wrapping long text lines.
67423* The Echo Area::       Displaying messages at the bottom of the screen.
67424* Warnings::            Displaying warning messages for the user.
67425* Invisible Text::      Hiding part of the buffer text.
67426* Selective Display::   Hiding part of the buffer text (the old way).
67427* Temporary Displays::  Displays that go away automatically.
67428* Overlays::            Use overlays to highlight parts of the buffer.
67429* Size of Displayed Text::  How large displayed text is.
67430* Line Height::         Controlling the height of lines.
67431* Faces::               A face defines a graphics style for text characters:
67432                          font, colors, etc.
67433* Fringes::             Controlling window fringes.
67434* Scroll Bars::         Controlling scroll bars.
67435* Window Dividers::     Separating windows visually.
67436* Display Property::    Images, margins, text size, etc.
67437* Images::              Displaying images in Emacs buffers.
67438* Xwidgets::            Displaying native widgets in Emacs buffers.
67439* Buttons::             Adding clickable buttons to Emacs buffers.
67440* Abstract Display::    Emacs’s Widget for Object Collections.
67441* Blinking::            How Emacs shows the matching open parenthesis.
67442* Character Display::   How Emacs displays individual characters.
67443* Beeping::             Audible signal to the user.
67444* Window Systems::      Which window system is being used.
67445* Tooltips::            Tooltip display in Emacs.
67446* Bidirectional Display:: Display of bidirectional scripts, such as
67447                             Arabic and Farsi.
67448
67449
67450File: elisp.info,  Node: Refresh Screen,  Next: Forcing Redisplay,  Up: Display
67451
6745239.1 Refreshing the Screen
67453==========================
67454
67455The function ‘redraw-frame’ clears and redisplays the entire contents of
67456a given frame (*note Frames::).  This is useful if the screen is
67457corrupted.
67458
67459 -- Function: redraw-frame &optional frame
67460     This function clears and redisplays frame FRAME.  If FRAME is
67461     omitted or ‘nil’, it redraws the selected frame.
67462
67463   Even more powerful is ‘redraw-display’:
67464
67465 -- Command: redraw-display
67466     This function clears and redisplays all visible frames.
67467
67468   In Emacs, processing user input takes priority over redisplay.  If
67469you call these functions when input is available, they don’t redisplay
67470immediately, but the requested redisplay does happen eventually—after
67471all the input has been processed.
67472
67473   On text terminals, suspending and resuming Emacs normally also
67474refreshes the screen.  Some terminal emulators record separate contents
67475for display-oriented programs such as Emacs and for ordinary sequential
67476display.  If you are using such a terminal, you might want to inhibit
67477the redisplay on resumption.
67478
67479 -- User Option: no-redraw-on-reenter
67480     This variable controls whether Emacs redraws the entire screen
67481     after it has been suspended and resumed.  Non-‘nil’ means there is
67482     no need to redraw, ‘nil’ means redrawing is needed.  The default is
67483     ‘nil’.
67484
67485
67486File: elisp.info,  Node: Forcing Redisplay,  Next: Truncation,  Prev: Refresh Screen,  Up: Display
67487
6748839.2 Forcing Redisplay
67489======================
67490
67491Emacs normally tries to redisplay the screen whenever it waits for
67492input.  With the following function, you can request an immediate
67493attempt to redisplay, in the middle of Lisp code, without actually
67494waiting for input.
67495
67496 -- Function: redisplay &optional force
67497     This function tries immediately to redisplay.  The optional
67498     argument FORCE, if non-‘nil’, forces the redisplay to be performed,
67499     instead of being preempted if input is pending.
67500
67501     The function returns ‘t’ if it actually tried to redisplay, and
67502     ‘nil’ otherwise.  A value of ‘t’ does not mean that redisplay
67503     proceeded to completion; it could have been preempted by newly
67504     arriving input.
67505
67506   Although ‘redisplay’ tries immediately to redisplay, it does not
67507change how Emacs decides which parts of its frame(s) to redisplay.  By
67508contrast, the following function adds certain windows to the pending
67509redisplay work (as if their contents had completely changed), but does
67510not immediately try to perform redisplay.
67511
67512 -- Function: force-window-update &optional object
67513     This function forces some or all windows to be updated the next
67514     time Emacs does a redisplay.  If OBJECT is a window, that window is
67515     to be updated.  If OBJECT is a buffer or buffer name, all windows
67516     displaying that buffer are to be updated.  If OBJECT is ‘nil’ (or
67517     omitted), all windows are to be updated.
67518
67519     This function does not do a redisplay immediately; Emacs does that
67520     as it waits for input, or when the function ‘redisplay’ is called.
67521
67522 -- Variable: pre-redisplay-function
67523     A function run just before redisplay.  It is called with one
67524     argument, the set of windows to be redisplayed.  The set can be
67525     ‘nil’, meaning only the selected window, or ‘t’, meaning all the
67526     windows.
67527
67528 -- Variable: pre-redisplay-functions
67529     This hook is run just before redisplay.  It is called once in each
67530     window that is about to be redisplayed, with ‘current-buffer’ set
67531     to the buffer displayed in that window.
67532
67533
67534File: elisp.info,  Node: Truncation,  Next: The Echo Area,  Prev: Forcing Redisplay,  Up: Display
67535
6753639.3 Truncation
67537===============
67538
67539When a line of text extends beyond the right edge of a window, Emacs can
67540“continue” the line (make it wrap to the next screen line), or
67541“truncate” the line (limit it to one screen line).  The additional
67542screen lines used to display a long text line are called “continuation”
67543lines.  Continuation is not the same as filling; continuation happens on
67544the screen only, not in the buffer contents, and it breaks a line
67545precisely at the right margin, not at a word boundary.  *Note Filling::.
67546
67547   On a graphical display, tiny arrow images in the window fringes
67548indicate truncated and continued lines (*note Fringes::).  On a text
67549terminal, a ‘$’ in the rightmost column of the window indicates
67550truncation; a ‘\’ on the rightmost column indicates a line that wraps.
67551(The display table can specify alternate characters to use for this;
67552*note Display Tables::).
67553
67554 -- User Option: truncate-lines
67555     If this buffer-local variable is non-‘nil’, lines that extend
67556     beyond the right edge of the window are truncated; otherwise, they
67557     are continued.  As a special exception, the variable
67558     ‘truncate-partial-width-windows’ takes precedence in
67559     “partial-width” windows (i.e., windows that do not occupy the
67560     entire frame width).
67561
67562 -- User Option: truncate-partial-width-windows
67563     This variable controls line truncation in “partial-width” windows.
67564     A partial-width window is one that does not occupy the entire frame
67565     width (*note Splitting Windows::).  If the value is ‘nil’, line
67566     truncation is determined by the variable ‘truncate-lines’ (see
67567     above).  If the value is an integer N, lines are truncated if the
67568     partial-width window has fewer than N columns, regardless of the
67569     value of ‘truncate-lines’; if the partial-width window has N or
67570     more columns, line truncation is determined by ‘truncate-lines’.
67571     For any other non-‘nil’ value, lines are truncated in every
67572     partial-width window, regardless of the value of ‘truncate-lines’.
67573
67574   When horizontal scrolling (*note Horizontal Scrolling::) is in use in
67575a window, that forces truncation.
67576
67577 -- Variable: wrap-prefix
67578     If this buffer-local variable is non-‘nil’, it defines a “wrap
67579     prefix” which Emacs displays at the start of every continuation
67580     line.  (If lines are truncated, ‘wrap-prefix’ is never used.)  Its
67581     value may be a string or an image (*note Other Display Specs::), or
67582     a stretch of whitespace such as specified by the ‘:width’ or
67583     ‘:align-to’ display properties (*note Specified Space::).  The
67584     value is interpreted in the same way as a ‘display’ text property.
67585     *Note Display Property::.
67586
67587     A wrap prefix may also be specified for regions of text, using the
67588     ‘wrap-prefix’ text or overlay property.  This takes precedence over
67589     the ‘wrap-prefix’ variable.  *Note Special Properties::.
67590
67591 -- Variable: line-prefix
67592     If this buffer-local variable is non-‘nil’, it defines a “line
67593     prefix” which Emacs displays at the start of every non-continuation
67594     line.  Its value may be a string or an image (*note Other Display
67595     Specs::), or a stretch of whitespace such as specified by the
67596     ‘:width’ or ‘:align-to’ display properties (*note Specified
67597     Space::).  The value is interpreted in the same way as a ‘display’
67598     text property.  *Note Display Property::.
67599
67600     A line prefix may also be specified for regions of text using the
67601     ‘line-prefix’ text or overlay property.  This takes precedence over
67602     the ‘line-prefix’ variable.  *Note Special Properties::.
67603
67604
67605File: elisp.info,  Node: The Echo Area,  Next: Warnings,  Prev: Truncation,  Up: Display
67606
6760739.4 The Echo Area
67608==================
67609
67610The “echo area” is used for displaying error messages (*note Errors::),
67611for messages made with the ‘message’ primitive, and for echoing
67612keystrokes.  It is not the same as the minibuffer, despite the fact that
67613the minibuffer appears (when active) in the same place on the screen as
67614the echo area.  *Note The Minibuffer: (emacs)Minibuffer.
67615
67616   Apart from the functions documented in this section, you can print
67617Lisp objects to the echo area by specifying ‘t’ as the output stream.
67618*Note Output Streams::.
67619
67620* Menu:
67621
67622* Displaying Messages:: Explicitly displaying text in the echo area.
67623* Progress::            Informing user about progress of a long operation.
67624* Logging Messages::    Echo area messages are logged for the user.
67625* Echo Area Customization:: Controlling the echo area.
67626
67627
67628File: elisp.info,  Node: Displaying Messages,  Next: Progress,  Up: The Echo Area
67629
6763039.4.1 Displaying Messages in the Echo Area
67631-------------------------------------------
67632
67633This section describes the standard functions for displaying messages in
67634the echo area.
67635
67636 -- Function: message format-string &rest arguments
67637     This function displays a message in the echo area.  FORMAT-STRING
67638     is a format string, and ARGUMENTS are the objects for its format
67639     specifications, like in the ‘format-message’ function (*note
67640     Formatting Strings::).  The resulting formatted string is displayed
67641     in the echo area; if it contains ‘face’ text properties, it is
67642     displayed with the specified faces (*note Faces::).  The string is
67643     also added to the ‘*Messages*’ buffer, but without text properties
67644     (*note Logging Messages::).
67645
67646     Typically grave accent and apostrophe in the format translate to
67647     matching curved quotes, e.g., "Missing `%s'" might result in
67648     "Missing ‘foo’".  *Note Text Quoting Style::, for how to influence
67649     or inhibit this translation.
67650
67651     In batch mode, the message is printed to the standard error stream,
67652     followed by a newline.
67653
67654     When ‘inhibit-message’ is non-‘nil’, no message will be displayed
67655     in the echo area, it will only be logged to ‘*Messages*’.
67656
67657     If FORMAT-STRING is ‘nil’ or the empty string, ‘message’ clears the
67658     echo area; if the echo area has been expanded automatically, this
67659     brings it back to its normal size.  If the minibuffer is active,
67660     this brings the minibuffer contents back onto the screen
67661     immediately.
67662
67663          (message "Reverting `%s'..." (buffer-name))
67664           ⊣ Reverting ‘subr.el’...
67665          ⇒ "Reverting ‘subr.el’..."
67666
67667          ---------- Echo Area ----------
67668          Reverting ‘subr.el’...
67669          ---------- Echo Area ----------
67670
67671     To automatically display a message in the echo area or in a
67672     pop-buffer, depending on its size, use ‘display-message-or-buffer’
67673     (see below).
67674
67675     *Warning:* If you want to use your own string as a message
67676     verbatim, don’t just write ‘(message STRING)’.  If STRING contains
67677     ‘%’, ‘`’, or ‘'’ it may be reformatted, with undesirable results.
67678     Instead, use ‘(message "%s" STRING)’.
67679
67680 -- Variable: set-message-function
67681     If this variable is non-‘nil’, it should be a function of one
67682     argument, the text of a message to display in the echo area.  This
67683     function will be called by ‘message’ and related functions.  If the
67684     function returns ‘nil’, the message is displayed in the echo area
67685     as usual.  If this function returns a string, that string is
67686     displayed in the echo area instead of the original one.  If this
67687     function returns other non-‘nil’ values, that means the message was
67688     already handled, so ‘message’ will not display anything in the echo
67689     area.  See also ‘clear-message-function’ that can be used to clear
67690     the message displayed by this function.
67691
67692     The default value is the function that displays the message at the
67693     end of the minibuffer when the minibuffer is active.  However, if
67694     the text shown in the active minibuffer has the
67695     ‘minibuffer-message’ text property (*note Special Properties::) on
67696     some character, the message will be displayed before the first
67697     character having that property.
67698
67699 -- Variable: clear-message-function
67700     If this variable is non-‘nil’, ‘message’ and related functions call
67701     it with no arguments when their argument message is ‘nil’ or the
67702     empty string.
67703
67704     Usually this function is called when the next input event arrives
67705     after displaying an echo-area message.  The function is expected to
67706     clear the message displayed by its counterpart function specified
67707     by ‘set-message-function’.
67708
67709     The default value is the function that clears the message displayed
67710     in an active minibuffer.
67711
67712 -- Variable: inhibit-message
67713     When this variable is non-‘nil’, ‘message’ and related functions
67714     will not use the Echo Area to display messages.
67715
67716 -- Macro: with-temp-message message &rest body
67717     This construct displays a message in the echo area temporarily,
67718     during the execution of BODY.  It displays MESSAGE, executes BODY,
67719     then returns the value of the last body form while restoring the
67720     previous echo area contents.
67721
67722 -- Function: message-or-box format-string &rest arguments
67723     This function displays a message like ‘message’, but may display it
67724     in a dialog box instead of the echo area.  If this function is
67725     called in a command that was invoked using the mouse—more
67726     precisely, if ‘last-nonmenu-event’ (*note Command Loop Info::) is
67727     either ‘nil’ or a list—then it uses a dialog box or pop-up menu to
67728     display the message.  Otherwise, it uses the echo area.  (This is
67729     the same criterion that ‘y-or-n-p’ uses to make a similar decision;
67730     see *note Yes-or-No Queries::.)
67731
67732     You can force use of the mouse or of the echo area by binding
67733     ‘last-nonmenu-event’ to a suitable value around the call.
67734
67735 -- Function: message-box format-string &rest arguments
67736     This function displays a message like ‘message’, but uses a dialog
67737     box (or a pop-up menu) whenever that is possible.  If it is
67738     impossible to use a dialog box or pop-up menu, because the terminal
67739     does not support them, then ‘message-box’ uses the echo area, like
67740     ‘message’.
67741
67742 -- Function: display-message-or-buffer message &optional buffer-name
67743          action frame
67744     This function displays the message MESSAGE, which may be either a
67745     string or a buffer.  If it is shorter than the maximum height of
67746     the echo area, as defined by ‘max-mini-window-height’, it is
67747     displayed in the echo area, using ‘message’.  Otherwise,
67748     ‘display-buffer’ is used to show it in a pop-up buffer.
67749
67750     Returns either the string shown in the echo area, or when a pop-up
67751     buffer is used, the window used to display it.
67752
67753     If MESSAGE is a string, then the optional argument BUFFER-NAME is
67754     the name of the buffer used to display it when a pop-up buffer is
67755     used, defaulting to ‘*Message*’.  In the case where MESSAGE is a
67756     string and displayed in the echo area, it is not specified whether
67757     the contents are inserted into the buffer anyway.
67758
67759     The optional arguments ACTION and FRAME are as for
67760     ‘display-buffer’, and only used if a buffer is displayed.
67761
67762 -- Function: current-message
67763     This function returns the message currently being displayed in the
67764     echo area, or ‘nil’ if there is none.
67765
67766
67767File: elisp.info,  Node: Progress,  Next: Logging Messages,  Prev: Displaying Messages,  Up: The Echo Area
67768
6776939.4.2 Reporting Operation Progress
67770-----------------------------------
67771
67772When an operation can take a while to finish, you should inform the user
67773about the progress it makes.  This way the user can estimate remaining
67774time and clearly see that Emacs is busy working, not hung.  A convenient
67775way to do this is to use a “progress reporter”.
67776
67777   Here is a working example that does nothing useful:
67778
67779     (let ((progress-reporter
67780            (make-progress-reporter "Collecting mana for Emacs..."
67781                                    0  500)))
67782       (dotimes (k 500)
67783         (sit-for 0.01)
67784         (progress-reporter-update progress-reporter k))
67785       (progress-reporter-done progress-reporter))
67786
67787 -- Function: make-progress-reporter message &optional min-value
67788          max-value current-value min-change min-time
67789     This function creates and returns a progress reporter object, which
67790     you will use as an argument for the other functions listed below.
67791     The idea is to precompute as much data as possible to make progress
67792     reporting very fast.
67793
67794     When this progress reporter is subsequently used, it will display
67795     MESSAGE in the echo area, followed by progress percentage.  MESSAGE
67796     is treated as a simple string.  If you need it to depend on a
67797     filename, for instance, use ‘format-message’ before calling this
67798     function.
67799
67800     The arguments MIN-VALUE and MAX-VALUE should be numbers standing
67801     for the starting and final states of the operation.  For instance,
67802     an operation that scans a buffer should set these to the results of
67803     ‘point-min’ and ‘point-max’ correspondingly.  MAX-VALUE should be
67804     greater than MIN-VALUE.
67805
67806     Alternatively, you can set MIN-VALUE and MAX-VALUE to ‘nil’.  In
67807     that case, the progress reporter does not report process
67808     percentages; it instead displays a “spinner” that rotates a notch
67809     each time you update the progress reporter.
67810
67811     If MIN-VALUE and MAX-VALUE are numbers, you can give the argument
67812     CURRENT-VALUE a numerical value specifying the initial progress; if
67813     omitted, this defaults to MIN-VALUE.
67814
67815     The remaining arguments control the rate of echo area updates.  The
67816     progress reporter will wait for at least MIN-CHANGE more percents
67817     of the operation to be completed before printing next message; the
67818     default is one percent.  MIN-TIME specifies the minimum time in
67819     seconds to pass between successive prints; the default is 0.2
67820     seconds.  (On some operating systems, the progress reporter may
67821     handle fractions of seconds with varying precision).
67822
67823     This function calls ‘progress-reporter-update’, so the first
67824     message is printed immediately.
67825
67826 -- Function: progress-reporter-update reporter &optional value suffix
67827     This function does the main work of reporting progress of your
67828     operation.  It displays the message of REPORTER, followed by
67829     progress percentage determined by VALUE.  If percentage is zero, or
67830     close enough according to the MIN-CHANGE and MIN-TIME arguments,
67831     then it is omitted from the output.
67832
67833     REPORTER must be the result of a call to ‘make-progress-reporter’.
67834     VALUE specifies the current state of your operation and must be
67835     between MIN-VALUE and MAX-VALUE (inclusive) as passed to
67836     ‘make-progress-reporter’.  For instance, if you scan a buffer, then
67837     VALUE should be the result of a call to ‘point’.
67838
67839     Optional argument SUFFIX is a string to be displayed after
67840     REPORTER’s main message and progress text.  If REPORTER is a
67841     non-numerical reporter, then VALUE should be ‘nil’, or a string to
67842     use instead of SUFFIX.
67843
67844     This function respects MIN-CHANGE and MIN-TIME as passed to
67845     ‘make-progress-reporter’ and so does not output new messages on
67846     every invocation.  It is thus very fast and normally you should not
67847     try to reduce the number of calls to it: resulting overhead will
67848     most likely negate your effort.
67849
67850 -- Function: progress-reporter-force-update reporter &optional value
67851          new-message suffix
67852     This function is similar to ‘progress-reporter-update’ except that
67853     it prints a message in the echo area unconditionally.
67854
67855     REPORTER, VALUE, and SUFFIX have the same meaning as for
67856     ‘progress-reporter-update’.  Optional NEW-MESSAGE allows you to
67857     change the message of the REPORTER.  Since this function always
67858     updates the echo area, such a change will be immediately presented
67859     to the user.
67860
67861 -- Function: progress-reporter-done reporter
67862     This function should be called when the operation is finished.  It
67863     prints the message of REPORTER followed by word ‘done’ in the echo
67864     area.
67865
67866     You should always call this function and not hope for
67867     ‘progress-reporter-update’ to print ‘100%’.  Firstly, it may never
67868     print it, there are many good reasons for this not to happen.
67869     Secondly, ‘done’ is more explicit.
67870
67871 -- Macro: dotimes-with-progress-reporter (var count [result])
67872          reporter-or-message body...
67873     This is a convenience macro that works the same way as ‘dotimes’
67874     does, but also reports loop progress using the functions described
67875     above.  It allows you to save some typing.  The argument
67876     REPORTER-OR-MESSAGE can be either a string or a progress reporter
67877     object.
67878
67879     You can rewrite the example in the beginning of this subsection
67880     using this macro as follows:
67881
67882          (dotimes-with-progress-reporter
67883              (k 500)
67884              "Collecting some mana for Emacs..."
67885            (sit-for 0.01))
67886
67887     Using a reporter object as the REPORTER-OR-MESSAGE argument is
67888     useful if you want to specify the optional arguments in
67889     MAKE-PROGRESS-REPORTER.  For instance, you can write the previous
67890     example as follows:
67891
67892          (dotimes-with-progress-reporter
67893              (k 500)
67894              (make-progress-reporter "Collecting some mana for Emacs..." 0 500 0 1 1.5)
67895            (sit-for 0.01))
67896
67897 -- Macro: dolist-with-progress-reporter (var count [result])
67898          reporter-or-message body...
67899     This is another convenience macro that works the same way as
67900     ‘dolist’ does, but also reports loop progress using the functions
67901     described above.  As in ‘dotimes-with-progress-reporter’,
67902     ‘reporter-or-message’ can be a progress reporter or a string.  You
67903     can rewrite the previous example with this macro as follows:
67904
67905          (dolist-with-progress-reporter
67906              (k (number-sequence 0 500))
67907              "Collecting some mana for Emacs..."
67908            (sit-for 0.01))
67909
67910
67911File: elisp.info,  Node: Logging Messages,  Next: Echo Area Customization,  Prev: Progress,  Up: The Echo Area
67912
6791339.4.3 Logging Messages in ‘*Messages*’
67914---------------------------------------
67915
67916Almost all the messages displayed in the echo area are also recorded in
67917the ‘*Messages*’ buffer so that the user can refer back to them.  This
67918includes all the messages that are output with ‘message’.  By default,
67919this buffer is read-only and uses the major mode ‘messages-buffer-mode’.
67920Nothing prevents the user from killing the ‘*Messages*’ buffer, but the
67921next display of a message recreates it.  Any Lisp code that needs to
67922access the ‘*Messages*’ buffer directly and wants to ensure that it
67923exists should use the function ‘messages-buffer’.
67924
67925 -- Function: messages-buffer
67926     This function returns the ‘*Messages*’ buffer.  If it does not
67927     exist, it creates it, and switches it to ‘messages-buffer-mode’.
67928
67929 -- User Option: message-log-max
67930     This variable specifies how many lines to keep in the ‘*Messages*’
67931     buffer.  The value ‘t’ means there is no limit on how many lines to
67932     keep.  The value ‘nil’ disables message logging entirely.  Here’s
67933     how to display a message and prevent it from being logged:
67934
67935          (let (message-log-max)
67936            (message ...))
67937
67938   To make ‘*Messages*’ more convenient for the user, the logging
67939facility combines successive identical messages.  It also combines
67940successive related messages for the sake of two cases: question followed
67941by answer, and a series of progress messages.
67942
67943   A question followed by an answer has two messages like the ones
67944produced by ‘y-or-n-p’: the first is ‘QUESTION’, and the second is
67945QUESTION...ANSWER’.  The first message conveys no additional
67946information beyond what’s in the second, so logging the second message
67947discards the first from the log.
67948
67949   A series of progress messages has successive messages like those
67950produced by ‘make-progress-reporter’.  They have the form
67951BASE...HOW-FAR’, where BASE is the same each time, while HOW-FAR
67952varies.  Logging each message in the series discards the previous one,
67953provided they are consecutive.
67954
67955   The functions ‘make-progress-reporter’ and ‘y-or-n-p’ don’t have to
67956do anything special to activate the message log combination feature.  It
67957operates whenever two consecutive messages are logged that share a
67958common prefix ending in ‘...’.
67959
67960
67961File: elisp.info,  Node: Echo Area Customization,  Prev: Logging Messages,  Up: The Echo Area
67962
6796339.4.4 Echo Area Customization
67964------------------------------
67965
67966These variables control details of how the echo area works.
67967
67968 -- Variable: cursor-in-echo-area
67969     This variable controls where the cursor appears when a message is
67970     displayed in the echo area.  If it is non-‘nil’, then the cursor
67971     appears at the end of the message.  Otherwise, the cursor appears
67972     at point—not in the echo area at all.
67973
67974     The value is normally ‘nil’; Lisp programs bind it to ‘t’ for brief
67975     periods of time.
67976
67977 -- Variable: echo-area-clear-hook
67978     This normal hook is run whenever the echo area is cleared—either by
67979     ‘(message nil)’ or for any other reason.
67980
67981 -- User Option: echo-keystrokes
67982     This variable determines how much time should elapse before command
67983     characters echo.  Its value must be a number, and specifies the
67984     number of seconds to wait before echoing.  If the user types a
67985     prefix key (such as ‘C-x’) and then delays this many seconds before
67986     continuing, the prefix key is echoed in the echo area.  (Once
67987     echoing begins in a key sequence, all subsequent characters in the
67988     same key sequence are echoed immediately.)
67989
67990     If the value is zero, then command input is not echoed.
67991
67992 -- Variable: message-truncate-lines
67993     Normally, displaying a long message resizes the echo area to
67994     display the entire message.  But if the variable
67995     ‘message-truncate-lines’ is non-‘nil’, the echo area does not
67996     resize, and the message is truncated to fit it.
67997
67998   The variable ‘max-mini-window-height’, which specifies the maximum
67999height for resizing minibuffer windows, also applies to the echo area
68000(which is really a special use of the minibuffer window; *note
68001Minibuffer Windows::).
68002
68003
68004File: elisp.info,  Node: Warnings,  Next: Invisible Text,  Prev: The Echo Area,  Up: Display
68005
6800639.5 Reporting Warnings
68007=======================
68008
68009“Warnings” are a facility for a program to inform the user of a possible
68010problem, but continue running.
68011
68012* Menu:
68013
68014* Warning Basics::      Warnings concepts and functions to report them.
68015* Warning Variables::   Variables programs bind to customize their warnings.
68016* Warning Options::     Variables users set to control display of warnings.
68017* Delayed Warnings::    Deferring a warning until the end of a command.
68018
68019
68020File: elisp.info,  Node: Warning Basics,  Next: Warning Variables,  Up: Warnings
68021
6802239.5.1 Warning Basics
68023---------------------
68024
68025Every warning has a textual message, which explains the problem for the
68026user, and a “severity level” which is a symbol.  Here are the possible
68027severity levels, in order of decreasing severity, and their meanings:
68028
68029‘:emergency’
68030     A problem that will seriously impair Emacs operation soon if you do
68031     not attend to it promptly.
68032‘:error’
68033     A report of data or circumstances that are inherently wrong.
68034‘:warning’
68035     A report of data or circumstances that are not inherently wrong,
68036     but raise suspicion of a possible problem.
68037‘:debug’
68038     A report of information that may be useful if you are debugging.
68039
68040   When your program encounters invalid input data, it can either signal
68041a Lisp error by calling ‘error’ or ‘signal’ or report a warning with
68042severity ‘:error’.  Signaling a Lisp error is the easiest thing to do,
68043but it means the program cannot continue processing.  If you want to
68044take the trouble to implement a way to continue processing despite the
68045bad data, then reporting a warning of severity ‘:error’ is the right way
68046to inform the user of the problem.  For instance, the Emacs Lisp byte
68047compiler can report an error that way and continue compiling other
68048functions.  (If the program signals a Lisp error and then handles it
68049with ‘condition-case’, the user won’t see the error message; it could
68050show the message to the user by reporting it as a warning.)
68051
68052   Each warning has a “warning type” to classify it.  The type is a list
68053of symbols.  The first symbol should be the custom group that you use
68054for the program’s user options.  For example, byte compiler warnings use
68055the warning type ‘(bytecomp)’.  You can also subcategorize the warnings,
68056if you wish, by using more symbols in the list.
68057
68058 -- Function: display-warning type message &optional level buffer-name
68059     This function reports a warning, using MESSAGE as the message and
68060     TYPE as the warning type.  LEVEL should be the severity level, with
68061     ‘:warning’ being the default.
68062
68063     BUFFER-NAME, if non-‘nil’, specifies the name of the buffer for
68064     logging the warning.  By default, it is ‘*Warnings*’.
68065
68066 -- Function: lwarn type level message &rest args
68067     This function reports a warning using the value of ‘(format-message
68068     MESSAGE ARGS...)’ as the message in the ‘*Warnings*’ buffer.  In
68069     other respects it is equivalent to ‘display-warning’.
68070
68071 -- Function: warn message &rest args
68072     This function reports a warning using the value of ‘(format-message
68073     MESSAGE ARGS...)’ as the message, ‘(emacs)’ as the type, and
68074     ‘:warning’ as the severity level.  It exists for compatibility
68075     only; we recommend not using it, because you should specify a
68076     specific warning type.
68077
68078
68079File: elisp.info,  Node: Warning Variables,  Next: Warning Options,  Prev: Warning Basics,  Up: Warnings
68080
6808139.5.2 Warning Variables
68082------------------------
68083
68084Programs can customize how their warnings appear by binding the
68085variables described in this section.
68086
68087 -- Variable: warning-levels
68088     This list defines the meaning and severity order of the warning
68089     severity levels.  Each element defines one severity level, and they
68090     are arranged in order of decreasing severity.
68091
68092     Each element has the form ‘(LEVEL STRING FUNCTION)’, where LEVEL is
68093     the severity level it defines.  STRING specifies the textual
68094     description of this level.  STRING should use ‘%s’ to specify where
68095     to put the warning type information, or it can omit the ‘%s’ so as
68096     not to include that information.
68097
68098     The optional FUNCTION, if non-‘nil’, is a function to call with no
68099     arguments, to get the user’s attention.
68100
68101     Normally you should not change the value of this variable.
68102
68103 -- Variable: warning-prefix-function
68104     If non-‘nil’, the value is a function to generate prefix text for
68105     warnings.  Programs can bind the variable to a suitable function.
68106     ‘display-warning’ calls this function with the warnings buffer
68107     current, and the function can insert text in it.  That text becomes
68108     the beginning of the warning message.
68109
68110     The function is called with two arguments, the severity level and
68111     its entry in ‘warning-levels’.  It should return a list to use as
68112     the entry (this value need not be an actual member of
68113     ‘warning-levels’).  By constructing this value, the function can
68114     change the severity of the warning, or specify different handling
68115     for a given severity level.
68116
68117     If the variable’s value is ‘nil’ then there is no function to call.
68118
68119 -- Variable: warning-series
68120     Programs can bind this variable to ‘t’ to say that the next warning
68121     should begin a series.  When several warnings form a series, that
68122     means to leave point on the first warning of the series, rather
68123     than keep moving it for each warning so that it appears on the last
68124     one.  The series ends when the local binding is unbound and
68125     ‘warning-series’ becomes ‘nil’ again.
68126
68127     The value can also be a symbol with a function definition.  That is
68128     equivalent to ‘t’, except that the next warning will also call the
68129     function with no arguments with the warnings buffer current.  The
68130     function can insert text which will serve as a header for the
68131     series of warnings.
68132
68133     Once a series has begun, the value is a marker which points to the
68134     buffer position in the warnings buffer of the start of the series.
68135
68136     The variable’s normal value is ‘nil’, which means to handle each
68137     warning separately.
68138
68139 -- Variable: warning-fill-prefix
68140     When this variable is non-‘nil’, it specifies a fill prefix to use
68141     for filling each warning’s text.
68142
68143 -- Variable: warning-fill-column
68144     The column at which to fill warnings.
68145
68146 -- Variable: warning-type-format
68147     This variable specifies the format for displaying the warning type
68148     in the warning message.  The result of formatting the type this way
68149     gets included in the message under the control of the string in the
68150     entry in ‘warning-levels’.  The default value is ‘" (%s)"’.  If you
68151     bind it to ‘""’ then the warning type won’t appear at all.
68152
68153
68154File: elisp.info,  Node: Warning Options,  Next: Delayed Warnings,  Prev: Warning Variables,  Up: Warnings
68155
6815639.5.3 Warning Options
68157----------------------
68158
68159These variables are used by users to control what happens when a Lisp
68160program reports a warning.
68161
68162 -- User Option: warning-minimum-level
68163     This user option specifies the minimum severity level that should
68164     be shown immediately to the user.  The default is ‘:warning’, which
68165     means to immediately display all warnings except ‘:debug’ warnings.
68166
68167 -- User Option: warning-minimum-log-level
68168     This user option specifies the minimum severity level that should
68169     be logged in the warnings buffer.  The default is ‘:warning’, which
68170     means to log all warnings except ‘:debug’ warnings.
68171
68172 -- User Option: warning-suppress-types
68173     This list specifies which warning types should not be displayed
68174     immediately for the user.  Each element of the list should be a
68175     list of symbols.  If its elements match the first elements in a
68176     warning type, then that warning is not displayed immediately.
68177
68178 -- User Option: warning-suppress-log-types
68179     This list specifies which warning types should not be logged in the
68180     warnings buffer.  Each element of the list should be a list of
68181     symbols.  If it matches the first few elements in a warning type,
68182     then that warning is not logged.
68183
68184
68185File: elisp.info,  Node: Delayed Warnings,  Prev: Warning Options,  Up: Warnings
68186
6818739.5.4 Delayed Warnings
68188-----------------------
68189
68190Sometimes, you may wish to avoid showing a warning while a command is
68191running, and only show it only after the end of the command.  You can
68192use the function ‘delay-warning’ for this.
68193
68194 -- Function: delay-warning type message &optional level buffer-name
68195     This function is the delayed counterpart to ‘display-warning’
68196     (*note Warning Basics::), and it is called with the same arguments.
68197     The warning message is queued into ‘delayed-warnings-list’.
68198
68199 -- Variable: delayed-warnings-list
68200     The value of this variable is a list of warnings to be displayed
68201     after the current command has finished.  Each element must be a
68202     list
68203
68204          (TYPE MESSAGE [LEVEL [BUFFER-NAME]])
68205
68206     with the same form, and the same meanings, as the argument list of
68207     ‘display-warning’.  Immediately after running ‘post-command-hook’
68208     (*note Command Overview::), the Emacs command loop displays all the
68209     warnings specified by this variable, then resets it to ‘nil’.
68210
68211   Programs which need to further customize the delayed warnings
68212mechanism can change the variable ‘delayed-warnings-hook’:
68213
68214 -- Variable: delayed-warnings-hook
68215     This is a normal hook which is run by the Emacs command loop, after
68216     ‘post-command-hook’, in order to process and display delayed
68217     warnings.
68218
68219     Its default value is a list of two functions:
68220
68221          (collapse-delayed-warnings display-delayed-warnings)
68222
68223     The function ‘collapse-delayed-warnings’ removes repeated entries
68224     from ‘delayed-warnings-list’.  The function
68225     ‘display-delayed-warnings’ calls ‘display-warning’ on each of the
68226     entries in ‘delayed-warnings-list’, in turn, and then sets
68227     ‘delayed-warnings-list’ to ‘nil’.
68228
68229
68230File: elisp.info,  Node: Invisible Text,  Next: Selective Display,  Prev: Warnings,  Up: Display
68231
6823239.6 Invisible Text
68233===================
68234
68235You can make characters “invisible”, so that they do not appear on the
68236screen, with the ‘invisible’ property.  This can be either a text
68237property (*note Text Properties::) or an overlay property (*note
68238Overlays::).  Cursor motion also partly ignores these characters; if the
68239command loop finds that point is inside a range of invisible text after
68240a command, it relocates point to the other side of the text.
68241
68242   In the simplest case, any non-‘nil’ ‘invisible’ property makes a
68243character invisible.  This is the default case—if you don’t alter the
68244default value of ‘buffer-invisibility-spec’, this is how the ‘invisible’
68245property works.  You should normally use ‘t’ as the value of the
68246‘invisible’ property if you don’t plan to set ‘buffer-invisibility-spec’
68247yourself.
68248
68249   More generally, you can use the variable ‘buffer-invisibility-spec’
68250to control which values of the ‘invisible’ property make text invisible.
68251This permits you to classify the text into different subsets in advance,
68252by giving them different ‘invisible’ values, and subsequently make
68253various subsets visible or invisible by changing the value of
68254‘buffer-invisibility-spec’.
68255
68256   Controlling visibility with ‘buffer-invisibility-spec’ is especially
68257useful in a program to display the list of entries in a database.  It
68258permits the implementation of convenient filtering commands to view just
68259a part of the entries in the database.  Setting this variable is very
68260fast, much faster than scanning all the text in the buffer looking for
68261properties to change.
68262
68263 -- Variable: buffer-invisibility-spec
68264     This variable specifies which kinds of ‘invisible’ properties
68265     actually make a character invisible.  Setting this variable makes
68266     it buffer-local.
68267
68268     ‘t’
68269          A character is invisible if its ‘invisible’ property is
68270          non-‘nil’.  This is the default.
68271
68272     a list
68273          Each element of the list specifies a criterion for
68274          invisibility; if a character’s ‘invisible’ property fits any
68275          one of these criteria, the character is invisible.  The list
68276          can have two kinds of elements:
68277
68278          ‘ATOM’
68279               A character is invisible if its ‘invisible’ property
68280               value is ATOM or if it is a list with ATOM as a member;
68281               comparison is done with ‘eq’.
68282
68283          ‘(ATOM . t)’
68284               A character is invisible if its ‘invisible’ property
68285               value is ATOM or if it is a list with ATOM as a member;
68286               comparison is done with ‘eq’.  Moreover, a sequence of
68287               such characters displays as an ellipsis.
68288
68289   Two functions are specifically provided for adding elements to
68290‘buffer-invisibility-spec’ and removing elements from it.
68291
68292 -- Function: add-to-invisibility-spec element
68293     This function adds the element ELEMENT to
68294     ‘buffer-invisibility-spec’.  If ‘buffer-invisibility-spec’ was ‘t’,
68295     it changes to a list, ‘(t)’, so that text whose ‘invisible’
68296     property is ‘t’ remains invisible.
68297
68298 -- Function: remove-from-invisibility-spec element
68299     This removes the element ELEMENT from ‘buffer-invisibility-spec’.
68300     This does nothing if ELEMENT is not in the list.
68301
68302   A convention for use of ‘buffer-invisibility-spec’ is that a major
68303mode should use the mode’s own name as an element of
68304‘buffer-invisibility-spec’ and as the value of the ‘invisible’ property:
68305
68306     ;; If you want to display an ellipsis:
68307     (add-to-invisibility-spec '(my-symbol . t))
68308     ;; If you don’t want ellipsis:
68309     (add-to-invisibility-spec 'my-symbol)
68310
68311     (overlay-put (make-overlay beginning end)
68312                  'invisible 'my-symbol)
68313
68314     ;; When done with the invisibility:
68315     (remove-from-invisibility-spec '(my-symbol . t))
68316     ;; Or respectively:
68317     (remove-from-invisibility-spec 'my-symbol)
68318
68319   You can check for invisibility using the following function:
68320
68321 -- Function: invisible-p pos-or-prop
68322     If POS-OR-PROP is a marker or number, this function returns a
68323     non-‘nil’ value if the text at that position is currently
68324     invisible.
68325
68326     If POS-OR-PROP is any other kind of Lisp object, that is taken to
68327     mean a possible value of the ‘invisible’ text or overlay property.
68328     In that case, this function returns a non-‘nil’ value if that value
68329     would cause text to become invisible, based on the current value of
68330     ‘buffer-invisibility-spec’.
68331
68332     The return value of this function is ‘t’ if the text would be
68333     completely hidden on display, or a non-‘nil’, non-‘t’ value if the
68334     text would be replaced by an ellipsis.
68335
68336   Ordinarily, functions that operate on text or move point do not care
68337whether the text is invisible, they process invisible characters and
68338visible characters alike.  The user-level line motion commands, such as
68339‘next-line’, ‘previous-line’, ignore invisible newlines if
68340‘line-move-ignore-invisible’ is non-‘nil’ (the default), i.e., behave
68341like these invisible newlines didn’t exist in the buffer, but only
68342because they are explicitly programmed to do so.
68343
68344   If a command ends with point inside or at the boundary of invisible
68345text, the main editing loop relocates point to one of the two ends of
68346the invisible text.  Emacs chooses the direction of relocation so that
68347it is the same as the overall movement direction of the command; if in
68348doubt, it prefers a position where an inserted char would not inherit
68349the ‘invisible’ property.  Additionally, if the text is not replaced by
68350an ellipsis and the command only moved within the invisible text, then
68351point is moved one extra character so as to try and reflect the
68352command’s movement by a visible movement of the cursor.
68353
68354   Thus, if the command moved point back to an invisible range (with the
68355usual stickiness), Emacs moves point back to the beginning of that
68356range.  If the command moved point forward into an invisible range,
68357Emacs moves point forward to the first visible character that follows
68358the invisible text and then forward one more character.
68359
68360   These “adjustments” of point that ended up in the middle of invisible
68361text can be disabled by setting ‘disable-point-adjustment’ to a
68362non-‘nil’ value.  *Note Adjusting Point::.
68363
68364   Incremental search can make invisible overlays visible temporarily
68365and/or permanently when a match includes invisible text.  To enable
68366this, the overlay should have a non-‘nil’ ‘isearch-open-invisible’
68367property.  The property value should be a function to be called with the
68368overlay as an argument.  This function should make the overlay visible
68369permanently; it is used when the match overlaps the overlay on exit from
68370the search.
68371
68372   During the search, such overlays are made temporarily visible by
68373temporarily modifying their invisible and intangible properties.  If you
68374want this to be done differently for a certain overlay, give it an
68375‘isearch-open-invisible-temporary’ property which is a function.  The
68376function is called with two arguments: the first is the overlay, and the
68377second is ‘nil’ to make the overlay visible, or ‘t’ to make it invisible
68378again.
68379
68380
68381File: elisp.info,  Node: Selective Display,  Next: Temporary Displays,  Prev: Invisible Text,  Up: Display
68382
6838339.7 Selective Display
68384======================
68385
68386“Selective display” refers to a pair of related features for hiding
68387certain lines on the screen.
68388
68389   The first variant, explicit selective display, was designed for use
68390in a Lisp program: it controls which lines are hidden by altering the
68391text.  This kind of hiding is now obsolete and deprecated; instead you
68392should use the ‘invisible’ property (*note Invisible Text::) to get the
68393same effect.
68394
68395   In the second variant, the choice of lines to hide is made
68396automatically based on indentation.  This variant is designed to be a
68397user-level feature.
68398
68399   The way you control explicit selective display is by replacing a
68400newline (control-j) with a carriage return (control-m).  The text that
68401was formerly a line following that newline is now hidden.  Strictly
68402speaking, it is temporarily no longer a line at all, since only newlines
68403can separate lines; it is now part of the previous line.
68404
68405   Selective display does not directly affect editing commands.  For
68406example, ‘C-f’ (‘forward-char’) moves point unhesitatingly into hidden
68407text.  However, the replacement of newline characters with carriage
68408return characters affects some editing commands.  For example,
68409‘next-line’ skips hidden lines, since it searches only for newlines.
68410Modes that use selective display can also define commands that take
68411account of the newlines, or that control which parts of the text are
68412hidden.
68413
68414   When you write a selectively displayed buffer into a file, all the
68415control-m’s are output as newlines.  This means that when you next read
68416in the file, it looks OK, with nothing hidden.  The selective display
68417effect is seen only within Emacs.
68418
68419 -- Variable: selective-display
68420     This buffer-local variable enables selective display.  This means
68421     that lines, or portions of lines, may be made hidden.
68422
68423        • If the value of ‘selective-display’ is ‘t’, then the character
68424          control-m marks the start of hidden text; the control-m, and
68425          the rest of the line following it, are not displayed.  This is
68426          explicit selective display.
68427
68428        • If the value of ‘selective-display’ is a positive integer,
68429          then lines that start with more than that many columns of
68430          indentation are not displayed.
68431
68432     When some portion of a buffer is hidden, the vertical movement
68433     commands operate as if that portion did not exist, allowing a
68434     single ‘next-line’ command to skip any number of hidden lines.
68435     However, character movement commands (such as ‘forward-char’) do
68436     not skip the hidden portion, and it is possible (if tricky) to
68437     insert or delete text in a hidden portion.
68438
68439     In the examples below, we show the _display appearance_ of the
68440     buffer ‘foo’, which changes with the value of ‘selective-display’.
68441     The _contents_ of the buffer do not change.
68442
68443          (setq selective-display nil)
68444               ⇒ nil
68445
68446          ---------- Buffer: foo ----------
68447          1 on this column
68448           2on this column
68449            3n this column
68450            3n this column
68451           2on this column
68452          1 on this column
68453          ---------- Buffer: foo ----------
68454
68455          (setq selective-display 2)
68456               ⇒ 2
68457
68458          ---------- Buffer: foo ----------
68459          1 on this column
68460           2on this column
68461           2on this column
68462          1 on this column
68463          ---------- Buffer: foo ----------
68464
68465 -- User Option: selective-display-ellipses
68466     If this buffer-local variable is non-‘nil’, then Emacs displays
68467     ‘...’ at the end of a line that is followed by hidden text.  This
68468     example is a continuation of the previous one.
68469
68470          (setq selective-display-ellipses t)
68471               ⇒ t
68472
68473          ---------- Buffer: foo ----------
68474          1 on this column
68475           2on this column ...
68476           2on this column
68477          1 on this column
68478          ---------- Buffer: foo ----------
68479
68480     You can use a display table to substitute other text for the
68481     ellipsis (‘...’).  *Note Display Tables::.
68482
68483
68484File: elisp.info,  Node: Temporary Displays,  Next: Overlays,  Prev: Selective Display,  Up: Display
68485
6848639.8 Temporary Displays
68487=======================
68488
68489Temporary displays are used by Lisp programs to put output into a buffer
68490and then present it to the user for perusal rather than for editing.
68491Many help commands use this feature.
68492
68493 -- Macro: with-output-to-temp-buffer buffer-name body...
68494     This function executes the forms in BODY while arranging to insert
68495     any output they print into the buffer named BUFFER-NAME, which is
68496     first created if necessary, and put into Help mode.  (See the
68497     similar form ‘with-temp-buffer-window’ below.)  Finally, the buffer
68498     is displayed in some window, but that window is not selected.
68499
68500     If the forms in BODY do not change the major mode in the output
68501     buffer, so that it is still Help mode at the end of their
68502     execution, then ‘with-output-to-temp-buffer’ makes this buffer
68503     read-only at the end, and also scans it for function and variable
68504     names to make them into clickable cross-references.  *Note Tips for
68505     Documentation Strings: Docstring hyperlinks, in particular the item
68506     on hyperlinks in documentation strings, for more details.
68507
68508     The string BUFFER-NAME specifies the temporary buffer, which need
68509     not already exist.  The argument must be a string, not a buffer.
68510     The buffer is erased initially (with no questions asked), and it is
68511     marked as unmodified after ‘with-output-to-temp-buffer’ exits.
68512
68513     ‘with-output-to-temp-buffer’ binds ‘standard-output’ to the
68514     temporary buffer, then it evaluates the forms in BODY.  Output
68515     using the Lisp output functions within BODY goes by default to that
68516     buffer (but screen display and messages in the echo area, although
68517     they are “output” in the general sense of the word, are not
68518     affected).  *Note Output Functions::.
68519
68520     Several hooks are available for customizing the behavior of this
68521     construct; they are listed below.
68522
68523     The value of the last form in BODY is returned.
68524
68525          ---------- Buffer: foo ----------
68526           This is the contents of foo.
68527          ---------- Buffer: foo ----------
68528
68529          (with-output-to-temp-buffer "foo"
68530              (print 20)
68531              (print standard-output))
68532          ⇒ #<buffer foo>
68533
68534          ---------- Buffer: foo ----------
68535
68536          20
68537
68538          #<buffer foo>
68539
68540          ---------- Buffer: foo ----------
68541
68542 -- User Option: temp-buffer-show-function
68543     If this variable is non-‘nil’, ‘with-output-to-temp-buffer’ calls
68544     it as a function to do the job of displaying a help buffer.  The
68545     function gets one argument, which is the buffer it should display.
68546
68547     It is a good idea for this function to run ‘temp-buffer-show-hook’
68548     just as ‘with-output-to-temp-buffer’ normally would, inside of
68549     ‘save-selected-window’ and with the chosen window and buffer
68550     selected.
68551
68552 -- Variable: temp-buffer-setup-hook
68553     This normal hook is run by ‘with-output-to-temp-buffer’ before
68554     evaluating BODY.  When the hook runs, the temporary buffer is
68555     current.  This hook is normally set up with a function to put the
68556     buffer in Help mode.
68557
68558 -- Variable: temp-buffer-show-hook
68559     This normal hook is run by ‘with-output-to-temp-buffer’ after
68560     displaying the temporary buffer.  When the hook runs, the temporary
68561     buffer is current, and the window it was displayed in is selected.
68562
68563 -- Macro: with-temp-buffer-window buffer-or-name action quit-function
68564          body...
68565     This macro is similar to ‘with-output-to-temp-buffer’.  Like that
68566     construct, it executes BODY while arranging to insert any output it
68567     prints into the buffer named BUFFER-OR-NAME and displays that
68568     buffer in some window.  Unlike ‘with-output-to-temp-buffer’,
68569     however, it does not automatically switch that buffer to Help mode.
68570
68571     The argument BUFFER-OR-NAME specifies the temporary buffer.  It can
68572     be either a buffer, which must already exist, or a string, in which
68573     case a buffer of that name is created, if necessary.  The buffer is
68574     marked as unmodified and read-only when ‘with-temp-buffer-window’
68575     exits.
68576
68577     This macro does not call ‘temp-buffer-show-function’.  Rather, it
68578     passes the ACTION argument to ‘display-buffer’ (*note Choosing
68579     Window::) in order to display the buffer.
68580
68581     The value of the last form in BODY is returned, unless the argument
68582     QUIT-FUNCTION is specified.  In that case, it is called with two
68583     arguments: the window showing the buffer and the result of BODY.
68584     The final return value is then whatever QUIT-FUNCTION returns.
68585
68586     This macro uses the normal hooks ‘temp-buffer-window-setup-hook’
68587     and ‘temp-buffer-window-show-hook’ in place of the analogous hooks
68588     run by ‘with-output-to-temp-buffer’.
68589
68590   The two constructs described next are mostly identical to
68591‘with-temp-buffer-window’ but differ from it as specified:
68592
68593 -- Macro: with-current-buffer-window buffer-or-name action
68594          quit-function &rest body
68595     This macro is like ‘with-temp-buffer-window’ but unlike that makes
68596     the buffer specified by BUFFER-OR-NAME current for running BODY.
68597
68598 -- Macro: with-displayed-buffer-window buffer-or-name action
68599          quit-function &rest body
68600     This macro is like ‘with-current-buffer-window’ but unlike that
68601     displays the buffer specified by BUFFER-OR-NAME _before_ running
68602     BODY.
68603
68604   A window showing a temporary buffer can be fitted to the size of that
68605buffer using the following mode:
68606
68607 -- User Option: temp-buffer-resize-mode
68608     When this minor mode is enabled, windows showing a temporary buffer
68609     are automatically resized to fit their buffer’s contents.
68610
68611     A window is resized if and only if it has been specially created
68612     for the buffer.  In particular, windows that have shown another
68613     buffer before are not resized.  By default, this mode uses
68614     ‘fit-window-to-buffer’ (*note Resizing Windows::) for resizing.
68615     You can specify a different function by customizing the options
68616     ‘temp-buffer-max-height’ and ‘temp-buffer-max-width’ below.
68617
68618 -- User Option: temp-buffer-max-height
68619     This option specifies the maximum height (in lines) of a window
68620     displaying a temporary buffer when ‘temp-buffer-resize-mode’ is
68621     enabled.  It can also be a function to be called to choose the
68622     height for such a buffer.  It gets one argument, the buffer, and
68623     should return a positive integer.  At the time the function is
68624     called, the window to be resized is selected.
68625
68626 -- User Option: temp-buffer-max-width
68627     This option specifies the maximum width of a window (in columns)
68628     displaying a temporary buffer when ‘temp-buffer-resize-mode’ is
68629     enabled.  It can also be a function to be called to choose the
68630     width for such a buffer.  It gets one argument, the buffer, and
68631     should return a positive integer.  At the time the function is
68632     called, the window to be resized is selected.
68633
68634   The following function uses the current buffer for temporary display:
68635
68636 -- Function: momentary-string-display string position &optional char
68637          message
68638     This function momentarily displays STRING in the current buffer at
68639     POSITION.  It has no effect on the undo list or on the buffer’s
68640     modification status.
68641
68642     The momentary display remains until the next input event.  If the
68643     next input event is CHAR, ‘momentary-string-display’ ignores it and
68644     returns.  Otherwise, that event remains buffered for subsequent use
68645     as input.  Thus, typing CHAR will simply remove the string from the
68646     display, while typing (say) ‘C-f’ will remove the string from the
68647     display and later (presumably) move point forward.  The argument
68648     CHAR is a space by default.
68649
68650     The return value of ‘momentary-string-display’ is not meaningful.
68651
68652     If the string STRING does not contain control characters, you can
68653     do the same job in a more general way by creating (and then
68654     subsequently deleting) an overlay with a ‘before-string’ property.
68655     *Note Overlay Properties::.
68656
68657     If MESSAGE is non-‘nil’, it is displayed in the echo area while
68658     STRING is displayed in the buffer.  If it is ‘nil’, a default
68659     message says to type CHAR to continue.
68660
68661     In this example, point is initially located at the beginning of the
68662     second line:
68663
68664          ---------- Buffer: foo ----------
68665          This is the contents of foo.
68666          ★Second line.
68667          ---------- Buffer: foo ----------
68668
68669          (momentary-string-display
68670            "**** Important Message! ****"
68671            (point) ?\r
68672            "Type RET when done reading")
68673          ⇒ t
68674
68675          ---------- Buffer: foo ----------
68676          This is the contents of foo.
68677          **** Important Message! ****Second line.
68678          ---------- Buffer: foo ----------
68679
68680          ---------- Echo Area ----------
68681          Type RET when done reading
68682          ---------- Echo Area ----------
68683
68684
68685File: elisp.info,  Node: Overlays,  Next: Size of Displayed Text,  Prev: Temporary Displays,  Up: Display
68686
6868739.9 Overlays
68688=============
68689
68690You can use “overlays” to alter the appearance of a buffer’s text on the
68691screen, for the sake of presentation features.  An overlay is an object
68692that belongs to a particular buffer, and has a specified beginning and
68693end.  It also has properties that you can examine and set; these affect
68694the display of the text within the overlay.
68695
68696   The visual effect of an overlay is the same as of the corresponding
68697text property (*note Text Properties::).  However, due to a different
68698implementation, overlays generally don’t scale well (many operations
68699take a time that is proportional to the number of overlays in the
68700buffer).  If you need to affect the visual appearance of many portions
68701in the buffer, we recommend using text properties.
68702
68703   An overlay uses markers to record its beginning and end; thus,
68704editing the text of the buffer adjusts the beginning and end of each
68705overlay so that it stays with the text.  When you create the overlay,
68706you can specify whether text inserted at the beginning should be inside
68707the overlay or outside, and likewise for the end of the overlay.
68708
68709* Menu:
68710
68711* Managing Overlays::   Creating and moving overlays.
68712* Overlay Properties::  How to read and set properties.
68713                          What properties do to the screen display.
68714* Finding Overlays::    Searching for overlays.
68715
68716
68717File: elisp.info,  Node: Managing Overlays,  Next: Overlay Properties,  Up: Overlays
68718
6871939.9.1 Managing Overlays
68720------------------------
68721
68722This section describes the functions to create, delete and move
68723overlays, and to examine their contents.  Overlay changes are not
68724recorded in the buffer’s undo list, since the overlays are not part of
68725the buffer’s contents.
68726
68727 -- Function: overlayp object
68728     This function returns ‘t’ if OBJECT is an overlay.
68729
68730 -- Function: make-overlay start end &optional buffer front-advance
68731          rear-advance
68732     This function creates and returns an overlay that belongs to BUFFER
68733     and ranges from START to END.  Both START and END must specify
68734     buffer positions; they may be integers or markers.  If BUFFER is
68735     omitted, the overlay is created in the current buffer.
68736
68737     An overlay whose START and END specify the same buffer position is
68738     known as “empty”.  A non-empty overlay can become empty if the text
68739     between its START and END is deleted.  When that happens, the
68740     overlay is by default not deleted, but you can cause it to be
68741     deleted by giving it the ‘evaporate’ property (*note evaporate
68742     property: Overlay Properties.).
68743
68744     The arguments FRONT-ADVANCE and REAR-ADVANCE specify the marker
68745     insertion type for the start of the overlay and for the end of the
68746     overlay, respectively.  *Note Marker Insertion Types::.  If they
68747     are both ‘nil’, the default, then the overlay extends to include
68748     any text inserted at the beginning, but not text inserted at the
68749     end.  If FRONT-ADVANCE is non-‘nil’, text inserted at the beginning
68750     of the overlay is excluded from the overlay.  If REAR-ADVANCE is
68751     non-‘nil’, text inserted at the end of the overlay is included in
68752     the overlay.
68753
68754 -- Function: overlay-start overlay
68755     This function returns the position at which OVERLAY starts, as an
68756     integer.
68757
68758 -- Function: overlay-end overlay
68759     This function returns the position at which OVERLAY ends, as an
68760     integer.
68761
68762 -- Function: overlay-buffer overlay
68763     This function returns the buffer that OVERLAY belongs to.  It
68764     returns ‘nil’ if OVERLAY has been deleted.
68765
68766 -- Function: delete-overlay overlay
68767     This function deletes OVERLAY.  The overlay continues to exist as a
68768     Lisp object, and its property list is unchanged, but it ceases to
68769     be attached to the buffer it belonged to, and ceases to have any
68770     effect on display.
68771
68772     A deleted overlay is not permanently disconnected.  You can give it
68773     a position in a buffer again by calling ‘move-overlay’.
68774
68775 -- Function: move-overlay overlay start end &optional buffer
68776     This function moves OVERLAY to BUFFER, and places its bounds at
68777     START and END.  Both arguments START and END must specify buffer
68778     positions; they may be integers or markers.
68779
68780     If BUFFER is omitted, OVERLAY stays in the same buffer it was
68781     already associated with; if OVERLAY was deleted, it goes into the
68782     current buffer.
68783
68784     The return value is OVERLAY.
68785
68786     This is the only valid way to change the endpoints of an overlay.
68787     Do not try modifying the markers in the overlay by hand, as that
68788     fails to update other vital data structures and can cause some
68789     overlays to be lost.
68790
68791 -- Function: remove-overlays &optional start end name value
68792     This function removes all the overlays between START and END whose
68793     property NAME has the value VALUE.  It can move the endpoints of
68794     the overlays in the region, or split them.
68795
68796     If NAME is omitted or ‘nil’, it means to delete all overlays in the
68797     specified region.  If START and/or END are omitted or ‘nil’, that
68798     means the beginning and end of the buffer respectively.  Therefore,
68799     ‘(remove-overlays)’ removes all the overlays in the current buffer.
68800
68801 -- Function: copy-overlay overlay
68802     This function returns a copy of OVERLAY.  The copy has the same
68803     endpoints and properties as OVERLAY.  However, the marker insertion
68804     type for the start of the overlay and for the end of the overlay
68805     are set to their default values (*note Marker Insertion Types::).
68806
68807   Here are some examples:
68808
68809     ;; Create an overlay.
68810     (setq foo (make-overlay 1 10))
68811          ⇒ #<overlay from 1 to 10 in display.texi>
68812     (overlay-start foo)
68813          ⇒ 1
68814     (overlay-end foo)
68815          ⇒ 10
68816     (overlay-buffer foo)
68817          ⇒ #<buffer display.texi>
68818     ;; Give it a property we can check later.
68819     (overlay-put foo 'happy t)
68820          ⇒ t
68821     ;; Verify the property is present.
68822     (overlay-get foo 'happy)
68823          ⇒ t
68824     ;; Move the overlay.
68825     (move-overlay foo 5 20)
68826          ⇒ #<overlay from 5 to 20 in display.texi>
68827     (overlay-start foo)
68828          ⇒ 5
68829     (overlay-end foo)
68830          ⇒ 20
68831     ;; Delete the overlay.
68832     (delete-overlay foo)
68833          ⇒ nil
68834     ;; Verify it is deleted.
68835     foo
68836          ⇒ #<overlay in no buffer>
68837     ;; A deleted overlay has no position.
68838     (overlay-start foo)
68839          ⇒ nil
68840     (overlay-end foo)
68841          ⇒ nil
68842     (overlay-buffer foo)
68843          ⇒ nil
68844     ;; Undelete the overlay.
68845     (move-overlay foo 1 20)
68846          ⇒ #<overlay from 1 to 20 in display.texi>
68847     ;; Verify the results.
68848     (overlay-start foo)
68849          ⇒ 1
68850     (overlay-end foo)
68851          ⇒ 20
68852     (overlay-buffer foo)
68853          ⇒ #<buffer display.texi>
68854     ;; Moving and deleting the overlay does not change its properties.
68855     (overlay-get foo 'happy)
68856          ⇒ t
68857
68858   Emacs stores the overlays of each buffer in two lists, divided around
68859an arbitrary center position.  One list extends backwards through the
68860buffer from that center position, and the other extends forwards from
68861that center position.  The center position can be anywhere in the
68862buffer.
68863
68864 -- Function: overlay-recenter pos
68865     This function recenters the overlays of the current buffer around
68866     position POS.  That makes overlay lookup faster for positions near
68867     POS, but slower for positions far away from POS.
68868
68869   A loop that scans the buffer forwards, creating overlays, can run
68870faster if you do ‘(overlay-recenter (point-max))’ first.
68871
68872
68873File: elisp.info,  Node: Overlay Properties,  Next: Finding Overlays,  Prev: Managing Overlays,  Up: Overlays
68874
6887539.9.2 Overlay Properties
68876-------------------------
68877
68878Overlay properties are like text properties in that the properties that
68879alter how a character is displayed can come from either source.  But in
68880most respects they are different.  *Note Text Properties::, for
68881comparison.
68882
68883   Text properties are considered a part of the text; overlays and their
68884properties are specifically considered not to be part of the text.
68885Thus, copying text between various buffers and strings preserves text
68886properties, but does not try to preserve overlays.  Changing a buffer’s
68887text properties marks the buffer as modified, while moving an overlay or
68888changing its properties does not.  Unlike text property changes, overlay
68889property changes are not recorded in the buffer’s undo list.
68890
68891   Since more than one overlay can specify a property value for the same
68892character, Emacs lets you specify a priority value of each overlay.  The
68893priority value is used to decide which of the overlapping overlays will
68894“win”.
68895
68896   These functions read and set the properties of an overlay:
68897
68898 -- Function: overlay-get overlay prop
68899     This function returns the value of property PROP recorded in
68900     OVERLAY, if any.  If OVERLAY does not record any value for that
68901     property, but it does have a ‘category’ property which is a symbol,
68902     that symbol’s PROP property is used.  Otherwise, the value is
68903     ‘nil’.
68904
68905 -- Function: overlay-put overlay prop value
68906     This function sets the value of property PROP recorded in OVERLAY
68907     to VALUE.  It returns VALUE.
68908
68909 -- Function: overlay-properties overlay
68910     This returns a copy of the property list of OVERLAY.
68911
68912   See also the function ‘get-char-property’ which checks both overlay
68913properties and text properties for a given character.  *Note Examining
68914Properties::.
68915
68916   Many overlay properties have special meanings; here is a table of
68917them:
68918
68919‘priority’
68920     This property’s value determines the priority of the overlay.  If
68921     you want to specify a priority value, use either ‘nil’ (or zero),
68922     or a positive integer.  Any other value has undefined behavior.
68923
68924     The priority matters when two or more overlays cover the same
68925     character and both specify the same property; the one whose
68926     ‘priority’ value is larger overrides the other.  (For the ‘face’
68927     property, the higher priority overlay’s value does not completely
68928     override the other value; instead, its face attributes override the
68929     face attributes of the lower priority ‘face’ property.)  If two
68930     overlays have the same priority value, and one is nested in the
68931     other, then the inner one will prevail over the outer one.  If
68932     neither is nested in the other then you should not make assumptions
68933     about which overlay will prevail.
68934
68935     Currently, all overlays take priority over text properties.
68936
68937     Note that Emacs sometimes uses non-numeric priority values for some
68938     of its internal overlays, so do not try to do arithmetic on the
68939     priority of an overlay (unless it is one that you created).  In
68940     particular, the overlay used for showing the region uses a priority
68941     value of the form ‘(PRIMARY . SECONDARY)’, where the PRIMARY value
68942     is used as described above, and SECONDARY is the fallback value
68943     used when PRIMARY and the nesting considerations fail to resolve
68944     the precedence between overlays.  However, you are advised not to
68945     design Lisp programs based on this implementation detail; if you
68946     need to put overlays in priority order, use the SORTED argument of
68947     ‘overlays-at’.  *Note Finding Overlays::.
68948
68949‘window’
68950     If the ‘window’ property is non-‘nil’, then the overlay applies
68951     only on that window.
68952
68953‘category’
68954     If an overlay has a ‘category’ property, we call it the “category”
68955     of the overlay.  It should be a symbol.  The properties of the
68956     symbol serve as defaults for the properties of the overlay.
68957
68958‘face’
68959     This property controls the appearance of the text (*note Faces::).
68960     The value of the property can be the following:
68961
68962        • A face name (a symbol or string).
68963
68964        • An anonymous face: a property list of the form ‘(KEYWORD VALUE
68965          ...)’, where each KEYWORD is a face attribute name and VALUE
68966          is a value for that attribute.
68967
68968        • A list of faces.  Each list element should be either a face
68969          name or an anonymous face.  This specifies a face which is an
68970          aggregate of the attributes of each of the listed faces.
68971          Faces occurring earlier in the list have higher priority.
68972
68973        • A cons cell of the form ‘(foreground-color . COLOR-NAME)’ or
68974          ‘(background-color . COLOR-NAME)’.  This specifies the
68975          foreground or background color, similar to ‘(:foreground
68976          COLOR-NAME)’ or ‘(:background COLOR-NAME)’.  This form is
68977          supported for backward compatibility only, and should be
68978          avoided.
68979
68980‘mouse-face’
68981     This property is used instead of ‘face’ when the mouse is within
68982     the range of the overlay.  However, Emacs ignores all face
68983     attributes from this property that alter the text size (e.g.,
68984     ‘:height’, ‘:weight’, and ‘:slant’).  Those attributes are always
68985     the same as in the unhighlighted text.
68986
68987‘display’
68988     This property activates various features that change the way text
68989     is displayed.  For example, it can make text appear taller or
68990     shorter, higher or lower, wider or narrower, or replaced with an
68991     image.  *Note Display Property::.
68992
68993‘help-echo’
68994     If an overlay has a ‘help-echo’ property, then when you move the
68995     mouse onto the text in the overlay, Emacs displays a help string in
68996     the echo area, or in the tooltip window.  For details see *note
68997     Text help-echo::.
68998
68999‘field’
69000     Consecutive characters with the same ‘field’ property constitute a
69001     _field_.  Some motion functions including ‘forward-word’ and
69002     ‘beginning-of-line’ stop moving at a field boundary.  *Note
69003     Fields::.
69004
69005‘modification-hooks’
69006     This property’s value is a list of functions to be called if any
69007     character within the overlay is changed or if text is inserted
69008     strictly within the overlay.
69009
69010     The hook functions are called both before and after each change.
69011     If the functions save the information they receive, and compare
69012     notes between calls, they can determine exactly what change has
69013     been made in the buffer text.
69014
69015     When called before a change, each function receives four arguments:
69016     the overlay, ‘nil’, and the beginning and end of the text range to
69017     be modified.
69018
69019     When called after a change, each function receives five arguments:
69020     the overlay, ‘t’, the beginning and end of the text range just
69021     modified, and the length of the pre-change text replaced by that
69022     range.  (For an insertion, the pre-change length is zero; for a
69023     deletion, that length is the number of characters deleted, and the
69024     post-change beginning and end are equal.)
69025
69026     When these functions are called, ‘inhibit-modification-hooks’ is
69027     bound to non-‘nil’.  If the functions modify the buffer, you might
69028     want to bind ‘inhibit-modification-hooks’ to ‘nil’, so as to cause
69029     the change hooks to run for these modifications.  However, doing
69030     this may call your own change hook recursively, so be sure to
69031     prepare for that.  *Note Change Hooks::.
69032
69033     Text properties also support the ‘modification-hooks’ property, but
69034     the details are somewhat different (*note Special Properties::).
69035
69036‘insert-in-front-hooks’
69037     This property’s value is a list of functions to be called before
69038     and after inserting text right at the beginning of the overlay.
69039     The calling conventions are the same as for the
69040     ‘modification-hooks’ functions.
69041
69042‘insert-behind-hooks’
69043     This property’s value is a list of functions to be called before
69044     and after inserting text right at the end of the overlay.  The
69045     calling conventions are the same as for the ‘modification-hooks’
69046     functions.
69047
69048‘invisible’
69049     The ‘invisible’ property can make the text in the overlay
69050     invisible, which means that it does not appear on the screen.
69051     *Note Invisible Text::, for details.
69052
69053‘intangible’
69054     The ‘intangible’ property on an overlay works just like the
69055     ‘intangible’ text property.  It is obsolete.  *Note Special
69056     Properties::, for details.
69057
69058‘isearch-open-invisible’
69059     This property tells incremental search how to make an invisible
69060     overlay visible, permanently, if the final match overlaps it.
69061     *Note Invisible Text::.
69062
69063‘isearch-open-invisible-temporary’
69064     This property tells incremental search how to make an invisible
69065     overlay visible, temporarily, during the search.  *Note Invisible
69066     Text::.
69067
69068‘before-string’
69069     This property’s value is a string to add to the display at the
69070     beginning of the overlay.  The string does not appear in the buffer
69071     in any sense—only on the screen.
69072
69073‘after-string’
69074     This property’s value is a string to add to the display at the end
69075     of the overlay.  The string does not appear in the buffer in any
69076     sense—only on the screen.
69077
69078‘line-prefix’
69079     This property specifies a display spec to prepend to each
69080     non-continuation line at display-time.  *Note Truncation::.
69081
69082‘wrap-prefix’
69083     This property specifies a display spec to prepend to each
69084     continuation line at display-time.  *Note Truncation::.
69085
69086‘evaporate’
69087     If this property is non-‘nil’, the overlay is deleted automatically
69088     if it becomes empty (i.e., if its length becomes zero).  If you
69089     give an empty overlay (*note empty overlay: Managing Overlays.) a
69090     non-‘nil’ ‘evaporate’ property, that deletes it immediately.  Note
69091     that, unless an overlay has this property, it will not be deleted
69092     when the text between its starting and ending positions is deleted
69093     from the buffer.
69094
69095‘keymap’
69096     If this property is non-‘nil’, it specifies a keymap for a portion
69097     of the text.  This keymap is used when the character after point is
69098     within the overlay, and takes precedence over most other keymaps.
69099     *Note Active Keymaps::.
69100
69101‘local-map’
69102     The ‘local-map’ property is similar to ‘keymap’ but replaces the
69103     buffer’s local map rather than augmenting existing keymaps.  This
69104     also means it has lower precedence than minor mode keymaps.
69105
69106   The ‘keymap’ and ‘local-map’ properties do not affect a string
69107displayed by the ‘before-string’, ‘after-string’, or ‘display’
69108properties.  This is only relevant for mouse clicks and other mouse
69109events that fall on the string, since point is never on the string.  To
69110bind special mouse events for the string, assign it a ‘keymap’ or
69111‘local-map’ text property.  *Note Special Properties::.
69112
69113
69114File: elisp.info,  Node: Finding Overlays,  Prev: Overlay Properties,  Up: Overlays
69115
6911639.9.3 Searching for Overlays
69117-----------------------------
69118
69119 -- Function: overlays-at pos &optional sorted
69120     This function returns a list of all the overlays that cover the
69121     character at position POS in the current buffer.  If SORTED is
69122     non-‘nil’, the list is in decreasing order of priority, otherwise
69123     it is in no particular order.  An overlay contains position POS if
69124     it begins at or before POS, and ends after POS.
69125
69126     To illustrate usage, here is a Lisp function that returns a list of
69127     the overlays that specify property PROP for the character at point:
69128
69129          (defun find-overlays-specifying (prop)
69130            (let ((overlays (overlays-at (point)))
69131                  found)
69132              (while overlays
69133                (let ((overlay (car overlays)))
69134                  (if (overlay-get overlay prop)
69135                      (setq found (cons overlay found))))
69136                (setq overlays (cdr overlays)))
69137              found))
69138
69139 -- Function: overlays-in beg end
69140     This function returns a list of the overlays that overlap the
69141     region BEG through END.  An overlay overlaps with a region if it
69142     contains one or more characters in the region; empty overlays
69143     (*note empty overlay: Managing Overlays.) overlap if they are at
69144     BEG, strictly between BEG and END, or at END when END denotes the
69145     position at the end of the buffer.
69146
69147 -- Function: next-overlay-change pos
69148     This function returns the buffer position of the next beginning or
69149     end of an overlay, after POS.  If there is none, it returns
69150     ‘(point-max)’.
69151
69152 -- Function: previous-overlay-change pos
69153     This function returns the buffer position of the previous beginning
69154     or end of an overlay, before POS.  If there is none, it returns
69155     ‘(point-min)’.
69156
69157   As an example, here’s a simplified (and inefficient) version of the
69158primitive function ‘next-single-char-property-change’ (*note Property
69159Search::).  It searches forward from position POS for the next position
69160where the value of a given property ‘prop’, as obtained from either
69161overlays or text properties, changes.
69162
69163     (defun next-single-char-property-change (position prop)
69164       (save-excursion
69165         (goto-char position)
69166         (let ((propval (get-char-property (point) prop)))
69167           (while (and (not (eobp))
69168                       (eq (get-char-property (point) prop) propval))
69169             (goto-char (min (next-overlay-change (point))
69170                             (next-single-property-change (point) prop)))))
69171         (point)))
69172
69173
69174File: elisp.info,  Node: Size of Displayed Text,  Next: Line Height,  Prev: Overlays,  Up: Display
69175
6917639.10 Size of Displayed Text
69177============================
69178
69179Since not all characters have the same width, these functions let you
69180check the width of a character.  *Note Primitive Indent::, and *note
69181Screen Lines::, for related functions.
69182
69183 -- Function: char-width char
69184     This function returns the width in columns of the character CHAR,
69185     if it were displayed in the current buffer (i.e., taking into
69186     account the buffer’s display table, if any; *note Display
69187     Tables::).  The width of a tab character is usually ‘tab-width’
69188     (*note Usual Display::).
69189
69190 -- Function: string-width string
69191     This function returns the width in columns of the string STRING, if
69192     it were displayed in the current buffer and the selected window.
69193
69194 -- Function: truncate-string-to-width string width &optional
69195          start-column padding ellipsis
69196     This function returns the part of STRING that fits within WIDTH
69197     columns, as a new string.
69198
69199     If STRING does not reach WIDTH, then the result ends where STRING
69200     ends.  If one multi-column character in STRING extends across the
69201     column WIDTH, that character is not included in the result.  Thus,
69202     the result can fall short of WIDTH but cannot go beyond it.
69203
69204     The optional argument START-COLUMN specifies the starting column.
69205     If this is non-‘nil’, then the first START-COLUMN columns of the
69206     string are omitted from the value.  If one multi-column character
69207     in STRING extends across the column START-COLUMN, that character is
69208     not included.
69209
69210     The optional argument PADDING, if non-‘nil’, is a padding character
69211     added at the beginning and end of the result string, to extend it
69212     to exactly WIDTH columns.  The padding character is used at the end
69213     of the result if it falls short of WIDTH.  It is also used at the
69214     beginning of the result if one multi-column character in STRING
69215     extends across the column START-COLUMN.
69216
69217     If ELLIPSIS is non-‘nil’, it should be a string which will replace
69218     the end of STRING (including any padding) if it extends beyond
69219     WIDTH, unless the display width of STRING is equal to or less than
69220     the display width of ELLIPSIS.  If ELLIPSIS is non-‘nil’ and not a
69221     string, it stands for the value of the variable
69222     ‘truncate-string-ellipsis’.
69223
69224          (truncate-string-to-width "\tab\t" 12 4)
69225               ⇒ "ab"
69226          (truncate-string-to-width "\tab\t" 12 4 ?\s)
69227               ⇒ "    ab  "
69228
69229   The following function returns the size in pixels of text as if it
69230were displayed in a given window.  This function is used by
69231‘fit-window-to-buffer’ and ‘fit-frame-to-buffer’ (*note Resizing
69232Windows::) to make a window exactly as large as the text it contains.
69233
69234 -- Function: window-text-pixel-size &optional window from to x-limit
69235          y-limit mode-and-header-line
69236     This function returns the size of the text of WINDOW’s buffer in
69237     pixels.  WINDOW must be a live window and defaults to the selected
69238     one.  The return value is a cons of the maximum pixel-width of any
69239     text line and the maximum pixel-height of all text lines.  This
69240     function exists to allow Lisp programs to adjust the dimensions of
69241     WINDOW to the buffer text it needs to display.
69242
69243     The optional argument FROM, if non-‘nil’, specifies the first text
69244     position to consider, and defaults to the minimum accessible
69245     position of the buffer.  If FROM is ‘t’, it stands for the minimum
69246     accessible position that is not a newline character.  The optional
69247     argument TO, if non-‘nil’, specifies the last text position to
69248     consider, and defaults to the maximum accessible position of the
69249     buffer.  If TO is ‘t’, it stands for the maximum accessible
69250     position that is not a newline character.
69251
69252     The optional argument X-LIMIT, if non-‘nil’, specifies the maximum
69253     X coordinate beyond which text should be ignored; it is therefore
69254     also the largest value of pixel-width that the function can return.
69255     If X-LIMIT ‘nil’ or omitted, it means to use the pixel-width of
69256     WINDOW’s body (*note Window Sizes::); this default means that text
69257     of truncated lines wider than the window will be ignored.  This
69258     default is useful when the caller does not intend to change the
69259     width of WINDOW.  Otherwise, the caller should specify here the
69260     maximum width WINDOW’s body may assume; in particular, if truncated
69261     lines are expected and their text needs to be accounted for,
69262     X-LIMIT should be set to a large value.  Since calculating the
69263     width of long lines can take some time, it’s always a good idea to
69264     make this argument as small as needed; in particular, if the buffer
69265     might contain long lines that will be truncated anyway.
69266
69267     The optional argument Y-LIMIT, if non-‘nil’, specifies the maximum
69268     Y coordinate beyond which text is to be ignored; it is therefore
69269     also the maximum pixel-height that the function can return.  If
69270     Y-LIMIT is nil or omitted, it means to considers all the lines of
69271     text till the buffer position specified by TO.  Since calculating
69272     the pixel-height of a large buffer can take some time, it makes
69273     sense to specify this argument; in particular, if the caller does
69274     not know the size of the buffer.
69275
69276     The optional argument MODE-AND-HEADER-LINE ‘nil’ or omitted means
69277     to not include the height of the mode- or header-line of WINDOW in
69278     the return value.  If it is either the symbol ‘mode-line’ or
69279     ‘header-line’, include only the height of that line, if present, in
69280     the return value.  If it is ‘t’, include the height of both, if
69281     present, in the return value.
69282
69283   ‘window-text-pixel-size’ treats the text displayed in a window as a
69284whole and does not care about the size of individual lines.  The
69285following function does.
69286
69287 -- Function: window-lines-pixel-dimensions &optional window first last
69288          body inverse left
69289     This function calculates the pixel dimensions of each line
69290     displayed in the specified WINDOW.  It does so by walking WINDOW’s
69291     current glyph matrix—a matrix storing the glyph (*note Glyphs::) of
69292     each buffer character currently displayed in WINDOW.  If
69293     successful, it returns a list of cons pairs representing the x- and
69294     y-coordinates of the lower right corner of the last character of
69295     each line.  Coordinates are measured in pixels from an origin (0,
69296     0) at the top-left corner of WINDOW.  WINDOW must be a live window
69297     and defaults to the selected one.
69298
69299     If the optional argument FIRST is an integer, it denotes the index
69300     (starting with 0) of the first line of WINDOW’s glyph matrix to be
69301     returned.  Note that if WINDOW has a header line, the line with
69302     index 0 is that header line.  If FIRST is ‘nil’, the first line to
69303     be considered is determined by the value of the optional argument
69304     BODY: If BODY is non-‘nil’, this means to start with the first line
69305     of WINDOW’s body, skipping any header line, if present.  Otherwise,
69306     this function will start with the first line of WINDOW’s glyph
69307     matrix, possibly the header line.
69308
69309     If the optional argument LAST is an integer, it denotes the index
69310     of the last line of WINDOW’s glyph matrix that shall be returned.
69311     If LAST is ‘nil’, the last line to be considered is determined by
69312     the value of BODY: If BODY is non-‘nil’, this means to use the last
69313     line of WINDOW’s body, omitting WINDOW’s mode line, if present.
69314     Otherwise, this means to use the last line of WINDOW which may be
69315     the mode line.
69316
69317     The optional argument INVERSE, if ‘nil’, means that the y-pixel
69318     value returned for any line specifies the distance in pixels from
69319     the left edge (body edge if BODY is non-‘nil’) of WINDOW to the
69320     right edge of the last glyph of that line.  INVERSE non-‘nil’ means
69321     that the y-pixel value returned for any line specifies the distance
69322     in pixels from the right edge of the last glyph of that line to the
69323     right edge (body edge if BODY is non-‘nil’) of WINDOW.  This is
69324     useful for determining the amount of slack space at the end of each
69325     line.
69326
69327     The optional argument LEFT, if non-‘nil’ means to return the x- and
69328     y-coordinates of the lower left corner of the leftmost character on
69329     each line.  This is the value that should be used for windows that
69330     mostly display text from right to left.
69331
69332     If LEFT is non-‘nil’ and INVERSE is ‘nil’, this means that the
69333     y-pixel value returned for any line specifies the distance in
69334     pixels from the left edge of the last (leftmost) glyph of that line
69335     to the right edge (body edge if BODY is non-‘nil’) of WINDOW.  If
69336     LEFT and INVERSE are both non-‘nil’, the y-pixel value returned for
69337     any line specifies the distance in pixels from the left edge (body
69338     edge if BODY is non-‘nil’) of WINDOW to the left edge of the last
69339     (leftmost) glyph of that line.
69340
69341     This function returns ‘nil’ if the current glyph matrix of WINDOW
69342     is not up-to-date which usually happens when Emacs is busy, for
69343     example, when processing a command.  The value should be
69344     retrievable though when this function is run from an idle timer
69345     with a delay of zero seconds.
69346
69347 -- Function: line-pixel-height
69348     This function returns the height in pixels of the line at point in
69349     the selected window.  The value includes the line spacing of the
69350     line (*note Line Height::).
69351
69352   When a buffer is displayed with line numbers (*note (emacs)Display
69353Custom::), it is sometimes useful to know the width taken for displaying
69354the line numbers.  The following function is for Lisp programs which
69355need this information for layout calculations.
69356
69357 -- Function: line-number-display-width &optional pixelwise
69358     This function returns the width used for displaying the line
69359     numbers in the selected window.  If the optional argument PIXELWISE
69360     is the symbol ‘columns’, the return value is a float number of the
69361     frame’s canonical columns; if PIXELWISE is ‘t’ or any other
69362     non-‘nil’ value, the value is an integer and is measured in pixels.
69363     If PIXELWISE is omitted or ‘nil’, the value is the integer number
69364     of columns of the font defined for the ‘line-number’ face, and
69365     doesn’t include the 2 columns used to pad the numbers on display.
69366     If line numbers are not displayed in the selected window, the value
69367     is zero regardless of the value of PIXELWISE.  Use
69368     ‘with-selected-window’ (*note Selecting Windows::) if you need this
69369     information about another window.
69370
69371
69372File: elisp.info,  Node: Line Height,  Next: Faces,  Prev: Size of Displayed Text,  Up: Display
69373
6937439.11 Line Height
69375=================
69376
69377The total height of each display line consists of the height of the
69378contents of the line, plus optional additional vertical line spacing
69379above or below the display line.
69380
69381   The height of the line contents is the maximum height of any
69382character or image on that display line, including the final newline if
69383there is one.  (A display line that is continued doesn’t include a final
69384newline.)  That is the default line height, if you do nothing to specify
69385a greater height.  (In the most common case, this equals the height of
69386the corresponding frame’s default font, see *note Frame Font::.)
69387
69388   There are several ways to explicitly specify a larger line height,
69389either by specifying an absolute height for the display line, or by
69390specifying vertical space.  However, no matter what you specify, the
69391actual line height can never be less than the default.
69392
69393   A newline can have a ‘line-height’ text or overlay property that
69394controls the total height of the display line ending in that newline.
69395The property value can be one of several forms:
69396
69397‘t’
69398     If the property value is ‘t’, the newline character has no effect
69399     on the displayed height of the line—the visible contents alone
69400     determine the height.  The ‘line-spacing’ property, described
69401     below, is also ignored in this case.  This is useful for tiling
69402     small images (or image slices) without adding blank areas between
69403     the images.
69404‘(HEIGHT TOTAL)’
69405     If the property value is a list of the form shown, that adds extra
69406     space _below_ the display line.  First Emacs uses HEIGHT as a
69407     height spec to control extra space _above_ the line; then it adds
69408     enough space _below_ the line to bring the total line height up to
69409     TOTAL.  In this case, any value of ‘line-spacing’ property for the
69410     newline is ignored.
69411
69412   Any other kind of property value is a height spec, which translates
69413into a number—the specified line height.  There are several ways to
69414write a height spec; here’s how each of them translates into a number:
69415
69416‘INTEGER’
69417     If the height spec is a positive integer, the height value is that
69418     integer.
69419‘FLOAT’
69420     If the height spec is a float, FLOAT, the numeric height value is
69421     FLOAT times the frame’s default line height.
69422‘(FACE . RATIO)’
69423     If the height spec is a cons of the format shown, the numeric
69424     height is RATIO times the height of face FACE.  RATIO can be any
69425     type of number, or ‘nil’ which means a ratio of 1.  If FACE is ‘t’,
69426     it refers to the current face.
69427‘(nil . RATIO)’
69428     If the height spec is a cons of the format shown, the numeric
69429     height is RATIO times the height of the contents of the line.
69430
69431   Thus, any valid height spec determines the height in pixels, one way
69432or another.  If the line contents’ height is less than that, Emacs adds
69433extra vertical space above the line to achieve the specified total
69434height.
69435
69436   If you don’t specify the ‘line-height’ property, the line’s height
69437consists of the contents’ height plus the line spacing.  There are
69438several ways to specify the line spacing for different parts of Emacs
69439text.
69440
69441   On graphical terminals, you can specify the line spacing for all
69442lines in a frame, using the ‘line-spacing’ frame parameter (*note Layout
69443Parameters::).  However, if the default value of ‘line-spacing’ is
69444non-‘nil’, it overrides the frame’s ‘line-spacing’ parameter.  An
69445integer specifies the number of pixels put below lines.  A
69446floating-point number specifies the spacing relative to the frame’s
69447default line height.
69448
69449   You can specify the line spacing for all lines in a buffer via the
69450buffer-local ‘line-spacing’ variable.  An integer specifies the number
69451of pixels put below lines.  A floating-point number specifies the
69452spacing relative to the default frame line height.  This overrides line
69453spacings specified for the frame.
69454
69455   Finally, a newline can have a ‘line-spacing’ text or overlay property
69456that can enlarge the default frame line spacing and the buffer local
69457‘line-spacing’ variable: if its value is larger than the buffer or frame
69458defaults, that larger value is used instead, for the display line ending
69459in that newline.
69460
69461   One way or another, these mechanisms specify a Lisp value for the
69462spacing of each line.  The value is a height spec, and it translates
69463into a Lisp value as described above.  However, in this case the numeric
69464height value specifies the line spacing, rather than the line height.
69465
69466   On text terminals, the line spacing cannot be altered.
69467
69468
69469File: elisp.info,  Node: Faces,  Next: Fringes,  Prev: Line Height,  Up: Display
69470
6947139.12 Faces
69472===========
69473
69474A “face” is a collection of graphical attributes for displaying text:
69475font, foreground color, background color, optional underlining, etc.
69476Faces control how Emacs displays text in buffers, as well as other parts
69477of the frame such as the mode line.
69478
69479   One way to represent a face is as a property list of attributes, like
69480‘(:foreground "red" :weight bold)’.  Such a list is called an “anonymous
69481face”.  For example, you can assign an anonymous face as the value of
69482the ‘face’ text property, and Emacs will display the underlying text
69483with the specified attributes.  *Note Special Properties::.
69484
69485   More commonly, a face is referred to via a “face name”: a Lisp symbol
69486associated with a set of face attributes(1).  Named faces are defined
69487using the ‘defface’ macro (*note Defining Faces::).  Emacs comes with
69488several standard named faces (*note Basic Faces::).
69489
69490   Some parts of Emacs require named faces (e.g., the functions
69491documented in *note Attribute Functions::).  Unless otherwise stated, we
69492will use the term “face” to refer only to named faces.
69493
69494 -- Function: facep object
69495     This function returns a non-‘nil’ value if OBJECT is a named face:
69496     a Lisp symbol or string which serves as a face name.  Otherwise, it
69497     returns ‘nil’.
69498
69499* Menu:
69500
69501* Face Attributes::     What is in a face?
69502* Defining Faces::      How to define a face.
69503* Attribute Functions::  Functions to examine and set face attributes.
69504* Displaying Faces::     How Emacs combines the faces specified for a character.
69505* Face Remapping::      Remapping faces to alternative definitions.
69506* Face Functions::      How to define and examine faces.
69507* Auto Faces::          Hook for automatic face assignment.
69508* Basic Faces::         Faces that are defined by default.
69509* Font Selection::      Finding the best available font for a face.
69510* Font Lookup::         Looking up the names of available fonts
69511                          and information about them.
69512* Fontsets::            A fontset is a collection of fonts
69513                          that handle a range of character sets.
69514* Low-Level Font::      Lisp representation for character display fonts.
69515
69516   ---------- Footnotes ----------
69517
69518   (1) For backward compatibility, you can also use a string to specify
69519a face name; that is equivalent to a Lisp symbol with the same name.
69520
69521
69522File: elisp.info,  Node: Face Attributes,  Next: Defining Faces,  Up: Faces
69523
6952439.12.1 Face Attributes
69525-----------------------
69526
69527“Face attributes” determine the visual appearance of a face.  The
69528following table lists all the face attributes, their possible values,
69529and their effects.
69530
69531   Apart from the values given below, each face attribute can have the
69532value ‘unspecified’.  This special value means that the face doesn’t
69533specify that attribute directly.  An ‘unspecified’ attribute tells Emacs
69534to refer instead to a parent face (see the description ‘:inherit’
69535attribute below); or, failing that, to an underlying face (*note
69536Displaying Faces::).  The ‘default’ face must specify all attributes.
69537
69538   Some of these attributes are meaningful only on certain kinds of
69539displays.  If your display cannot handle a certain attribute, the
69540attribute is ignored.
69541
69542‘:family’
69543     Font family name (a string).  *Note (emacs)Fonts::, for more
69544     information about font families.  The function ‘font-family-list’
69545     (see below) returns a list of available family names.
69546
69547‘:foundry’
69548     The name of the “font foundry” for the font family specified by the
69549     ‘:family’ attribute (a string).  *Note (emacs)Fonts::.
69550
69551‘:width’
69552     Relative character width.  This should be one of the symbols
69553     ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’,
69554     ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’,
69555     ‘extra-expanded’, or ‘ultra-expanded’.
69556
69557‘:height’
69558     The height of the font.  In the simplest case, this is an integer
69559     in units of 1/10 point.
69560
69561     The value can also be floating point or a function, which specifies
69562     the height relative to an “underlying face” (*note Displaying
69563     Faces::).  A floating-point value specifies the amount by which to
69564     scale the height of the underlying face.  A function value is
69565     called with one argument, the height of the underlying face, and
69566     returns the height of the new face.  If the function is passed an
69567     integer argument, it must return an integer.
69568
69569     The height of the default face must be specified using an integer;
69570     floating point and function values are not allowed.
69571
69572‘:weight’
69573     Font weight—one of the symbols (from densest to faintest)
69574     ‘ultra-bold’, ‘extra-bold’, ‘bold’, ‘semi-bold’, ‘normal’,
69575     ‘semi-light’, ‘light’, ‘extra-light’, or ‘ultra-light’.  On text
69576     terminals which support variable-brightness text, any weight
69577     greater than normal is displayed as extra bright, and any weight
69578     less than normal is displayed as half-bright.
69579
69580‘:slant’
69581     Font slant—one of the symbols ‘italic’, ‘oblique’, ‘normal’,
69582     ‘reverse-italic’, or ‘reverse-oblique’.  On text terminals that
69583     support variable-brightness text, slanted text is displayed as
69584     half-bright.
69585
69586‘:foreground’
69587     Foreground color, a string.  The value can be a system-defined
69588     color name, or a hexadecimal color specification.  *Note Color
69589     Names::.  On black-and-white displays, certain shades of gray are
69590     implemented by stipple patterns.
69591
69592‘:distant-foreground’
69593     Alternative foreground color, a string.  This is like ‘:foreground’
69594     but the color is only used as a foreground when the background
69595     color is near to the foreground that would have been used.  This is
69596     useful for example when marking text (i.e., the region face).  If
69597     the text has a foreground that is visible with the region face,
69598     that foreground is used.  If the foreground is near the region face
69599     background, ‘:distant-foreground’ is used instead so the text is
69600     readable.
69601
69602‘:background’
69603     Background color, a string.  The value can be a system-defined
69604     color name, or a hexadecimal color specification.  *Note Color
69605     Names::.
69606
69607‘:underline’
69608     Whether or not characters should be underlined, and in what way.
69609     The possible values of the ‘:underline’ attribute are:
69610
69611     ‘nil’
69612          Don’t underline.
69613
69614     ‘t’
69615          Underline with the foreground color of the face.
69616
69617     COLOR
69618          Underline in color COLOR, a string specifying a color.
69619
69620     ‘(:color COLOR :style STYLE)’
69621          COLOR is either a string, or the symbol ‘foreground-color’,
69622          meaning the foreground color of the face.  Omitting the
69623          attribute ‘:color’ means to use the foreground color of the
69624          face.  STYLE should be a symbol ‘line’ or ‘wave’, meaning to
69625          use a straight or wavy line.  Omitting the attribute ‘:style’
69626          means to use a straight line.
69627
69628‘:overline’
69629     Whether or not characters should be overlined, and in what color.
69630     If the value is ‘t’, overlining uses the foreground color of the
69631     face.  If the value is a string, overlining uses that color.  The
69632     value ‘nil’ means do not overline.
69633
69634‘:strike-through’
69635     Whether or not characters should be strike-through, and in what
69636     color.  The value is used like that of ‘:overline’.
69637
69638‘:box’
69639     Whether or not a box should be drawn around characters, its color,
69640     the width of the box lines, and 3D appearance.  Here are the
69641     possible values of the ‘:box’ attribute, and what they mean:
69642
69643     ‘nil’
69644          Don’t draw a box.
69645
69646     ‘t’
69647          Draw a box with lines of width 1, in the foreground color.
69648
69649     COLOR
69650          Draw a box with lines of width 1, in color COLOR.
69651
69652     ‘(:line-width WIDTH :color COLOR :style STYLE)’
69653          This way you can explicitly specify all aspects of the box.
69654          The value WIDTH specifies the width of the lines to draw; it
69655          defaults to 1.  A negative width −N means to draw a line of
69656          width N whose top and bottom parts occupy the space of the
69657          underlying text, thus avoiding any increase in the character
69658          height.
69659
69660          The value COLOR specifies the color to draw with.  The default
69661          is the foreground color of the face for simple boxes, and the
69662          background color of the face for 3D boxes.
69663
69664          The value STYLE specifies whether to draw a 3D box.  If it is
69665          ‘released-button’, the box looks like a 3D button that is not
69666          being pressed.  If it is ‘pressed-button’, the box looks like
69667          a 3D button that is being pressed.  If it is ‘nil’ or omitted,
69668          a plain 2D box is used.
69669
69670‘:inverse-video’
69671     Whether or not characters should be displayed in inverse video.
69672     The value should be ‘t’ (yes) or ‘nil’ (no).
69673
69674‘:stipple’
69675     The background stipple, a bitmap.
69676
69677     The value can be a string; that should be the name of a file
69678     containing external-format X bitmap data.  The file is found in the
69679     directories listed in the variable ‘x-bitmap-file-path’.
69680
69681     Alternatively, the value can specify the bitmap directly, with a
69682     list of the form ‘(WIDTH HEIGHT DATA)’.  Here, WIDTH and HEIGHT
69683     specify the size in pixels, and DATA is a string containing the raw
69684     bits of the bitmap, row by row.  Each row occupies (WIDTH + 7) / 8
69685     consecutive bytes in the string (which should be a unibyte string
69686     for best results).  This means that each row always occupies at
69687     least one whole byte.
69688
69689     If the value is ‘nil’, that means use no stipple pattern.
69690
69691     Normally you do not need to set the stipple attribute, because it
69692     is used automatically to handle certain shades of gray.
69693
69694‘:font’
69695     The font used to display the face.  Its value should be a font
69696     object or a fontset.  *Note Low-Level Font::, for information about
69697     font objects, font specs, and font entities.  *Note Fontsets::, for
69698     information about fontsets.
69699
69700     When specifying this attribute using ‘set-face-attribute’ or
69701     ‘set-face-font’ (*note Attribute Functions::), you may also supply
69702     a font spec, a font entity, or a string.  Emacs converts such
69703     values to an appropriate font object, and stores that font object
69704     as the actual attribute value.  If you specify a string, the
69705     contents of the string should be a font name (*note
69706     (emacs)Fonts::); if the font name is an XLFD containing wildcards,
69707     Emacs chooses the first font matching those wildcards.  Specifying
69708     this attribute also changes the values of the ‘:family’,
69709     ‘:foundry’, ‘:width’, ‘:height’, ‘:weight’, and ‘:slant’
69710     attributes.
69711
69712‘:inherit’
69713     The name of a face from which to inherit attributes, or a list of
69714     face names.  Attributes from inherited faces are merged into the
69715     face like an underlying face would be, with higher priority than
69716     underlying faces (*note Displaying Faces::).  If the face to
69717     inherit from is ‘unspecified’, it is treated the same as ‘nil’,
69718     since Emacs never merges ‘:inherit’ attributes.  If a list of faces
69719     is used, attributes from faces earlier in the list override those
69720     from later faces.
69721
69722‘:extend’
69723     Whether or not this face will be extended beyond end of line and
69724     will affect the display of the empty space between the end of line
69725     and the edge of the window.  The value should be ‘t’ to display the
69726     empty space between end of line and edge of the window using this
69727     face, or ‘nil’ to not use this face for the space between the end
69728     of the line and the edge of the window.  When Emacs merges several
69729     faces for displaying the empty space beyond end of line, only those
69730     faces with ‘:extend’ non-‘nil’ will be merged.  By default, only a
69731     small number of faces, notably, ‘region’, have this attribute set.
69732     This attribute is different from the others in that when a theme
69733     doesn’t specify an explicit value for a face, the value from the
69734     original face definition by ‘defface’ is inherited (*note Defining
69735     Faces::).
69736
69737 -- Function: font-family-list &optional frame
69738     This function returns a list of available font family names.  The
69739     optional argument FRAME specifies the frame on which the text is to
69740     be displayed; if it is ‘nil’, the selected frame is used.
69741
69742 -- User Option: underline-minimum-offset
69743     This variable specifies the minimum distance between the baseline
69744     and the underline, in pixels, when displaying underlined text.
69745
69746 -- User Option: x-bitmap-file-path
69747     This variable specifies a list of directories for searching for
69748     bitmap files, for the ‘:stipple’ attribute.
69749
69750 -- Function: bitmap-spec-p object
69751     This returns ‘t’ if OBJECT is a valid bitmap specification,
69752     suitable for use with ‘:stipple’ (see above).  It returns ‘nil’
69753     otherwise.
69754
69755
69756File: elisp.info,  Node: Defining Faces,  Next: Attribute Functions,  Prev: Face Attributes,  Up: Faces
69757
6975839.12.2 Defining Faces
69759----------------------
69760
69761The usual way to define a face is through the ‘defface’ macro.  This
69762macro associates a face name (a symbol) with a default “face spec”.  A
69763face spec is a construct which specifies what attributes a face should
69764have on any given terminal; for example, a face spec might specify one
69765foreground color on high-color terminals, and a different foreground
69766color on low-color terminals.
69767
69768   People are sometimes tempted to create a variable whose value is a
69769face name.  In the vast majority of cases, this is not necessary; the
69770usual procedure is to define a face with ‘defface’, and then use its
69771name directly.
69772
69773   Note that once you have defined a face (usually with ‘defface’), you
69774cannot later undefine this face safely, except by restarting Emacs.
69775
69776 -- Macro: defface face spec doc [keyword value]...
69777     This macro declares FACE as a named face whose default face spec is
69778     given by SPEC.  You should not quote the symbol FACE, and it should
69779     not end in ‘-face’ (that would be redundant).  The argument DOC is
69780     a documentation string for the face.  The additional KEYWORD
69781     arguments have the same meanings as in ‘defgroup’ and ‘defcustom’
69782     (*note Common Keywords::).
69783
69784     If FACE already has a default face spec, this macro does nothing.
69785
69786     The default face spec determines FACE’s appearance when no
69787     customizations are in effect (*note Customization::).  If FACE has
69788     already been customized (via Custom themes or via customizations
69789     read from the init file), its appearance is determined by the
69790     custom face spec(s), which override the default face spec SPEC.
69791     However, if the customizations are subsequently removed, the
69792     appearance of FACE will again be determined by its default face
69793     spec.
69794
69795     As an exception, if you evaluate a ‘defface’ form with ‘C-M-x’ in
69796     Emacs Lisp mode (‘eval-defun’), a special feature of ‘eval-defun’
69797     overrides any custom face specs on the face, causing the face to
69798     reflect exactly what the ‘defface’ says.
69799
69800     The SPEC argument is a “face spec”, which states how the face
69801     should appear on different kinds of terminals.  It should be an
69802     alist whose elements each have the form
69803
69804          (DISPLAY . PLIST)
69805
69806     DISPLAY specifies a class of terminals (see below).  PLIST is a
69807     property list of face attributes and their values, specifying how
69808     the face appears on such terminals.  For backward compatibility,
69809     you can also write an element as ‘(DISPLAY PLIST)’.
69810
69811     The DISPLAY part of an element of SPEC determines which terminals
69812     the element matches.  If more than one element of SPEC matches a
69813     given terminal, the first element that matches is the one used for
69814     that terminal.  There are three possibilities for DISPLAY:
69815
69816     ‘default’
69817          This element of SPEC doesn’t match any terminal; instead, it
69818          specifies defaults that apply to all terminals.  This element,
69819          if used, must be the first element of SPEC.  Each of the
69820          following elements can override any or all of these defaults.
69821
69822     ‘t’
69823          This element of SPEC matches all terminals.  Therefore, any
69824          subsequent elements of SPEC are never used.  Normally ‘t’ is
69825          used in the last (or only) element of SPEC.
69826
69827     a list
69828          If DISPLAY is a list, each element should have the form
69829          ‘(CHARACTERISTIC VALUE...)’.  Here CHARACTERISTIC specifies a
69830          way of classifying terminals, and the VALUEs are possible
69831          classifications which DISPLAY should apply to.  Here are the
69832          possible values of CHARACTERISTIC:
69833
69834          ‘type’
69835               The kind of window system the terminal uses—either
69836               ‘graphic’ (any graphics-capable display), ‘x’, ‘pc’ (for
69837               the MS-DOS console), ‘w32’ (for MS Windows 9X/NT/2K/XP),
69838               or ‘tty’ (a non-graphics-capable display).  *Note
69839               window-system: Window Systems.
69840
69841          ‘class’
69842               What kinds of colors the terminal supports—either
69843               ‘color’, ‘grayscale’, or ‘mono’.
69844
69845          ‘background’
69846               The kind of background—either ‘light’ or ‘dark’.
69847
69848          ‘min-colors’
69849               An integer that represents the minimum number of colors
69850               the terminal should support.  This matches a terminal if
69851               its ‘display-color-cells’ value is at least the specified
69852               integer.
69853
69854          ‘supports’
69855               Whether or not the terminal can display the face
69856               attributes given in VALUE... (*note Face Attributes::).
69857               *Note Display Face Attribute Testing::, for more
69858               information on exactly how this testing is done.
69859
69860          If an element of DISPLAY specifies more than one VALUE for a
69861          given CHARACTERISTIC, any of those values is acceptable.  If
69862          DISPLAY has more than one element, each element should specify
69863          a different CHARACTERISTIC; then _each_ characteristic of the
69864          terminal must match one of the VALUEs specified for it in
69865          DISPLAY.
69866
69867   For example, here’s the definition of the standard face ‘highlight’:
69868
69869     (defface highlight
69870       '((((class color) (min-colors 88) (background light))
69871          :background "darkseagreen2")
69872         (((class color) (min-colors 88) (background dark))
69873          :background "darkolivegreen")
69874         (((class color) (min-colors 16) (background light))
69875          :background "darkseagreen2")
69876         (((class color) (min-colors 16) (background dark))
69877          :background "darkolivegreen")
69878         (((class color) (min-colors 8))
69879          :background "green" :foreground "black")
69880         (t :inverse-video t))
69881       "Basic face for highlighting."
69882       :group 'basic-faces)
69883
69884   Internally, Emacs stores each face’s default spec in its
69885‘face-defface-spec’ symbol property (*note Symbol Properties::).  The
69886‘saved-face’ property stores any face spec saved by the user using the
69887customization buffer; the ‘customized-face’ property stores the face
69888spec customized for the current session, but not saved; and the
69889‘theme-face’ property stores an alist associating the active
69890customization settings and Custom themes with the face specs for that
69891face.  The face’s documentation string is stored in the
69892‘face-documentation’ property.
69893
69894   Normally, a face is declared just once, using ‘defface’, and any
69895further changes to its appearance are applied using the Customize
69896framework (e.g., via the Customize user interface or via the
69897‘custom-set-faces’ function; *note Applying Customizations::), or by
69898face remapping (*note Face Remapping::).  In the rare event that you
69899need to change a face spec directly from Lisp, you can use the
69900‘face-spec-set’ function.
69901
69902 -- Function: face-spec-set face spec &optional spec-type
69903     This function applies SPEC as a face spec for ‘face’.  SPEC should
69904     be a face spec, as described in the above documentation for
69905     ‘defface’.
69906
69907     This function also defines FACE as a valid face name if it is not
69908     already one, and (re)calculates its attributes on existing frames.
69909
69910     The optional argument SPEC-TYPE determines which spec to set.  If
69911     it is omitted or ‘nil’ or ‘face-override-spec’, this function sets
69912     the “override spec”, which overrides face specs on FACE of all the
69913     other types mentioned below.  This is useful when calling this
69914     function outside of Custom code.  If SPEC-TYPE is ‘customized-face’
69915     or ‘saved-face’, this function sets the customized spec or the
69916     saved custom spec, respectively.  If it is ‘face-defface-spec’,
69917     this function sets the default face spec (the same one set by
69918     ‘defface’).  If it is ‘reset’, this function clears out all
69919     customization specs and override specs from FACE (in this case, the
69920     value of SPEC is ignored).  The effect of any other value of
69921     SPEC-TYPE on the face specs is reserved for internal use, but the
69922     function will still define FACE itself and recalculate its
69923     attributes, as described above.
69924
69925
69926File: elisp.info,  Node: Attribute Functions,  Next: Displaying Faces,  Prev: Defining Faces,  Up: Faces
69927
6992839.12.3 Face Attribute Functions
69929--------------------------------
69930
69931This section describes functions for directly accessing and modifying
69932the attributes of a named face.
69933
69934 -- Function: face-attribute face attribute &optional frame inherit
69935     This function returns the value of the ATTRIBUTE attribute for FACE
69936     on FRAME.
69937
69938     If FRAME is omitted or ‘nil’, that means the selected frame (*note
69939     Input Focus::).  If FRAME is ‘t’, this function returns the value
69940     of the specified attribute for newly-created frames (this is
69941     normally ‘unspecified’, unless you have specified some value using
69942     ‘set-face-attribute’; see below).
69943
69944     If INHERIT is ‘nil’, only attributes directly defined by FACE are
69945     considered, so the return value may be ‘unspecified’, or a relative
69946     value.  If INHERIT is non-‘nil’, FACE’s definition of ATTRIBUTE is
69947     merged with the faces specified by its ‘:inherit’ attribute;
69948     however the return value may still be ‘unspecified’ or relative.
69949     If INHERIT is a face or a list of faces, then the result is further
69950     merged with that face (or faces), until it becomes specified and
69951     absolute.
69952
69953     To ensure that the return value is always specified and absolute,
69954     use a value of ‘default’ for INHERIT; this will resolve any
69955     unspecified or relative values by merging with the ‘default’ face
69956     (which is always completely specified).
69957
69958     For example,
69959
69960          (face-attribute 'bold :weight)
69961               ⇒ bold
69962
69963 -- Function: face-attribute-relative-p attribute value
69964     This function returns non-‘nil’ if VALUE, when used as the value of
69965     the face attribute ATTRIBUTE, is relative.  This means it would
69966     modify, rather than completely override, any value that comes from
69967     a subsequent face in the face list or that is inherited from
69968     another face.
69969
69970     ‘unspecified’ is a relative value for all attributes.  For
69971     ‘:height’, floating point and function values are also relative.
69972
69973     For example:
69974
69975          (face-attribute-relative-p :height 2.0)
69976               ⇒ t
69977
69978 -- Function: face-all-attributes face &optional frame
69979     This function returns an alist of attributes of FACE.  The elements
69980     of the result are name-value pairs of the form
69981     ‘(ATTR-NAME . ATTR-VALUE)’.  Optional argument FRAME specifies the
69982     frame whose definition of FACE to return; if omitted or ‘nil’, the
69983     returned value describes the default attributes of FACE for newly
69984     created frames.
69985
69986 -- Function: merge-face-attribute attribute value1 value2
69987     If VALUE1 is a relative value for the face attribute ATTRIBUTE,
69988     returns it merged with the underlying value VALUE2; otherwise, if
69989     VALUE1 is an absolute value for the face attribute ATTRIBUTE,
69990     returns VALUE1 unchanged.
69991
69992   Normally, Emacs uses the face specs of each face to automatically
69993calculate its attributes on each frame (*note Defining Faces::).  The
69994function ‘set-face-attribute’ can override this calculation by directly
69995assigning attributes to a face, either on a specific frame or for all
69996frames.  This function is mostly intended for internal usage.
69997
69998 -- Function: set-face-attribute face frame &rest arguments
69999     This function sets one or more attributes of FACE for FRAME.  The
70000     attributes specifies in this way override the face spec(s)
70001     belonging to FACE.
70002
70003     The extra arguments ARGUMENTS specify the attributes to set, and
70004     the values for them.  They should consist of alternating attribute
70005     names (such as ‘:family’ or ‘:underline’) and values.  Thus,
70006
70007          (set-face-attribute 'foo nil :weight 'bold :slant 'italic)
70008
70009     sets the attribute ‘:weight’ to ‘bold’ and the attribute ‘:slant’
70010     to ‘italic’.
70011
70012     If FRAME is ‘t’, this function sets the default attributes for
70013     newly created frames.  If FRAME is ‘nil’, this function sets the
70014     attributes for all existing frames, as well as for newly created
70015     frames.
70016
70017   The following commands and functions mostly provide compatibility
70018with old versions of Emacs.  They work by calling ‘set-face-attribute’.
70019Values of ‘t’ and ‘nil’ (or omitted) for their FRAME argument are
70020handled just like ‘set-face-attribute’ and ‘face-attribute’.  The
70021commands read their arguments using the minibuffer, if called
70022interactively.
70023
70024 -- Command: set-face-foreground face color &optional frame
70025 -- Command: set-face-background face color &optional frame
70026     These set the ‘:foreground’ attribute (or ‘:background’ attribute,
70027     respectively) of FACE to COLOR.
70028
70029 -- Command: set-face-stipple face pattern &optional frame
70030     This sets the ‘:stipple’ attribute of FACE to PATTERN.
70031
70032 -- Command: set-face-font face font &optional frame
70033     Change the font-related attributes of FACE to those of FONT (a
70034     string or a font object).  *Note face-font-attribute::, for the
70035     supported formats of the FONT argument.  This function sets the
70036     attribute ‘:font’ of the face, and indirectly also the ‘:family’,
70037     ‘:foundry’, ‘:width’, ‘:height’, ‘:weight’, and ‘:slant’
70038     attributes, as defined by the font.  If FRAME is non-‘nil’, only
70039     change the attributes on the specified frame.
70040
70041 -- Function: set-face-bold face bold-p &optional frame
70042     This sets the ‘:weight’ attribute of FACE to NORMAL if BOLD-P is
70043     ‘nil’, and to BOLD otherwise.
70044
70045 -- Function: set-face-italic face italic-p &optional frame
70046     This sets the ‘:slant’ attribute of FACE to NORMAL if ITALIC-P is
70047     ‘nil’, and to ITALIC otherwise.
70048
70049 -- Command: set-face-underline face underline &optional frame
70050     This sets the ‘:underline’ attribute of FACE to UNDERLINE.
70051
70052 -- Command: set-face-inverse-video face inverse-video-p &optional frame
70053     This sets the ‘:inverse-video’ attribute of FACE to
70054     INVERSE-VIDEO-P.
70055
70056 -- Command: invert-face face &optional frame
70057     This swaps the foreground and background colors of face FACE.
70058
70059 -- Command: set-face-extend face extend &optional frame
70060     This sets the ‘:extend’ attribute of FACE to EXTEND.
70061
70062   The following functions examine the attributes of a face.  They
70063mostly provide compatibility with old versions of Emacs.  If you don’t
70064specify FRAME, they refer to the selected frame; ‘t’ refers to the
70065default data for new frames.  They return ‘unspecified’ if the face
70066doesn’t define any value for that attribute.  If INHERIT is ‘nil’, only
70067an attribute directly defined by the face is returned.  If INHERIT is
70068non-‘nil’, any faces specified by its ‘:inherit’ attribute are
70069considered as well, and if INHERIT is a face or a list of faces, then
70070they are also considered, until a specified attribute is found.  To
70071ensure that the return value is always specified, use a value of
70072‘default’ for INHERIT.
70073
70074 -- Function: face-font face &optional frame character
70075     This function returns the name of the font of face FACE.
70076
70077     If the optional argument FRAME is specified, it returns the name of
70078     the font of FACE for that frame.  If FRAME is omitted or ‘nil’, the
70079     selected frame is used.  In the latter case, if the optional third
70080     argument CHARACTER is supplied, it returns the font name used for
70081     CHARACTER.
70082
70083 -- Function: face-foreground face &optional frame inherit
70084 -- Function: face-background face &optional frame inherit
70085     These functions return the foreground color (or background color,
70086     respectively) of face FACE, as a string.  If the color is
70087     unspecified, they return ‘nil’.
70088
70089 -- Function: face-stipple face &optional frame inherit
70090     This function returns the name of the background stipple pattern of
70091     face FACE, or ‘nil’ if it doesn’t have one.
70092
70093 -- Function: face-bold-p face &optional frame inherit
70094     This function returns a non-‘nil’ value if the ‘:weight’ attribute
70095     of FACE is bolder than normal (i.e., one of ‘semi-bold’, ‘bold’,
70096     ‘extra-bold’, or ‘ultra-bold’).  Otherwise, it returns ‘nil’.
70097
70098 -- Function: face-italic-p face &optional frame inherit
70099     This function returns a non-‘nil’ value if the ‘:slant’ attribute
70100     of FACE is ‘italic’ or ‘oblique’, and ‘nil’ otherwise.
70101
70102 -- Function: face-underline-p face &optional frame inherit
70103     This function returns non-‘nil’ if face FACE specifies a non-‘nil’
70104     ‘:underline’ attribute.
70105
70106 -- Function: face-inverse-video-p face &optional frame inherit
70107     This function returns non-‘nil’ if face FACE specifies a non-‘nil’
70108     ‘:inverse-video’ attribute.
70109
70110 -- Function: face-extend-p face &optional frame
70111     This function returns non-‘nil’ if face FACE specifies a non-‘nil’
70112     ‘:extend’ attribute.
70113
70114
70115File: elisp.info,  Node: Displaying Faces,  Next: Face Remapping,  Prev: Attribute Functions,  Up: Faces
70116
7011739.12.4 Displaying Faces
70118------------------------
70119
70120When Emacs displays a given piece of text, the visual appearance of the
70121text may be determined by faces drawn from different sources.  If these
70122various sources together specify more than one face for a particular
70123character, Emacs merges the attributes of the various faces.  Here is
70124the order in which Emacs merges the faces, from highest to lowest
70125priority:
70126
70127   • If the text consists of a special glyph, the glyph can specify a
70128     particular face.  *Note Glyphs::.
70129
70130   • If the text lies within an active region, Emacs highlights it using
70131     the ‘region’ face.  *Note (emacs)Standard Faces::.
70132
70133   • If the text lies within an overlay with a non-‘nil’ ‘face’
70134     property, Emacs applies the face(s) specified by that property.  If
70135     the overlay has a ‘mouse-face’ property and the mouse is near
70136     enough to the overlay, Emacs applies the face or face attributes
70137     specified by the ‘mouse-face’ property instead.  *Note Overlay
70138     Properties::.
70139
70140     When multiple overlays cover one character, an overlay with higher
70141     priority overrides those with lower priority.  *Note Overlays::.
70142
70143   • If the text contains a ‘face’ or ‘mouse-face’ property, Emacs
70144     applies the specified faces and face attributes.  *Note Special
70145     Properties::.  (This is how Font Lock mode faces are applied.
70146     *Note Font Lock Mode::.)
70147
70148   • If the text lies within the mode line of the selected window, Emacs
70149     applies the ‘mode-line’ face.  For the mode line of a non-selected
70150     window, Emacs applies the ‘mode-line-inactive’ face.  For a header
70151     line, Emacs applies the ‘header-line’ face.  For a tab line, Emacs
70152     applies the ‘tab-line’ face.
70153
70154   • If the text comes from an overlay string via ‘before-string’ or
70155     ‘after-string’ properties (*note Overlay Properties::), or from a
70156     display string (*note Other Display Specs::), and the string
70157     doesn’t contain a ‘face’ or ‘mouse-face’ property, or these
70158     properties leave some face attributes undefined, but the buffer
70159     text affected by the overlay/display property does define a face or
70160     those attributes, Emacs applies the face attributes of the
70161     “underlying” buffer text.  Note that this is so even if the overlay
70162     or display string is displayed in the display margins (*note
70163     Display Margins::).
70164
70165   • If any given attribute has not been specified during the preceding
70166     steps, Emacs applies the attribute of the ‘default’ face.
70167
70168   At each stage, if a face has a valid ‘:inherit’ attribute, Emacs
70169treats any attribute with an ‘unspecified’ value as having the
70170corresponding value drawn from the parent face(s).  *note Face
70171Attributes::.  Note that the parent face(s) may also leave the attribute
70172unspecified; in that case, the attribute remains unspecified at the next
70173level of face merging.
70174
70175
70176File: elisp.info,  Node: Face Remapping,  Next: Face Functions,  Prev: Displaying Faces,  Up: Faces
70177
7017839.12.5 Face Remapping
70179----------------------
70180
70181The variable ‘face-remapping-alist’ is used for buffer-local or global
70182changes in the appearance of a face.  For instance, it is used to
70183implement the ‘text-scale-adjust’ command (*note (emacs)Text Scale::).
70184
70185 -- Variable: face-remapping-alist
70186     The value of this variable is an alist whose elements have the form
70187     ‘(FACE . REMAPPING)’.  This causes Emacs to display any text having
70188     the face FACE with REMAPPING, rather than the ordinary definition
70189     of FACE.
70190
70191     REMAPPING may be any face spec suitable for a ‘face’ text property:
70192     either a face (i.e., a face name or a property list of
70193     attribute/value pairs), or a list of faces.  For details, see the
70194     description of the ‘face’ text property in *note Special
70195     Properties::.  REMAPPING serves as the complete specification for
70196     the remapped face—it replaces the normal definition of FACE,
70197     instead of modifying it.
70198
70199     If ‘face-remapping-alist’ is buffer-local, its local value takes
70200     effect only within that buffer.  If ‘face-remapping-alist’ includes
70201     faces applicable only to certain windows, by using the
70202     ‘(:filtered (:window PARAM VAL) SPEC)’, that face takes effect only
70203     in windows that match the filter conditions (*note Special
70204     Properties::).  To turn off face filtering temporarily, bind
70205     ‘face-filters-always-match’ to a non-‘nil’ value, then all face
70206     filters will match any window.
70207
70208     Note: face remapping is non-recursive.  If REMAPPING references the
70209     same face name FACE, either directly or via the ‘:inherit’
70210     attribute of some other face in REMAPPING, that reference uses the
70211     normal definition of FACE.  For instance, if the ‘mode-line’ face
70212     is remapped using this entry in ‘face-remapping-alist’:
70213
70214          (mode-line italic mode-line)
70215
70216     then the new definition of the ‘mode-line’ face inherits from the
70217     ‘italic’ face, and the _normal_ (non-remapped) definition of
70218     ‘mode-line’ face.
70219
70220   The following functions implement a higher-level interface to
70221‘face-remapping-alist’.  Most Lisp code should use these functions
70222instead of setting ‘face-remapping-alist’ directly, to avoid trampling
70223on remappings applied elsewhere.  These functions are intended for
70224buffer-local remappings, so they all make ‘face-remapping-alist’
70225buffer-local as a side-effect.  They manage ‘face-remapping-alist’
70226entries of the form
70227
70228       (FACE RELATIVE-SPEC-1 RELATIVE-SPEC-2 ... BASE-SPEC)
70229
70230where, as explained above, each of the RELATIVE-SPEC-N and BASE-SPEC is
70231either a face name, or a property list of attribute/value pairs.  Each
70232of the “relative remapping” entries, RELATIVE-SPEC-N, is managed by the
70233‘face-remap-add-relative’ and ‘face-remap-remove-relative’ functions;
70234these are intended for simple modifications like changing the text size.
70235The “base remapping” entry, BASE-SPEC, has the lowest priority and is
70236managed by the ‘face-remap-set-base’ and ‘face-remap-reset-base’
70237functions; it is intended for major modes to remap faces in the buffers
70238they control.
70239
70240 -- Function: face-remap-add-relative face &rest specs
70241     This function adds the face spec in SPECS as relative remappings
70242     for face FACE in the current buffer.  The remaining arguments,
70243     SPECS, should form either a list of face names, or a property list
70244     of attribute/value pairs.
70245
70246     The return value is a Lisp object that serves as a cookie; you can
70247     pass this object as an argument to ‘face-remap-remove-relative’ if
70248     you need to remove the remapping later.
70249
70250          ;; Remap the 'escape-glyph' face into a combination
70251          ;; of the 'highlight' and 'italic' faces:
70252          (face-remap-add-relative 'escape-glyph 'highlight 'italic)
70253
70254          ;; Increase the size of the 'default' face by 50%:
70255          (face-remap-add-relative 'default :height 1.5)
70256
70257 -- Function: face-remap-remove-relative cookie
70258     This function removes a relative remapping previously added by
70259     ‘face-remap-add-relative’.  COOKIE should be the Lisp object
70260     returned by ‘face-remap-add-relative’ when the remapping was added.
70261
70262 -- Function: face-remap-set-base face &rest specs
70263     This function sets the base remapping of FACE in the current buffer
70264     to SPECS.  If SPECS is empty, the default base remapping is
70265     restored, similar to calling ‘face-remap-reset-base’ (see below);
70266     note that this is different from SPECS containing a single value
70267     ‘nil’, which has the opposite result (the global definition of FACE
70268     is ignored).
70269
70270     This overwrites the default BASE-SPEC, which inherits the global
70271     face definition, so it is up to the caller to add such inheritance
70272     if so desired.
70273
70274 -- Function: face-remap-reset-base face
70275     This function sets the base remapping of FACE to its default value,
70276     which inherits from FACE’s global definition.
70277
70278
70279File: elisp.info,  Node: Face Functions,  Next: Auto Faces,  Prev: Face Remapping,  Up: Faces
70280
7028139.12.6 Functions for Working with Faces
70282----------------------------------------
70283
70284Here are additional functions for creating and working with faces.
70285
70286 -- Function: face-list
70287     This function returns a list of all defined face names.
70288
70289 -- Function: face-id face
70290     This function returns the “face number” of face FACE.  This is a
70291     number that uniquely identifies a face at low levels within Emacs.
70292     It is seldom necessary to refer to a face by its face number.
70293     However, functions that manipulate glyphs, such as
70294     ‘make-glyph-code’ and ‘glyph-face’ (*note Glyphs::) access the face
70295     numbers internally.  Note that the face number is stored as the
70296     value of the ‘face’ property of the face symbol, so we recommend
70297     not to set that property of a face to any value of your own.
70298
70299 -- Function: face-documentation face
70300     This function returns the documentation string of face FACE, or
70301     ‘nil’ if none was specified for it.
70302
70303 -- Function: face-equal face1 face2 &optional frame
70304     This returns ‘t’ if the faces FACE1 and FACE2 have the same
70305     attributes for display.
70306
70307 -- Function: face-differs-from-default-p face &optional frame
70308     This returns non-‘nil’ if the face FACE displays differently from
70309     the default face.
70310
70311   A “face alias” provides an equivalent name for a face.  You can
70312define a face alias by giving the alias symbol the ‘face-alias’
70313property, with a value of the target face name.  The following example
70314makes ‘modeline’ an alias for the ‘mode-line’ face.
70315
70316     (put 'modeline 'face-alias 'mode-line)
70317
70318 -- Macro: define-obsolete-face-alias obsolete-face current-face when
70319     This macro defines ‘obsolete-face’ as an alias for CURRENT-FACE,
70320     and also marks it as obsolete, indicating that it may be removed in
70321     future.  WHEN should be a string indicating when ‘obsolete-face’
70322     was made obsolete (usually a version number string).
70323
70324
70325File: elisp.info,  Node: Auto Faces,  Next: Basic Faces,  Prev: Face Functions,  Up: Faces
70326
7032739.12.7 Automatic Face Assignment
70328---------------------------------
70329
70330This hook is used for automatically assigning faces to text in the
70331buffer.  It is part of the implementation of Jit-Lock mode, used by
70332Font-Lock.
70333
70334 -- Variable: fontification-functions
70335     This variable holds a list of functions that are called by Emacs
70336     redisplay as needed, just before doing redisplay.  They are called
70337     even when Font Lock Mode isn’t enabled.  When Font Lock Mode is
70338     enabled, this variable usually holds just one function,
70339     ‘jit-lock-function’.
70340
70341     The functions are called in the order listed, with one argument, a
70342     buffer position POS.  Collectively they should attempt to assign
70343     faces to the text in the current buffer starting at POS.
70344
70345     The functions should record the faces they assign by setting the
70346     ‘face’ property.  They should also add a non-‘nil’ ‘fontified’
70347     property to all the text they have assigned faces to.  That
70348     property tells redisplay that faces have been assigned to that text
70349     already.
70350
70351     It is probably a good idea for the functions to do nothing if the
70352     character after POS already has a non-‘nil’ ‘fontified’ property,
70353     but this is not required.  If one function overrides the
70354     assignments made by a previous one, the properties after the last
70355     function finishes are the ones that really matter.
70356
70357     For efficiency, we recommend writing these functions so that they
70358     usually assign faces to around 400 to 600 characters at each call.
70359
70360
70361File: elisp.info,  Node: Basic Faces,  Next: Font Selection,  Prev: Auto Faces,  Up: Faces
70362
7036339.12.8 Basic Faces
70364-------------------
70365
70366If your Emacs Lisp program needs to assign some faces to text, it is
70367often a good idea to use certain existing faces or inherit from them,
70368rather than defining entirely new faces.  This way, if other users have
70369customized the basic faces to give Emacs a certain look, your program
70370will fit in without additional customization.
70371
70372   Some of the basic faces defined in Emacs are listed below.  In
70373addition to these, you might want to make use of the Font Lock faces for
70374syntactic highlighting, if highlighting is not already handled by Font
70375Lock mode, or if some Font Lock faces are not in use.  *Note Faces for
70376Font Lock::.
70377
70378‘default’
70379     The default face, whose attributes are all specified.  All other
70380     faces implicitly inherit from it: any unspecified attribute
70381     defaults to the attribute on this face (*note Face Attributes::).
70382
70383‘bold’
70384‘italic’
70385‘bold-italic’
70386‘underline’
70387‘fixed-pitch’
70388‘fixed-pitch-serif’
70389‘variable-pitch’
70390     These have the attributes indicated by their names (e.g., ‘bold’
70391     has a bold ‘:weight’ attribute), with all other attributes
70392     unspecified (and so given by ‘default’).
70393
70394‘shadow’
70395     For dimmed-out text.  For example, it is used for the ignored part
70396     of a filename in the minibuffer (*note Minibuffers for File Names:
70397     (emacs)Minibuffer File.).
70398
70399‘link’
70400‘link-visited’
70401     For clickable text buttons that send the user to a different buffer
70402     or location.
70403
70404‘highlight’
70405     For stretches of text that should temporarily stand out.  For
70406     example, it is commonly assigned to the ‘mouse-face’ property for
70407     cursor highlighting (*note Special Properties::).
70408
70409‘match’
70410‘isearch’
70411‘lazy-highlight’
70412     For text matching (respectively) permanent search matches,
70413     interactive search matches, and lazy highlighting other matches
70414     than the current interactive one.
70415
70416‘error’
70417‘warning’
70418‘success’
70419     For text concerning errors, warnings, or successes.  For example,
70420     these are used for messages in ‘*Compilation*’ buffers.
70421
70422
70423File: elisp.info,  Node: Font Selection,  Next: Font Lookup,  Prev: Basic Faces,  Up: Faces
70424
7042539.12.9 Font Selection
70426----------------------
70427
70428Before Emacs can draw a character on a graphical display, it must select
70429a “font” for that character(1).  *Note (emacs)Fonts::.  Normally, Emacs
70430automatically chooses a font based on the faces assigned to that
70431character—specifically, the face attributes ‘:family’, ‘:weight’,
70432‘:slant’, and ‘:width’ (*note Face Attributes::).  The choice of font
70433also depends on the character to be displayed; some fonts can only
70434display a limited set of characters.  If no available font exactly fits
70435the requirements, Emacs looks for the “closest matching font”.  The
70436variables in this section control how Emacs makes this selection.
70437
70438 -- User Option: face-font-family-alternatives
70439     If a given family is specified but does not exist, this variable
70440     specifies alternative font families to try.  Each element should
70441     have this form:
70442
70443          (FAMILY ALTERNATE-FAMILIES...)
70444
70445     If FAMILY is specified but not available, Emacs will try the other
70446     families given in ALTERNATE-FAMILIES, one by one, until it finds a
70447     family that does exist.
70448
70449 -- User Option: face-font-selection-order
70450     If there is no font that exactly matches all desired face
70451     attributes (‘:width’, ‘:height’, ‘:weight’, and ‘:slant’), this
70452     variable specifies the order in which these attributes should be
70453     considered when selecting the closest matching font.  The value
70454     should be a list containing those four attribute symbols, in order
70455     of decreasing importance.  The default is ‘(:width :height :weight
70456     :slant)’.
70457
70458     Font selection first finds the best available matches for the first
70459     attribute in the list; then, among the fonts which are best in that
70460     way, it searches for the best matches in the second attribute, and
70461     so on.
70462
70463     The attributes ‘:weight’ and ‘:width’ have symbolic values in a
70464     range centered around ‘normal’.  Matches that are more extreme
70465     (farther from ‘normal’) are somewhat preferred to matches that are
70466     less extreme (closer to ‘normal’); this is designed to ensure that
70467     non-normal faces contrast with normal ones, whenever possible.
70468
70469     One example of a case where this variable makes a difference is
70470     when the default font has no italic equivalent.  With the default
70471     ordering, the ‘italic’ face will use a non-italic font that is
70472     similar to the default one.  But if you put ‘:slant’ before
70473     ‘:height’, the ‘italic’ face will use an italic font, even if its
70474     height is not quite right.
70475
70476 -- User Option: face-font-registry-alternatives
70477     This variable lets you specify alternative font registries to try,
70478     if a given registry is specified and doesn’t exist.  Each element
70479     should have this form:
70480
70481          (REGISTRY ALTERNATE-REGISTRIES...)
70482
70483     If REGISTRY is specified but not available, Emacs will try the
70484     other registries given in ALTERNATE-REGISTRIES, one by one, until
70485     it finds a registry that does exist.
70486
70487   Emacs can make use of scalable fonts, but by default it does not use
70488them.
70489
70490 -- User Option: scalable-fonts-allowed
70491     This variable controls which scalable fonts to use.  A value of
70492     ‘nil’, the default, means do not use scalable fonts.  ‘t’ means to
70493     use any scalable font that seems appropriate for the text.
70494
70495     Otherwise, the value must be a list of regular expressions.  Then a
70496     scalable font is enabled for use if its name matches any regular
70497     expression in the list.  For example,
70498
70499          (setq scalable-fonts-allowed '("iso10646-1$"))
70500
70501     allows the use of scalable fonts with registry ‘iso10646-1’.
70502
70503 -- Variable: face-font-rescale-alist
70504     This variable specifies scaling for certain faces.  Its value
70505     should be a list of elements of the form
70506
70507          (FONTNAME-REGEXP . SCALE-FACTOR)
70508
70509     If FONTNAME-REGEXP matches the font name that is about to be used,
70510     this says to choose a larger similar font according to the factor
70511     SCALE-FACTOR.  You would use this feature to normalize the font
70512     size if certain fonts are bigger or smaller than their nominal
70513     heights and widths would suggest.
70514
70515   ---------- Footnotes ----------
70516
70517   (1) In this context, the term “font” has nothing to do with Font Lock
70518(*note Font Lock Mode::).
70519
70520
70521File: elisp.info,  Node: Font Lookup,  Next: Fontsets,  Prev: Font Selection,  Up: Faces
70522
7052339.12.10 Looking Up Fonts
70524-------------------------
70525
70526 -- Function: x-list-fonts name &optional reference-face frame maximum
70527          width
70528     This function returns a list of available font names that match
70529     NAME.  NAME should be a string containing a font name in either the
70530     Fontconfig, GTK+, or XLFD format (*note (emacs)Fonts::).  Within an
70531     XLFD string, wildcard characters may be used: the ‘*’ character
70532     matches any substring, and the ‘?’ character matches any single
70533     character.  Case is ignored when matching font names.
70534
70535     If the optional arguments REFERENCE-FACE and FRAME are specified,
70536     the returned list includes only fonts that are the same size as
70537     REFERENCE-FACE (a face name) currently is on the frame FRAME.
70538
70539     The optional argument MAXIMUM sets a limit on how many fonts to
70540     return.  If it is non-‘nil’, then the return value is truncated
70541     after the first MAXIMUM matching fonts.  Specifying a small value
70542     for MAXIMUM can make this function much faster, in cases where many
70543     fonts match the pattern.
70544
70545     The optional argument WIDTH specifies a desired font width.  If it
70546     is non-‘nil’, the function only returns those fonts whose
70547     characters are (on average) WIDTH times as wide as REFERENCE-FACE.
70548
70549 -- Function: x-family-fonts &optional family frame
70550     This function returns a list describing the available fonts for
70551     family FAMILY on FRAME.  If FAMILY is omitted or ‘nil’, this list
70552     applies to all families, and therefore, it contains all available
70553     fonts.  Otherwise, FAMILY must be a string; it may contain the
70554     wildcards ‘?’ and ‘*’.
70555
70556     The list describes the display that FRAME is on; if FRAME is
70557     omitted or ‘nil’, it applies to the selected frame’s display (*note
70558     Input Focus::).
70559
70560     Each element in the list is a vector of the following form:
70561
70562          [FAMILY WIDTH POINT-SIZE WEIGHT SLANT
70563           FIXED-P FULL REGISTRY-AND-ENCODING]
70564
70565     The first five elements correspond to face attributes; if you
70566     specify these attributes for a face, it will use this font.
70567
70568     The last three elements give additional information about the font.
70569     FIXED-P is non-‘nil’ if the font is fixed-pitch.  FULL is the full
70570     name of the font, and REGISTRY-AND-ENCODING is a string giving the
70571     registry and encoding of the font.
70572
70573
70574File: elisp.info,  Node: Fontsets,  Next: Low-Level Font,  Prev: Font Lookup,  Up: Faces
70575
7057639.12.11 Fontsets
70577-----------------
70578
70579A “fontset” is a list of fonts, each assigned to a range of character
70580codes.  An individual font cannot display the whole range of characters
70581that Emacs supports, but a fontset can.  Fontsets have names, just as
70582fonts do, and you can use a fontset name in place of a font name when
70583you specify the font for a frame or a face.  Here is information about
70584defining a fontset under Lisp program control.
70585
70586 -- Function: create-fontset-from-fontset-spec fontset-spec &optional
70587          style-variant-p noerror
70588     This function defines a new fontset according to the specification
70589     string FONTSET-SPEC.  The string should have this format:
70590
70591          FONTPATTERN, [CHARSET:FONT]...
70592
70593     Whitespace characters before and after the commas are ignored.
70594
70595     The first part of the string, FONTPATTERN, should have the form of
70596     a standard X font name, except that the last two fields should be
70597     ‘fontset-ALIAS’.
70598
70599     The new fontset has two names, one long and one short.  The long
70600     name is FONTPATTERN in its entirety.  The short name is
70601     ‘fontset-ALIAS’.  You can refer to the fontset by either name.  If
70602     a fontset with the same name already exists, an error is signaled,
70603     unless NOERROR is non-‘nil’, in which case this function does
70604     nothing.
70605
70606     If optional argument STYLE-VARIANT-P is non-‘nil’, that says to
70607     create bold, italic and bold-italic variants of the fontset as
70608     well.  These variant fontsets do not have a short name, only a long
70609     one, which is made by altering FONTPATTERN to indicate the bold
70610     and/or italic status.
70611
70612     The specification string also says which fonts to use in the
70613     fontset.  See below for the details.
70614
70615   The construct ‘CHARSET:FONT’ specifies which font to use (in this
70616fontset) for one particular character set.  Here, CHARSET is the name of
70617a character set, and FONT is the font to use for that character set.
70618You can use this construct any number of times in the specification
70619string.
70620
70621   For the remaining character sets, those that you don’t specify
70622explicitly, Emacs chooses a font based on FONTPATTERN: it replaces
70623‘fontset-ALIAS’ with a value that names one character set.  For the
70624ASCII character set, ‘fontset-ALIAS’ is replaced with ‘ISO8859-1’.
70625
70626   In addition, when several consecutive fields are wildcards, Emacs
70627collapses them into a single wildcard.  This is to prevent use of
70628auto-scaled fonts.  Fonts made by scaling larger fonts are not usable
70629for editing, and scaling a smaller font is not useful because it is
70630better to use the smaller font in its own size, which Emacs does.
70631
70632   Thus if FONTPATTERN is this,
70633
70634     -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24
70635
70636the font specification for ASCII characters would be this:
70637
70638     -*-fixed-medium-r-normal-*-24-*-ISO8859-1
70639
70640and the font specification for Chinese GB2312 characters would be this:
70641
70642     -*-fixed-medium-r-normal-*-24-*-gb2312*-*
70643
70644   You may not have any Chinese font matching the above font
70645specification.  Most X distributions include only Chinese fonts that
70646have ‘song ti’ or ‘fangsong ti’ in the FAMILY field.  In such a case,
70647‘Fontset-N’ can be specified as below:
70648
70649     Emacs.Fontset-0: -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24,\
70650             chinese-gb2312:-*-*-medium-r-normal-*-24-*-gb2312*-*
70651
70652Then, the font specifications for all but Chinese GB2312 characters have
70653‘fixed’ in the FAMILY field, and the font specification for Chinese
70654GB2312 characters has a wild card ‘*’ in the FAMILY field.
70655
70656 -- Function: set-fontset-font name character font-spec &optional frame
70657          add
70658     This function modifies the existing fontset NAME to use the font
70659     matching with FONT-SPEC for the specified CHARACTER.
70660
70661     If NAME is ‘nil’, this function modifies the fontset of the
70662     selected frame or that of FRAME if FRAME is not ‘nil’.
70663
70664     If NAME is ‘t’, this function modifies the default fontset, whose
70665     short name is ‘fontset-default’.
70666
70667     In addition to specifying a single codepoint, CHARACTER may be a
70668     cons ‘(FROM . TO)’, where FROM and TO are character codepoints.  In
70669     that case, use FONT-SPEC for all the characters in the range FROM
70670     and TO (inclusive).
70671
70672     CHARACTER may be a charset (*note Character Sets::).  In that case,
70673     use FONT-SPEC for all the characters in the charset.
70674
70675     CHARACTER may be a script name (*note char-script-table: Character
70676     Properties.).  In that case, use FONT-SPEC for all the characters
70677     belonging to the script.
70678
70679     CHARACTER may be ‘nil’, which means to use FONT-SPEC for any
70680     character which no font-spec is specified.
70681
70682     FONT-SPEC may be a font-spec object created by the function
70683     ‘font-spec’ (*note Low-Level Font::).
70684
70685     FONT-SPEC may be a cons; ‘(FAMILY . REGISTRY)’, where FAMILY is a
70686     family name of a font (possibly including a foundry name at the
70687     head), REGISTRY is a registry name of a font (possibly including an
70688     encoding name at the tail).
70689
70690     FONT-SPEC may be a font name, a string.
70691
70692     FONT-SPEC may be ‘nil’, which explicitly specifies that there’s no
70693     font for the specified CHARACTER.  This is useful, for example, to
70694     avoid expensive system-wide search for fonts for characters that
70695     have no glyphs, like those from the Unicode Private Use Area (PUA).
70696
70697     The optional argument ADD, if non-‘nil’, specifies how to add
70698     FONT-SPEC to the font specifications previously set.  If it is
70699     ‘prepend’, FONT-SPEC is prepended.  If it is ‘append’, FONT-SPEC is
70700     appended.  By default, FONT-SPEC overrides the previous settings.
70701
70702     For instance, this changes the default fontset to use a font of
70703     which family name is ‘Kochi Gothic’ for all characters belonging to
70704     the charset ‘japanese-jisx0208’.
70705
70706          (set-fontset-font t 'japanese-jisx0208
70707                            (font-spec :family "Kochi Gothic"))
70708
70709 -- Function: char-displayable-p char
70710     This function returns ‘t’ if Emacs ought to be able to display
70711     CHAR.  More precisely, if the selected frame’s fontset has a font
70712     to display the character set that CHAR belongs to.
70713
70714     Fontsets can specify a font on a per-character basis; when the
70715     fontset does that, this function’s value may not be accurate.
70716
70717
70718File: elisp.info,  Node: Low-Level Font,  Prev: Fontsets,  Up: Faces
70719
7072039.12.12 Low-Level Font Representation
70721--------------------------------------
70722
70723Normally, it is not necessary to manipulate fonts directly.  In case you
70724need to do so, this section explains how.
70725
70726   In Emacs Lisp, fonts are represented using three different Lisp
70727object types: “font objects”, “font specs”, and “font entities”.
70728
70729 -- Function: fontp object &optional type
70730     Return ‘t’ if OBJECT is a font object, font spec, or font entity.
70731     Otherwise, return ‘nil’.
70732
70733     The optional argument TYPE, if non-‘nil’, determines the exact type
70734     of Lisp object to check for.  In that case, TYPE should be one of
70735     ‘font-object’, ‘font-spec’, or ‘font-entity’.
70736
70737   A font object is a Lisp object that represents a font that Emacs has
70738“opened”.  Font objects cannot be modified in Lisp, but they can be
70739inspected.
70740
70741 -- Function: font-at position &optional window string
70742     Return the font object that is being used to display the character
70743     at position POSITION in the window WINDOW.  If WINDOW is ‘nil’, it
70744     defaults to the selected window.  If STRING is ‘nil’, POSITION
70745     specifies a position in the current buffer; otherwise, STRING
70746     should be a string, and POSITION specifies a position in that
70747     string.
70748
70749   A font spec is a Lisp object that contains a set of specifications
70750that can be used to find a font.  More than one font may match the
70751specifications in a font spec.
70752
70753 -- Function: font-spec &rest arguments
70754     Return a new font spec using the specifications in ARGUMENTS, which
70755     should come in ‘property’-‘value’ pairs.  The possible
70756     specifications are as follows:
70757
70758     ‘:name’
70759          The font name (a string), in either XLFD, Fontconfig, or GTK+
70760          format.  *Note (emacs)Fonts::.
70761
70762     ‘:family’
70763     ‘:foundry’
70764     ‘:weight’
70765     ‘:slant’
70766     ‘:width’
70767          These have the same meanings as the face attributes of the
70768          same name.  *Note Face Attributes::.  ‘:family’ and ‘:foundry’
70769          are strings, while the other three are symbols.  As example
70770          values, ‘:slant’ may be ‘italic’, ‘:weight’ may be ‘bold’ and
70771          ‘:width’ may be ‘normal’.
70772
70773     ‘:size’
70774          The font size—either a non-negative integer that specifies the
70775          pixel size, or a floating-point number that specifies the
70776          point size.
70777
70778     ‘:adstyle’
70779          Additional typographic style information for the font, such as
70780          ‘sans’.  The value should be a string or a symbol.
70781
70782     ‘:registry’
70783          The charset registry and encoding of the font, such as
70784          ‘iso8859-1’.  The value should be a string or a symbol.
70785
70786     ‘:dpi’
70787          The resolution in dots per inch for which the font is
70788          designed.  The value must be a non-negative number.
70789
70790     ‘:spacing’
70791          The spacing of the font: proportional, dual, mono, or
70792          charcell.  The value should be either an integer (0 for
70793          proportional, 90 for dual, 100 for mono, 110 for charcell) or
70794          a one-letter symbol (one of ‘P’, ‘D’, ‘M’, or ‘C’).
70795
70796     ‘:avgwidth’
70797          The average width of the font in 1/10 pixel units.  The value
70798          should be a non-negative number.
70799
70800     ‘:script’
70801          The script that the font must support (a symbol).
70802
70803     ‘:lang’
70804          The language that the font should support.  The value should
70805          be a symbol whose name is a two-letter ISO-639 language name.
70806          On X, the value is matched against the “Additional Style”
70807          field of the XLFD name of a font, if it is non-empty.  On
70808          MS-Windows, fonts matching the spec are required to support
70809          codepages needed for the language.  Currently, only a small
70810          set of CJK languages is supported with this property: ‘ja’,
70811          ‘ko’, and ‘zh’.
70812
70813     ‘:otf’
70814          The font must be an OpenType font that supports these OpenType
70815          features, provided Emacs is compiled with a library, such as
70816          ‘libotf’ on GNU/Linux, that supports complex text layout for
70817          scripts which need that.  The value must be a list of the form
70818
70819               (SCRIPT-TAG LANGSYS-TAG GSUB GPOS)
70820
70821          where SCRIPT-TAG is the OpenType script tag symbol;
70822          LANGSYS-TAG is the OpenType language system tag symbol, or
70823          ‘nil’ to use the default language system; ‘gsub’ is a list of
70824          OpenType GSUB feature tag symbols, or ‘nil’ if none is
70825          required; and ‘gpos’ is a list of OpenType GPOS feature tag
70826          symbols, or ‘nil’ if none is required.  If ‘gsub’ or ‘gpos’ is
70827          a list, a ‘nil’ element in that list means that the font must
70828          not match any of the remaining tag symbols.  The ‘gpos’
70829          element may be omitted.
70830
70831 -- Function: font-put font-spec property value
70832     Set the font property PROPERTY in the font-spec FONT-SPEC to VALUE.
70833
70834   A font entity is a reference to a font that need not be open.  Its
70835properties are intermediate between a font object and a font spec: like
70836a font object, and unlike a font spec, it refers to a single, specific
70837font.  Unlike a font object, creating a font entity does not load the
70838contents of that font into computer memory.  Emacs may open multiple
70839font objects of different sizes from a single font entity referring to a
70840scalable font.
70841
70842 -- Function: find-font font-spec &optional frame
70843     This function returns a font entity that best matches the font spec
70844     FONT-SPEC on frame FRAME.  If FRAME is ‘nil’, it defaults to the
70845     selected frame.
70846
70847 -- Function: list-fonts font-spec &optional frame num prefer
70848     This function returns a list of all font entities that match the
70849     font spec FONT-SPEC.
70850
70851     The optional argument FRAME, if non-‘nil’, specifies the frame on
70852     which the fonts are to be displayed.  The optional argument NUM, if
70853     non-‘nil’, should be an integer that specifies the maximum length
70854     of the returned list.  The optional argument PREFER, if non-‘nil’,
70855     should be another font spec, which is used to control the order of
70856     the returned list; the returned font entities are sorted in order
70857     of decreasing closeness to that font spec.
70858
70859   If you call ‘set-face-attribute’ and pass a font spec, font entity,
70860or font name string as the value of the ‘:font’ attribute, Emacs opens
70861the best matching font that is available for display.  It then stores
70862the corresponding font object as the actual value of the ‘:font’
70863attribute for that face.
70864
70865   The following functions can be used to obtain information about a
70866font.  For these functions, the FONT argument can be a font object, a
70867font entity, or a font spec.
70868
70869 -- Function: font-get font property
70870     This function returns the value of the font property PROPERTY for
70871     FONT.
70872
70873     If FONT is a font spec and the font spec does not specify PROPERTY,
70874     the return value is ‘nil’.  If FONT is a font object or font
70875     entity, the value for the :SCRIPT property may be a list of scripts
70876     supported by the font.
70877
70878 -- Function: font-face-attributes font &optional frame
70879     This function returns a list of face attributes corresponding to
70880     FONT.  The optional argument FRAME specifies the frame on which the
70881     font is to be displayed.  If it is ‘nil’, the selected frame is
70882     used.  The return value has the form
70883
70884          (:family FAMILY :height HEIGHT :weight WEIGHT
70885             :slant SLANT :width WIDTH)
70886
70887     where the values of FAMILY, HEIGHT, WEIGHT, SLANT, and WIDTH are
70888     face attribute values.  Some of these key-attribute pairs may be
70889     omitted from the list if they are not specified by FONT.
70890
70891 -- Function: font-xlfd-name font &optional fold-wildcards
70892     This function returns the XLFD (X Logical Font Descriptor), a
70893     string, matching FONT.  *Note (emacs)Fonts::, for information about
70894     XLFDs.  If the name is too long for an XLFD (which can contain at
70895     most 255 characters), the function returns ‘nil’.
70896
70897     If the optional argument FOLD-WILDCARDS is non-‘nil’, consecutive
70898     wildcards in the XLFD are folded into one.
70899
70900   The following two functions return important information about a
70901font.
70902
70903 -- Function: font-info name &optional frame
70904     This function returns information about a font specified by its
70905     NAME, a string, as it is used on FRAME.  If FRAME is omitted or
70906     ‘nil’, it defaults to the selected frame.
70907
70908     The value returned by the function is a vector of the form
70909     ‘[OPENED-NAME FULL-NAME SIZE HEIGHT BASELINE-OFFSET
70910     RELATIVE-COMPOSE DEFAULT-ASCENT MAX-WIDTH ASCENT DESCENT
70911     SPACE-WIDTH AVERAGE-WIDTH FILENAME CAPABILITY]’.  Here’s the
70912     description of each components of this vector:
70913
70914     OPENED-NAME
70915          The name used to open the font, a string.
70916
70917     FULL-NAME
70918          The full name of the font, a string.
70919
70920     SIZE
70921          The pixel size of the font.
70922
70923     HEIGHT
70924          The height of the font in pixels.
70925
70926     BASELINE-OFFSET
70927          The offset in pixels from the ASCII baseline, positive upward.
70928
70929     RELATIVE-COMPOSE
70930     DEFAULT-ASCENT
70931          Numbers controlling how to compose characters.
70932
70933     MAX-WIDTH
70934          The maximum advance width of the font.
70935
70936     ASCENT
70937     DESCENT
70938          The ascent and descent of this font.  The sum of these two
70939          numbers should be equal to the value of HEIGHT above.
70940
70941     SPACE-WIDTH
70942          The width, in pixels, of the font’s space character.
70943
70944     AVERAGE-WIDTH
70945          The average width of the font characters.  If this is zero,
70946          Emacs uses the value of SPACE-WIDTH instead, when it
70947          calculates text layout on display.
70948
70949     FILENAME
70950          The file name of the font as a string.  This can be ‘nil’ if
70951          the font back-end does not provide a way to find out the
70952          font’s file name.
70953
70954     CAPABILITY
70955          A list whose first element is a symbol representing the font
70956          type, one of ‘x’, ‘opentype’, ‘truetype’, ‘type1’, ‘pcf’, or
70957          ‘bdf’.  For OpenType fonts, the list includes 2 additional
70958          elements describing the GSUB and GPOS features supported by
70959          the font.  Each of these elements is a list of the form
70960          ‘((SCRIPT (LANGSYS FEATURE ...) ...) ...)’, where SCRIPT is a
70961          symbol representing an OpenType script tag, LANGSYS is a
70962          symbol representing an OpenType langsys tag (or ‘nil’, which
70963          stands for the default langsys), and each FEATURE is a symbol
70964          representing an OpenType feature tag.
70965
70966 -- Function: query-font font-object
70967     This function returns information about a FONT-OBJECT.  (This is in
70968     contrast to ‘font-info’, which takes the font name, a string, as
70969     its argument.)
70970
70971     The value returned by the function is a vector of the form ‘[NAME
70972     FILENAME PIXEL-SIZE MAX-WIDTH ASCENT DESCENT SPACE-WIDTH
70973     AVERAGE-WIDTH CAPABILITY]’.  Here’s the description of each
70974     components of this vector:
70975
70976     NAME
70977          The font name, a string.
70978
70979     FILENAME
70980          The file name of the font as a string.  This can be ‘nil’ if
70981          the font back-end does not provide a way to find out the
70982          font’s file name.
70983
70984     PIXEL-SIZE
70985          The pixel size of the font used to open the font.
70986
70987     MAX-WIDTH
70988          The maximum advance width of the font.
70989
70990     ASCENT
70991     DESCENT
70992          The ascent and descent of this font.  The sum of these two
70993          numbers gives the font height.
70994
70995     SPACE-WIDTH
70996          The width, in pixels, of the font’s space character.
70997
70998     AVERAGE-WIDTH
70999          The average width of the font characters.  If this is zero,
71000          Emacs uses the value of SPACE-WIDTH instead, when it
71001          calculates text layout on display.
71002
71003     CAPABILITY
71004          A list whose first element is a symbol representing the font
71005          type, one of ‘x’, ‘opentype’, ‘truetype’, ‘type1’, ‘pcf’, or
71006          ‘bdf’.  For OpenType fonts, the list includes 2 additional
71007          elements describing the GSUB and GPOS features supported by
71008          the font.  Each of these elements is a list of the form
71009          ‘((SCRIPT (LANGSYS FEATURE ...) ...) ...)’, where SCRIPT is a
71010          symbol representing an OpenType script tag, LANGSYS is a
71011          symbol representing an OpenType langsys tag (or ‘nil’, which
71012          stands for the default langsys), and each FEATURE is a symbol
71013          representing an OpenType feature tag.
71014
71015   The following four functions return size information about fonts used
71016by various faces, allowing various layout considerations in Lisp
71017programs.  These functions take face remapping into consideration,
71018returning information about the remapped face, if the face in question
71019was remapped.  *Note Face Remapping::.
71020
71021 -- Function: default-font-width
71022     This function returns the average width in pixels of the font used
71023     by the current buffer’s default face, as that face is defined for
71024     the selected frame.
71025
71026 -- Function: default-font-height
71027     This function returns the height in pixels of the font used by the
71028     current buffer’s default face, as that face is defined for the
71029     selected frame.
71030
71031 -- Function: window-font-width &optional window face
71032     This function returns the average width in pixels for the font used
71033     by FACE in WINDOW.  The specified WINDOW must be a live window.  If
71034     ‘nil’ or omitted, WINDOW defaults to the selected window, and FACE
71035     defaults to the default face in WINDOW.
71036
71037 -- Function: window-font-height &optional window face
71038     This function returns the height in pixels for the font used by
71039     FACE in WINDOW.  The specified WINDOW must be a live window.  If
71040     ‘nil’ or omitted, WINDOW defaults to the selected window, and FACE
71041     defaults to the default face in WINDOW.
71042
71043
71044File: elisp.info,  Node: Fringes,  Next: Scroll Bars,  Prev: Faces,  Up: Display
71045
7104639.13 Fringes
71047=============
71048
71049On graphical displays, Emacs draws “fringes” next to each window: thin
71050vertical strips down the sides which can display bitmaps indicating
71051truncation, continuation, horizontal scrolling, and so on.
71052
71053* Menu:
71054
71055* Fringe Size/Pos::     Specifying where to put the window fringes.
71056* Fringe Indicators::   Displaying indicator icons in the window fringes.
71057* Fringe Cursors::      Displaying cursors in the right fringe.
71058* Fringe Bitmaps::      Specifying bitmaps for fringe indicators.
71059* Customizing Bitmaps:: Specifying your own bitmaps to use in the fringes.
71060* Overlay Arrow::       Display of an arrow to indicate position.
71061
71062
71063File: elisp.info,  Node: Fringe Size/Pos,  Next: Fringe Indicators,  Up: Fringes
71064
7106539.13.1 Fringe Size and Position
71066--------------------------------
71067
71068The following buffer-local variables control the position and width of
71069fringes in windows showing that buffer.
71070
71071 -- Variable: fringes-outside-margins
71072     The fringes normally appear between the display margins and the
71073     window text.  If the value is non-‘nil’, they appear outside the
71074     display margins.  *Note Display Margins::.
71075
71076 -- Variable: left-fringe-width
71077     This variable, if non-‘nil’, specifies the width of the left fringe
71078     in pixels.  A value of ‘nil’ means to use the left fringe width
71079     from the window’s frame.
71080
71081 -- Variable: right-fringe-width
71082     This variable, if non-‘nil’, specifies the width of the right
71083     fringe in pixels.  A value of ‘nil’ means to use the right fringe
71084     width from the window’s frame.
71085
71086   Any buffer which does not specify values for these variables uses the
71087values specified by the ‘left-fringe’ and ‘right-fringe’ frame
71088parameters (*note Layout Parameters::).
71089
71090   The above variables actually take effect via the function
71091‘set-window-buffer’ (*note Buffers and Windows::), which calls
71092‘set-window-fringes’ as a subroutine.  If you change one of these
71093variables, the fringe display is not updated in existing windows showing
71094the buffer, unless you call ‘set-window-buffer’ again in each affected
71095window.  You can also use ‘set-window-fringes’ to control the fringe
71096display in individual windows.
71097
71098 -- Function: set-window-fringes window left &optional right
71099          outside-margins persistent
71100     This function sets the fringe widths of window WINDOW.  If WINDOW
71101     is ‘nil’, the selected window is used.
71102
71103     The argument LEFT specifies the width in pixels of the left fringe,
71104     and likewise RIGHT for the right fringe.  A value of ‘nil’ for
71105     either one stands for the default width.  If OUTSIDE-MARGINS is
71106     non-‘nil’, that specifies that fringes should appear outside of the
71107     display margins.
71108
71109     If WINDOW is not large enough to accommodate fringes of the desired
71110     width, this leaves the fringes of WINDOW unchanged.
71111
71112     The values specified here may be later overridden by invoking
71113     ‘set-window-buffer’ (*note Buffers and Windows::) on WINDOW with
71114     its KEEP-MARGINS argument ‘nil’ or omitted.  However, if the
71115     optional fifth argument PERSISTENT is non-‘nil’ and the other
71116     arguments are processed successfully, the values specified here
71117     unconditionally survive subsequent invocations of
71118     ‘set-window-buffer’.  This can be used to permanently turn off
71119     fringes in the minibuffer window, consult the description of
71120     ‘set-window-scroll-bars’ for an example (*note Scroll Bars::).
71121
71122 -- Function: window-fringes &optional window
71123     This function returns information about the fringes of a window
71124     WINDOW.  If WINDOW is omitted or ‘nil’, the selected window is
71125     used.  The value has the form ‘(LEFT-WIDTH RIGHT-WIDTH
71126     OUTSIDE-MARGINS PERSISTENT)’.
71127
71128
71129File: elisp.info,  Node: Fringe Indicators,  Next: Fringe Cursors,  Prev: Fringe Size/Pos,  Up: Fringes
71130
7113139.13.2 Fringe Indicators
71132-------------------------
71133
71134“Fringe indicators” are tiny icons displayed in the window fringe to
71135indicate truncated or continued lines, buffer boundaries, etc.
71136
71137 -- User Option: indicate-empty-lines
71138     When this is non-‘nil’, Emacs displays a special glyph in the
71139     fringe of each empty line at the end of the buffer, on graphical
71140     displays.  *Note Fringes::.  This variable is automatically
71141     buffer-local in every buffer.
71142
71143 -- User Option: indicate-buffer-boundaries
71144     This buffer-local variable controls how the buffer boundaries and
71145     window scrolling are indicated in the window fringes.
71146
71147     Emacs can indicate the buffer boundaries—that is, the first and
71148     last line in the buffer—with angle icons when they appear on the
71149     screen.  In addition, Emacs can display an up-arrow in the fringe
71150     to show that there is text above the screen, and a down-arrow to
71151     show there is text below the screen.
71152
71153     There are three kinds of basic values:
71154
71155     ‘nil’
71156          Don’t display any of these fringe icons.
71157     ‘left’
71158          Display the angle icons and arrows in the left fringe.
71159     ‘right’
71160          Display the angle icons and arrows in the right fringe.
71161     any non-alist
71162          Display the angle icons in the left fringe and don’t display
71163          the arrows.
71164
71165     Otherwise the value should be an alist that specifies which fringe
71166     indicators to display and where.  Each element of the alist should
71167     have the form ‘(INDICATOR . POSITION)’.  Here, INDICATOR is one of
71168     ‘top’, ‘bottom’, ‘up’, ‘down’, and ‘t’ (which covers all the icons
71169     not yet specified), while POSITION is one of ‘left’, ‘right’ and
71170     ‘nil’.
71171
71172     For example, ‘((top . left) (t . right))’ places the top angle
71173     bitmap in left fringe, and the bottom angle bitmap as well as both
71174     arrow bitmaps in right fringe.  To show the angle bitmaps in the
71175     left fringe, and no arrow bitmaps, use ‘((top . left) (bottom .
71176     left))’.
71177
71178 -- Variable: fringe-indicator-alist
71179     This buffer-local variable specifies the mapping from logical
71180     fringe indicators to the actual bitmaps displayed in the window
71181     fringes.  The value is an alist of elements ‘(INDICATOR .
71182     BITMAPS)’, where INDICATOR specifies a logical indicator type and
71183     BITMAPS specifies the fringe bitmaps to use for that indicator.
71184
71185     Each INDICATOR should be one of the following symbols:
71186
71187     ‘truncation’, ‘continuation’.
71188          Used for truncation and continuation lines.
71189
71190     ‘up’, ‘down’, ‘top’, ‘bottom’, ‘top-bottom’
71191          Used when ‘indicate-buffer-boundaries’ is non-‘nil’: ‘up’ and
71192          ‘down’ indicate a buffer boundary lying above or below the
71193          window edge; ‘top’ and ‘bottom’ indicate the topmost and
71194          bottommost buffer text line; and ‘top-bottom’ indicates where
71195          there is just one line of text in the buffer.
71196
71197     ‘empty-line’
71198          Used to indicate empty lines after the buffer end when
71199          ‘indicate-empty-lines’ is non-‘nil’.
71200
71201     ‘overlay-arrow’
71202          Used for overlay arrows (*note Overlay Arrow::).
71203
71204     Each BITMAPS value may be a list of symbols ‘(LEFT RIGHT [LEFT1
71205     RIGHT1])’.  The LEFT and RIGHT symbols specify the bitmaps shown in
71206     the left and/or right fringe, for the specific indicator.  LEFT1
71207     and RIGHT1 are specific to the ‘bottom’ and ‘top-bottom’
71208     indicators, and are used to indicate that the last text line has no
71209     final newline.  Alternatively, BITMAPS may be a single symbol which
71210     is used in both left and right fringes.
71211
71212     *Note Fringe Bitmaps::, for a list of standard bitmap symbols and
71213     how to define your own.  In addition, ‘nil’ represents the empty
71214     bitmap (i.e., an indicator that is not shown).
71215
71216     When ‘fringe-indicator-alist’ has a buffer-local value, and there
71217     is no bitmap defined for a logical indicator, or the bitmap is ‘t’,
71218     the corresponding value from the default value of
71219     ‘fringe-indicator-alist’ is used.
71220
71221
71222File: elisp.info,  Node: Fringe Cursors,  Next: Fringe Bitmaps,  Prev: Fringe Indicators,  Up: Fringes
71223
7122439.13.3 Fringe Cursors
71225----------------------
71226
71227When a line is exactly as wide as the window, Emacs displays the cursor
71228in the right fringe instead of using two lines.  Different bitmaps are
71229used to represent the cursor in the fringe depending on the current
71230buffer’s cursor type.
71231
71232 -- User Option: overflow-newline-into-fringe
71233     If this is non-‘nil’, lines exactly as wide as the window (not
71234     counting the final newline character) are not continued.  Instead,
71235     when point is at the end of the line, the cursor appears in the
71236     right fringe.
71237
71238 -- Variable: fringe-cursor-alist
71239     This variable specifies the mapping from logical cursor type to the
71240     actual fringe bitmaps displayed in the right fringe.  The value is
71241     an alist where each element has the form ‘(CURSOR-TYPE . BITMAP)’,
71242     which means to use the fringe bitmap BITMAP to display cursors of
71243     type CURSOR-TYPE.
71244
71245     Each CURSOR-TYPE should be one of ‘box’, ‘hollow’, ‘bar’, ‘hbar’,
71246     or ‘hollow-small’.  The first four have the same meanings as in the
71247     ‘cursor-type’ frame parameter (*note Cursor Parameters::).  The
71248     ‘hollow-small’ type is used instead of ‘hollow’ when the normal
71249     ‘hollow-rectangle’ bitmap is too tall to fit on a specific display
71250     line.
71251
71252     Each BITMAP should be a symbol specifying the fringe bitmap to be
71253     displayed for that logical cursor type.  *Note Fringe Bitmaps::.
71254
71255     When ‘fringe-cursor-alist’ has a buffer-local value, and there is
71256     no bitmap defined for a cursor type, the corresponding value from
71257     the default value of ‘fringes-indicator-alist’ is used.
71258
71259
71260File: elisp.info,  Node: Fringe Bitmaps,  Next: Customizing Bitmaps,  Prev: Fringe Cursors,  Up: Fringes
71261
7126239.13.4 Fringe Bitmaps
71263----------------------
71264
71265The “fringe bitmaps” are the actual bitmaps which represent the logical
71266fringe indicators for truncated or continued lines, buffer boundaries,
71267overlay arrows, etc.  Each bitmap is represented by a symbol.  These
71268symbols are referred to by the variable ‘fringe-indicator-alist’, which
71269maps fringe indicators to bitmaps (*note Fringe Indicators::), and the
71270variable ‘fringe-cursor-alist’, which maps fringe cursors to bitmaps
71271(*note Fringe Cursors::).
71272
71273   Lisp programs can also directly display a bitmap in the left or right
71274fringe, by using a ‘display’ property for one of the characters
71275appearing in the line (*note Other Display Specs::).  Such a display
71276specification has the form
71277
71278     (FRINGE BITMAP [FACE])
71279
71280FRINGE is either the symbol ‘left-fringe’ or ‘right-fringe’.  BITMAP is
71281a symbol identifying the bitmap to display.  The optional FACE names a
71282face whose foreground and background colors are to be used to display
71283the bitmap, using the attributes of the ‘fringe’ face for colors that
71284FACE didn’t specify.  If FACE is omitted, that means to use the
71285attributes of the ‘default’ face for the colors which the ‘fringe’ face
71286didn’t specify.  For predictable results that don’t depend on the
71287attributes of the ‘default’ and ‘fringe’ faces, we recommend you never
71288omit FACE, but always provide a specific face.  In particular, if you
71289want the bitmap to be always displayed in the ‘fringe’ face, use
71290‘fringe’ as FACE.
71291
71292   For instance, to display an arrow in the left fringe, using the
71293‘warning’ face, you could say something like:
71294
71295     (overlay-put
71296      (make-overlay (point) (point))
71297      'before-string (propertize
71298                      "x" 'display
71299                      `(left-fringe right-arrow warning)))
71300
71301   Here is a list of the standard fringe bitmaps defined in Emacs, and
71302how they are currently used in Emacs (via ‘fringe-indicator-alist’ and
71303‘fringe-cursor-alist’):
71304
71305‘left-arrow’, ‘right-arrow’
71306     Used to indicate truncated lines.
71307
71308‘left-curly-arrow’, ‘right-curly-arrow’
71309     Used to indicate continued lines.
71310
71311‘right-triangle’, ‘left-triangle’
71312     The former is used by overlay arrows.  The latter is unused.
71313
71314‘up-arrow’, ‘down-arrow’
71315‘bottom-left-angle’, ‘bottom-right-angle’
71316‘top-left-angle’, ‘top-right-angle’
71317‘left-bracket’, ‘right-bracket’
71318‘empty-line’
71319     Used to indicate buffer boundaries.
71320
71321‘filled-rectangle’, ‘hollow-rectangle’
71322‘filled-square’, ‘hollow-square’
71323‘vertical-bar’, ‘horizontal-bar’
71324     Used for different types of fringe cursors.
71325
71326‘exclamation-mark’, ‘question-mark’
71327     Not used by core Emacs features.
71328
71329The next subsection describes how to define your own fringe bitmaps.
71330
71331 -- Function: fringe-bitmaps-at-pos &optional pos window
71332     This function returns the fringe bitmaps of the display line
71333     containing position POS in window WINDOW.  The return value has the
71334     form ‘(LEFT RIGHT OV)’, where LEFT is the symbol for the fringe
71335     bitmap in the left fringe (or ‘nil’ if no bitmap), RIGHT is similar
71336     for the right fringe, and OV is non-‘nil’ if there is an overlay
71337     arrow in the left fringe.
71338
71339     The value is ‘nil’ if POS is not visible in WINDOW.  If WINDOW is
71340     ‘nil’, that stands for the selected window.  If POS is ‘nil’, that
71341     stands for the value of point in WINDOW.
71342
71343
71344File: elisp.info,  Node: Customizing Bitmaps,  Next: Overlay Arrow,  Prev: Fringe Bitmaps,  Up: Fringes
71345
7134639.13.5 Customizing Fringe Bitmaps
71347----------------------------------
71348
71349 -- Function: define-fringe-bitmap bitmap bits &optional height width
71350          align
71351     This function defines the symbol BITMAP as a new fringe bitmap, or
71352     replaces an existing bitmap with that name.
71353
71354     The argument BITS specifies the image to use.  It should be either
71355     a string or a vector of integers, where each element (an integer)
71356     corresponds to one row of the bitmap.  Each bit of an integer
71357     corresponds to one pixel of the bitmap, where the low bit
71358     corresponds to the rightmost pixel of the bitmap.  (Note that this
71359     order of bits is opposite of the order in XBM images; *note XBM
71360     Images::.)
71361
71362     The height is normally the length of BITS.  However, you can
71363     specify a different height with non-‘nil’ HEIGHT.  The width is
71364     normally 8, but you can specify a different width with non-‘nil’
71365     WIDTH.  The width must be an integer between 1 and 16.
71366
71367     The argument ALIGN specifies the positioning of the bitmap relative
71368     to the range of rows where it is used; the default is to center the
71369     bitmap.  The allowed values are ‘top’, ‘center’, or ‘bottom’.
71370
71371     The ALIGN argument may also be a list ‘(ALIGN PERIODIC)’ where
71372     ALIGN is interpreted as described above.  If PERIODIC is non-‘nil’,
71373     it specifies that the rows in ‘bits’ should be repeated enough
71374     times to reach the specified height.
71375
71376 -- Function: destroy-fringe-bitmap bitmap
71377     This function destroys the fringe bitmap identified by BITMAP.  If
71378     BITMAP identifies a standard fringe bitmap, it actually restores
71379     the standard definition of that bitmap, instead of eliminating it
71380     entirely.
71381
71382 -- Function: set-fringe-bitmap-face bitmap &optional face
71383     This sets the face for the fringe bitmap BITMAP to FACE.  If FACE
71384     is ‘nil’, it selects the ‘fringe’ face.  The bitmap’s face controls
71385     the color to draw it in.
71386
71387     FACE is merged with the ‘fringe’ face, so normally FACE should
71388     specify only the foreground color.
71389
71390
71391File: elisp.info,  Node: Overlay Arrow,  Prev: Customizing Bitmaps,  Up: Fringes
71392
7139339.13.6 The Overlay Arrow
71394-------------------------
71395
71396The “overlay arrow” is useful for directing the user’s attention to a
71397particular line in a buffer.  For example, in the modes used for
71398interface to debuggers, the overlay arrow indicates the line of code
71399about to be executed.  This feature has nothing to do with “overlays”
71400(*note Overlays::).
71401
71402 -- Variable: overlay-arrow-string
71403     This variable holds the string to display to call attention to a
71404     particular line, or ‘nil’ if the arrow feature is not in use.  On a
71405     graphical display the contents of the string are ignored; instead a
71406     glyph is displayed in the fringe area to the left of the display
71407     area.
71408
71409 -- Variable: overlay-arrow-position
71410     This variable holds a marker that indicates where to display the
71411     overlay arrow.  It should point at the beginning of a line.  On a
71412     non-graphical display the arrow text appears at the beginning of
71413     that line, overlaying any text that would otherwise appear.  Since
71414     the arrow is usually short, and the line usually begins with
71415     indentation, normally nothing significant is overwritten.
71416
71417     The overlay-arrow string is displayed in any given buffer if the
71418     value of ‘overlay-arrow-position’ in that buffer points into that
71419     buffer.  Thus, it is possible to display multiple overlay arrow
71420     strings by creating buffer-local bindings of
71421     ‘overlay-arrow-position’.  However, it is usually cleaner to use
71422     ‘overlay-arrow-variable-list’ to achieve this result.
71423
71424   You can do a similar job by creating an overlay with a
71425‘before-string’ property.  *Note Overlay Properties::.
71426
71427   You can define multiple overlay arrows via the variable
71428‘overlay-arrow-variable-list’.
71429
71430 -- Variable: overlay-arrow-variable-list
71431     This variable’s value is a list of variables, each of which
71432     specifies the position of an overlay arrow.  The variable
71433     ‘overlay-arrow-position’ has its normal meaning because it is on
71434     this list.
71435
71436   Each variable on this list can have properties ‘overlay-arrow-string’
71437and ‘overlay-arrow-bitmap’ that specify an overlay arrow string (for
71438text terminals) or fringe bitmap (for graphical terminals) to display at
71439the corresponding overlay arrow position.  If either property is not
71440set, the default ‘overlay-arrow-string’ or ‘overlay-arrow’ fringe
71441indicator is used.
71442
71443
71444File: elisp.info,  Node: Scroll Bars,  Next: Window Dividers,  Prev: Fringes,  Up: Display
71445
7144639.14 Scroll Bars
71447=================
71448
71449Normally the frame parameter ‘vertical-scroll-bars’ controls whether the
71450windows in the frame have vertical scroll bars, and whether they are on
71451the left or right.  The frame parameter ‘scroll-bar-width’ specifies how
71452wide they are (‘nil’ meaning the default).
71453
71454   The frame parameter ‘horizontal-scroll-bars’ controls whether the
71455windows in the frame have horizontal scroll bars.  The frame parameter
71456‘scroll-bar-height’ specifies how high they are (‘nil’ meaning the
71457default).  *Note Layout Parameters::.
71458
71459   Horizontal scroll bars are not available on all platforms.  The
71460function ‘horizontal-scroll-bars-available-p’ which takes no argument
71461returns non-‘nil’ if they are available on your system.
71462
71463   The following three functions take as argument a live frame which
71464defaults to the selected one.
71465
71466 -- Function: frame-current-scroll-bars &optional frame
71467     This function reports the scroll bar types for frame FRAME.  The
71468     value is a cons cell ‘(VERTICAL-TYPE . HORIZONTAL-TYPE)’, where
71469     VERTICAL-TYPE is either ‘left’, ‘right’, or ‘nil’ (which means no
71470     vertical scroll bar.)  HORIZONTAL-TYPE is either ‘bottom’ or ‘nil’
71471     (which means no horizontal scroll bar).
71472
71473 -- Function: frame-scroll-bar-width &optional frame
71474     This function returns the width of vertical scroll bars of FRAME in
71475     pixels.
71476
71477 -- Function: frame-scroll-bar-height &optional frame
71478     This function returns the height of horizontal scroll bars of FRAME
71479     in pixels.
71480
71481   You can override the frame specific settings for individual windows
71482by using the following function:
71483
71484 -- Function: set-window-scroll-bars window &optional width
71485          vertical-type height horizontal-type persistent
71486     This function sets the width and/or height and the types of scroll
71487     bars for window WINDOW.  If WINDOW is ‘nil’, the selected window is
71488     used.
71489
71490     WIDTH specifies the width of the vertical scroll bar in pixels
71491     (‘nil’ means use the width specified for the frame).  VERTICAL-TYPE
71492     specifies whether to have a vertical scroll bar and, if so, where.
71493     The possible values are ‘left’, ‘right’, ‘t’, which means to use
71494     the frame’s default, and ‘nil’ for no vertical scroll bar.
71495
71496     HEIGHT specifies the height of the horizontal scroll bar in pixels
71497     (‘nil’ means use the height specified for the frame).
71498     HORIZONTAL-TYPE specifies whether to have a horizontal scroll bar.
71499     The possible values are ‘bottom’, ‘t’, which means to use the
71500     frame’s default, and ‘nil’ for no horizontal scroll bar.  Note that
71501     for a mini window the value ‘t’ has the same meaning as ‘nil’,
71502     namely to not show a horizontal scroll bar.  You have to explicitly
71503     specify ‘bottom’ in order to show a horizontal scroll bar in a mini
71504     window.
71505
71506     If WINDOW is not large enough to accommodate a scroll bar of the
71507     desired dimension, this leaves the corresponding scroll bar
71508     unchanged.
71509
71510     The values specified here may be later overridden by invoking
71511     ‘set-window-buffer’ (*note Buffers and Windows::) on WINDOW with
71512     its KEEP-MARGINS argument ‘nil’ or omitted.  However, if the
71513     optional fifth argument PERSISTENT is non-‘nil’ and the other
71514     arguments are processed successfully, the values specified here
71515     unconditionally survive subsequent invocations of
71516     ‘set-window-buffer’.
71517
71518   Using the PERSISTENT argument of ‘set-window-scroll-bars’ and
71519‘set-window-fringes’ (*note Fringe Size/Pos::) you can reliably and
71520permanently turn off scroll bars and/or fringes in any minibuffer window
71521by adding the following snippet to your early init file (*note Init
71522File::).
71523
71524     (add-hook 'after-make-frame-functions
71525               (lambda (frame)
71526                 (set-window-scroll-bars
71527                  (minibuffer-window frame) 0 nil 0 nil t)
71528                 (set-window-fringes
71529                  (minibuffer-window frame) 0 0 nil t)))
71530
71531   The following four functions take as argument a live window which
71532defaults to the selected one.
71533
71534 -- Function: window-scroll-bars &optional window
71535     This function returns a list of the form ‘(WIDTH COLUMNS
71536     VERTICAL-TYPE HEIGHT LINES HORIZONTAL-TYPE PERSISTENT)’.
71537
71538     The value WIDTH is the value that was specified for the width of
71539     the vertical scroll bar (which may be ‘nil’); COLUMNS is the
71540     (possibly rounded) number of columns that the vertical scroll bar
71541     actually occupies.
71542
71543     The value HEIGHT is the value that was specified for the height of
71544     the horizontal scroll bar (which may be ‘nil’); LINES is the
71545     (possibly rounded) number of lines that the horizontally scroll bar
71546     actually occupies.
71547
71548     The value of PERSISTENT is the value specified for WINDOW with the
71549     last successful invocation of ‘set-window-scroll-bars’, ‘nil’ if
71550     there never was one.
71551
71552 -- Function: window-current-scroll-bars &optional window
71553     This function reports the scroll bar type for window WINDOW.  The
71554     value is a cons cell ‘(VERTICAL-TYPE . HORIZONTAL-TYPE)’.  Unlike
71555     ‘window-scroll-bars’, this reports the scroll bar type actually
71556     used, once frame defaults and ‘scroll-bar-mode’ are taken into
71557     account.
71558
71559 -- Function: window-scroll-bar-width &optional window
71560     This function returns the width in pixels of WINDOW’s vertical
71561     scrollbar.
71562
71563 -- Function: window-scroll-bar-height &optional window
71564     This function returns the height in pixels of WINDOW’s horizontal
71565     scrollbar.
71566
71567   If you do not specify a window’s scroll bar settings via
71568‘set-window-scroll-bars’, the buffer-local variables
71569‘vertical-scroll-bar’, ‘horizontal-scroll-bar’, ‘scroll-bar-width’ and
71570‘scroll-bar-height’ in the buffer being displayed control the window’s
71571scroll bars.  The function ‘set-window-buffer’ examines these variables.
71572If you change them in a buffer that is already visible in a window, you
71573can make the window take note of the new values by calling
71574‘set-window-buffer’ specifying the same buffer that is already
71575displayed.
71576
71577   You can control the appearance of scroll bars for a particular buffer
71578by setting the following variables which automatically become
71579buffer-local when set.
71580
71581 -- Variable: vertical-scroll-bar
71582     This variable specifies the location of the vertical scroll bar.
71583     The possible values are ‘left’, ‘right’, ‘t’, which means to use
71584     the frame’s default, and ‘nil’ for no scroll bar.
71585
71586 -- Variable: horizontal-scroll-bar
71587     This variable specifies the location of the horizontal scroll bar.
71588     The possible values are ‘bottom’, ‘t’, which means to use the
71589     frame’s default, and ‘nil’ for no scroll bar.
71590
71591 -- Variable: scroll-bar-width
71592     This variable specifies the width of the buffer’s vertical scroll
71593     bars, measured in pixels.  A value of ‘nil’ means to use the value
71594     specified by the frame.
71595
71596 -- Variable: scroll-bar-height
71597     This variable specifies the height of the buffer’s horizontal
71598     scroll bar, measured in pixels.  A value of ‘nil’ means to use the
71599     value specified by the frame.
71600
71601   Finally you can toggle the display of scroll bars on all frames by
71602customizing the variables ‘scroll-bar-mode’ and
71603‘horizontal-scroll-bar-mode’.
71604
71605 -- User Option: scroll-bar-mode
71606     This variable controls whether and where to put vertical scroll
71607     bars in all frames.  The possible values are ‘nil’ for no scroll
71608     bars, ‘left’ to put scroll bars on the left and ‘right’ to put
71609     scroll bars on the right.
71610
71611 -- User Option: horizontal-scroll-bar-mode
71612     This variable controls whether to display horizontal scroll bars on
71613     all frames.
71614
71615
71616File: elisp.info,  Node: Window Dividers,  Next: Display Property,  Prev: Scroll Bars,  Up: Display
71617
7161839.15 Window Dividers
71619=====================
71620
71621Window dividers are bars drawn between a frame’s windows.  A right
71622divider is drawn between a window and any adjacent windows on the right.
71623Its width (thickness) is specified by the frame parameter
71624‘right-divider-width’.  A bottom divider is drawn between a window and
71625adjacent windows on the bottom or the echo area.  Its width is specified
71626by the frame parameter ‘bottom-divider-width’.  In either case,
71627specifying a width of zero means to not draw such dividers.  *Note
71628Layout Parameters::.
71629
71630   Technically, a right divider belongs to the window on its left, which
71631means that its width contributes to the total width of that window.  A
71632bottom divider belongs to the window above it, which means that its
71633width contributes to the total height of that window.  *Note Window
71634Sizes::.  When a window has both, a right and a bottom divider, the
71635bottom divider prevails.  This means that a bottom divider is drawn over
71636the full total width of its window while the right divider ends above
71637the bottom divider.
71638
71639   Dividers can be dragged with the mouse and are therefore useful for
71640adjusting the sizes of adjacent windows with the mouse.  They also serve
71641to visually set apart adjacent windows when no scroll bars or mode lines
71642are present.  The following three faces allow the customization of the
71643appearance of dividers:
71644
71645‘window-divider’
71646     When a divider is less than three pixels wide, it is drawn solidly
71647     with the foreground of this face.  For larger dividers this face is
71648     used for the inner part only, excluding the first and last pixel.
71649
71650‘window-divider-first-pixel’
71651     This is the face used for drawing the first pixel of a divider that
71652     is at least three pixels wide.  To obtain a solid appearance, set
71653     this to the same value used for the ‘window-divider’ face.
71654
71655‘window-divider-last-pixel’
71656     This is the face used for drawing the last pixel of a divider that
71657     is at least three pixels wide.  To obtain a solid appearance, set
71658     this to the same value used for the ‘window-divider’ face.
71659
71660   You can get the sizes of the dividers of a specific window with the
71661following two functions.
71662
71663 -- Function: window-right-divider-width &optional window
71664     Return the width (thickness) in pixels of WINDOW’s right divider.
71665     WINDOW must be a live window and defaults to the selected one.  The
71666     return value is always zero for a rightmost window.
71667
71668 -- Function: window-bottom-divider-width &optional window
71669     Return the width (thickness) in pixels of WINDOW’s bottom divider.
71670     WINDOW must be a live window and defaults to the selected one.  The
71671     return value is zero for the minibuffer window or a bottommost
71672     window on a minibuffer-less frame.
71673
71674
71675File: elisp.info,  Node: Display Property,  Next: Images,  Prev: Window Dividers,  Up: Display
71676
7167739.16 The ‘display’ Property
71678============================
71679
71680The ‘display’ text property (or overlay property) is used to insert
71681images into text, and to control other aspects of how text displays.
71682The value of the ‘display’ property should be a display specification,
71683or a list or vector containing several display specifications.  Display
71684specifications in the same ‘display’ property value generally apply in
71685parallel to the text they cover.
71686
71687   If several sources (overlays and/or a text property) specify values
71688for the ‘display’ property, only one of the values takes effect,
71689following the rules of ‘get-char-property’.  *Note Examining
71690Properties::.
71691
71692   Some of the display specifications allow inclusion of Lisp forms,
71693which are evaluated at display time.  This could be unsafe in certain
71694situations, e.g., when the display specification was generated by some
71695external program/agent.  Wrapping a display specification in a list that
71696begins with the special symbol ‘disable-eval’, as in
71697‘('disable-eval SPEC)’, will disable evaluation of any Lisp in SPEC,
71698while still supporting all the other display property features.
71699
71700   The rest of this section describes several kinds of display
71701specifications and what they mean.
71702
71703* Menu:
71704
71705* Replacing Specs::      Display specs that replace the text.
71706* Specified Space::      Displaying one space with a specified width.
71707* Pixel Specification::  Specifying space width or height in pixels.
71708* Other Display Specs::     Displaying an image; adjusting the height,
71709                              spacing, and other properties of text.
71710* Display Margins::     Displaying text or images to the side of the main text.
71711
71712
71713File: elisp.info,  Node: Replacing Specs,  Next: Specified Space,  Up: Display Property
71714
7171539.16.1 Display Specs That Replace The Text
71716-------------------------------------------
71717
71718Some kinds of display specifications specify something to display
71719instead of the text that has the property.  These are called “replacing”
71720display specifications.  Emacs does not allow the user to interactively
71721move point into the middle of buffer text that is replaced in this way.
71722
71723   If a list of display specifications includes more than one replacing
71724display specification, the first overrides the rest.  Replacing display
71725specifications make most other display specifications irrelevant, since
71726those don’t apply to the replacement.
71727
71728   For replacing display specifications, “the text that has the
71729property” means all the consecutive characters that have the same Lisp
71730object as their ‘display’ property; these characters are replaced as a
71731single unit.  If two characters have different Lisp objects as their
71732‘display’ properties (i.e., objects which are not ‘eq’), they are
71733handled separately.
71734
71735   Here is an example which illustrates this point.  A string serves as
71736a replacing display specification, which replaces the text that has the
71737property with the specified string (*note Other Display Specs::).
71738Consider the following function:
71739
71740     (defun foo ()
71741       (dotimes (i 5)
71742         (let ((string (concat "A"))
71743               (start (+ i i (point-min))))
71744           (put-text-property start (1+ start) 'display string)
71745           (put-text-property start (+ 2 start) 'display string))))
71746
71747This function gives each of the first ten characters in the buffer a
71748‘display’ property which is a string ‘"A"’, but they don’t all get the
71749same string object.  The first two characters get the same string
71750object, so they are replaced with one ‘A’; the fact that the display
71751property was assigned in two separate calls to ‘put-text-property’ is
71752irrelevant.  Similarly, the next two characters get a second string
71753(‘concat’ creates a new string object), so they are replaced with one
71754‘A’; and so on.  Thus, the ten characters appear as five A’s.
71755
71756
71757File: elisp.info,  Node: Specified Space,  Next: Pixel Specification,  Prev: Replacing Specs,  Up: Display Property
71758
7175939.16.2 Specified Spaces
71760------------------------
71761
71762To display a space of specified width and/or height, use a display
71763specification of the form ‘(space . PROPS)’, where PROPS is a property
71764list (a list of alternating properties and values).  You can put this
71765property on one or more consecutive characters; a space of the specified
71766height and width is displayed in place of _all_ of those characters.
71767These are the properties you can use in PROPS to specify the weight of
71768the space:
71769
71770‘:width WIDTH’
71771     If WIDTH is a number, it specifies that the space width should be
71772     WIDTH times the normal character width.  WIDTH can also be a “pixel
71773     width” specification (*note Pixel Specification::).
71774
71775‘:relative-width FACTOR’
71776     Specifies that the width of the stretch should be computed from the
71777     first character in the group of consecutive characters that have
71778     the same ‘display’ property.  The space width is the pixel width of
71779     that character, multiplied by FACTOR.  (On text-mode terminals, the
71780     “pixel width” of a character is usually 1, but it could be more for
71781     TABs and double-width CJK characters.)
71782
71783‘:align-to HPOS’
71784     Specifies that the space should be wide enough to reach HPOS.  If
71785     HPOS is a number, it is measured in units of the normal character
71786     width.  HPOS can also be a “pixel width” specification (*note Pixel
71787     Specification::).
71788
71789   You should use one and only one of the above properties.  You can
71790also specify the height of the space, with these properties:
71791
71792‘:height HEIGHT’
71793     Specifies the height of the space.  If HEIGHT is a number, it
71794     specifies that the space height should be HEIGHT times the normal
71795     character height.  The HEIGHT may also be a “pixel height”
71796     specification (*note Pixel Specification::).
71797
71798‘:relative-height FACTOR’
71799     Specifies the height of the space, multiplying the ordinary height
71800     of the text having this display specification by FACTOR.
71801
71802‘:ascent ASCENT’
71803     If the value of ASCENT is a non-negative number no greater than
71804     100, it specifies that ASCENT percent of the height of the space
71805     should be considered as the ascent of the space—that is, the part
71806     above the baseline.  The ascent may also be specified in pixel
71807     units with a “pixel ascent” specification (*note Pixel
71808     Specification::).
71809
71810   Don’t use both ‘:height’ and ‘:relative-height’ together.
71811
71812   The ‘:width’ and ‘:align-to’ properties are supported on non-graphic
71813terminals, but the other space properties in this section are not.
71814
71815   Note that space properties are treated as paragraph separators for
71816the purposes of reordering bidirectional text for display.  *Note
71817Bidirectional Display::, for the details.
71818
71819
71820File: elisp.info,  Node: Pixel Specification,  Next: Other Display Specs,  Prev: Specified Space,  Up: Display Property
71821
7182239.16.3 Pixel Specification for Spaces
71823--------------------------------------
71824
71825The value of the ‘:width’, ‘:align-to’, ‘:height’, and ‘:ascent’
71826properties can be a special kind of expression that is evaluated during
71827redisplay.  The result of the evaluation is used as an absolute number
71828of pixels.
71829
71830   The following expressions are supported:
71831
71832       EXPR ::= NUM | (NUM) | UNIT | ELEM | POS | IMAGE | XWIDGET | FORM
71833       NUM  ::= INTEGER | FLOAT | SYMBOL
71834       UNIT ::= in | mm | cm | width | height
71835       ELEM ::= left-fringe | right-fringe | left-margin | right-margin
71836             |  scroll-bar | text
71837       POS  ::= left | center | right
71838       FORM ::= (NUM . EXPR) | (OP EXPR ...)
71839       OP   ::= + | -
71840
71841   The form NUM specifies a fraction of the default frame font height or
71842width.  The form ‘(NUM)’ specifies an absolute number of pixels.  If NUM
71843is a symbol, SYMBOL, its buffer-local variable binding is used; that
71844binding can be either a number or a cons cell of the forms shown above
71845(including yet another cons cell whose ‘car’ is a symbol that has a
71846buffer-local binding).
71847
71848   The ‘in’, ‘mm’, and ‘cm’ units specify the number of pixels per inch,
71849millimeter, and centimeter, respectively.  The ‘width’ and ‘height’
71850units correspond to the default width and height of the current face.
71851An image specification of the form ‘(image . PROPS)’ (*note Image
71852Descriptors::) corresponds to the width or height of the specified
71853image.  Similarly, an xwidget specification of the form
71854‘(xwidget . PROPS)’ stands for the width or height of the specified
71855xwidget.  *Note Xwidgets::.
71856
71857   The elements ‘left-fringe’, ‘right-fringe’, ‘left-margin’,
71858‘right-margin’, ‘scroll-bar’, and ‘text’ specify the width of the
71859corresponding area of the window.  When the window displays line numbers
71860(*note Size of Displayed Text::), the width of the ‘text’ area is
71861decreased by the screen space taken by the line-number display.
71862
71863   The ‘left’, ‘center’, and ‘right’ positions can be used with
71864‘:align-to’ to specify a position relative to the left edge, center, or
71865right edge of the text area.  When the window displays line numbers, the
71866‘left’ and the ‘center’ positions are offset to account for the screen
71867space taken by the line-number display.
71868
71869   Any of the above window elements (except ‘text’) can also be used
71870with ‘:align-to’ to specify that the position is relative to the left
71871edge of the given area.  Once the base offset for a relative position
71872has been set (by the first occurrence of one of these symbols), further
71873occurrences of these symbols are interpreted as the width of the
71874specified area.  For example, to align to the center of the left-margin,
71875use
71876
71877     :align-to (+ left-margin (0.5 . left-margin))
71878
71879   If no specific base offset is set for alignment, it is always
71880relative to the left edge of the text area.  For example, ‘:align-to 0’
71881in a header-line aligns with the first text column in the text area.
71882When the window displays line numbers, the text is considered to start
71883where the space used for line-number display ends.
71884
71885   A value of the form ‘(NUM . EXPR)’ stands for the product of the
71886values of NUM and EXPR.  For example, ‘(2 . in)’ specifies a width of 2
71887inches, while ‘(0.5 . IMAGE)’ specifies half the width (or height) of
71888the specified IMAGE (which should be given by its image spec).
71889
71890   The form ‘(+ EXPR ...)’ adds up the value of the expressions.  The
71891form ‘(- EXPR ...)’ negates or subtracts the value of the expressions.
71892
71893
71894File: elisp.info,  Node: Other Display Specs,  Next: Display Margins,  Prev: Pixel Specification,  Up: Display Property
71895
7189639.16.4 Other Display Specifications
71897------------------------------------
71898
71899Here are the other sorts of display specifications that you can use in
71900the ‘display’ text property.
71901
71902‘STRING’
71903     Display STRING instead of the text that has this property.
71904
71905     Recursive display specifications are not supported—STRING’s
71906     ‘display’ properties, if any, are not used.
71907
71908‘(image . IMAGE-PROPS)’
71909     This kind of display specification is an image descriptor (*note
71910     Image Descriptors::).  When used as a display specification, it
71911     means to display the image instead of the text that has the display
71912     specification.
71913
71914‘(slice X Y WIDTH HEIGHT)’
71915     This specification together with ‘image’ specifies a “slice” (a
71916     partial area) of the image to display.  The elements Y and X
71917     specify the top left corner of the slice, within the image; WIDTH
71918     and HEIGHT specify the width and height of the slice.  Integers are
71919     numbers of pixels.  A floating-point number in the range 0.0–1.0
71920     stands for that fraction of the width or height of the entire
71921     image.
71922
71923‘((margin nil) STRING)’
71924     A display specification of this form means to display STRING
71925     instead of the text that has the display specification, at the same
71926     position as that text.  It is equivalent to using just STRING, but
71927     it is done as a special case of marginal display (*note Display
71928     Margins::).
71929
71930‘(left-fringe BITMAP [FACE])’
71931‘(right-fringe BITMAP [FACE])’
71932     This display specification on any character of a line of text
71933     causes the specified BITMAP be displayed in the left or right
71934     fringes for that line, instead of the characters that have the
71935     display specification.  The optional FACE specifies the face whose
71936     colors are to be used for the bitmap display.  *Note Fringe
71937     Bitmaps::, for the details.
71938
71939‘(space-width FACTOR)’
71940     This display specification affects all the space characters within
71941     the text that has the specification.  It displays all of these
71942     spaces FACTOR times as wide as normal.  The element FACTOR should
71943     be an integer or float.  Characters other than spaces are not
71944     affected at all; in particular, this has no effect on tab
71945     characters.
71946
71947‘(height HEIGHT)’
71948     This display specification makes the text taller or shorter.  Here
71949     are the possibilities for HEIGHT:
71950
71951     ‘(+ N)’
71952          This means to use a font that is N steps larger.  A “step” is
71953          defined by the set of available fonts—specifically, those that
71954          match what was otherwise specified for this text, in all
71955          attributes except height.  Each size for which a suitable font
71956          is available counts as another step.  N should be an integer.
71957
71958     ‘(- N)’
71959          This means to use a font that is N steps smaller.
71960
71961     a number, FACTOR
71962          A number, FACTOR, means to use a font that is FACTOR times as
71963          tall as the default font.
71964
71965     a symbol, FUNCTION
71966          A symbol is a function to compute the height.  It is called
71967          with the current height as argument, and should return the new
71968          height to use.
71969
71970     anything else, FORM
71971          If the HEIGHT value doesn’t fit the previous possibilities, it
71972          is a form.  Emacs evaluates it to get the new height, with the
71973          symbol ‘height’ bound to the current specified font height.
71974
71975‘(raise FACTOR)’
71976     This kind of display specification raises or lowers the text it
71977     applies to, relative to the baseline of the line.  It is mainly
71978     meant to support display of subscripts and superscripts.
71979
71980     The FACTOR must be a number, which is interpreted as a multiple of
71981     the height of the affected text.  If it is positive, that means to
71982     display the characters raised.  If it is negative, that means to
71983     display them lower down.
71984
71985     Note that if the text also has a ‘height’ display specification,
71986     which was specified before (i.e. to the left of) ‘raise’, the
71987     latter will affect the amount of raising or lowering in pixels,
71988     because that is based on the height of the text being raised.
71989     Therefore, if you want to display a sub- or superscript that is
71990     smaller than the normal text height, consider specifying ‘raise’
71991     before ‘height’.
71992
71993   You can make any display specification conditional.  To do that,
71994package it in another list of the form ‘(when CONDITION . SPEC)’.  Then
71995the specification SPEC applies only when CONDITION evaluates to a
71996non-‘nil’ value.  During the evaluation, ‘object’ is bound to the string
71997or buffer having the conditional ‘display’ property.  ‘position’ and
71998‘buffer-position’ are bound to the position within ‘object’ and the
71999buffer position where the ‘display’ property was found, respectively.
72000Both positions can be different when ‘object’ is a string.
72001
72002   Note that CONDITION will only be evaluated when redisplay examines
72003the text where this display spec is located, so this feature is best
72004suited for conditions that are relatively stable, i.e. yield, for each
72005particular buffer position, the same results on every evaluation.  If
72006the results change for the same text location, e.g., if the result
72007depends on the position of point, then the conditional specification
72008might not do what you want, because redisplay examines only those parts
72009of buffer text where it has reasons to assume that something changed
72010since the last display cycle.
72011
72012
72013File: elisp.info,  Node: Display Margins,  Prev: Other Display Specs,  Up: Display Property
72014
7201539.16.5 Displaying in the Margins
72016---------------------------------
72017
72018A buffer can have blank areas called “display margins” on the left and
72019on the right.  Ordinary text never appears in these areas, but you can
72020put things into the display margins using the ‘display’ property.  There
72021is currently no way to make text or images in the margin
72022mouse-sensitive.
72023
72024   The way to display something in the margins is to specify it in a
72025margin display specification in the ‘display’ property of some text.
72026This is a replacing display specification, meaning that the text you put
72027it on does not get displayed; the margin display appears, but that text
72028does not.
72029
72030   A margin display specification looks like ‘((margin right-margin)
72031SPEC)’ or ‘((margin left-margin) SPEC)’.  Here, SPEC is another display
72032specification that says what to display in the margin.  Typically it is
72033a string of text to display, or an image descriptor.
72034
72035   To display something in the margin _in association with_ certain
72036buffer text, without altering or preventing the display of that text,
72037put a ‘before-string’ property on the text and put the margin display
72038specification on the contents of the before-string.
72039
72040   Note that if the string to be displayed in the margin doesn’t specify
72041a face, its face is determined using the same rules and priorities as it
72042is for strings displayed in the text area (*note Displaying Faces::).
72043If this results in undesirable “leaking” of faces into the margin, make
72044sure the string has an explicit face specified for it.
72045
72046   Before the display margins can display anything, you must give them a
72047nonzero width.  The usual way to do that is to set these variables:
72048
72049 -- Variable: left-margin-width
72050     This variable specifies the width of the left margin, in character
72051     cell (a.k.a. “column”) units.  It is buffer-local in all buffers.
72052     A value of ‘nil’ means no left marginal area.
72053
72054 -- Variable: right-margin-width
72055     This variable specifies the width of the right margin, in character
72056     cell units.  It is buffer-local in all buffers.  A value of ‘nil’
72057     means no right marginal area.
72058
72059   Setting these variables does not immediately affect the window.
72060These variables are checked when a new buffer is displayed in the
72061window.  Thus, you can make changes take effect by calling
72062‘set-window-buffer’.  Do not use these variables to try to determine the
72063current width of the left or right margin.  Instead, use the function
72064‘window-margins’.
72065
72066   You can also set the margin widths immediately.
72067
72068 -- Function: set-window-margins window left &optional right
72069     This function specifies the margin widths for window WINDOW, in
72070     character cell units.  The argument LEFT controls the left margin,
72071     and RIGHT controls the right margin (default ‘0’).
72072
72073     If WINDOW is not large enough to accommodate margins of the desired
72074     width, this leaves the margins of WINDOW unchanged.
72075
72076     The values specified here may be later overridden by invoking
72077     ‘set-window-buffer’ (*note Buffers and Windows::) on WINDOW with
72078     its KEEP-MARGINS argument ‘nil’ or omitted.
72079
72080 -- Function: window-margins &optional window
72081     This function returns the width of the left and right margins of
72082     WINDOW as a cons cell of the form ‘(LEFT . RIGHT)’.  If one of the
72083     two marginal areas does not exist, its width is returned as ‘nil’;
72084     if neither of the two margins exist, the function returns ‘(nil)’.
72085     If WINDOW is ‘nil’, the selected window is used.
72086
72087
72088File: elisp.info,  Node: Images,  Next: Xwidgets,  Prev: Display Property,  Up: Display
72089
7209039.17 Images
72091============
72092
72093To display an image in an Emacs buffer, you must first create an image
72094descriptor, then use it as a display specifier in the ‘display’ property
72095of text that is displayed (*note Display Property::).
72096
72097   Emacs is usually able to display images when it is run on a graphical
72098terminal.  Images cannot be displayed in a text terminal, on certain
72099graphical terminals that lack the support for this, or if Emacs is
72100compiled without image support.  You can use the function
72101‘display-images-p’ to determine if images can in principle be displayed
72102(*note Display Feature Testing::).
72103
72104* Menu:
72105
72106* Image Formats::       Supported image formats.
72107* Image Descriptors::   How to specify an image for use in ‘:display’.
72108* XBM Images::          Special features for XBM format.
72109* XPM Images::          Special features for XPM format.
72110* ImageMagick Images::  Special features available through ImageMagick.
72111* SVG Images::          Creating and manipulating SVG images.
72112* Other Image Types::   Various other formats are supported.
72113* Defining Images::     Convenient ways to define an image for later use.
72114* Showing Images::      Convenient ways to display an image once it is defined.
72115* Multi-Frame Images::  Some images contain more than one frame.
72116* Image Cache::         Internal mechanisms of image display.
72117
72118
72119File: elisp.info,  Node: Image Formats,  Next: Image Descriptors,  Up: Images
72120
7212139.17.1 Image Formats
72122---------------------
72123
72124Emacs can display a number of different image formats.  Some of these
72125image formats are supported only if particular support libraries are
72126installed.  On some platforms, Emacs can load support libraries on
72127demand; if so, the variable ‘dynamic-library-alist’ can be used to
72128modify the set of known names for these dynamic libraries.  *Note
72129Dynamic Libraries::.
72130
72131   Supported image formats (and the required support libraries) include
72132PBM and XBM (which do not depend on support libraries and are always
72133available), XPM (‘libXpm’), GIF (‘libgif’ or ‘libungif’), JPEG
72134(‘libjpeg’), TIFF (‘libtiff’), PNG (‘libpng’), and SVG (‘librsvg’).
72135
72136   Each of these image formats is associated with an “image type
72137symbol”.  The symbols for the above formats are, respectively, ‘pbm’,
72138‘xbm’, ‘xpm’, ‘gif’, ‘jpeg’, ‘tiff’, ‘png’, and ‘svg’.
72139
72140   Furthermore, if you build Emacs with ImageMagick (‘libMagickWand’)
72141support, Emacs can display any image format that ImageMagick can.  *Note
72142ImageMagick Images::.  All images displayed via ImageMagick have type
72143symbol ‘imagemagick’.
72144
72145 -- Variable: image-types
72146     This variable contains a list of type symbols for image formats
72147     which are potentially supported in the current configuration.
72148
72149     “Potentially” means that Emacs knows about the image types, not
72150     necessarily that they can be used (for example, they could depend
72151     on unavailable dynamic libraries).  To know which image types are
72152     really available, use ‘image-type-available-p’.
72153
72154 -- Function: image-type-available-p type
72155     This function returns non-‘nil’ if images of type TYPE can be
72156     loaded and displayed.  TYPE must be an image type symbol.
72157
72158     For image types whose support libraries are statically linked, this
72159     function always returns ‘t’.  For image types whose support
72160     libraries are dynamically loaded, it returns ‘t’ if the library
72161     could be loaded and ‘nil’ otherwise.
72162
72163
72164File: elisp.info,  Node: Image Descriptors,  Next: XBM Images,  Prev: Image Formats,  Up: Images
72165
7216639.17.2 Image Descriptors
72167-------------------------
72168
72169An “image descriptor” is a list which specifies the underlying data for
72170an image, and how to display it.  It is typically used as the value of a
72171‘display’ overlay or text property (*note Other Display Specs::); but
72172*Note Showing Images::, for convenient helper functions to insert images
72173into buffers.
72174
72175   Each image descriptor has the form ‘(image . PROPS)’, where PROPS is
72176a property list of alternating keyword symbols and values, including at
72177least the pair ‘:type TYPE’ that specifies the image type.
72178
72179   The following is a list of properties that are meaningful for all
72180image types (there are also properties which are meaningful only for
72181certain image types, as documented in the following subsections):
72182
72183‘:type TYPE’
72184     The image type.  *Note Image Formats::.  Every image descriptor
72185     must include this property.
72186
72187‘:file FILE’
72188     This says to load the image from file FILE.  If FILE is not an
72189     absolute file name, it is expanded relative to the ‘images’
72190     subdirectory of ‘data-directory’, and failing that, relative to the
72191     directories listed by ‘x-bitmap-file-path’ (*note Face
72192     Attributes::).
72193
72194‘:data DATA’
72195     This specifies the raw image data.  Each image descriptor must have
72196     either ‘:data’ or ‘:file’, but not both.
72197
72198     For most image types, the value of a ‘:data’ property should be a
72199     string containing the image data.  Some image types do not support
72200     ‘:data’; for some others, ‘:data’ alone is not enough, so you need
72201     to use other image properties along with ‘:data’.  See the
72202     following subsections for details.
72203
72204‘:margin MARGIN’
72205     This specifies how many pixels to add as an extra margin around the
72206     image.  The value, MARGIN, must be a non-negative number, or a pair
72207     ‘(X . Y)’ of such numbers.  If it is a pair, X specifies how many
72208     pixels to add horizontally, and Y specifies how many pixels to add
72209     vertically.  If ‘:margin’ is not specified, the default is zero.
72210
72211‘:ascent ASCENT’
72212     This specifies the amount of the image’s height to use for its
72213     ascent—that is, the part above the baseline.  The value, ASCENT,
72214     must be a number in the range 0 to 100, or the symbol ‘center’.
72215
72216     If ASCENT is a number, that percentage of the image’s height is
72217     used for its ascent.
72218
72219     If ASCENT is ‘center’, the image is vertically centered around a
72220     centerline which would be the vertical centerline of text drawn at
72221     the position of the image, in the manner specified by the text
72222     properties and overlays that apply to the image.
72223
72224     If this property is omitted, it defaults to 50.
72225
72226‘:relief RELIEF’
72227     This adds a shadow rectangle around the image.  The value, RELIEF,
72228     specifies the width of the shadow lines, in pixels.  If RELIEF is
72229     negative, shadows are drawn so that the image appears as a pressed
72230     button; otherwise, it appears as an unpressed button.
72231
72232‘:width WIDTH, :height HEIGHT’
72233     The ‘:width’ and ‘:height’ keywords are used for scaling the image.
72234     If only one of them is specified, the other one will be calculated
72235     so as to preserve the aspect ratio.  If both are specified, aspect
72236     ratio may not be preserved.
72237
72238‘:max-width MAX-WIDTH, :max-height MAX-HEIGHT’
72239     The ‘:max-width’ and ‘:max-height’ keywords are used for scaling if
72240     the size of the image exceeds these values.  If ‘:width’ is set, it
72241     will have precedence over ‘max-width’, and if ‘:height’ is set, it
72242     will have precedence over ‘max-height’, but you can otherwise mix
72243     these keywords as you wish.
72244
72245     If both ‘:max-width’ and ‘:height’ are specified, but ‘:width’ is
72246     not, preserving the aspect ratio might require that width exceeds
72247     ‘:max-width’.  If this happens, scaling will use a smaller value
72248     for the height so as to preserve the aspect ratio while not
72249     exceeding ‘:max-width’.  Similarly when both ‘:max-height’ and
72250     ‘:width’ are specified, but ‘:height’ is not.  For example, if you
72251     have a 200x100 image and specify that ‘:width’ should be 400 and
72252     ‘:max-height’ should be 150, you’ll end up with an image that is
72253     300x150: Preserving the aspect ratio and not exceeding the “max”
72254     setting.  This combination of parameters is a useful way of saying
72255     “display this image as large as possible, but no larger than the
72256     available display area”.
72257
72258‘:scale SCALE’
72259     This should be a number, where values higher than 1 means to
72260     increase the size, and lower means to decrease the size, by
72261     multiplying both the width and height.  For instance, a value of
72262     0.25 will make the image a quarter size of what it originally was.
72263     If the scaling makes the image larger than specified by
72264     ‘:max-width’ or ‘:max-height’, the resulting size will not exceed
72265     those two values.  If both ‘:scale’ and ‘:height’/‘:width’ are
72266     specified, the height/width will be adjusted by the specified
72267     scaling factor.
72268
72269‘:rotation ANGLE’
72270     Specifies a rotation angle in degrees.  Only multiples of 90
72271     degrees are supported, unless the image type is ‘imagemagick’.
72272     Positive values rotate clockwise, negative values
72273     counter-clockwise.  Rotation is performed after scaling and
72274     cropping.
72275
72276‘:index FRAME’
72277     *Note Multi-Frame Images::.
72278
72279‘:conversion ALGORITHM’
72280     This specifies a conversion algorithm that should be applied to the
72281     image before it is displayed; the value, ALGORITHM, specifies which
72282     algorithm.
72283
72284     ‘laplace’
72285     ‘emboss’
72286          Specifies the Laplace edge detection algorithm, which blurs
72287          out small differences in color while highlighting larger
72288          differences.  People sometimes consider this useful for
72289          displaying the image for a disabled button.
72290
72291     ‘(edge-detection :matrix MATRIX :color-adjust ADJUST)’
72292          Specifies a general edge-detection algorithm.  MATRIX must be
72293          either a nine-element list or a nine-element vector of
72294          numbers.  A pixel at position x/y in the transformed image is
72295          computed from original pixels around that position.  MATRIX
72296          specifies, for each pixel in the neighborhood of x/y, a factor
72297          with which that pixel will influence the transformed pixel;
72298          element 0 specifies the factor for the pixel at x-1/y-1,
72299          element 1 the factor for the pixel at x/y-1 etc., as shown
72300          below:
72301                 (x-1/y-1  x/y-1  x+1/y-1
72302                  x-1/y    x/y    x+1/y
72303                  x-1/y+1  x/y+1  x+1/y+1)
72304
72305          The resulting pixel is computed from the color intensity of
72306          the color resulting from summing up the RGB values of
72307          surrounding pixels, multiplied by the specified factors, and
72308          dividing that sum by the sum of the factors’ absolute values.
72309
72310          Laplace edge-detection currently uses a matrix of
72311                 (1  0  0
72312                  0  0  0
72313                  0  0 -1)
72314
72315          Emboss edge-detection uses a matrix of
72316                 ( 2 -1  0
72317                  -1  0  1
72318                   0  1 -2)
72319
72320     ‘disabled’
72321          Specifies transforming the image so that it looks disabled.
72322
72323‘:mask MASK’
72324     If MASK is ‘heuristic’ or ‘(heuristic BG)’, build a clipping mask
72325     for the image, so that the background of a frame is visible behind
72326     the image.  If BG is not specified, or if BG is ‘t’, determine the
72327     background color of the image by looking at the four corners of the
72328     image, assuming the most frequently occurring color from the
72329     corners is the background color of the image.  Otherwise, BG must
72330     be a list ‘(RED GREEN BLUE)’ specifying the color to assume for the
72331     background of the image.
72332
72333     If MASK is ‘nil’, remove a mask from the image, if it has one.
72334     Images in some formats include a mask which can be removed by
72335     specifying ‘:mask nil’.
72336
72337‘:pointer SHAPE’
72338     This specifies the pointer shape when the mouse pointer is over
72339     this image.  *Note Pointer Shape::, for available pointer shapes.
72340
72341‘:map MAP’
72342     This associates an image map of “hot spots” with this image.
72343
72344     An image map is an alist where each element has the format ‘(AREA
72345     ID PLIST)’.  An AREA is specified as either a rectangle, a circle,
72346     or a polygon.
72347
72348     A rectangle is a cons ‘(rect . ((X0 . Y0) . (X1 . Y1)))’ which
72349     specifies the pixel coordinates of the upper left and bottom right
72350     corners of the rectangle area.
72351
72352     A circle is a cons ‘(circle . ((X0 . Y0) . R))’ which specifies the
72353     center and the radius of the circle; R may be a float or integer.
72354
72355     A polygon is a cons ‘(poly . [X0 Y0 X1 Y1 ...])’ where each pair in
72356     the vector describes one corner in the polygon.
72357
72358     When the mouse pointer lies on a hot-spot area of an image, the
72359     PLIST of that hot-spot is consulted; if it contains a ‘help-echo’
72360     property, that defines a tool-tip for the hot-spot, and if it
72361     contains a ‘pointer’ property, that defines the shape of the mouse
72362     cursor when it is on the hot-spot.  *Note Pointer Shape::, for
72363     available pointer shapes.
72364
72365     When you click the mouse when the mouse pointer is over a hot-spot,
72366     an event is composed by combining the ID of the hot-spot with the
72367     mouse event; for instance, ‘[area4 mouse-1]’ if the hot-spot’s ID
72368     is ‘area4’.
72369
72370 -- Function: image-mask-p spec &optional frame
72371     This function returns ‘t’ if image SPEC has a mask bitmap.  FRAME
72372     is the frame on which the image will be displayed.  FRAME ‘nil’ or
72373     omitted means to use the selected frame (*note Input Focus::).
72374
72375 -- Function: image-transforms-p &optional frame
72376     This function returns non-‘nil’ if FRAME supports image scaling and
72377     rotation.  FRAME ‘nil’ or omitted means to use the selected frame
72378     (*note Input Focus::).  The returned list includes symbols that
72379     indicate which image transform operations are supported:
72380
72381     ‘scale’
72382          Image scaling is supported by FRAME via the ‘:scale’,
72383          ‘:width’, ‘:height’, ‘:max-width’, and ‘:max-height’
72384          properties.
72385     ‘rotate90’
72386          Image rotation is supported by FRAME if the rotation angle is
72387          an integral multiple of 90 degrees.
72388
72389     If image transforms are not supported, ‘:rotation’, ‘:crop’,
72390     ‘:width’, ‘:height’, ‘:scale’, ‘:max-width’ and ‘:max-height’ will
72391     only be usable through ImageMagick, if available (*note ImageMagick
72392     Images::).
72393
72394
72395File: elisp.info,  Node: XBM Images,  Next: XPM Images,  Prev: Image Descriptors,  Up: Images
72396
7239739.17.3 XBM Images
72398------------------
72399
72400To use XBM format, specify ‘xbm’ as the image type.  This image format
72401doesn’t require an external library, so images of this type are always
72402supported.
72403
72404   Additional image properties supported for the ‘xbm’ image type are:
72405
72406‘:foreground FOREGROUND’
72407     The value, FOREGROUND, should be a string specifying the image
72408     foreground color, or ‘nil’ for the default color.  This color is
72409     used for each pixel in the XBM that is 1.  The default is the
72410     frame’s foreground color.
72411
72412‘:background BACKGROUND’
72413     The value, BACKGROUND, should be a string specifying the image
72414     background color, or ‘nil’ for the default color.  This color is
72415     used for each pixel in the XBM that is 0.  The default is the
72416     frame’s background color.
72417
72418   If you specify an XBM image using data within Emacs instead of an
72419external file, use the following three properties:
72420
72421‘:data DATA’
72422     The value, DATA, specifies the contents of the image.  There are
72423     three formats you can use for DATA:
72424
72425        • A vector of strings or bool-vectors, each specifying one line
72426          of the image.  Do specify ‘:height’ and ‘:width’.
72427
72428        • A string containing the same byte sequence as an XBM file
72429          would contain.  You must not specify ‘:height’ and ‘:width’ in
72430          this case, because omitting them is what indicates the data
72431          has the format of an XBM file.  The file contents specify the
72432          height and width of the image.
72433
72434        • A string or a bool-vector containing the bits of the image
72435          (plus perhaps some extra bits at the end that will not be
72436          used).  It should contain at least ‘STRIDE * HEIGHT’ bits,
72437          where STRIDE is the smallest multiple of 8 greater than or
72438          equal to the width of the image.  In this case, you should
72439          specify ‘:height’, ‘:width’ and ‘:stride’, both to indicate
72440          that the string contains just the bits rather than a whole XBM
72441          file, and to specify the size of the image.
72442
72443‘:width WIDTH’
72444     The value, WIDTH, specifies the width of the image, in pixels.
72445
72446‘:height HEIGHT’
72447     The value, HEIGHT, specifies the height of the image, in pixels.
72448
72449‘:stride STRIDE’
72450     The number of bool vector entries stored for each row; the smallest
72451     multiple of 8 greater than or equal to WIDTH.
72452
72453
72454File: elisp.info,  Node: XPM Images,  Next: ImageMagick Images,  Prev: XBM Images,  Up: Images
72455
7245639.17.4 XPM Images
72457------------------
72458
72459To use XPM format, specify ‘xpm’ as the image type.  The additional
72460image property ‘:color-symbols’ is also meaningful with the ‘xpm’ image
72461type:
72462
72463‘:color-symbols SYMBOLS’
72464     The value, SYMBOLS, should be an alist whose elements have the form
72465     ‘(NAME . COLOR)’.  In each element, NAME is the name of a color as
72466     it appears in the image file, and COLOR specifies the actual color
72467     to use for displaying that name.
72468
72469
72470File: elisp.info,  Node: ImageMagick Images,  Next: SVG Images,  Prev: XPM Images,  Up: Images
72471
7247239.17.5 ImageMagick Images
72473--------------------------
72474
72475If your Emacs build has ImageMagick support, you can use the ImageMagick
72476library to load many image formats (*note (emacs)File Conveniences::).
72477The image type symbol for images loaded via ImageMagick is
72478‘imagemagick’, regardless of the actual underlying image format.
72479
72480   To check for ImageMagick support, use the following:
72481
72482     (image-type-available-p 'imagemagick)
72483
72484 -- Function: imagemagick-types
72485     This function returns a list of image file extensions supported by
72486     the current ImageMagick installation.  Each list element is a
72487     symbol representing an internal ImageMagick name for an image type,
72488     such as ‘BMP’ for ‘.bmp’ images.
72489
72490 -- User Option: imagemagick-enabled-types
72491     The value of this variable is a list of ImageMagick image types
72492     which Emacs may attempt to render using ImageMagick.  Each list
72493     element should be one of the symbols in the list returned by
72494     ‘imagemagick-types’, or an equivalent string.  Alternatively, a
72495     value of ‘t’ enables ImageMagick for all possible image types.
72496     Regardless of the value of this variable,
72497     ‘imagemagick-types-inhibit’ (see below) takes precedence.
72498
72499 -- User Option: imagemagick-types-inhibit
72500     The value of this variable lists the ImageMagick image types which
72501     should never be rendered using ImageMagick, regardless of the value
72502     of ‘imagemagick-enabled-types’.  A value of ‘t’ disables
72503     ImageMagick entirely.
72504
72505 -- Variable: image-format-suffixes
72506     This variable is an alist mapping image types to file name
72507     extensions.  Emacs uses this in conjunction with the ‘:format’
72508     image property (see below) to give a hint to the ImageMagick
72509     library as to the type of an image.  Each element has the form
72510     ‘(TYPE EXTENSION)’, where TYPE is a symbol specifying an image
72511     content-type, and EXTENSION is a string that specifies the
72512     associated file name extension.
72513
72514   Images loaded with ImageMagick support the following additional image
72515descriptor properties:
72516
72517‘:background BACKGROUND’
72518     BACKGROUND, if non-‘nil’, should be a string specifying a color,
72519     which is used as the image’s background color if the image supports
72520     transparency.  If the value is ‘nil’, it defaults to the frame’s
72521     background color.
72522
72523‘:format TYPE’
72524     The value, TYPE, should be a symbol specifying the type of the
72525     image data, as found in ‘image-format-suffixes’.  This is used when
72526     the image does not have an associated file name, to provide a hint
72527     to ImageMagick to help it detect the image type.
72528
72529‘:crop GEOMETRY’
72530     The value of GEOMETRY should be a list of the form ‘(WIDTH HEIGHT X
72531     Y)’.  WIDTH and HEIGHT specify the width and height of the cropped
72532     image.  If X is a positive number it specifies the offset of the
72533     cropped area from the left of the original image, and if negative
72534     the offset from the right.  If Y is a positive number it specifies
72535     the offset from the top of the original image, and if negative from
72536     the bottom.  If X or Y are ‘nil’ or unspecified the crop area will
72537     be centered on the original image.
72538
72539     If the crop area is outside or overlaps the edge of the image it
72540     will be reduced to exclude any areas outside of the image.  This
72541     means it is not possible to use ‘:crop’ to increase the size of the
72542     image by entering large WIDTH or HEIGHT values.
72543
72544     Cropping is performed after scaling but before rotation.
72545
72546
72547File: elisp.info,  Node: SVG Images,  Next: Other Image Types,  Prev: ImageMagick Images,  Up: Images
72548
7254939.17.6 SVG Images
72550------------------
72551
72552SVG (Scalable Vector Graphics) is an XML format for specifying images.
72553If your Emacs build has SVG support, you can create and manipulate these
72554images with the following functions from the ‘svg.el’ library.
72555
72556 -- Function: svg-create width height &rest args
72557     Create a new, empty SVG image with the specified dimensions.  ARGS
72558     is an argument plist with you can specify following:
72559
72560     ‘:stroke-width’
72561          The default width (in pixels) of any lines created.
72562
72563     ‘:stroke’
72564          The default stroke color on any lines created.
72565
72566     This function returns an “SVG object”, a Lisp data structure that
72567     specifies an SVG image, and all the following functions work on
72568     that structure.  The argument SVG in the following functions
72569     specifies such an SVG object.
72570
72571 -- Function: svg-gradient svg id type stops
72572     Create a gradient in SVG with identifier ID.  TYPE specifies the
72573     gradient type, and can be either ‘linear’ or ‘radial’.  STOPS is a
72574     list of percentage/color pairs.
72575
72576     The following will create a linear gradient that goes from red at
72577     the start, to green 25% of the way, to blue at the end:
72578
72579          (svg-gradient svg "gradient1" 'linear
72580                        '((0 . "red") (25 . "green") (100 . "blue")))
72581
72582     The gradient created (and inserted into the SVG object) can later
72583     be used by all functions that create shapes.
72584
72585   All the following functions take an optional list of keyword
72586parameters that alter the various attributes from their default values.
72587Valid attributes include:
72588
72589‘:stroke-width’
72590     The width (in pixels) of lines drawn, and outlines around solid
72591     shapes.
72592
72593‘:stroke-color’
72594     The color of lines drawn, and outlines around solid shapes.
72595
72596‘:fill-color’
72597     The color used for solid shapes.
72598
72599‘:id’
72600     The identified of the shape.
72601
72602‘:gradient’
72603     If given, this should be the identifier of a previously defined
72604     gradient object.
72605
72606‘:clip-path’
72607     Identifier of a clip path.
72608
72609 -- Function: svg-rectangle svg x y width height &rest args
72610     Add to SVG a rectangle whose upper left corner is at position X/Y
72611     and whose size is WIDTH/HEIGHT.
72612
72613          (svg-rectangle svg 100 100 500 500 :gradient "gradient1")
72614
72615 -- Function: svg-circle svg x y radius &rest args
72616     Add to SVG a circle whose center is at X/Y and whose radius is
72617     RADIUS.
72618
72619 -- Function: svg-ellipse svg x y x-radius y-radius &rest args
72620     Add to SVG an ellipse whose center is at X/Y, and whose horizontal
72621     radius is X-RADIUS and the vertical radius is Y-RADIUS.
72622
72623 -- Function: svg-line svg x1 y1 x2 y2 &rest args
72624     Add to SVG a line that starts at X1/Y1 and extends to X2/Y2.
72625
72626 -- Function: svg-polyline svg points &rest args
72627     Add to SVG a multiple-segment line (a.k.a. “polyline”) that goes
72628     through POINTS, which is a list of X/Y position pairs.
72629
72630          (svg-polyline svg '((200 . 100) (500 . 450) (80 . 100))
72631                        :stroke-color "green")
72632
72633 -- Function: svg-polygon svg points &rest args
72634     Add a polygon to SVG where POINTS is a list of X/Y pairs that
72635     describe the outer circumference of the polygon.
72636
72637          (svg-polygon svg '((100 . 100) (200 . 150) (150 . 90))
72638                       :stroke-color "blue" :fill-color "red")
72639
72640 -- Function: svg-path svg commands &rest args
72641     Add the outline of a shape to SVG according to COMMANDS, see *note
72642     SVG Path Commands::.
72643
72644     Coordinates by default are absolute.  To use coordinates relative
72645     to the last position, or – initially – to the origin, set the
72646     attribute :RELATIVE to ‘t’.  This attribute can be specified for
72647     the function or for individual commands.  If specified for the
72648     function, then all commands use relative coordinates by default.
72649     To make an individual command use absolute coordinates, set
72650     :RELATIVE to ‘nil’.
72651
72652          (svg-path svg
72653          	  '((moveto ((100 . 100)))
72654          	    (lineto ((200 . 0) (0 . 200) (-200 . 0)))
72655          	    (lineto ((100 . 100)) :relative nil))
72656          	  :stroke-color "blue"
72657          	  :fill-color "lightblue"
72658          	  :relative t)
72659
72660 -- Function: svg-text svg text &rest args
72661     Add the specified TEXT to SVG.
72662
72663          (svg-text
72664           svg "This is a text"
72665           :font-size "40"
72666           :font-weight "bold"
72667           :stroke "black"
72668           :fill "white"
72669           :font-family "impact"
72670           :letter-spacing "4pt"
72671           :x 300
72672           :y 400
72673           :stroke-width 1)
72674
72675 -- Function: svg-embed svg image image-type datap &rest args
72676     Add an embedded (raster) image to SVG.  If DATAP is ‘nil’, IMAGE
72677     should be a file name; otherwise it should be a string containing
72678     the image data as raw bytes.  IMAGE-TYPE should be a MIME image
72679     type, for instance ‘"image/jpeg"’.
72680
72681          (svg-embed svg "~/rms.jpg" "image/jpeg" nil
72682                     :width "100px" :height "100px"
72683                     :x "50px" :y "75px")
72684
72685 -- Function: svg-clip-path svg &rest args
72686     Add a clipping path to SVG.  If applied to a shape via the
72687     :CLIP-PATH property, parts of that shape which lie outside of the
72688     clipping path are not drawn.
72689
72690          (let ((clip-path (svg-clip-path svg :id "foo")))
72691            (svg-circle clip-path 200 200 175))
72692          (svg-rectangle svg 50 50 300 300
72693                         :fill-color "red"
72694                         :clip-path "url(#foo)")
72695
72696 -- Function: svg-node svg tag &rest args
72697     Add the custom node TAG to SVG.
72698
72699          (svg-node svg
72700                    'rect
72701                    :width 300 :height 200 :x 50 :y 100 :fill-color "green")
72702
72703 -- Function: svg-remove svg id
72704     Remove the element with identifier ‘id’ from the ‘svg’.
72705
72706 -- Function: svg-image svg
72707     Finally, the ‘svg-image’ takes an SVG object as its argument and
72708     returns an image object suitable for use in functions like
72709     ‘insert-image’.
72710
72711   Here’s a complete example that creates and inserts an image with a
72712circle:
72713
72714     (let ((svg (svg-create 400 400 :stroke-width 10)))
72715       (svg-gradient svg "gradient1" 'linear '((0 . "red") (100 . "blue")))
72716       (svg-circle svg 200 200 100 :gradient "gradient1"
72717                       :stroke-color "green")
72718       (insert-image (svg-image svg)))
72719
72720SVG Path Commands
72721.................
72722
72723“SVG paths” allow creation of complex images by combining lines, curves,
72724arcs, and other basic shapes.  The functions described below allow
72725invoking SVG path commands from a Lisp program.
72726
72727 -- Command: moveto points
72728     Move the pen to the first point in POINTS.  Additional points are
72729     connected with lines.  POINTS is a list of X/Y coordinate pairs.
72730     Subsequent ‘moveto’ commands represent the start of a new
72731     “subpath”.
72732
72733          (svg-path svg '((moveto ((200 . 100) (100 . 200) (0 . 100))))
72734                    :fill "white" :stroke "black")
72735
72736 -- Command: closepath
72737     End the current subpath by connecting it back to its initial point.
72738     A line is drawn along the connection.
72739
72740          (svg-path svg '((moveto ((200 . 100) (100 . 200) (0 . 100)))
72741                          (closepath)
72742                          (moveto ((75 . 125) (100 . 150) (125 . 125)))
72743                          (closepath))
72744                    :fill "red" :stroke "black")
72745
72746 -- Command: lineto points
72747     Draw a line from the current point to the first element in POINTS,
72748     a list of X/Y position pairs.  If more than one point is specified,
72749     draw a polyline.
72750          (svg-path svg '((moveto ((200 . 100)))
72751                          (lineto ((100 . 200) (0 . 100))))
72752                    :fill "yellow" :stroke "red")
72753
72754 -- Command: horizontal-lineto x-coordinates
72755     Draw a horizontal line from the current point to the first element
72756     in X-COORDINATES.  Specifying multiple coordinates is possible,
72757     although usually this doesn’t make sense.
72758
72759          (svg-path svg '((moveto ((100 . 200)))
72760                          (horizontal-lineto (300)))
72761                    :stroke "green")
72762
72763 -- Command: vertical-lineto y-coordinates
72764     Draw vertical lines.
72765
72766          (svg-path svg '((moveto ((200 . 100)))
72767                          (vertical-lineto (300)))
72768                    :stroke "green")
72769
72770 -- Command: curveto coordinate-sets
72771     Using the first element in COORDINATE-SETS, draw a cubic Bézier
72772     curve from the current point.  If there are multiple coordinate
72773     sets, draw a polybezier.  Each coordinate set is a list of the form
72774     ‘(X1 Y1 X2 Y2 X Y)’, where (X, Y) is the curve’s end point.
72775     (X1, Y1) and (X2, Y2) are control points at the beginning and at
72776     the end, respectively.
72777
72778          (svg-path svg '((moveto ((100 . 100)))
72779                          (curveto ((200 100 100 200 200 200)
72780                                    (300 200 0 100 100 100))))
72781                    :fill "transparent" :stroke "red")
72782
72783 -- Command: smooth-curveto coordinate-sets
72784     Using the first element in COORDINATE-SETS, draw a cubic Bézier
72785     curve from the current point.  If there are multiple coordinate
72786     sets, draw a polybezier.  Each coordinate set is a list of the form
72787     ‘(X2 Y2 X Y)’, where (X, Y) is the curve’s end point and (X2, Y2)
72788     is the corresponding control point.  The first control point is the
72789     reflection of the second control point of the previous command
72790     relative to the current point, if that command was ‘curveto’ or
72791     ‘smooth-curveto’.  Otherwise the first control point coincides with
72792     the current point.
72793
72794          (svg-path svg '((moveto ((100 . 100)))
72795                          (curveto ((200 100 100 200 200 200)))
72796                          (smooth-curveto ((0 100 100 100))))
72797                    :fill "transparent" :stroke "blue")
72798
72799 -- Command: quadratic-bezier-curveto coordinate-sets
72800     Using the first element in COORDINATE-SETS, draw a quadratic Bézier
72801     curve from the current point.  If there are multiple coordinate
72802     sets, draw a polybezier.  Each coordinate set is a list of the form
72803     ‘(X1 Y1 X Y)’, where (X, Y) is the curve’s end point and (X1, Y1)
72804     is the control point.
72805
72806          (svg-path svg '((moveto ((200 . 100)))
72807                          (quadratic-bezier-curveto ((300 100 300 200)))
72808                          (quadratic-bezier-curveto ((300 300 200 300)))
72809                          (quadratic-bezier-curveto ((100 300 100 200)))
72810                          (quadratic-bezier-curveto ((100 100 200 100))))
72811                    :fill "transparent" :stroke "pink")
72812
72813 -- Command: smooth-quadratic-bezier-curveto coordinate-sets
72814     Using the first element in COORDINATE-SETS, draw a quadratic Bézier
72815     curve from the current point.  If there are multiple coordinate
72816     sets, draw a polybezier.  Each coordinate set is a list of the form
72817     ‘(X Y)’, where (X, Y) is the curve’s end point.  The control point
72818     is the reflection of the control point of the previous command
72819     relative to the current point, if that command was
72820     ‘quadratic-bezier-curveto’ or ‘smooth-quadratic-bezier-curveto’.
72821     Otherwise the control point coincides with the current point.
72822
72823          (svg-path svg '((moveto ((200 . 100)))
72824                          (quadratic-bezier-curveto ((300 100 300 200)))
72825                          (smooth-quadratic-bezier-curveto ((200 300)))
72826                          (smooth-quadratic-bezier-curveto ((100 200)))
72827                          (smooth-quadratic-bezier-curveto ((200 100))))
72828                    :fill "transparent" :stroke "lightblue")
72829
72830 -- Command: elliptical-arc coordinate-sets
72831     Using the first element in COORDINATE-SETS, draw an elliptical arc
72832     from the current point.  If there are multiple coordinate sets,
72833     draw a sequence of elliptical arcs.  Each coordinate set is a list
72834     of the form ‘(RX RY X Y)’, where (X, Y) is the end point of the
72835     ellipse, and (RX, RY) are its radii.  Attributes may be appended to
72836     the list:
72837
72838     ‘:x-axis-rotation’
72839          The angle in degrees by which the x-axis of the ellipse is
72840          rotated relative to the x-axis of the current coordinate
72841          system.
72842
72843     ‘:large-arc’
72844          If set to ‘t’, draw an arc sweep greater than or equal to 180
72845          degrees.  Otherwise, draw an arc sweep smaller than or equal
72846          to 180 degrees.
72847
72848     ‘:sweep’
72849          If set to ‘t’, draw an arc in “positive angle direction”.
72850          Otherwise, draw it in “negative angle direction”.
72851
72852          (svg-path svg '((moveto ((200 . 250)))
72853                          (elliptical-arc ((75 75 200 350))))
72854                    :fill "transparent" :stroke "red")
72855          (svg-path svg '((moveto ((200 . 250)))
72856                          (elliptical-arc ((75 75 200 350 :large-arc t))))
72857                    :fill "transparent" :stroke "green")
72858          (svg-path svg '((moveto ((200 . 250)))
72859                          (elliptical-arc ((75 75 200 350 :sweep t))))
72860                    :fill "transparent" :stroke "blue")
72861          (svg-path svg '((moveto ((200 . 250)))
72862                          (elliptical-arc ((75 75 200 350 :large-arc t
72863                                               :sweep t))))
72864                    :fill "transparent" :stroke "gray")
72865          (svg-path svg '((moveto ((160 . 100)))
72866                          (elliptical-arc ((40 100 80 0)))
72867                          (elliptical-arc ((40 100 -40 -70
72868                                               :x-axis-rotation -120)))
72869                          (elliptical-arc ((40 100 -40 70
72870                                               :x-axis-rotation -240))))
72871                    :stroke "pink" :fill "lightblue"
72872                    :relative t)
72873
72874
72875File: elisp.info,  Node: Other Image Types,  Next: Defining Images,  Prev: SVG Images,  Up: Images
72876
7287739.17.7 Other Image Types
72878-------------------------
72879
72880For PBM images, specify image type ‘pbm’.  Color, gray-scale and
72881monochromatic images are supported.  For mono PBM images, two additional
72882image properties are supported.
72883
72884‘:foreground FOREGROUND’
72885     The value, FOREGROUND, should be a string specifying the image
72886     foreground color, or ‘nil’ for the default color.  This color is
72887     used for each pixel in the PBM that is 1.  The default is the
72888     frame’s foreground color.
72889
72890‘:background BACKGROUND’
72891     The value, BACKGROUND, should be a string specifying the image
72892     background color, or ‘nil’ for the default color.  This color is
72893     used for each pixel in the PBM that is 0.  The default is the
72894     frame’s background color.
72895
72896The remaining image types that Emacs can support are:
72897
72898GIF
72899     Image type ‘gif’.  Supports the ‘:index’ property.  *Note
72900     Multi-Frame Images::.
72901
72902JPEG
72903     Image type ‘jpeg’.
72904
72905PNG
72906     Image type ‘png’.
72907
72908TIFF
72909     Image type ‘tiff’.  Supports the ‘:index’ property.  *Note
72910     Multi-Frame Images::.
72911
72912
72913File: elisp.info,  Node: Defining Images,  Next: Showing Images,  Prev: Other Image Types,  Up: Images
72914
7291539.17.8 Defining Images
72916-----------------------
72917
72918The functions ‘create-image’, ‘defimage’ and ‘find-image’ provide
72919convenient ways to create image descriptors.
72920
72921 -- Function: create-image file-or-data &optional type data-p &rest
72922          props
72923     This function creates and returns an image descriptor which uses
72924     the data in FILE-OR-DATA.  FILE-OR-DATA can be a file name or a
72925     string containing the image data; DATA-P should be ‘nil’ for the
72926     former case, non-‘nil’ for the latter case.
72927
72928     The optional argument TYPE is a symbol specifying the image type.
72929     If TYPE is omitted or ‘nil’, ‘create-image’ tries to determine the
72930     image type from the file’s first few bytes, or else from the file’s
72931     name.
72932
72933     The remaining arguments, PROPS, specify additional image
72934     properties—for example,
72935
72936          (create-image "foo.xpm" 'xpm nil :heuristic-mask t)
72937
72938     The function returns ‘nil’ if images of this type are not
72939     supported.  Otherwise it returns an image descriptor.
72940
72941 -- Macro: defimage symbol specs &optional doc
72942     This macro defines SYMBOL as an image name.  The arguments SPECS is
72943     a list which specifies how to display the image.  The third
72944     argument, DOC, is an optional documentation string.
72945
72946     Each argument in SPECS has the form of a property list, and each
72947     one should specify at least the ‘:type’ property and either the
72948     ‘:file’ or the ‘:data’ property.  The value of ‘:type’ should be a
72949     symbol specifying the image type, the value of ‘:file’ is the file
72950     to load the image from, and the value of ‘:data’ is a string
72951     containing the actual image data.  Here is an example:
72952
72953          (defimage test-image
72954            ((:type xpm :file "~/test1.xpm")
72955             (:type xbm :file "~/test1.xbm")))
72956
72957     ‘defimage’ tests each argument, one by one, to see if it is
72958     usable—that is, if the type is supported and the file exists.  The
72959     first usable argument is used to make an image descriptor which is
72960     stored in SYMBOL.
72961
72962     If none of the alternatives will work, then SYMBOL is defined as
72963     ‘nil’.
72964
72965 -- Function: image-property image property
72966     Return the value of PROPERTY in IMAGE.  Properties can be set by
72967     using ‘setf’.  Setting a property to ‘nil’ will remove the property
72968     from the image.
72969
72970 -- Function: find-image specs
72971     This function provides a convenient way to find an image satisfying
72972     one of a list of image specifications SPECS.
72973
72974     Each specification in SPECS is a property list with contents
72975     depending on image type.  All specifications must at least contain
72976     the properties ‘:type TYPE’ and either ‘:file FILE’ or
72977     ‘:data DATA’, where TYPE is a symbol specifying the image type,
72978     e.g., ‘xbm’, FILE is the file to load the image from, and DATA is a
72979     string containing the actual image data.  The first specification
72980     in the list whose TYPE is supported, and FILE exists, is used to
72981     construct the image specification to be returned.  If no
72982     specification is satisfied, ‘nil’ is returned.
72983
72984     The image is looked for in ‘image-load-path’.
72985
72986 -- User Option: image-load-path
72987     This variable’s value is a list of locations in which to search for
72988     image files.  If an element is a string or a variable symbol whose
72989     value is a string, the string is taken to be the name of a
72990     directory to search.  If an element is a variable symbol whose
72991     value is a list, that is taken to be a list of directories to
72992     search.
72993
72994     The default is to search in the ‘images’ subdirectory of the
72995     directory specified by ‘data-directory’, then the directory
72996     specified by ‘data-directory’, and finally in the directories in
72997     ‘load-path’.  Subdirectories are not automatically included in the
72998     search, so if you put an image file in a subdirectory, you have to
72999     supply the subdirectory explicitly.  For example, to find the image
73000images/foo/bar.xpm’ within ‘data-directory’, you should specify
73001     the image as follows:
73002
73003          (defimage foo-image '((:type xpm :file "foo/bar.xpm")))
73004
73005 -- Function: image-load-path-for-library library image &optional path
73006          no-error
73007     This function returns a suitable search path for images used by the
73008     Lisp package LIBRARY.
73009
73010     The function searches for IMAGE first using ‘image-load-path’,
73011     excluding ‘data-directory/images’, and then in ‘load-path’,
73012     followed by a path suitable for LIBRARY, which includes
73013     ‘../../etc/images’ and ‘../etc/images’ relative to the library file
73014     itself, and finally in ‘data-directory/images’.
73015
73016     Then this function returns a list of directories which contains
73017     first the directory in which IMAGE was found, followed by the value
73018     of ‘load-path’.  If PATH is given, it is used instead of
73019     ‘load-path’.
73020
73021     If NO-ERROR is non-‘nil’ and a suitable path can’t be found, don’t
73022     signal an error.  Instead, return a list of directories as before,
73023     except that ‘nil’ appears in place of the image directory.
73024
73025     Here is an example of using ‘image-load-path-for-library’:
73026
73027          (defvar image-load-path) ; shush compiler
73028          (let* ((load-path (image-load-path-for-library
73029                              "mh-e" "mh-logo.xpm"))
73030                 (image-load-path (cons (car load-path)
73031                                        image-load-path)))
73032            (mh-tool-bar-folder-buttons-init))
73033
73034   Images are automatically scaled when created based on the
73035‘image-scaling-factor’ variable.  The value is either a floating point
73036number (where numbers higher than 1 means to increase the size and lower
73037means to shrink the size), or the symbol ‘auto’, which will compute a
73038scaling factor based on the font pixel size.
73039
73040
73041File: elisp.info,  Node: Showing Images,  Next: Multi-Frame Images,  Prev: Defining Images,  Up: Images
73042
7304339.17.9 Showing Images
73044----------------------
73045
73046You can use an image descriptor by setting up the ‘display’ property
73047yourself, but it is easier to use the functions in this section.
73048
73049 -- Function: insert-image image &optional string area slice
73050     This function inserts IMAGE in the current buffer at point.  The
73051     value IMAGE should be an image descriptor; it could be a value
73052     returned by ‘create-image’, or the value of a symbol defined with
73053     ‘defimage’.  The argument STRING specifies the text to put in the
73054     buffer to hold the image.  If it is omitted or ‘nil’,
73055     ‘insert-image’ uses ‘" "’ by default.
73056
73057     The argument AREA specifies whether to put the image in a margin.
73058     If it is ‘left-margin’, the image appears in the left margin;
73059     ‘right-margin’ specifies the right margin.  If AREA is ‘nil’ or
73060     omitted, the image is displayed at point within the buffer’s text.
73061
73062     The argument SLICE specifies a slice of the image to insert.  If
73063     SLICE is ‘nil’ or omitted the whole image is inserted.  Otherwise,
73064     SLICE is a list ‘(X Y WIDTH HEIGHT)’ which specifies the X and Y
73065     positions and WIDTH and HEIGHT of the image area to insert.
73066     Integer values are in units of pixels.  A floating-point number in
73067     the range 0.0–1.0 stands for that fraction of the width or height
73068     of the entire image.
73069
73070     Internally, this function inserts STRING in the buffer, and gives
73071     it a ‘display’ property which specifies IMAGE.  *Note Display
73072     Property::.
73073
73074 -- Function: insert-sliced-image image &optional string area rows cols
73075     This function inserts IMAGE in the current buffer at point, like
73076     ‘insert-image’, but splits the image into ROWSxCOLS equally sized
73077     slices.
73078
73079     Emacs displays each slice as a separate image, and allows more
73080     intuitive scrolling up/down, instead of jumping up/down the entire
73081     image when paging through a buffer that displays (large) images.
73082
73083 -- Function: put-image image pos &optional string area
73084     This function puts image IMAGE in front of POS in the current
73085     buffer.  The argument POS should be an integer or a marker.  It
73086     specifies the buffer position where the image should appear.  The
73087     argument STRING specifies the text that should hold the image as an
73088     alternative to the default.
73089
73090     The argument IMAGE must be an image descriptor, perhaps returned by
73091     ‘create-image’ or stored by ‘defimage’.
73092
73093     The argument AREA specifies whether to put the image in a margin.
73094     If it is ‘left-margin’, the image appears in the left margin;
73095     ‘right-margin’ specifies the right margin.  If AREA is ‘nil’ or
73096     omitted, the image is displayed at point within the buffer’s text.
73097
73098     Internally, this function creates an overlay, and gives it a
73099     ‘before-string’ property containing text that has a ‘display’
73100     property whose value is the image.  (Whew!)
73101
73102 -- Function: remove-images start end &optional buffer
73103     This function removes images in BUFFER between positions START and
73104     END.  If BUFFER is omitted or ‘nil’, images are removed from the
73105     current buffer.
73106
73107     This removes only images that were put into BUFFER the way
73108     ‘put-image’ does it, not images that were inserted with
73109     ‘insert-image’ or in other ways.
73110
73111 -- Function: image-size spec &optional pixels frame
73112     This function returns the size of an image as a pair
73113     ‘(WIDTH . HEIGHT)’.  SPEC is an image specification.  PIXELS
73114     non-‘nil’ means return sizes measured in pixels, otherwise return
73115     sizes measured in the default character size of FRAME (*note Frame
73116     Font::).  FRAME is the frame on which the image will be displayed.
73117     FRAME ‘nil’ or omitted means use the selected frame (*note Input
73118     Focus::).
73119
73120 -- Variable: max-image-size
73121     This variable is used to define the maximum size of image that
73122     Emacs will load.  Emacs will refuse to load (and display) any image
73123     that is larger than this limit.
73124
73125     If the value is an integer, it directly specifies the maximum image
73126     height and width, measured in pixels.  If it is floating point, it
73127     specifies the maximum image height and width as a ratio to the
73128     frame height and width.  If the value is non-numeric, there is no
73129     explicit limit on the size of images.
73130
73131     The purpose of this variable is to prevent unreasonably large
73132     images from accidentally being loaded into Emacs.  It only takes
73133     effect the first time an image is loaded.  Once an image is placed
73134     in the image cache, it can always be displayed, even if the value
73135     of ‘max-image-size’ is subsequently changed (*note Image Cache::).
73136
73137   Images inserted with the insertion functions above also get a local
73138keymap installed in the text properties (or overlays) that span the
73139displayed image.  This keymap defines the following commands:
73140
73141‘+’
73142     Increase the image size (‘image-increase-size’).  A prefix value of
73143     ‘4’ means to increase the size by 40%.  The default is 20%.
73144
73145‘-’
73146     Decrease the image size (‘image-increase-size’).  A prefix value of
73147     ‘4’ means to decrease the size by 40%.  The default is 20%.
73148
73149‘r’
73150     Rotate the image by 90 degrees clockwise (‘image-rotate’).  A
73151     prefix means to rotate by 90 degrees counter-clockwise instead.
73152
73153‘o’
73154     Save the image to a file (‘image-save’).
73155
73156
73157File: elisp.info,  Node: Multi-Frame Images,  Next: Image Cache,  Prev: Showing Images,  Up: Images
73158
7315939.17.10 Multi-Frame Images
73160---------------------------
73161
73162Some image files can contain more than one image.  We say that there are
73163multiple “frames” in the image.  At present, Emacs supports multiple
73164frames for GIF, TIFF, and certain ImageMagick formats such as DJVM.
73165
73166   The frames can be used either to represent multiple pages (this is
73167usually the case with multi-frame TIFF files, for example), or to create
73168animation (usually the case with multi-frame GIF files).
73169
73170   A multi-frame image has a property ‘:index’, whose value is an
73171integer (counting from 0) that specifies which frame is being displayed.
73172
73173 -- Function: image-multi-frame-p image
73174     This function returns non-‘nil’ if IMAGE contains more than one
73175     frame.  The actual return value is a cons ‘(NIMAGES . DELAY)’,
73176     where NIMAGES is the number of frames and DELAY is the delay in
73177     seconds between them, or ‘nil’ if the image does not specify a
73178     delay.  Images that are intended to be animated usually specify a
73179     frame delay, whereas ones that are intended to be treated as
73180     multiple pages do not.
73181
73182 -- Function: image-current-frame image
73183     This function returns the index of the current frame number for
73184     IMAGE, counting from 0.
73185
73186 -- Function: image-show-frame image n &optional nocheck
73187     This function switches IMAGE to frame number N.  It replaces a
73188     frame number outside the valid range with that of the end of the
73189     range, unless NOCHECK is non-‘nil’.  If IMAGE does not contain a
73190     frame with the specified number, the image displays as a hollow
73191     box.
73192
73193 -- Function: image-animate image &optional index limit
73194     This function animates IMAGE.  The optional integer INDEX specifies
73195     the frame from which to start (default 0).  The optional argument
73196     LIMIT controls the length of the animation.  If omitted or ‘nil’,
73197     the image animates once only; if ‘t’ it loops forever; if a number
73198     animation stops after that many seconds.
73199
73200Animation operates by means of a timer.  Note that Emacs imposes a
73201minimum frame delay of 0.01 (‘image-minimum-frame-delay’) seconds.  If
73202the image itself does not specify a delay, Emacs uses
73203‘image-default-frame-delay’.
73204
73205 -- Function: image-animate-timer image
73206     This function returns the timer responsible for animating IMAGE, if
73207     there is one.
73208
73209
73210File: elisp.info,  Node: Image Cache,  Prev: Multi-Frame Images,  Up: Images
73211
7321239.17.11 Image Cache
73213--------------------
73214
73215Emacs caches images so that it can display them again more efficiently.
73216When Emacs displays an image, it searches the image cache for an
73217existing image specification ‘equal’ to the desired specification.  If a
73218match is found, the image is displayed from the cache.  Otherwise, Emacs
73219loads the image normally.
73220
73221 -- Function: image-flush spec &optional frame
73222     This function removes the image with specification SPEC from the
73223     image cache of frame FRAME.  Image specifications are compared
73224     using ‘equal’.  If FRAME is ‘nil’, it defaults to the selected
73225     frame.  If FRAME is ‘t’, the image is flushed on all existing
73226     frames.
73227
73228     In Emacs’s current implementation, each graphical terminal
73229     possesses an image cache, which is shared by all the frames on that
73230     terminal (*note Multiple Terminals::).  Thus, refreshing an image
73231     in one frame also refreshes it in all other frames on the same
73232     terminal.
73233
73234   One use for ‘image-flush’ is to tell Emacs about a change in an image
73235file.  If an image specification contains a ‘:file’ property, the image
73236is cached based on the file’s contents when the image is first
73237displayed.  Even if the file subsequently changes, Emacs continues
73238displaying the old version of the image.  Calling ‘image-flush’ flushes
73239the image from the cache, forcing Emacs to re-read the file the next
73240time it needs to display that image.
73241
73242   Another use for ‘image-flush’ is for memory conservation.  If your
73243Lisp program creates a large number of temporary images over a period
73244much shorter than ‘image-cache-eviction-delay’ (see below), you can opt
73245to flush unused images yourself, instead of waiting for Emacs to do it
73246automatically.
73247
73248 -- Function: clear-image-cache &optional filter
73249     This function clears an image cache, removing all the images stored
73250     in it.  If FILTER is omitted or ‘nil’, it clears the cache for the
73251     selected frame.  If FILTER is a frame, it clears the cache for that
73252     frame.  If FILTER is ‘t’, all image caches are cleared.  Otherwise,
73253     FILTER is taken to be a file name, and all images associated with
73254     that file name are removed from all image caches.
73255
73256   If an image in the image cache has not been displayed for a specified
73257period of time, Emacs removes it from the cache and frees the associated
73258memory.
73259
73260 -- Variable: image-cache-eviction-delay
73261     This variable specifies the number of seconds an image can remain
73262     in the cache without being displayed.  When an image is not
73263     displayed for this length of time, Emacs removes it from the image
73264     cache.
73265
73266     Under some circumstances, if the number of images in the cache
73267     grows too large, the actual eviction delay may be shorter than
73268     this.
73269
73270     If the value is ‘nil’, Emacs does not remove images from the cache
73271     except when you explicitly clear it.  This mode can be useful for
73272     debugging.
73273
73274
73275File: elisp.info,  Node: Xwidgets,  Next: Buttons,  Prev: Images,  Up: Display
73276
7327739.18 Embedded Native Widgets
73278=============================
73279
73280Emacs is able to display native widgets, such as GTK+ WebKit widgets, in
73281Emacs buffers when it was built with the necessary support libraries and
73282is running on a graphical terminal.  To test whether Emacs supports
73283display of embedded widgets, check that the ‘xwidget-internal’ feature
73284is available (*note Named Features::).
73285
73286   To display an embedded widget in a buffer, you must first create an
73287xwidget object, and then use that object as the display specifier in a
73288‘display’ text or overlay property (*note Display Property::).
73289
73290 -- Function: make-xwidget type title width height arguments &optional
73291          buffer
73292     This creates and returns an xwidget object.  If BUFFER is omitted
73293     or ‘nil’, it defaults to the current buffer.  If BUFFER names a
73294     buffer that doesn’t exist, it will be created.  The TYPE identifies
73295     the type of the xwidget component, it can be one of the following:
73296
73297     ‘webkit’
73298          The WebKit component.
73299
73300     The WIDTH and HEIGHT arguments specify the widget size in pixels,
73301     and TITLE, a string, specifies its title.
73302
73303 -- Function: xwidgetp object
73304     This function returns ‘t’ if OBJECT is an xwidget, ‘nil’ otherwise.
73305
73306 -- Function: xwidget-plist xwidget
73307     This function returns the property list of XWIDGET.
73308
73309 -- Function: set-xwidget-plist xwidget plist
73310     This function replaces the property list of XWIDGET with a new
73311     property list given by PLIST.
73312
73313 -- Function: xwidget-buffer xwidget
73314     This function returns the buffer of XWIDGET.
73315
73316 -- Function: get-buffer-xwidgets buffer
73317     This function returns a list of xwidget objects associated with the
73318     BUFFER, which can be specified as a buffer object or a name of an
73319     existing buffer, a string.  The value is ‘nil’ if BUFFER contains
73320     no xwidgets.
73321
73322 -- Function: xwidget-webkit-goto-uri xwidget uri
73323     This function browses the specified URI in the given XWIDGET.  The
73324     URI is a string that specifies the name of a file or a URL.
73325
73326 -- Function: xwidget-webkit-execute-script xwidget script
73327     This function causes the browser widget specified by XWIDGET to
73328     execute the specified JavaScript ‘script’.
73329
73330 -- Function: xwidget-webkit-execute-script-rv xwidget script &optional
73331          default
73332     This function executes the specified SCRIPT like
73333     ‘xwidget-webkit-execute-script’ does, but it also returns the
73334     script’s return value as a string.  If SCRIPT doesn’t return a
73335     value, this function returns DEFAULT, or ‘nil’ if DEFAULT was
73336     omitted.
73337
73338 -- Function: xwidget-webkit-get-title xwidget
73339     This function returns the title of XWIDGET as a string.
73340
73341 -- Function: xwidget-resize xwidget width height
73342     This function resizes the specified XWIDGET to the size
73343     WIDTHxHEIGHT pixels.
73344
73345 -- Function: xwidget-size-request xwidget
73346     This function returns the desired size of XWIDGET as a list of the
73347     form ‘(WIDTH HEIGHT)’.  The dimensions are in pixels.
73348
73349 -- Function: xwidget-info xwidget
73350     This function returns the attributes of XWIDGET as a vector of the
73351     form ‘[TYPE TITLE WIDTH HEIGHT]’.  The attributes are usually
73352     determined by ‘make-xwidget’ when the xwidget is created.
73353
73354 -- Function: set-xwidget-query-on-exit-flag xwidget flag
73355     This function allows you to arrange that Emacs will ask the user
73356     for confirmation before exiting or before killing a buffer that has
73357     XWIDGET associated with it.  If FLAG is non-‘nil’, Emacs will query
73358     the user, otherwise it will not.
73359
73360 -- Function: xwidget-query-on-exit-flag xwidget
73361     This function returns the current setting of XWIDGETs query-on-exit
73362     flag, either ‘t’ or ‘nil’.
73363
73364
73365File: elisp.info,  Node: Buttons,  Next: Abstract Display,  Prev: Xwidgets,  Up: Display
73366
7336739.19 Buttons
73368=============
73369
73370The Button package defines functions for inserting and manipulating
73371“buttons” that can be activated with the mouse or via keyboard commands.
73372These buttons are typically used for various kinds of hyperlinks.
73373
73374   A button is essentially a set of text or overlay properties, attached
73375to a stretch of text in a buffer.  These properties are called “button
73376properties”.  One of these properties, the “action property”, specifies
73377a function which is called when the user invokes the button using the
73378keyboard or the mouse.  The action function may examine the button and
73379use its other properties as desired.
73380
73381   In some ways, the Button package duplicates the functionality in the
73382Widget package.  *Note Introduction: (widget)Top.  The advantage of the
73383Button package is that it is faster, smaller, and simpler to program.
73384From the point of view of the user, the interfaces produced by the two
73385packages are very similar.
73386
73387* Menu:
73388
73389* Button Properties::      Button properties with special meanings.
73390* Button Types::           Defining common properties for classes of buttons.
73391* Making Buttons::         Adding buttons to Emacs buffers.
73392* Manipulating Buttons::   Getting and setting properties of buttons.
73393* Button Buffer Commands:: Buffer-wide commands and bindings for buttons.
73394
73395
73396File: elisp.info,  Node: Button Properties,  Next: Button Types,  Up: Buttons
73397
7339839.19.1 Button Properties
73399-------------------------
73400
73401Each button has an associated list of properties defining its appearance
73402and behavior, and other arbitrary properties may be used for application
73403specific purposes.  The following properties have special meaning to the
73404Button package:
73405
73406‘action’
73407     The function to call when the user invokes the button, which is
73408     passed the single argument BUTTON.  By default this is ‘ignore’,
73409     which does nothing.
73410
73411‘mouse-action’
73412     This is similar to ‘action’, and when present, will be used instead
73413     of ‘action’ for button invocations resulting from mouse-clicks
73414     (instead of the user hitting <RET>).  If not present, mouse-clicks
73415     use ‘action’ instead.
73416
73417‘face’
73418     This is an Emacs face controlling how buttons of this type are
73419     displayed; by default this is the ‘button’ face.
73420
73421‘mouse-face’
73422     This is an additional face which controls appearance during
73423     mouse-overs (merged with the usual button face); by default this is
73424     the usual Emacs ‘highlight’ face.
73425
73426‘keymap’
73427     The button’s keymap, defining bindings active within the button
73428     region.  By default this is the usual button region keymap, stored
73429     in the variable ‘button-map’, which defines <RET> and <mouse-2> to
73430     invoke the button.
73431
73432‘type’
73433     The button type.  *Note Button Types::.
73434
73435‘help-echo’
73436     A string displayed by the Emacs tooltip help system; by default,
73437     ‘"mouse-2, RET: Push this button"’.  Alternatively, a function that
73438     returns, or a form that evaluates to, a string to be displayed or
73439     ‘nil’.  For details see *note Text help-echo::.
73440
73441     The function is called with three arguments, WINDOW, OBJECT, and
73442     POS.  The second argument, OBJECT, is either the overlay that had
73443     the property (for overlay buttons), or the buffer containing the
73444     button (for text property buttons).  The other arguments have the
73445     same meaning as for the special text property ‘help-echo’.
73446
73447‘follow-link’
73448     The ‘follow-link’ property, defining how a <mouse-1> click behaves
73449     on this button, *Note Clickable Text::.
73450
73451‘button’
73452     All buttons have a non-‘nil’ ‘button’ property, which may be useful
73453     in finding regions of text that comprise buttons (which is what the
73454     standard button functions do).
73455
73456   There are other properties defined for the regions of text in a
73457button, but these are not generally interesting for typical uses.
73458
73459
73460File: elisp.info,  Node: Button Types,  Next: Making Buttons,  Prev: Button Properties,  Up: Buttons
73461
7346239.19.2 Button Types
73463--------------------
73464
73465Every button has a “button type”, which defines default values for the
73466button’s properties.  Button types are arranged in a hierarchy, with
73467specialized types inheriting from more general types, so that it’s easy
73468to define special-purpose types of buttons for specific tasks.
73469
73470 -- Function: define-button-type name &rest properties
73471     Define a button type called NAME (a symbol).  The remaining
73472     arguments form a sequence of PROPERTY VALUE pairs, specifying
73473     default property values for buttons with this type (a button’s type
73474     may be set by giving it a ‘type’ property when creating the button,
73475     using the ‘:type’ keyword argument).
73476
73477     In addition, the keyword argument ‘:supertype’ may be used to
73478     specify a button-type from which NAME inherits its default property
73479     values.  Note that this inheritance happens only when NAME is
73480     defined; subsequent changes to a supertype are not reflected in its
73481     subtypes.
73482
73483   Using ‘define-button-type’ to define default properties for buttons
73484is not necessary—buttons without any specified type use the built-in
73485button-type ‘button’—but it is encouraged, since doing so usually makes
73486the resulting code clearer and more efficient.
73487
73488
73489File: elisp.info,  Node: Making Buttons,  Next: Manipulating Buttons,  Prev: Button Types,  Up: Buttons
73490
7349139.19.3 Making Buttons
73492----------------------
73493
73494Buttons are associated with a region of text, using an overlay or text
73495properties to hold button-specific information, all of which are
73496initialized from the button’s type (which defaults to the built-in
73497button type ‘button’).  Like all Emacs text, the appearance of the
73498button is governed by the ‘face’ property; by default (via the ‘face’
73499property inherited from the ‘button’ button-type) this is a simple
73500underline, like a typical web-page link.
73501
73502   For convenience, there are two sorts of button-creation functions,
73503those that add button properties to an existing region of a buffer,
73504called ‘make-...button’, and those that also insert the button text,
73505called ‘insert-...button’.
73506
73507   The button-creation functions all take the ‘&rest’ argument
73508PROPERTIES, which should be a sequence of PROPERTY VALUE pairs,
73509specifying properties to add to the button; see *note Button
73510Properties::.  In addition, the keyword argument ‘:type’ may be used to
73511specify a button-type from which to inherit other properties; see *note
73512Button Types::.  Any properties not explicitly specified during creation
73513will be inherited from the button’s type (if the type defines such a
73514property).
73515
73516   The following functions add a button using an overlay (*note
73517Overlays::) to hold the button properties:
73518
73519 -- Function: make-button beg end &rest properties
73520     This makes a button from BEG to END in the current buffer, and
73521     returns it.
73522
73523 -- Function: insert-button label &rest properties
73524     This insert a button with the label LABEL at point, and returns it.
73525
73526   The following functions are similar, but using text properties (*note
73527Text Properties::) to hold the button properties.  Such buttons do not
73528add markers to the buffer, so editing in the buffer does not slow down
73529if there is an extremely large numbers of buttons.  However, if there is
73530an existing face text property on the text (e.g., a face assigned by
73531Font Lock mode), the button face may not be visible.  Both of these
73532functions return the starting position of the new button.
73533
73534 -- Function: make-text-button beg end &rest properties
73535     This makes a button from BEG to END in the current buffer, using
73536     text properties.
73537
73538 -- Function: insert-text-button label &rest properties
73539     This inserts a button with the label LABEL at point, using text
73540     properties.
73541
73542
73543File: elisp.info,  Node: Manipulating Buttons,  Next: Button Buffer Commands,  Prev: Making Buttons,  Up: Buttons
73544
7354539.19.4 Manipulating Buttons
73546----------------------------
73547
73548These are functions for getting and setting properties of buttons.
73549Often these are used by a button’s invocation function to determine what
73550to do.
73551
73552   Where a BUTTON parameter is specified, it means an object referring
73553to a specific button, either an overlay (for overlay buttons), or a
73554buffer-position or marker (for text property buttons).  Such an object
73555is passed as the first argument to a button’s invocation function when
73556it is invoked.
73557
73558 -- Function: button-start button
73559     Return the position at which BUTTON starts.
73560
73561 -- Function: button-end button
73562     Return the position at which BUTTON ends.
73563
73564 -- Function: button-get button prop
73565     Get the property of button BUTTON named PROP.
73566
73567 -- Function: button-put button prop val
73568     Set BUTTON’s PROP property to VAL.
73569
73570 -- Function: button-activate button &optional use-mouse-action
73571     Call BUTTON’s ‘action’ property (i.e., invoke the function that is
73572     the value of that property, passing it the single argument BUTTON).
73573     If USE-MOUSE-ACTION is non-‘nil’, try to invoke the button’s
73574     ‘mouse-action’ property instead of ‘action’; if the button has no
73575     ‘mouse-action’ property, use ‘action’ as normal.  If the
73576     ‘button-data’ property is present in BUTTON, use that as the
73577     argument for the ‘action’ function instead of BUTTON.
73578
73579 -- Function: button-label button
73580     Return BUTTON’s text label.
73581
73582 -- Function: button-type button
73583     Return BUTTON’s button-type.
73584
73585 -- Function: button-has-type-p button type
73586     Return ‘t’ if BUTTON has button-type TYPE, or one of TYPE’s
73587     subtypes.
73588
73589 -- Function: button-at pos
73590     Return the button at position POS in the current buffer, or ‘nil’.
73591     If the button at POS is a text property button, the return value is
73592     a marker pointing to POS.
73593
73594 -- Function: button-type-put type prop val
73595     Set the button-type TYPE’s PROP property to VAL.
73596
73597 -- Function: button-type-get type prop
73598     Get the property of button-type TYPE named PROP.
73599
73600 -- Function: button-type-subtype-p type supertype
73601     Return ‘t’ if button-type TYPE is a subtype of SUPERTYPE.
73602
73603
73604File: elisp.info,  Node: Button Buffer Commands,  Prev: Manipulating Buttons,  Up: Buttons
73605
7360639.19.5 Button Buffer Commands
73607------------------------------
73608
73609These are commands and functions for locating and operating on buttons
73610in an Emacs buffer.
73611
73612   ‘push-button’ is the command that a user uses to actually push a
73613button, and is bound by default in the button itself to <RET> and to
73614<mouse-2> using a local keymap in the button’s overlay or text
73615properties.  Commands that are useful outside the buttons itself, such
73616as ‘forward-button’ and ‘backward-button’ are additionally available in
73617the keymap stored in ‘button-buffer-map’; a mode which uses buttons may
73618want to use ‘button-buffer-map’ as a parent keymap for its keymap.
73619
73620   If the button has a non-‘nil’ ‘follow-link’ property, and
73621‘mouse-1-click-follows-link’ is set, a quick <mouse-1> click will also
73622activate the ‘push-button’ command.  *Note Clickable Text::.
73623
73624 -- Command: push-button &optional pos use-mouse-action
73625     Perform the action specified by a button at location POS.  POS may
73626     be either a buffer position or a mouse-event.  If USE-MOUSE-ACTION
73627     is non-‘nil’, or POS is a mouse-event (*note Mouse Events::), try
73628     to invoke the button’s ‘mouse-action’ property instead of ‘action’;
73629     if the button has no ‘mouse-action’ property, use ‘action’ as
73630     normal.  POS defaults to point, except when ‘push-button’ is
73631     invoked interactively as the result of a mouse-event, in which
73632     case, the mouse event’s position is used.  If there’s no button at
73633     POS, do nothing and return ‘nil’, otherwise return ‘t’.
73634
73635 -- Command: forward-button n &optional wrap display-message no-error
73636     Move to the Nth next button, or Nth previous button if N is
73637     negative.  If N is zero, move to the start of any button at point.
73638     If WRAP is non-‘nil’, moving past either end of the buffer
73639     continues from the other end.  If DISPLAY-MESSAGE is non-‘nil’, the
73640     button’s help-echo string is displayed.  Any button with a
73641     non-‘nil’ ‘skip’ property is skipped over.  Returns the button
73642     found, and signals an error if no buttons can be found.  If
73643     NO-ERROR is non-‘nil’, return nil instead of signaling the error.
73644
73645 -- Command: backward-button n &optional wrap display-message no-error
73646     Move to the Nth previous button, or Nth next button if N is
73647     negative.  If N is zero, move to the start of any button at point.
73648     If WRAP is non-‘nil’, moving past either end of the buffer
73649     continues from the other end.  If DISPLAY-MESSAGE is non-‘nil’, the
73650     button’s help-echo string is displayed.  Any button with a
73651     non-‘nil’ ‘skip’ property is skipped over.  Returns the button
73652     found, and signals an error if no buttons can be found.  If
73653     NO-ERROR is non-‘nil’, return nil instead of signaling the error.
73654
73655 -- Function: next-button pos &optional count-current
73656 -- Function: previous-button pos &optional count-current
73657     Return the next button after (for ‘next-button’) or before (for
73658     ‘previous-button’) position POS in the current buffer.  If
73659     COUNT-CURRENT is non-‘nil’, count any button at POS in the search,
73660     instead of starting at the next button.
73661
73662
73663File: elisp.info,  Node: Abstract Display,  Next: Blinking,  Prev: Buttons,  Up: Display
73664
7366539.20 Abstract Display
73666======================
73667
73668The Ewoc package constructs buffer text that represents a structure of
73669Lisp objects, and updates the text to follow changes in that structure.
73670This is like the “view” component in the “model–view–controller” design
73671paradigm.  Ewoc means “Emacs’s Widget for Object Collections”.
73672
73673   An “ewoc” is a structure that organizes information required to
73674construct buffer text that represents certain Lisp data.  The buffer
73675text of the ewoc has three parts, in order: first, fixed “header” text;
73676next, textual descriptions of a series of data elements (Lisp objects
73677that you specify); and last, fixed “footer” text.  Specifically, an ewoc
73678contains information on:
73679
73680   • The buffer which its text is generated in.
73681
73682   • The text’s start position in the buffer.
73683
73684   • The header and footer strings.
73685
73686   • A doubly-linked chain of “nodes”, each of which contains:
73687
73688        • A “data element”, a single Lisp object.
73689
73690        • Links to the preceding and following nodes in the chain.
73691
73692   • A “pretty-printer” function which is responsible for inserting the
73693     textual representation of a data element value into the current
73694     buffer.
73695
73696   Typically, you define an ewoc with ‘ewoc-create’, and then pass the
73697resulting ewoc structure to other functions in the Ewoc package to build
73698nodes within it, and display it in the buffer.  Once it is displayed in
73699the buffer, other functions determine the correspondence between buffer
73700positions and nodes, move point from one node’s textual representation
73701to another, and so forth.  *Note Abstract Display Functions::.
73702
73703   A node “encapsulates” a data element much the way a variable holds a
73704value.  Normally, encapsulation occurs as a part of adding a node to the
73705ewoc.  You can retrieve the data element value and place a new value in
73706its place, like so:
73707
73708     (ewoc-data NODE)
73709     ⇒ value
73710
73711     (ewoc-set-data NODE NEW-VALUE)
73712     ⇒ NEW-VALUE
73713
73714You can also use, as the data element value, a Lisp object (list or
73715vector) that is a container for the real value, or an index into some
73716other structure.  The example (*note Abstract Display Example::) uses
73717the latter approach.
73718
73719   When the data changes, you will want to update the text in the
73720buffer.  You can update all nodes by calling ‘ewoc-refresh’, or just
73721specific nodes using ‘ewoc-invalidate’, or all nodes satisfying a
73722predicate using ‘ewoc-map’.  Alternatively, you can delete invalid nodes
73723using ‘ewoc-delete’ or ‘ewoc-filter’, and add new nodes in their place.
73724Deleting a node from an ewoc deletes its associated textual description
73725from buffer, as well.
73726
73727* Menu:
73728
73729* Abstract Display Functions::  Functions in the Ewoc package.
73730* Abstract Display Example::    Example of using Ewoc.
73731
73732
73733File: elisp.info,  Node: Abstract Display Functions,  Next: Abstract Display Example,  Up: Abstract Display
73734
7373539.20.1 Abstract Display Functions
73736----------------------------------
73737
73738In this subsection, EWOC and NODE stand for the structures described
73739above (*note Abstract Display::), while DATA stands for an arbitrary
73740Lisp object used as a data element.
73741
73742 -- Function: ewoc-create pretty-printer &optional header footer nosep
73743     This constructs and returns a new ewoc, with no nodes (and thus no
73744     data elements).  PRETTY-PRINTER should be a function that takes one
73745     argument, a data element of the sort you plan to use in this ewoc,
73746     and inserts its textual description at point using ‘insert’ (and
73747     never ‘insert-before-markers’, because that would interfere with
73748     the Ewoc package’s internal mechanisms).
73749
73750     Normally, a newline is automatically inserted after the header, the
73751     footer and every node’s textual description.  If NOSEP is
73752     non-‘nil’, no newline is inserted.  This may be useful for
73753     displaying an entire ewoc on a single line, for example, or for
73754     making nodes invisible by arranging for PRETTY-PRINTER to do
73755     nothing for those nodes.
73756
73757     An ewoc maintains its text in the buffer that is current when you
73758     create it, so switch to the intended buffer before calling
73759     ‘ewoc-create’.
73760
73761 -- Function: ewoc-buffer ewoc
73762     This returns the buffer where EWOC maintains its text.
73763
73764 -- Function: ewoc-get-hf ewoc
73765     This returns a cons cell ‘(HEADER . FOOTER)’ made from EWOC’s
73766     header and footer.
73767
73768 -- Function: ewoc-set-hf ewoc header footer
73769     This sets the header and footer of EWOC to the strings HEADER and
73770     FOOTER, respectively.
73771
73772 -- Function: ewoc-enter-first ewoc data
73773 -- Function: ewoc-enter-last ewoc data
73774     These add a new node encapsulating DATA, putting it, respectively,
73775     at the beginning or end of EWOC’s chain of nodes.
73776
73777 -- Function: ewoc-enter-before ewoc node data
73778 -- Function: ewoc-enter-after ewoc node data
73779     These add a new node encapsulating DATA, adding it to EWOC before
73780     or after NODE, respectively.
73781
73782 -- Function: ewoc-prev ewoc node
73783 -- Function: ewoc-next ewoc node
73784     These return, respectively, the previous node and the next node of
73785     NODE in EWOC.
73786
73787 -- Function: ewoc-nth ewoc n
73788     This returns the node in EWOC found at zero-based index N.  A
73789     negative N means count from the end.  ‘ewoc-nth’ returns ‘nil’ if N
73790     is out of range.
73791
73792 -- Function: ewoc-data node
73793     This extracts the data encapsulated by NODE and returns it.
73794
73795 -- Function: ewoc-set-data node data
73796     This sets the data encapsulated by NODE to DATA.
73797
73798 -- Function: ewoc-locate ewoc &optional pos guess
73799     This determines the node in EWOC which contains point (or POS if
73800     specified), and returns that node.  If EWOC has no nodes, it
73801     returns ‘nil’.  If POS is before the first node, it returns the
73802     first node; if POS is after the last node, it returns the last
73803     node.  The optional third arg GUESS should be a node that is likely
73804     to be near POS; this doesn’t alter the result, but makes the
73805     function run faster.
73806
73807 -- Function: ewoc-location node
73808     This returns the start position of NODE.
73809
73810 -- Function: ewoc-goto-prev ewoc arg
73811 -- Function: ewoc-goto-next ewoc arg
73812     These move point to the previous or next, respectively, ARGth node
73813     in EWOC.  ‘ewoc-goto-prev’ does not move if it is already at the
73814     first node or if EWOC is empty, whereas ‘ewoc-goto-next’ moves past
73815     the last node, returning ‘nil’.  Excepting this special case, these
73816     functions return the node moved to.
73817
73818 -- Function: ewoc-goto-node ewoc node
73819     This moves point to the start of NODE in EWOC.
73820
73821 -- Function: ewoc-refresh ewoc
73822     This function regenerates the text of EWOC.  It works by deleting
73823     the text between the header and the footer, i.e., all the data
73824     elements’ representations, and then calling the pretty-printer
73825     function for each node, one by one, in order.
73826
73827 -- Function: ewoc-invalidate ewoc &rest nodes
73828     This is similar to ‘ewoc-refresh’, except that only NODES in EWOC
73829     are updated instead of the entire set.
73830
73831 -- Function: ewoc-delete ewoc &rest nodes
73832     This deletes each node in NODES from EWOC.
73833
73834 -- Function: ewoc-filter ewoc predicate &rest args
73835     This calls PREDICATE for each data element in EWOC and deletes
73836     those nodes for which PREDICATE returns ‘nil’.  Any ARGS are passed
73837     to PREDICATE.
73838
73839 -- Function: ewoc-collect ewoc predicate &rest args
73840     This calls PREDICATE for each data element in EWOC and returns a
73841     list of those elements for which PREDICATE returns non-‘nil’.  The
73842     elements in the list are ordered as in the buffer.  Any ARGS are
73843     passed to PREDICATE.
73844
73845 -- Function: ewoc-map map-function ewoc &rest args
73846     This calls MAP-FUNCTION for each data element in EWOC and updates
73847     those nodes for which MAP-FUNCTION returns non-‘nil’.  Any ARGS are
73848     passed to MAP-FUNCTION.
73849
73850
73851File: elisp.info,  Node: Abstract Display Example,  Prev: Abstract Display Functions,  Up: Abstract Display
73852
7385339.20.2 Abstract Display Example
73854--------------------------------
73855
73856Here is a simple example using functions of the ewoc package to
73857implement a “color components” display, an area in a buffer that
73858represents a vector of three integers (itself representing a 24-bit RGB
73859value) in various ways.
73860
73861     (setq colorcomp-ewoc nil
73862           colorcomp-data nil
73863           colorcomp-mode-map nil
73864           colorcomp-labels ["Red" "Green" "Blue"])
73865
73866     (defun colorcomp-pp (data)
73867       (if data
73868           (let ((comp (aref colorcomp-data data)))
73869             (insert (aref colorcomp-labels data) "\t: #x"
73870                     (format "%02X" comp) " "
73871                     (make-string (ash comp -2) ?#) "\n"))
73872         (let ((cstr (format "#%02X%02X%02X"
73873                             (aref colorcomp-data 0)
73874                             (aref colorcomp-data 1)
73875                             (aref colorcomp-data 2)))
73876               (samp " (sample text) "))
73877           (insert "Color\t: "
73878                   (propertize samp 'face
73879                               `(foreground-color . ,cstr))
73880                   (propertize samp 'face
73881                               `(background-color . ,cstr))
73882                   "\n"))))
73883
73884     (defun colorcomp (color)
73885       "Allow fiddling with COLOR in a new buffer.
73886     The buffer is in Color Components mode."
73887       (interactive "sColor (name or #RGB or #RRGGBB): ")
73888       (when (string= "" color)
73889         (setq color "green"))
73890       (unless (color-values color)
73891         (error "No such color: %S" color))
73892       (switch-to-buffer
73893        (generate-new-buffer (format "originally: %s" color)))
73894       (kill-all-local-variables)
73895       (setq major-mode 'colorcomp-mode
73896             mode-name "Color Components")
73897       (use-local-map colorcomp-mode-map)
73898       (erase-buffer)
73899       (buffer-disable-undo)
73900       (let ((data (apply 'vector (mapcar (lambda (n) (ash n -8))
73901                                          (color-values color))))
73902             (ewoc (ewoc-create 'colorcomp-pp
73903                                "\nColor Components\n\n"
73904                                (substitute-command-keys
73905                                 "\n\\{colorcomp-mode-map}"))))
73906         (set (make-local-variable 'colorcomp-data) data)
73907         (set (make-local-variable 'colorcomp-ewoc) ewoc)
73908         (ewoc-enter-last ewoc 0)
73909         (ewoc-enter-last ewoc 1)
73910         (ewoc-enter-last ewoc 2)
73911         (ewoc-enter-last ewoc nil)))
73912
73913   This example can be extended to be a color selection widget (in other
73914words, the “controller” part of the “model–view–controller” design
73915paradigm) by defining commands to modify ‘colorcomp-data’ and to finish
73916the selection process, and a keymap to tie it all together conveniently.
73917
73918     (defun colorcomp-mod (index limit delta)
73919       (let ((cur (aref colorcomp-data index)))
73920         (unless (= limit cur)
73921           (aset colorcomp-data index (+ cur delta)))
73922         (ewoc-invalidate
73923          colorcomp-ewoc
73924          (ewoc-nth colorcomp-ewoc index)
73925          (ewoc-nth colorcomp-ewoc -1))))
73926
73927     (defun colorcomp-R-more () (interactive) (colorcomp-mod 0 255 1))
73928     (defun colorcomp-G-more () (interactive) (colorcomp-mod 1 255 1))
73929     (defun colorcomp-B-more () (interactive) (colorcomp-mod 2 255 1))
73930     (defun colorcomp-R-less () (interactive) (colorcomp-mod 0 0 -1))
73931     (defun colorcomp-G-less () (interactive) (colorcomp-mod 1 0 -1))
73932     (defun colorcomp-B-less () (interactive) (colorcomp-mod 2 0 -1))
73933
73934     (defun colorcomp-copy-as-kill-and-exit ()
73935       "Copy the color components into the kill ring and kill the buffer.
73936     The string is formatted #RRGGBB (hash followed by six hex digits)."
73937       (interactive)
73938       (kill-new (format "#%02X%02X%02X"
73939                         (aref colorcomp-data 0)
73940                         (aref colorcomp-data 1)
73941                         (aref colorcomp-data 2)))
73942       (kill-buffer nil))
73943
73944     (setq colorcomp-mode-map
73945           (let ((m (make-sparse-keymap)))
73946             (suppress-keymap m)
73947             (define-key m "i" 'colorcomp-R-less)
73948             (define-key m "o" 'colorcomp-R-more)
73949             (define-key m "k" 'colorcomp-G-less)
73950             (define-key m "l" 'colorcomp-G-more)
73951             (define-key m "," 'colorcomp-B-less)
73952             (define-key m "." 'colorcomp-B-more)
73953             (define-key m " " 'colorcomp-copy-as-kill-and-exit)
73954             m))
73955
73956   Note that we never modify the data in each node, which is fixed when
73957the ewoc is created to be either ‘nil’ or an index into the vector
73958‘colorcomp-data’, the actual color components.
73959
73960
73961File: elisp.info,  Node: Blinking,  Next: Character Display,  Prev: Abstract Display,  Up: Display
73962
7396339.21 Blinking Parentheses
73964==========================
73965
73966This section describes the mechanism by which Emacs shows a matching
73967open parenthesis when the user inserts a close parenthesis.
73968
73969 -- Variable: blink-paren-function
73970     The value of this variable should be a function (of no arguments)
73971     to be called whenever a character with close parenthesis syntax is
73972     inserted.  The value of ‘blink-paren-function’ may be ‘nil’, in
73973     which case nothing is done.
73974
73975 -- User Option: blink-matching-paren
73976     If this variable is ‘nil’, then ‘blink-matching-open’ does nothing.
73977
73978 -- User Option: blink-matching-paren-distance
73979     This variable specifies the maximum distance to scan for a matching
73980     parenthesis before giving up.
73981
73982 -- User Option: blink-matching-delay
73983     This variable specifies the number of seconds to keep indicating
73984     the matching parenthesis.  A fraction of a second often gives good
73985     results, but the default is 1, which works on all systems.
73986
73987 -- Command: blink-matching-open
73988     This function is the default value of ‘blink-paren-function’.  It
73989     assumes that point follows a character with close parenthesis
73990     syntax and applies the appropriate effect momentarily to the
73991     matching opening character.  If that character is not already on
73992     the screen, it displays the character’s context in the echo area.
73993     To avoid long delays, this function does not search farther than
73994     ‘blink-matching-paren-distance’ characters.
73995
73996     Here is an example of calling this function explicitly.
73997
73998          (defun interactive-blink-matching-open ()
73999            "Indicate momentarily the start of parenthesized sexp before point."
74000            (interactive)
74001            (let ((blink-matching-paren-distance
74002                   (buffer-size))
74003                  (blink-matching-paren t))
74004              (blink-matching-open)))
74005
74006
74007File: elisp.info,  Node: Character Display,  Next: Beeping,  Prev: Blinking,  Up: Display
74008
7400939.22 Character Display
74010=======================
74011
74012This section describes how characters are actually displayed by Emacs.
74013Typically, a character is displayed as a “glyph” (a graphical symbol
74014which occupies one character position on the screen), whose appearance
74015corresponds to the character itself.  For example, the character ‘a’
74016(character code 97) is displayed as ‘a’.  Some characters, however, are
74017displayed specially.  For example, the formfeed character (character
74018code 12) is usually displayed as a sequence of two glyphs, ‘^L’, while
74019the newline character (character code 10) starts a new screen line.
74020
74021   You can modify how each character is displayed by defining a “display
74022table”, which maps each character code into a sequence of glyphs.  *Note
74023Display Tables::.
74024
74025* Menu:
74026
74027* Usual Display::       The usual conventions for displaying characters.
74028* Display Tables::      What a display table consists of.
74029* Active Display Table::  How Emacs selects a display table to use.
74030* Glyphs::              How to define a glyph, and what glyphs mean.
74031* Glyphless Chars::     How glyphless characters are drawn.
74032
74033
74034File: elisp.info,  Node: Usual Display,  Next: Display Tables,  Up: Character Display
74035
7403639.22.1 Usual Display Conventions
74037---------------------------------
74038
74039Here are the conventions for displaying each character code (in the
74040absence of a display table, which can override these conventions; *note
74041Display Tables::).
74042
74043   • The “printable ASCII characters”, character codes 32 through 126
74044     (consisting of numerals, English letters, and symbols like ‘#’) are
74045     displayed literally.
74046
74047   • The tab character (character code 9) displays as whitespace
74048     stretching up to the next tab stop column.  *Note (emacs)Text
74049     Display::.  The variable ‘tab-width’ controls the number of spaces
74050     per tab stop (see below).
74051
74052   • The newline character (character code 10) has a special effect: it
74053     ends the preceding line and starts a new line.
74054
74055   • The non-printable “ASCII control characters”—character codes 0
74056     through 31, as well as the <DEL> character (character code
74057     127)—display in one of two ways according to the variable
74058     ‘ctl-arrow’.  If this variable is non-‘nil’ (the default), these
74059     characters are displayed as sequences of two glyphs, where the
74060     first glyph is ‘^’ (a display table can specify a glyph to use
74061     instead of ‘^’); e.g., the <DEL> character is displayed as ‘^?’.
74062
74063     If ‘ctl-arrow’ is ‘nil’, these characters are displayed as octal
74064     escapes (see below).
74065
74066     This rule also applies to carriage return (character code 13), if
74067     that character appears in the buffer.  But carriage returns usually
74068     do not appear in buffer text; they are eliminated as part of
74069     end-of-line conversion (*note Coding System Basics::).
74070
74071   • “Raw bytes” are non-ASCII characters with codes 128 through 255
74072     (*note Text Representations::).  These characters display as “octal
74073     escapes”: sequences of four glyphs, where the first glyph is the
74074     ASCII code for ‘\’, and the others are digit characters
74075     representing the character code in octal.  (A display table can
74076     specify a glyph to use instead of ‘\’.)
74077
74078   • Each non-ASCII character with code above 255 is displayed
74079     literally, if the terminal supports it.  If the terminal does not
74080     support it, the character is said to be “glyphless”, and it is
74081     usually displayed using a placeholder glyph.  For example, if a
74082     graphical terminal has no font for a character, Emacs usually
74083     displays a box containing the character code in hexadecimal.  *Note
74084     Glyphless Chars::.
74085
74086   The above display conventions apply even when there is a display
74087table, for any character whose entry in the active display table is
74088‘nil’.  Thus, when you set up a display table, you need only specify the
74089characters for which you want special behavior.
74090
74091   The following variables affect how certain characters are displayed
74092on the screen.  Since they change the number of columns the characters
74093occupy, they also affect the indentation functions.  They also affect
74094how the mode line is displayed; if you want to force redisplay of the
74095mode line using the new values, call the function
74096‘force-mode-line-update’ (*note Mode Line Format::).
74097
74098 -- User Option: ctl-arrow
74099     This buffer-local variable controls how control characters are
74100     displayed.  If it is non-‘nil’, they are displayed as a caret
74101     followed by the character: ‘^A’.  If it is ‘nil’, they are
74102     displayed as octal escapes: a backslash followed by three octal
74103     digits, as in ‘\001’.
74104
74105 -- User Option: tab-width
74106     The value of this buffer-local variable is the spacing between tab
74107     stops used for displaying tab characters in Emacs buffers.  The
74108     value is in units of columns, and the default is 8.  Note that this
74109     feature is completely independent of the user-settable tab stops
74110     used by the command ‘tab-to-tab-stop’.  *Note Indent Tabs::.
74111
74112
74113File: elisp.info,  Node: Display Tables,  Next: Active Display Table,  Prev: Usual Display,  Up: Character Display
74114
7411539.22.2 Display Tables
74116----------------------
74117
74118A display table is a special-purpose char-table (*note Char-Tables::),
74119with ‘display-table’ as its subtype, which is used to override the usual
74120character display conventions.  This section describes how to make,
74121inspect, and assign elements to a display table object.
74122
74123 -- Function: make-display-table
74124     This creates and returns a display table.  The table initially has
74125     ‘nil’ in all elements.
74126
74127   The ordinary elements of the display table are indexed by character
74128codes; the element at index C says how to display the character code C.
74129The value should be ‘nil’ (which means to display the character C
74130according to the usual display conventions; *note Usual Display::), or a
74131vector of glyph codes (which means to display the character C as those
74132glyphs; *note Glyphs::).
74133
74134   *Warning:* if you use the display table to change the display of
74135newline characters, the whole buffer will be displayed as one long line.
74136
74137   The display table also has six “extra slots” which serve special
74138purposes.  Here is a table of their meanings; ‘nil’ in any slot means to
74139use the default for that slot, as stated below.
74140
741410
74142     The glyph for the end of a truncated screen line (the default for
74143     this is ‘$’).  *Note Glyphs::.  On graphical terminals, Emacs by
74144     default uses arrows in the fringes to indicate truncation, so the
74145     display table has no effect, unless you disable the fringes (*note
74146     Window Fringes: (emacs)Fringes.).
74147
741481
74149     The glyph for the end of a continued line (the default is ‘\’).  On
74150     graphical terminals, Emacs by default uses curved arrows in the
74151     fringes to indicate continuation, so the display table has no
74152     effect, unless you disable the fringes.
74153
741542
74155     The glyph for indicating a character displayed as an octal
74156     character code (the default is ‘\’).
74157
741583
74159     The glyph for indicating a control character (the default is ‘^’).
74160
741614
74162     A vector of glyphs for indicating the presence of invisible lines
74163     (the default is ‘...’).  *Note Selective Display::.
74164
741655
74166     The glyph used to draw the border between side-by-side windows (the
74167     default is ‘|’).  *Note Splitting Windows::.  This currently has
74168     effect only on text terminals; on graphical terminals, if vertical
74169     scroll bars are supported and in use, a scroll bar separates the
74170     two windows, and if there are no vertical scroll bars and no
74171     dividers (*note Window Dividers::), Emacs uses a thin line to
74172     indicate the border.
74173
74174   For example, here is how to construct a display table that mimics the
74175effect of setting ‘ctl-arrow’ to a non-‘nil’ value (*note Glyphs::, for
74176the function ‘make-glyph-code’):
74177
74178     (setq disptab (make-display-table))
74179     (dotimes (i 32)
74180       (or (= i ?\t)
74181           (= i ?\n)
74182           (aset disptab i
74183                 (vector (make-glyph-code ?^ 'escape-glyph)
74184                         (make-glyph-code (+ i 64) 'escape-glyph)))))
74185     (aset disptab 127
74186           (vector (make-glyph-code ?^ 'escape-glyph)
74187                   (make-glyph-code ?? 'escape-glyph)))))
74188
74189 -- Function: display-table-slot display-table slot
74190     This function returns the value of the extra slot SLOT of
74191     DISPLAY-TABLE.  The argument SLOT may be a number from 0 to 5
74192     inclusive, or a slot name (symbol).  Valid symbols are
74193     ‘truncation’, ‘wrap’, ‘escape’, ‘control’, ‘selective-display’, and
74194     ‘vertical-border’.
74195
74196 -- Function: set-display-table-slot display-table slot value
74197     This function stores VALUE in the extra slot SLOT of DISPLAY-TABLE.
74198     The argument SLOT may be a number from 0 to 5 inclusive, or a slot
74199     name (symbol).  Valid symbols are ‘truncation’, ‘wrap’, ‘escape’,
74200     ‘control’, ‘selective-display’, and ‘vertical-border’.
74201
74202 -- Function: describe-display-table display-table
74203     This function displays a description of the display table
74204     DISPLAY-TABLE in a help buffer.
74205
74206 -- Command: describe-current-display-table
74207     This command displays a description of the current display table in
74208     a help buffer.
74209
74210
74211File: elisp.info,  Node: Active Display Table,  Next: Glyphs,  Prev: Display Tables,  Up: Character Display
74212
7421339.22.3 Active Display Table
74214----------------------------
74215
74216Each window can specify a display table, and so can each buffer.  The
74217window’s display table, if there is one, takes precedence over the
74218buffer’s display table.  If neither exists, Emacs tries to use the
74219standard display table; if that is ‘nil’, Emacs uses the usual character
74220display conventions (*note Usual Display::).
74221
74222   Note that display tables affect how the mode line is displayed, so if
74223you want to force redisplay of the mode line using a new display table,
74224call ‘force-mode-line-update’ (*note Mode Line Format::).
74225
74226 -- Function: window-display-table &optional window
74227     This function returns WINDOW’s display table, or ‘nil’ if there is
74228     none.  The default for WINDOW is the selected window.
74229
74230 -- Function: set-window-display-table window table
74231     This function sets the display table of WINDOW to TABLE.  The
74232     argument TABLE should be either a display table or ‘nil’.
74233
74234 -- Variable: buffer-display-table
74235     This variable is automatically buffer-local in all buffers; its
74236     value specifies the buffer’s display table.  If it is ‘nil’, there
74237     is no buffer display table.
74238
74239 -- Variable: standard-display-table
74240     The value of this variable is the standard display table, which is
74241     used when Emacs is displaying a buffer in a window with neither a
74242     window display table nor a buffer display table defined, or when
74243     Emacs is outputting text to the standard output or error streams.
74244     Although its default is typically ‘nil’, in an interactive session
74245     if the terminal cannot display curved quotes, its default maps
74246     curved quotes to ASCII approximations.  *Note Text Quoting Style::.
74247
74248   The ‘disp-table’ library defines several functions for changing the
74249standard display table.
74250
74251
74252File: elisp.info,  Node: Glyphs,  Next: Glyphless Chars,  Prev: Active Display Table,  Up: Character Display
74253
7425439.22.4 Glyphs
74255--------------
74256
74257A “glyph” is a graphical symbol which occupies a single character
74258position on the screen.  Each glyph is represented in Lisp as a “glyph
74259code”, which specifies a character and optionally a face to display it
74260in (*note Faces::).  The main use of glyph codes is as the entries of
74261display tables (*note Display Tables::).  The following functions are
74262used to manipulate glyph codes:
74263
74264 -- Function: make-glyph-code char &optional face
74265     This function returns a glyph code representing char CHAR with face
74266     FACE.  If FACE is omitted or ‘nil’, the glyph uses the default
74267     face; in that case, the glyph code is an integer.  If FACE is
74268     non-‘nil’, the glyph code is not necessarily an integer object.
74269
74270 -- Function: glyph-char glyph
74271     This function returns the character of glyph code GLYPH.
74272
74273 -- Function: glyph-face glyph
74274     This function returns face of glyph code GLYPH, or ‘nil’ if GLYPH
74275     uses the default face.
74276
74277   You can set up a “glyph table” to change how glyph codes are actually
74278displayed on text terminals.  This feature is semi-obsolete; use
74279‘glyphless-char-display’ instead (*note Glyphless Chars::).
74280
74281 -- Variable: glyph-table
74282     The value of this variable, if non-‘nil’, is the current glyph
74283     table.  It takes effect only on character terminals; on graphical
74284     displays, all glyphs are displayed literally.  The glyph table
74285     should be a vector whose Gth element specifies how to display glyph
74286     code G, where G is the glyph code for a glyph whose face is
74287     unspecified.  Each element should be one of the following:
74288
74289     ‘nil’
74290          Display this glyph literally.
74291
74292     a string
74293          Display this glyph by sending the specified string to the
74294          terminal.
74295
74296     a glyph code
74297          Display the specified glyph code instead.
74298
74299     Any integer glyph code greater than or equal to the length of the
74300     glyph table is displayed literally.
74301
74302
74303File: elisp.info,  Node: Glyphless Chars,  Prev: Glyphs,  Up: Character Display
74304
7430539.22.5 Glyphless Character Display
74306-----------------------------------
74307
74308“Glyphless characters” are characters which are displayed in a special
74309way, e.g., as a box containing a hexadecimal code, instead of being
74310displayed literally.  These include characters which are explicitly
74311defined to be glyphless, as well as characters for which there is no
74312available font (on a graphical display), and characters which cannot be
74313encoded by the terminal’s coding system (on a text terminal).
74314
74315 -- Variable: glyphless-char-display
74316     The value of this variable is a char-table which defines glyphless
74317     characters and how they are displayed.  Each entry must be one of
74318     the following display methods:
74319
74320     ‘nil’
74321          Display the character in the usual way.
74322
74323     ‘zero-width’
74324          Don’t display the character.
74325
74326     ‘thin-space’
74327          Display a thin space, 1-pixel wide on graphical displays, or
74328          1-character wide on text terminals.
74329
74330     ‘empty-box’
74331          Display an empty box.
74332
74333     ‘hex-code’
74334          Display a box containing the Unicode codepoint of the
74335          character, in hexadecimal notation.
74336
74337     an ASCII string
74338          Display a box containing that string.  The string should
74339          contain at most 6 ASCII characters.
74340
74341     a cons cell ‘(GRAPHICAL . TEXT)’
74342          Display with GRAPHICAL on graphical displays, and with TEXT on
74343          text terminals.  Both GRAPHICAL and TEXT must be one of the
74344          display methods described above.
74345
74346     The ‘thin-space’, ‘empty-box’, ‘hex-code’, and ASCII string display
74347     methods are drawn with the ‘glyphless-char’ face.  On text
74348     terminals, a box is emulated by square brackets, ‘[]’.
74349
74350     The char-table has one extra slot, which determines how to display
74351     any character that cannot be displayed with any available font, or
74352     cannot be encoded by the terminal’s coding system.  Its value
74353     should be one of the above display methods, except ‘zero-width’ or
74354     a cons cell.
74355
74356     If a character has a non-‘nil’ entry in an active display table,
74357     the display table takes effect; in this case, Emacs does not
74358     consult ‘glyphless-char-display’ at all.
74359
74360 -- User Option: glyphless-char-display-control
74361     This user option provides a convenient way to set
74362     ‘glyphless-char-display’ for groups of similar characters.  Do not
74363     set its value directly from Lisp code; the value takes effect only
74364     via a custom ‘:set’ function (*note Variable Definitions::), which
74365     updates ‘glyphless-char-display’.
74366
74367     Its value should be an alist of elements ‘(GROUP . METHOD)’, where
74368     GROUP is a symbol specifying a group of characters, and METHOD is a
74369     symbol specifying how to display them.
74370
74371     GROUP should be one of the following:
74372
74373     ‘c0-control’
74374          ASCII control characters ‘U+0000’ to ‘U+001F’, excluding the
74375          newline and tab characters (normally displayed as escape
74376          sequences like ‘^A’; *note How Text Is Displayed: (emacs)Text
74377          Display.).
74378
74379     ‘c1-control’
74380          Non-ASCII, non-printing characters ‘U+0080’ to ‘U+009F’
74381          (normally displayed as octal escape sequences like ‘\230’).
74382
74383     ‘format-control’
74384          Characters of Unicode General Category [Cf], such as U+200E
74385          LEFT-TO-RIGHT MARK, but excluding characters that have graphic
74386          images, such as U+00AD SOFT HYPHEN.
74387
74388     ‘no-font’
74389          Characters for which there is no suitable font, or which
74390          cannot be encoded by the terminal’s coding system.
74391
74392     The METHOD symbol should be one of ‘zero-width’, ‘thin-space’,
74393     ‘empty-box’, or ‘hex-code’.  These have the same meanings as in
74394     ‘glyphless-char-display’, above.
74395
74396
74397File: elisp.info,  Node: Beeping,  Next: Window Systems,  Prev: Character Display,  Up: Display
74398
7439939.23 Beeping
74400=============
74401
74402This section describes how to make Emacs ring the bell (or blink the
74403screen) to attract the user’s attention.  Be conservative about how
74404often you do this; frequent bells can become irritating.  Also be
74405careful not to use just beeping when signaling an error is more
74406appropriate (*note Errors::).
74407
74408 -- Function: ding &optional do-not-terminate
74409     This function beeps, or flashes the screen (see ‘visible-bell’
74410     below).  It also terminates any keyboard macro currently executing
74411     unless DO-NOT-TERMINATE is non-‘nil’.
74412
74413 -- Function: beep &optional do-not-terminate
74414     This is a synonym for ‘ding’.
74415
74416 -- User Option: visible-bell
74417     This variable determines whether Emacs should flash the screen to
74418     represent a bell.  Non-‘nil’ means yes, ‘nil’ means no.  This is
74419     effective on graphical displays, and on text terminals provided the
74420     terminal’s Termcap entry defines the visible bell capability
74421     (‘vb’).
74422
74423 -- User Option: ring-bell-function
74424     If this is non-‘nil’, it specifies how Emacs should ring the bell.
74425     Its value should be a function of no arguments.  If this is
74426     non-‘nil’, it takes precedence over the ‘visible-bell’ variable.
74427
74428
74429File: elisp.info,  Node: Window Systems,  Next: Tooltips,  Prev: Beeping,  Up: Display
74430
7443139.24 Window Systems
74432====================
74433
74434Emacs works with several window systems, most notably the X Window
74435System.  Both Emacs and X use the term “window”, but use it differently.
74436An Emacs frame is a single window as far as X is concerned; the
74437individual Emacs windows are not known to X at all.
74438
74439 -- Variable: window-system
74440     This terminal-local variable tells Lisp programs what window system
74441     Emacs is using for displaying the frame.  The possible values are
74442
74443     ‘x’
74444          Emacs is displaying the frame using X.
74445     ‘w32’
74446          Emacs is displaying the frame using native MS-Windows GUI.
74447     ‘ns’
74448          Emacs is displaying the frame using the Nextstep interface
74449          (used on GNUstep and macOS).
74450     ‘pc’
74451          Emacs is displaying the frame using MS-DOS direct screen
74452          writes.
74453     ‘nil’
74454          Emacs is displaying the frame on a character-based terminal.
74455
74456 -- Variable: initial-window-system
74457     This variable holds the value of ‘window-system’ used for the first
74458     frame created by Emacs during startup.  (When Emacs is invoked as a
74459     daemon, it does not create any initial frames, so
74460     ‘initial-window-system’ is ‘nil’, except on MS-Windows, where it is
74461     still ‘w32’.  *Note daemon: (emacs)Initial Options.)
74462
74463 -- Function: window-system &optional frame
74464     This function returns a symbol whose name tells what window system
74465     is used for displaying FRAME (which defaults to the currently
74466     selected frame).  The list of possible symbols it returns is the
74467     same one documented for the variable ‘window-system’ above.
74468
74469   Do _not_ use ‘window-system’ and ‘initial-window-system’ as
74470predicates or boolean flag variables, if you want to write code that
74471works differently on text terminals and graphic displays.  That is
74472because ‘window-system’ is not a good indicator of Emacs capabilities on
74473a given display type.  Instead, use ‘display-graphic-p’ or any of the
74474other ‘display-*-p’ predicates described in *note Display Feature
74475Testing::.
74476
74477
74478File: elisp.info,  Node: Tooltips,  Next: Bidirectional Display,  Prev: Window Systems,  Up: Display
74479
7448039.25 Tooltips
74481==============
74482
74483“Tooltips” are special frames (*note Frames::) that are used to display
74484helpful hints (a.k.a. “tips”) related to the current position of the
74485mouse pointer.  Emacs uses tooltips to display help strings about active
74486portions of text (*note Special Properties::) and about various UI
74487elements, such as menu items (*note Extended Menu Items::) and tool-bar
74488buttons (*note Tool Bar::).
74489
74490 -- Function: tooltip-mode
74491     Tooltip Mode is a minor mode that enables display of tooltips.
74492     Turning off this mode causes the tooltips be displayed in the echo
74493     area.  On text-mode (a.k.a. “TTY”) frames, tooltips are always
74494     displayed in the echo area.
74495
74496   When Emacs is built with GTK+ support, it by default displays
74497tooltips using GTK+ functions, and the appearance of the tooltips is
74498then controlled by GTK+ settings.  GTK+ tooltips can be disabled by
74499changing the value of the variable ‘x-gtk-use-system-tooltips’ to ‘nil’.
74500The rest of this subsection describes how to control non-GTK+ tooltips,
74501which are presented by Emacs itself.
74502
74503   Tooltips are displayed in special frames called tooltip frames, which
74504have their own frame parameters (*note Frame Parameters::).  Unlike
74505other frames, the default parameters for tooltip frames are stored in a
74506special variable.
74507
74508 -- User Option: tooltip-frame-parameters
74509     This customizable option holds the default frame parameters used
74510     for displaying tooltips.  Any font and color parameters are
74511     ignored, and the corresponding attributes of the ‘tooltip’ face are
74512     used instead.  If ‘left’ or ‘top’ parameters are included, they are
74513     used as absolute frame-relative coordinates where the tooltip
74514     should be shown.  (Mouse-relative position of the tooltip can be
74515     customized using the variables described in *note
74516     (emacs)Tooltips::.)  Note that the ‘left’ and ‘top’ parameters, if
74517     present, override the values of mouse-relative offsets.
74518
74519   The ‘tooltip’ face determines the appearance of text shown in
74520tooltips.  It should generally use a variable-pitch font of size that is
74521preferably smaller than the default frame font.
74522
74523 -- Variable: tooltip-functions
74524     This abnormal hook is a list of functions to call when Emacs needs
74525     to display a tooltip.  Each function is called with a single
74526     argument EVENT which is a copy of the last mouse movement event.
74527     If a function on this list actually displays the tooltip, it should
74528     return non-‘nil’, and then the rest of the functions will not be
74529     called.  The default value of this variable is a single function
74530     ‘tooltip-help-tips’.
74531
74532   If you write your own function to be put on the ‘tooltip-functions’
74533list, you may need to know the buffer of the mouse event that triggered
74534the tooltip display.  The following function provides that information.
74535
74536 -- Function: tooltip-event-buffer event
74537     This function returns the buffer over which EVENT occurred.  Call
74538     it with the argument of the function from ‘tooltip-functions’ to
74539     obtain the buffer whose text triggered the tooltip.  Note that the
74540     event might occur not over a buffer (e.g., over the tool bar), in
74541     which case this function will return ‘nil’.
74542
74543   Other aspects of tooltip display are controlled by several
74544customizable settings; see *note (emacs)Tooltips::.
74545
74546
74547File: elisp.info,  Node: Bidirectional Display,  Prev: Tooltips,  Up: Display
74548
7454939.26 Bidirectional Display
74550===========================
74551
74552Emacs can display text written in scripts, such as Arabic, Farsi, and
74553Hebrew, whose natural ordering for horizontal text display runs from
74554right to left.  Furthermore, segments of Latin script and digits
74555embedded in right-to-left text are displayed left-to-right, while
74556segments of right-to-left script embedded in left-to-right text (e.g.,
74557Arabic or Hebrew text in comments or strings in a program source file)
74558are appropriately displayed right-to-left.  We call such mixtures of
74559left-to-right and right-to-left text “bidirectional text”.  This section
74560describes the facilities and options for editing and displaying
74561bidirectional text.
74562
74563   Text is stored in Emacs buffers and strings in “logical” (or
74564“reading”) order, i.e., the order in which a human would read each
74565character.  In right-to-left and bidirectional text, the order in which
74566characters are displayed on the screen (called “visual order”) is not
74567the same as logical order; the characters’ screen positions do not
74568increase monotonically with string or buffer position.  In performing
74569this “bidirectional reordering”, Emacs follows the Unicode Bidirectional
74570Algorithm (a.k.a. UBA), which is described in Annex #9 of the Unicode
74571standard (<http://www.unicode.org/reports/tr9/>).  Emacs provides a
74572“Full Bidirectionality” class implementation of the UBA, consistent with
74573the requirements of the Unicode Standard v9.0.  Note, however, that the
74574way Emacs displays continuation lines when text direction is opposite to
74575the base paragraph direction deviates from the UBA, which requires to
74576perform line wrapping before reordering text for display.
74577
74578 -- Variable: bidi-display-reordering
74579     If the value of this buffer-local variable is non-‘nil’ (the
74580     default), Emacs performs bidirectional reordering for display.  The
74581     reordering affects buffer text, as well as display strings and
74582     overlay strings from text and overlay properties in the buffer
74583     (*note Overlay Properties::, and *note Display Property::).  If the
74584     value is ‘nil’, Emacs does not perform bidirectional reordering in
74585     the buffer.
74586
74587     The default value of ‘bidi-display-reordering’ controls the
74588     reordering of strings which are not directly supplied by a buffer,
74589     including the text displayed in mode lines (*note Mode Line
74590     Format::) and header lines (*note Header Lines::).
74591
74592   Emacs never reorders the text of a unibyte buffer, even if
74593‘bidi-display-reordering’ is non-‘nil’ in the buffer.  This is because
74594unibyte buffers contain raw bytes, not characters, and thus lack the
74595directionality properties required for reordering.  Therefore, to test
74596whether text in a buffer will be reordered for display, it is not enough
74597to test the value of ‘bidi-display-reordering’ alone.  The correct test
74598is this:
74599
74600      (if (and enable-multibyte-characters
74601               bidi-display-reordering)
74602          ;; Buffer is being reordered for display
74603        )
74604
74605   However, unibyte display and overlay strings _are_ reordered if their
74606parent buffer is reordered.  This is because plain-ASCII strings are
74607stored by Emacs as unibyte strings.  If a unibyte display or overlay
74608string includes non-ASCII characters, these characters are assumed to
74609have left-to-right direction.
74610
74611   Text covered by ‘display’ text properties, by overlays with ‘display’
74612properties whose value is a string, and by any other properties that
74613replace buffer text, is treated as a single unit when it is reordered
74614for display.  That is, the entire chunk of text covered by these
74615properties is reordered together.  Moreover, the bidirectional
74616properties of the characters in such a chunk of text are ignored, and
74617Emacs reorders them as if they were replaced with a single character
74618‘U+FFFC’, known as the “Object Replacement Character”.  This means that
74619placing a display property over a portion of text may change the way
74620that the surrounding text is reordered for display.  To prevent this
74621unexpected effect, always place such properties on text whose
74622directionality is identical with text that surrounds it.
74623
74624   Each paragraph of bidirectional text has a “base direction”, either
74625right-to-left or left-to-right.  Left-to-right paragraphs are displayed
74626beginning at the left margin of the window, and are truncated or
74627continued when the text reaches the right margin.  Right-to-left
74628paragraphs are displayed beginning at the right margin, and are
74629continued or truncated at the left margin.
74630
74631   Where exactly paragraphs start and end, for the purpose of the Emacs
74632UBA implementation, is determined by the following two buffer-local
74633variables (note that ‘paragraph-start’ and ‘paragraph-separate’ have no
74634influence on this).  By default both of these variables are ‘nil’, and
74635paragraphs are bounded by empty lines, i.e., lines that consist entirely
74636of zero or more whitespace characters followed by a newline.
74637
74638 -- Variable: bidi-paragraph-start-re
74639     If non-‘nil’, this variable’s value should be a regular expression
74640     matching a line that starts or separates two paragraphs.  The
74641     regular expression is always matched after a newline, so it is best
74642     to anchor it, i.e., begin it with a ‘"^"’.
74643
74644 -- Variable: bidi-paragraph-separate-re
74645     If non-‘nil’, this variable’s value should be a regular expression
74646     matching a line separates two paragraphs.  The regular expression
74647     is always matched after a newline, so it is best to anchor it,
74648     i.e., begin it with a ‘"^"’.
74649
74650   If you modify any of these two variables, you should normally modify
74651both, to make sure they describe paragraphs consistently.  For example,
74652to have each new line start a new paragraph for bidi-reordering
74653purposes, set both variables to ‘"^"’.
74654
74655   By default, Emacs determines the base direction of each paragraph by
74656looking at the text at its beginning.  The precise method of determining
74657the base direction is specified by the UBA; in a nutshell, the first
74658character in a paragraph that has an explicit directionality determines
74659the base direction of the paragraph.  However, sometimes a buffer may
74660need to force a certain base direction for its paragraphs.  For example,
74661buffers containing program source code should force all paragraphs to be
74662displayed left-to-right.  You can use following variable to do this:
74663
74664 -- User Option: bidi-paragraph-direction
74665     If the value of this buffer-local variable is the symbol
74666     ‘right-to-left’ or ‘left-to-right’, all paragraphs in the buffer
74667     are assumed to have that specified direction.  Any other value is
74668     equivalent to ‘nil’ (the default), which means to determine the
74669     base direction of each paragraph from its contents.
74670
74671     Modes for program source code should set this to ‘left-to-right’.
74672     Prog mode does this by default, so modes derived from Prog mode do
74673     not need to set this explicitly (*note Basic Major Modes::).
74674
74675 -- Function: current-bidi-paragraph-direction &optional buffer
74676     This function returns the paragraph direction at point in the named
74677     BUFFER.  The returned value is a symbol, either ‘left-to-right’ or
74678     ‘right-to-left’.  If BUFFER is omitted or ‘nil’, it defaults to the
74679     current buffer.  If the buffer-local value of the variable
74680     ‘bidi-paragraph-direction’ is non-‘nil’, the returned value will be
74681     identical to that value; otherwise, the returned value reflects the
74682     paragraph direction determined dynamically by Emacs.  For buffers
74683     whose value of ‘bidi-display-reordering’ is ‘nil’ as well as
74684     unibyte buffers, this function always returns ‘left-to-right’.
74685
74686   Sometimes there’s a need to move point in strict visual order, either
74687to the left or to the right of its current screen position.  Emacs
74688provides a primitive to do that.
74689
74690 -- Function: move-point-visually direction
74691     This function moves point of the currently selected window to the
74692     buffer position that appears immediately to the right or to the
74693     left of point on the screen.  If DIRECTION is positive, point will
74694     move one screen position to the right, otherwise it will move one
74695     screen position to the left.  Note that, depending on the
74696     surrounding bidirectional context, this could potentially move
74697     point many buffer positions away.  If invoked at the end of a
74698     screen line, the function moves point to the rightmost or leftmost
74699     screen position of the next or previous screen line, as appropriate
74700     for the value of DIRECTION.
74701
74702     The function returns the new buffer position as its value.
74703
74704   Bidirectional reordering can have surprising and unpleasant effects
74705when two strings with bidirectional content are juxtaposed in a buffer,
74706or otherwise programmatically concatenated into a string of text.  A
74707typical problematic case is when a buffer consists of sequences of text
74708fields separated by whitespace or punctuation characters, like Buffer
74709Menu mode or Rmail Summary Mode.  Because the punctuation characters
74710used as separators have “weak directionality”, they take on the
74711directionality of surrounding text.  As result, a numeric field that
74712follows a field with bidirectional content can be displayed _to the
74713left_ of the preceding field, messing up the expected layout.  There are
74714several ways to avoid this problem:
74715
74716   − Append the special character U+200E LEFT-TO-RIGHT MARK, or LRM, to
74717     the end of each field that may have bidirectional content, or
74718     prepend it to the beginning of the following field.  The function
74719     ‘bidi-string-mark-left-to-right’, described below, comes in handy
74720     for this purpose.  (In a right-to-left paragraph, use U+200F
74721     RIGHT-TO-LEFT MARK, or RLM, instead.)  This is one of the solutions
74722     recommended by the UBA.
74723
74724   − Include the tab character in the field separator.  The tab
74725     character plays the role of “segment separator” in bidirectional
74726     reordering, causing the text on either side to be reordered
74727     separately.
74728
74729   − Separate fields with a ‘display’ property or overlay with a
74730     property value of the form ‘(space . PROPS)’ (*note Specified
74731     Space::).  Emacs treats this display specification as a “paragraph
74732     separator”, and reorders the text on either side separately.
74733
74734 -- Function: bidi-string-mark-left-to-right string
74735     This function returns its argument STRING, possibly modified, such
74736     that the result can be safely concatenated with another string, or
74737     juxtaposed with another string in a buffer, without disrupting the
74738     relative layout of this string and the next one on display.  If the
74739     string returned by this function is displayed as part of a
74740     left-to-right paragraph, it will always appear on display to the
74741     left of the text that follows it.  The function works by examining
74742     the characters of its argument, and if any of those characters
74743     could cause reordering on display, the function appends the LRM
74744     character to the string.  The appended LRM character is made
74745     invisible by giving it an ‘invisible’ text property of ‘t’ (*note
74746     Invisible Text::).
74747
74748   The reordering algorithm uses the bidirectional properties of the
74749characters stored as their ‘bidi-class’ property (*note Character
74750Properties::).  Lisp programs can change these properties by calling the
74751‘put-char-code-property’ function.  However, doing this requires a
74752thorough understanding of the UBA, and is therefore not recommended.
74753Any changes to the bidirectional properties of a character have global
74754effect: they affect all Emacs frames and windows.
74755
74756   Similarly, the ‘mirroring’ property is used to display the
74757appropriate mirrored character in the reordered text.  Lisp programs can
74758affect the mirrored display by changing this property.  Again, any such
74759changes affect all of Emacs display.
74760
74761   The bidirectional properties of characters can be overridden by
74762inserting into the text special directional control characters,
74763LEFT-TO-RIGHT OVERRIDE (LRO) and RIGHT-TO-LEFT OVERRIDE (RLO).  Any
74764characters between a RLO and the following newline or POP DIRECTIONAL
74765FORMATTING (PDF) control character, whichever comes first, will be
74766displayed as if they were strong right-to-left characters, i.e. they
74767will be reversed on display.  Similarly, any characters between LRO and
74768PDF or newline will display as if they were strong left-to-right, and
74769will _not_ be reversed even if they are strong right-to-left characters.
74770
74771   These overrides are useful when you want to make some text unaffected
74772by the reordering algorithm, and instead directly control the display
74773order.  But they can also be used for malicious purposes, known as
74774“phishing”.  Specifically, a URL on a Web page or a link in an email
74775message can be manipulated to make its visual appearance unrecognizable,
74776or similar to some popular benign location, while the real location,
74777interpreted by a browser in the logical order, is very different.
74778
74779   Emacs provides a primitive that applications can use to detect
74780instances of text whose bidirectional properties were overridden so as
74781to make a left-to-right character display as if it were a right-to-left
74782character, or vice versa.
74783
74784 -- Function: bidi-find-overridden-directionality from to &optional
74785          object
74786     This function looks at the text of the specified OBJECT between
74787     positions FROM (inclusive) and TO (exclusive), and returns the
74788     first position where it finds a strong left-to-right character
74789     whose directional properties were forced to display the character
74790     as right-to-left, or for a strong right-to-left character that was
74791     forced to display as left-to-right.  If it finds no such characters
74792     in the specified region of text, it returns ‘nil’.
74793
74794     The optional argument OBJECT specifies which text to search, and
74795     defaults to the current buffer.  If OBJECT is non-‘nil’, it can be
74796     some other buffer, or it can be a string or a window.  If it is a
74797     string, the function searches that string.  If it is a window, the
74798     function searches the buffer displayed in that window.  If a buffer
74799     whose text you want to examine is displayed in some window, we
74800     recommend to specify it by that window, rather than pass the buffer
74801     to the function.  This is because telling the function about the
74802     window allows it to correctly account for window-specific overlays,
74803     which might change the result of the function if some text in the
74804     buffer is covered by overlays.
74805
74806   When text that includes mixed right-to-left and left-to-right
74807characters and bidirectional controls is copied into a different
74808location, it can change its visual appearance, and also can affect the
74809visual appearance of the surrounding text at destination.  This is
74810because reordering of bidirectional text specified by the UBA has
74811non-trivial context-dependent effects both on the copied text and on the
74812text at copy destination that will surround it.
74813
74814   Sometimes, a Lisp program may need to preserve the exact visual
74815appearance of the copied text at destination, and of the text that
74816surrounds the copy.  Lisp programs can use the following function to
74817achieve that effect.
74818
74819 -- Function: buffer-substring-with-bidi-context start end &optional
74820          no-properties
74821     This function works similar to ‘buffer-substring’ (*note Buffer
74822     Contents::), but it prepends and appends to the copied text bidi
74823     directional control characters necessary to preserve the visual
74824     appearance of the text when it is inserted at another place.
74825     Optional argument NO-PROPERTIES, if non-‘nil’, means remove the
74826     text properties from the copy of the text.
74827
74828
74829File: elisp.info,  Node: System Interface,  Next: Packaging,  Prev: Display,  Up: Top
74830
7483140 Operating System Interface
74832*****************************
74833
74834This chapter is about starting and getting out of Emacs, access to
74835values in the operating system environment, and terminal input, output.
74836
74837   *Note Building Emacs::, for related information.  *Note Display::,
74838for additional operating system status information pertaining to the
74839terminal and the screen.
74840
74841* Menu:
74842
74843* Starting Up::         Customizing Emacs startup processing.
74844* Getting Out::         How exiting works (permanent or temporary).
74845* System Environment::  Distinguish the name and kind of system.
74846* User Identification:: Finding the name and user id of the user.
74847* Time of Day::         Getting the current time.
74848* Time Zone Rules::     Rules for time zones and daylight saving time.
74849* Time Conversion::     Converting among timestamp forms.
74850* Time Parsing::        Converting timestamps to text and vice versa.
74851* Processor Run Time::  Getting the run time used by Emacs.
74852* Time Calculations::   Adding, subtracting, comparing times, etc.
74853* Timers::              Setting a timer to call a function at a certain time.
74854* Idle Timers::         Setting a timer to call a function when Emacs has
74855                          been idle for a certain length of time.
74856* Terminal Input::      Accessing and recording terminal input.
74857* Terminal Output::     Controlling and recording terminal output.
74858* Sound Output::        Playing sounds on the computer’s speaker.
74859* X11 Keysyms::         Operating on key symbols for X Windows.
74860* Batch Mode::          Running Emacs without terminal interaction.
74861* Session Management::  Saving and restoring state with X Session Management.
74862* Desktop Notifications:: Desktop notifications.
74863* File Notifications::  File notifications.
74864* Dynamic Libraries::   On-demand loading of support libraries.
74865* Security Considerations:: Running Emacs in an unfriendly environment.
74866
74867
74868File: elisp.info,  Node: Starting Up,  Next: Getting Out,  Up: System Interface
74869
7487040.1 Starting Up Emacs
74871======================
74872
74873This section describes what Emacs does when it is started, and how you
74874can customize these actions.
74875
74876* Menu:
74877
74878* Startup Summary::         Sequence of actions Emacs performs at startup.
74879* Init File::               Details on reading the init file.
74880* Terminal-Specific::       How the terminal-specific Lisp file is read.
74881* Command-Line Arguments::  How command-line arguments are processed,
74882                              and how you can customize them.
74883
74884
74885File: elisp.info,  Node: Startup Summary,  Next: Init File,  Up: Starting Up
74886
7488740.1.1 Summary: Sequence of Actions at Startup
74888----------------------------------------------
74889
74890When Emacs is started up, it performs the following operations (see
74891‘normal-top-level’ in ‘startup.el’):
74892
74893  1. It adds subdirectories to ‘load-path’, by running the file named
74894subdirs.el’ in each directory in the list.  Normally, this file
74895     adds the directory’s subdirectories to the list, and those are
74896     scanned in their turn.  The files ‘subdirs.el’ are normally
74897     generated automatically when Emacs is installed.
74898
74899  2. It loads any ‘leim-list.el’ that it finds in the ‘load-path’
74900     directories.  This file is intended for registering input methods.
74901     The search is only for any personal ‘leim-list.el’ files that you
74902     may have created; it skips the directories containing the standard
74903     Emacs libraries (these should contain only a single ‘leim-list.el74904     file, which is compiled into the Emacs executable).
74905
74906  3. It sets the variable ‘before-init-time’ to the value of
74907     ‘current-time’ (*note Time of Day::).  It also sets
74908     ‘after-init-time’ to ‘nil’, which signals to Lisp programs that
74909     Emacs is being initialized.
74910
74911  4. It sets the language environment and the terminal coding system, if
74912     requested by environment variables such as ‘LANG’.
74913
74914  5. It does some basic parsing of the command-line arguments.
74915
74916  6. It loads your early init file (*note (emacs)Early Init File::).
74917     This is not done if the options ‘-q’, ‘-Q’, or ‘--batch’ were
74918     specified.  If the ‘-u’ option was specified, Emacs looks for the
74919     init file in that user’s home directory instead.
74920
74921  7. It calls the function ‘package-activate-all’ to activate any
74922     optional Emacs Lisp package that has been installed.  *Note
74923     Packaging Basics::.  However, Emacs doesn’t activate the packages
74924     when ‘package-enable-at-startup’ is ‘nil’ or when it’s started with
74925     one of the options ‘-q’, ‘-Q’, or ‘--batch’.  To activate the
74926     packages in the latter case, ‘package-activate-all’ should be
74927     called explicitly (e.g., via the ‘--funcall’ option).
74928
74929  8. If not running in batch mode, it initializes the window system that
74930     the variable ‘initial-window-system’ specifies (*note
74931     initial-window-system: Window Systems.).  The initialization
74932     function, ‘window-system-initialization’, is a “generic function”
74933     (*note Generic Functions::) whose actual implementation is
74934     different for each supported window system.  If the value of
74935     ‘initial-window-system’ is WINDOWSYSTEM, then the appropriate
74936     implementation of the initialization function is defined in the
74937     file ‘term/WINDOWSYSTEM-win.el’.  This file should have been
74938     compiled into the Emacs executable when it was built.
74939
74940  9. It runs the normal hook ‘before-init-hook’.
74941
74942  10. If appropriate, it creates a graphical frame.  As part of creating
74943     the graphical frame, it initializes the window system specified by
74944     ‘initial-frame-alist’ and ‘default-frame-alist’ (*note Initial
74945     Parameters::) for the graphical frame, by calling the
74946     ‘window-system-initialization’ function for that window system.
74947     This is not done in batch (noninteractive) or daemon mode.
74948
74949  11. It initializes the initial frame’s faces, and sets up the menu bar
74950     and tool bar if needed.  If graphical frames are supported, it sets
74951     up the tool bar even if the current frame is not a graphical one,
74952     since a graphical frame may be created later on.
74953
74954  12. It use ‘custom-reevaluate-setting’ to re-initialize the members of
74955     the list ‘custom-delayed-init-variables’.  These are any pre-loaded
74956     user options whose default value depends on the run-time, rather
74957     than build-time, context.  *Note custom-initialize-delay: Building
74958     Emacs.
74959
74960  13. It loads the library ‘site-start’, if it exists.  This is not done
74961     if the options ‘-Q’ or ‘--no-site-file’ were specified.
74962
74963  14. It loads your init file (*note Init File::).  This is not done if
74964     the options ‘-q’, ‘-Q’, or ‘--batch’ were specified.  If the ‘-u’
74965     option was specified, Emacs looks for the init file in that user’s
74966     home directory instead.
74967
74968  15. It loads the library ‘default’, if it exists.  This is not done if
74969     ‘inhibit-default-init’ is non-‘nil’, nor if the options ‘-q’, ‘-Q’,
74970     or ‘--batch’ were specified.
74971
74972  16. It loads your abbrevs from the file specified by
74973     ‘abbrev-file-name’, if that file exists and can be read (*note
74974     abbrev-file-name: Abbrev Files.).  This is not done if the option
74975     ‘--batch’ was specified.
74976
74977  17. It sets the variable ‘after-init-time’ to the value of
74978     ‘current-time’.  This variable was set to ‘nil’ earlier; setting it
74979     to the current time signals that the initialization phase is over,
74980     and, together with ‘before-init-time’, provides the measurement of
74981     how long it took.
74982
74983  18. It runs the normal hook ‘after-init-hook’.
74984
74985  19. If the buffer ‘*scratch*’ exists and is still in Fundamental mode
74986     (as it should be by default), it sets its major mode according to
74987     ‘initial-major-mode’.
74988
74989  20. If started on a text terminal, it loads the terminal-specific Lisp
74990     library (*note Terminal-Specific::), and runs the hook
74991     ‘tty-setup-hook’.  This is not done in ‘--batch’ mode, nor if
74992     ‘term-file-prefix’ is ‘nil’.
74993
74994  21. It displays the initial echo area message, unless you have
74995     suppressed that with ‘inhibit-startup-echo-area-message’.
74996
74997  22. It processes any command-line options that were not handled
74998     earlier.
74999
75000  23. It now exits if the option ‘--batch’ was specified.
75001
75002  24. If the ‘*scratch*’ buffer exists and is empty, it inserts
75003     ‘(substitute-command-keys initial-scratch-message)’ into that
75004     buffer.
75005
75006  25. If ‘initial-buffer-choice’ is a string, it visits the file (or
75007     directory) with that name.  If it is a function, it calls the
75008     function with no arguments and selects the buffer that it returns.
75009     If one file is given as a command line argument, that file is
75010     visited and its buffer displayed alongside ‘initial-buffer-choice’.
75011     If more than one file is given, all of the files are visited and
75012     the ‘*Buffer List*’ buffer is displayed alongside
75013     ‘initial-buffer-choice’.
75014
75015  26. It runs ‘emacs-startup-hook’.
75016
75017  27. It calls ‘frame-notice-user-settings’, which modifies the
75018     parameters of the selected frame according to whatever the init
75019     files specify.
75020
75021  28. It runs ‘window-setup-hook’.  The only difference between this
75022     hook and ‘emacs-startup-hook’ is that this one runs after the
75023     previously mentioned modifications to the frame parameters.
75024
75025  29. It displays the “startup screen”, which is a special buffer that
75026     contains information about copyleft and basic Emacs usage.  This is
75027     not done if ‘inhibit-startup-screen’ or ‘initial-buffer-choice’ are
75028     non-‘nil’, or if the ‘--no-splash’ or ‘-Q’ command-line options
75029     were specified.
75030
75031  30. If a daemon was requested, it calls ‘server-start’.  (On POSIX
75032     systems, if a background daemon was requested, it then detaches
75033     from the controlling terminal.)  *Note (emacs)Emacs Server::.
75034
75035  31. If started by the X session manager, it calls
75036     ‘emacs-session-restore’ passing it as argument the ID of the
75037     previous session.  *Note Session Management::.
75038
75039The following options affect some aspects of the startup sequence.
75040
75041 -- User Option: inhibit-startup-screen
75042     This variable, if non-‘nil’, inhibits the startup screen.  In that
75043     case, Emacs typically displays the ‘*scratch*’ buffer; but see
75044     ‘initial-buffer-choice’, below.
75045
75046     Do not set this variable in the init file of a new user, or in a
75047     way that affects more than one user, as that would prevent new
75048     users from receiving information about copyleft and basic Emacs
75049     usage.
75050
75051     ‘inhibit-startup-message’ and ‘inhibit-splash-screen’ are aliases
75052     for this variable.
75053
75054 -- User Option: initial-buffer-choice
75055     If non-‘nil’, this variable is a string that specifies a file or
75056     directory for Emacs to display after starting up, instead of the
75057     startup screen.  If its value is a function, Emacs calls that
75058     function which must return a buffer which is then displayed.  If
75059     its value is ‘t’, Emacs displays the ‘*scratch*’ buffer.
75060
75061 -- User Option: inhibit-startup-echo-area-message
75062     This variable controls the display of the startup echo area
75063     message.  You can suppress the startup echo area message by adding
75064     text with this form to your init file:
75065
75066          (setq inhibit-startup-echo-area-message
75067                "YOUR-LOGIN-NAME")
75068
75069     Emacs explicitly checks for an expression as shown above in your
75070     init file; your login name must appear in the expression as a Lisp
75071     string constant.  You can also use the Customize interface.  Other
75072     methods of setting ‘inhibit-startup-echo-area-message’ to the same
75073     value do not inhibit the startup message.  This way, you can easily
75074     inhibit the message for yourself if you wish, but thoughtless
75075     copying of your init file will not inhibit the message for someone
75076     else.
75077
75078 -- User Option: initial-scratch-message
75079     This variable, if non-‘nil’, should be a string, which is treated
75080     as documentation to be inserted into the ‘*scratch*’ buffer when
75081     Emacs starts up.  If it is ‘nil’, the ‘*scratch*’ buffer is empty.
75082
75083The following command-line options affect some aspects of the startup
75084sequence.  *Note (emacs)Initial Options::.
75085
75086‘--no-splash’
75087     Do not display a splash screen.
75088
75089‘--batch’
75090     Run without an interactive terminal.  *Note Batch Mode::.
75091
75092‘--daemon’
75093‘--bg-daemon’
75094‘--fg-daemon’
75095     Do not initialize any display; just start a server.  (A
75096     “background” daemon automatically runs in the background.)
75097
75098‘--no-init-file’
75099‘-q’
75100     Do not load either the init file, or the ‘default’ library.
75101
75102‘--no-site-file’
75103     Do not load the ‘site-start’ library.
75104
75105‘--quick’
75106‘-Q’
75107     Equivalent to ‘-q --no-site-file --no-splash’.
75108
75109
75110File: elisp.info,  Node: Init File,  Next: Terminal-Specific,  Prev: Startup Summary,  Up: Starting Up
75111
7511240.1.2 The Init File
75113--------------------
75114
75115When you start Emacs, it normally attempts to load your “init file”.
75116This is either a file named ‘.emacs’ or ‘.emacs.el’ in your home
75117directory, or a file named ‘init.el’ in a subdirectory named ‘.emacs.d75118in your home directory.
75119
75120   The command-line switches ‘-q’, ‘-Q’, and ‘-u’ control whether and
75121where to find the init file; ‘-q’ (and the stronger ‘-Q’) says not to
75122load an init file, while ‘-u USER’ says to load USER’s init file instead
75123of yours.  *Note (emacs)Entering Emacs::.  If neither option is
75124specified, Emacs uses the ‘LOGNAME’ environment variable, or the ‘USER’
75125(most systems) or ‘USERNAME’ (MS systems) variable, to find your home
75126directory and thus your init file; this way, even if you have su’d,
75127Emacs still loads your own init file.  If those environment variables
75128are absent, though, Emacs uses your user-id to find your home directory.
75129
75130   Emacs also attempts to load a second init file, called the “early
75131init file”, if it exists.  This is a file named ‘early-init.el’ in your
75132‘~/.emacs.d’ directory.  The difference between the early init file and
75133the regular init file is that the early init file is loaded much earlier
75134during the startup process, so you can use it to customize some things
75135that are initialized before loading the regular init file.  For example,
75136you can customize the process of initializing the package system, by
75137setting variables such as PACKAGE-LOAD-LIST or
75138PACKAGE-ENABLE-AT-STARTUP.  *Note (emacs)Package Installation::.
75139
75140   An Emacs installation may have a “default init file”, which is a Lisp
75141library named ‘default.el’.  Emacs finds this file through the standard
75142search path for libraries (*note How Programs Do Loading::).  The Emacs
75143distribution does not come with this file; it is intended for local
75144customizations.  If the default init file exists, it is loaded whenever
75145you start Emacs.  But your own personal init file, if any, is loaded
75146first; if it sets ‘inhibit-default-init’ to a non-‘nil’ value, then
75147Emacs does not subsequently load the ‘default.el’ file.  In batch mode,
75148or if you specify ‘-q’ (or ‘-Q’), Emacs loads neither your personal init
75149file nor the default init file.
75150
75151   Another file for site-customization is ‘site-start.el’.  Emacs loads
75152this _before_ the user’s init file.  You can inhibit the loading of this
75153file with the option ‘--no-site-file’.
75154
75155 -- User Option: site-run-file
75156     This variable specifies the site-customization file to load before
75157     the user’s init file.  Its normal value is ‘"site-start"’.  The
75158     only way you can change it with real effect is to do so before
75159     dumping Emacs.
75160
75161   *Note Init File Examples: (emacs)Init Examples, for examples of how
75162to make various commonly desired customizations in your ‘.emacs’ file.
75163
75164 -- User Option: inhibit-default-init
75165     If this variable is non-‘nil’, it prevents Emacs from loading the
75166     default initialization library file.  The default value is ‘nil’.
75167
75168 -- Variable: before-init-hook
75169     This normal hook is run, once, just before loading all the init
75170     files (‘site-start.el’, your init file, and ‘default.el’).  (The
75171     only way to change it with real effect is before dumping Emacs.)
75172
75173 -- Variable: after-init-hook
75174     This normal hook is run, once, just after loading all the init
75175     files (‘site-start.el’, your init file, and ‘default.el’), before
75176     loading the terminal-specific library (if started on a text
75177     terminal) and processing the command-line action arguments.
75178
75179 -- Variable: emacs-startup-hook
75180     This normal hook is run, once, just after handling the command line
75181     arguments.  In batch mode, Emacs does not run this hook.
75182
75183 -- Variable: window-setup-hook
75184     This normal hook is very similar to ‘emacs-startup-hook’.  The only
75185     difference is that it runs slightly later, after setting of the
75186     frame parameters.  *Note window-setup-hook: Startup Summary.
75187
75188 -- Variable: user-init-file
75189     This variable holds the absolute file name of the user’s init file.
75190     If the actual init file loaded is a compiled file, such as
75191.emacs.elc’, the value refers to the corresponding source file.
75192
75193 -- Variable: user-emacs-directory
75194     This variable holds the name of the Emacs default directory.  It
75195     defaults to ‘${XDG_CONFIG_HOME-'~/.config'}/emacs/’ if that
75196     directory exists and ‘~/.emacs.d/’ and ‘~/.emacs’ do not exist,
75197     otherwise to ‘~/.emacs.d/’ on all platforms but MS-DOS.  Here,
75198     ‘${XDG_CONFIG_HOME-'~/.config'}’ stands for the value of the
75199     environment variable ‘XDG_CONFIG_HOME’ if that variable is set, and
75200     for ‘~/.config’ otherwise.  *Note How Emacs Finds Your Init File:
75201     (emacs)Find Init.
75202
75203
75204File: elisp.info,  Node: Terminal-Specific,  Next: Command-Line Arguments,  Prev: Init File,  Up: Starting Up
75205
7520640.1.3 Terminal-Specific Initialization
75207---------------------------------------
75208
75209Each terminal type can have its own Lisp library that Emacs loads when
75210run on that type of terminal.  The library’s name is constructed by
75211concatenating the value of the variable ‘term-file-prefix’ and the
75212terminal type (specified by the environment variable ‘TERM’).  Normally,
75213‘term-file-prefix’ has the value ‘"term/"’; changing this is not
75214recommended.  If there is an entry matching ‘TERM’ in the
75215‘term-file-aliases’ association list, Emacs uses the associated value in
75216place of ‘TERM’.  Emacs finds the file in the normal manner, by
75217searching the ‘load-path’ directories, and trying the ‘.elc’ and ‘.el’
75218suffixes.
75219
75220   The usual role of a terminal-specific library is to enable special
75221keys to send sequences that Emacs can recognize.  It may also need to
75222set or add to ‘input-decode-map’ if the Termcap or Terminfo entry does
75223not specify all the terminal’s function keys.  *Note Terminal Input::.
75224
75225   When the name of the terminal type contains a hyphen or underscore,
75226and no library is found whose name is identical to the terminal’s name,
75227Emacs strips from the terminal’s name the last hyphen or underscore and
75228everything that follows it, and tries again.  This process is repeated
75229until Emacs finds a matching library, or until there are no more hyphens
75230or underscores in the name (i.e., there is no terminal-specific
75231library).  For example, if the terminal name is ‘xterm-256color’ and
75232there is no ‘term/xterm-256color.el’ library, Emacs tries to load
75233term/xterm.el’.  If necessary, the terminal library can evaluate
75234‘(getenv "TERM")’ to find the full name of the terminal type.
75235
75236   Your init file can prevent the loading of the terminal-specific
75237library by setting the variable ‘term-file-prefix’ to ‘nil’.
75238
75239   You can also arrange to override some of the actions of the
75240terminal-specific library by using ‘tty-setup-hook’.  This is a normal
75241hook that Emacs runs after initializing a new text terminal.  You could
75242use this hook to define initializations for terminals that do not have
75243their own libraries.  *Note Hooks::.
75244
75245 -- User Option: term-file-prefix
75246     If the value of this variable is non-‘nil’, Emacs loads a
75247     terminal-specific initialization file as follows:
75248
75249          (load (concat term-file-prefix (getenv "TERM")))
75250
75251     You may set the ‘term-file-prefix’ variable to ‘nil’ in your init
75252     file if you do not wish to load the terminal-initialization file.
75253
75254     On MS-DOS, Emacs sets the ‘TERM’ environment variable to
75255     ‘internal’.
75256
75257 -- User Option: term-file-aliases
75258     This variable is an association list mapping terminal types to
75259     their aliases.  For example, an element of the form ‘("vt102" .
75260     "vt100")’ means to treat a terminal of type ‘vt102’ like one of
75261     type ‘vt100’.
75262
75263 -- Variable: tty-setup-hook
75264     This variable is a normal hook that Emacs runs after initializing a
75265     new text terminal.  (This applies when Emacs starts up in
75266     non-windowed mode, and when making a tty ‘emacsclient’ connection.)
75267     The hook runs after loading your init file (if applicable) and the
75268     terminal-specific Lisp file, so you can use it to adjust the
75269     definitions made by that file.
75270
75271     For a related feature, *note window-setup-hook: Init File.
75272
75273
75274File: elisp.info,  Node: Command-Line Arguments,  Prev: Terminal-Specific,  Up: Starting Up
75275
7527640.1.4 Command-Line Arguments
75277-----------------------------
75278
75279You can use command-line arguments to request various actions when you
75280start Emacs.  Note that the recommended way of using Emacs is to start
75281it just once, after logging in, and then do all editing in the same
75282Emacs session (*note (emacs)Entering Emacs::).  For this reason, you
75283might not use command-line arguments very often; nonetheless, they can
75284be useful when invoking Emacs from session scripts or debugging Emacs.
75285This section describes how Emacs processes command-line arguments.
75286
75287 -- Function: command-line
75288     This function parses the command line that Emacs was called with,
75289     processes it, and (amongst other things) loads the user’s init file
75290     and displays the startup messages.
75291
75292 -- Variable: command-line-processed
75293     The value of this variable is ‘t’ once the command line has been
75294     processed.
75295
75296     If you redump Emacs by calling ‘dump-emacs’ (*note Building
75297     Emacs::), you may wish to set this variable to ‘nil’ first in order
75298     to cause the new dumped Emacs to process its new command-line
75299     arguments.
75300
75301 -- Variable: command-switch-alist
75302     This variable is an alist of user-defined command-line options and
75303     associated handler functions.  By default it is empty, but you can
75304     add elements if you wish.
75305
75306     A “command-line option” is an argument on the command line, which
75307     has the form:
75308
75309          -OPTION
75310
75311     The elements of the ‘command-switch-alist’ look like this:
75312
75313          (OPTION . HANDLER-FUNCTION)
75314
75315     The CAR, OPTION, is a string, the name of a command-line option
75316     (including the initial hyphen).  The HANDLER-FUNCTION is called to
75317     handle OPTION, and receives the option name as its sole argument.
75318
75319     In some cases, the option is followed in the command line by an
75320     argument.  In these cases, the HANDLER-FUNCTION can find all the
75321     remaining command-line arguments in the variable
75322     ‘command-line-args-left’ (see below).  (The entire list of
75323     command-line arguments is in ‘command-line-args’.)
75324
75325     Note that the handling of ‘command-switch-alist’ doesn’t treat
75326     equals signs in OPTION specially.  That is, if there’s an option
75327     like ‘--name=value’ on the command line, then only a
75328     ‘command-switch-alist’ member whose ‘car’ is literally
75329     ‘--name=value’ will match this option.  If you want to parse such
75330     options, you need to use ‘command-line-functions’ instead (see
75331     below).
75332
75333     The command-line arguments are parsed by the ‘command-line-1’
75334     function in the ‘startup.el’ file.  See also *note Command Line
75335     Arguments for Emacs Invocation: (emacs)Emacs Invocation.
75336
75337 -- Variable: command-line-args
75338     The value of this variable is the list of command-line arguments
75339     passed to Emacs.
75340
75341 -- Variable: command-line-args-left
75342     The value of this variable is the list of command-line arguments
75343     that have not yet been processed.
75344
75345 -- Variable: command-line-functions
75346     This variable’s value is a list of functions for handling an
75347     unrecognized command-line argument.  Each time the next argument to
75348     be processed has no special meaning, the functions in this list are
75349     called, in order of appearance, until one of them returns a
75350     non-‘nil’ value.
75351
75352     These functions are called with no arguments.  They can access the
75353     command-line argument under consideration through the variable
75354     ‘argi’, which is bound temporarily at this point.  The remaining
75355     arguments (not including the current one) are in the variable
75356     ‘command-line-args-left’.
75357
75358     When a function recognizes and processes the argument in ‘argi’, it
75359     should return a non-‘nil’ value to say it has dealt with that
75360     argument.  If it has also dealt with some of the following
75361     arguments, it can indicate that by deleting them from
75362     ‘command-line-args-left’.
75363
75364     If all of these functions return ‘nil’, then the argument is
75365     treated as a file name to visit.
75366
75367
75368File: elisp.info,  Node: Getting Out,  Next: System Environment,  Prev: Starting Up,  Up: System Interface
75369
7537040.2 Getting Out of Emacs
75371=========================
75372
75373There are two ways to get out of Emacs: you can kill the Emacs job,
75374which exits permanently, or you can suspend it, which permits you to
75375reenter the Emacs process later.  (In a graphical environment, you can
75376of course simply switch to another application without doing anything
75377special to Emacs, then switch back to Emacs when you want.)
75378
75379* Menu:
75380
75381* Killing Emacs::        Exiting Emacs irreversibly.
75382* Suspending Emacs::     Exiting Emacs reversibly.
75383
75384
75385File: elisp.info,  Node: Killing Emacs,  Next: Suspending Emacs,  Up: Getting Out
75386
7538740.2.1 Killing Emacs
75388--------------------
75389
75390Killing Emacs means ending the execution of the Emacs process.  If you
75391started Emacs from a terminal, the parent process normally resumes
75392control.  The low-level primitive for killing Emacs is ‘kill-emacs’.
75393
75394 -- Command: kill-emacs &optional exit-data
75395     This command calls the hook ‘kill-emacs-hook’, then exits the Emacs
75396     process and kills it.
75397
75398     If EXIT-DATA is an integer, that is used as the exit status of the
75399     Emacs process.  (This is useful primarily in batch operation; see
75400     *note Batch Mode::.)
75401
75402     If EXIT-DATA is a string, its contents are stuffed into the
75403     terminal input buffer so that the shell (or whatever program next
75404     reads input) can read them.
75405
75406     If EXIT-DATA is neither an integer nor a string, or is omitted,
75407     that means to use the (system-specific) exit status which indicates
75408     successful program termination.
75409
75410   The ‘kill-emacs’ function is normally called via the higher-level
75411command ‘C-x C-c’ (‘save-buffers-kill-terminal’).  *Note
75412(emacs)Exiting::.  It is also called automatically if Emacs receives a
75413‘SIGTERM’ or ‘SIGHUP’ operating system signal (e.g., when the
75414controlling terminal is disconnected), or if it receives a ‘SIGINT’
75415signal while running in batch mode (*note Batch Mode::).
75416
75417 -- Variable: kill-emacs-hook
75418     This normal hook is run by ‘kill-emacs’, before it kills Emacs.
75419
75420     Because ‘kill-emacs’ can be called in situations where user
75421     interaction is impossible (e.g., when the terminal is
75422     disconnected), functions on this hook should not attempt to
75423     interact with the user.  If you want to interact with the user when
75424     Emacs is shutting down, use ‘kill-emacs-query-functions’, described
75425     below.
75426
75427   When Emacs is killed, all the information in the Emacs process, aside
75428from files that have been saved, is lost.  Because killing Emacs
75429inadvertently can lose a lot of work, the ‘save-buffers-kill-terminal’
75430command queries for confirmation if you have buffers that need saving or
75431subprocesses that are running.  It also runs the abnormal hook
75432‘kill-emacs-query-functions’:
75433
75434 -- User Option: kill-emacs-query-functions
75435     When ‘save-buffers-kill-terminal’ is killing Emacs, it calls the
75436     functions in this hook, after asking the standard questions and
75437     before calling ‘kill-emacs’.  The functions are called in order of
75438     appearance, with no arguments.  Each function can ask for
75439     additional confirmation from the user.  If any of them returns
75440     ‘nil’, ‘save-buffers-kill-emacs’ does not kill Emacs, and does not
75441     run the remaining functions in this hook.  Calling ‘kill-emacs’
75442     directly does not run this hook.
75443
75444
75445File: elisp.info,  Node: Suspending Emacs,  Prev: Killing Emacs,  Up: Getting Out
75446
7544740.2.2 Suspending Emacs
75448-----------------------
75449
75450On text terminals, it is possible to “suspend Emacs”, which means
75451stopping Emacs temporarily and returning control to its superior
75452process, which is usually the shell.  This allows you to resume editing
75453later in the same Emacs process, with the same buffers, the same kill
75454ring, the same undo history, and so on.  To resume Emacs, use the
75455appropriate command in the parent shell—most likely ‘fg’.
75456
75457   Suspending works only on a terminal device from which the Emacs
75458session was started.  We call that device the “controlling terminal” of
75459the session.  Suspending is not allowed if the controlling terminal is a
75460graphical terminal.  Suspending is usually not relevant in graphical
75461environments, since you can simply switch to another application without
75462doing anything special to Emacs.
75463
75464   Some operating systems (those without ‘SIGTSTP’, or MS-DOS) do not
75465support suspension of jobs; on these systems, suspension actually
75466creates a new shell temporarily as a subprocess of Emacs.  Then you
75467would exit the shell to return to Emacs.
75468
75469 -- Command: suspend-emacs &optional string
75470     This function stops Emacs and returns control to the superior
75471     process.  If and when the superior process resumes Emacs,
75472     ‘suspend-emacs’ returns ‘nil’ to its caller in Lisp.
75473
75474     This function works only on the controlling terminal of the Emacs
75475     session; to relinquish control of other tty devices, use
75476     ‘suspend-tty’ (see below).  If the Emacs session uses more than one
75477     terminal, you must delete the frames on all the other terminals
75478     before suspending Emacs, or this function signals an error.  *Note
75479     Multiple Terminals::.
75480
75481     If STRING is non-‘nil’, its characters are sent to Emacs’s superior
75482     shell, to be read as terminal input.  The characters in STRING are
75483     not echoed by the superior shell; only the results appear.
75484
75485     Before suspending, ‘suspend-emacs’ runs the normal hook
75486     ‘suspend-hook’.  After the user resumes Emacs, ‘suspend-emacs’ runs
75487     the normal hook ‘suspend-resume-hook’.  *Note Hooks::.
75488
75489     The next redisplay after resumption will redraw the entire screen,
75490     unless the variable ‘no-redraw-on-reenter’ is non-‘nil’.  *Note
75491     Refresh Screen::.
75492
75493     Here is an example of how you could use these hooks:
75494
75495          (add-hook 'suspend-hook
75496                    (lambda () (or (y-or-n-p "Really suspend? ")
75497                                   (error "Suspend canceled"))))
75498          (add-hook 'suspend-resume-hook (lambda () (message "Resumed!")
75499                                           (sit-for 2)))
75500
75501     Here is what you would see upon evaluating ‘(suspend-emacs "pwd")’:
75502
75503          ---------- Buffer: Minibuffer ----------
75504          Really suspend? y
75505          ---------- Buffer: Minibuffer ----------
75506
75507          ---------- Parent Shell ----------
75508          bash$ /home/username
75509          bash$ fg
75510
75511          ---------- Echo Area ----------
75512          Resumed!
75513
75514     Note that ‘pwd’ is not echoed after Emacs is suspended.  But it is
75515     read and executed by the shell.
75516
75517 -- Variable: suspend-hook
75518     This variable is a normal hook that Emacs runs before suspending.
75519
75520 -- Variable: suspend-resume-hook
75521     This variable is a normal hook that Emacs runs on resuming after a
75522     suspension.
75523
75524 -- Function: suspend-tty &optional tty
75525     If TTY specifies a terminal device used by Emacs, this function
75526     relinquishes the device and restores it to its prior state.  Frames
75527     that used the device continue to exist, but are not updated and
75528     Emacs doesn’t read input from them.  TTY can be a terminal object,
75529     a frame (meaning the terminal for that frame), or ‘nil’ (meaning
75530     the terminal for the selected frame).  *Note Multiple Terminals::.
75531
75532     If TTY is already suspended, this function does nothing.
75533
75534     This function runs the hook ‘suspend-tty-functions’, passing the
75535     terminal object as an argument to each function.
75536
75537 -- Function: resume-tty &optional tty
75538     This function resumes the previously suspended terminal device TTY;
75539     where TTY has the same possible values as it does for
75540     ‘suspend-tty’.
75541
75542     This function reopens the terminal device, re-initializes it, and
75543     redraws it with that terminal’s selected frame.  It then runs the
75544     hook ‘resume-tty-functions’, passing the terminal object as an
75545     argument to each function.
75546
75547     If the same device is already used by another Emacs terminal, this
75548     function signals an error.  If TTY is not suspended, this function
75549     does nothing.
75550
75551 -- Function: controlling-tty-p &optional tty
75552     This function returns non-‘nil’ if TTY is the controlling terminal
75553     of the Emacs session; TTY can be a terminal object, a frame
75554     (meaning the terminal for that frame), or ‘nil’ (meaning the
75555     terminal for the selected frame).
75556
75557 -- Command: suspend-frame
75558     This command “suspends” a frame.  For GUI frames, it calls
75559     ‘iconify-frame’ (*note Visibility of Frames::); for frames on text
75560     terminals, it calls either ‘suspend-emacs’ or ‘suspend-tty’,
75561     depending on whether the frame is displayed on the controlling
75562     terminal device or not.
75563
75564
75565File: elisp.info,  Node: System Environment,  Next: User Identification,  Prev: Getting Out,  Up: System Interface
75566
7556740.3 Operating System Environment
75568=================================
75569
75570Emacs provides access to variables in the operating system environment
75571through various functions.  These variables include the name of the
75572system, the user’s UID, and so on.
75573
75574 -- Variable: system-configuration
75575     This variable holds the standard GNU configuration name for the
75576     hardware/software configuration of your system, as a string.  For
75577     example, a typical value for a 64-bit GNU/Linux system is
75578     ‘"x86_64-unknown-linux-gnu"’.
75579
75580 -- Variable: system-type
75581     The value of this variable is a symbol indicating the type of
75582     operating system Emacs is running on.  The possible values are:
75583
75584     ‘aix’
75585          IBM’s AIX.
75586
75587     ‘berkeley-unix’
75588          Berkeley BSD and its variants.
75589
75590     ‘cygwin’
75591          Cygwin, a POSIX layer on top of MS-Windows.
75592
75593     ‘darwin’
75594          Darwin (macOS).
75595
75596     ‘gnu’
75597          The GNU system (using the GNU kernel, which consists of the
75598          HURD and Mach).
75599
75600gnu/linux75601          A GNU/Linux system—that is, a variant GNU system, using the
75602          Linux kernel.  (These systems are the ones people often call
75603          “Linux”, but actually Linux is just the kernel, not the whole
75604          system.)
75605
75606gnu/kfreebsd75607          A GNU (glibc-based) system with a FreeBSD kernel.
75608
75609     ‘hpux’
75610          Hewlett-Packard HPUX operating system.
75611
75612     ‘nacl’
75613          Google Native Client (NaCl) sandboxing system.
75614
75615     ‘ms-dos’
75616          Microsoft’s DOS.  Emacs compiled with DJGPP for MS-DOS binds
75617          ‘system-type’ to ‘ms-dos’ even when you run it on MS-Windows.
75618
75619     ‘usg-unix-v’
75620          AT&T Unix System V.
75621
75622     ‘windows-nt’
75623          Microsoft Windows NT, 9X and later.  The value of
75624          ‘system-type’ is always ‘windows-nt’, e.g., even on Windows
75625          10.
75626
75627     We do not wish to add new symbols to make finer distinctions unless
75628     it is absolutely necessary!  In fact, we hope to eliminate some of
75629     these alternatives in the future.  If you need to make a finer
75630     distinction than ‘system-type’ allows for, you can test
75631     ‘system-configuration’, e.g., against a regexp.
75632
75633 -- Function: system-name
75634     This function returns the name of the machine you are running on,
75635     as a string.
75636
75637 -- User Option: mail-host-address
75638     If this variable is non-‘nil’, it is used instead of ‘system-name’
75639     for purposes of generating email addresses.  For example, it is
75640     used when constructing the default value of ‘user-mail-address’.
75641     *Note User Identification::.
75642
75643 -- Command: getenv var &optional frame
75644     This function returns the value of the environment variable VAR, as
75645     a string.  VAR should be a string.  If VAR is undefined in the
75646     environment, ‘getenv’ returns ‘nil’.  It returns ‘""’ if VAR is set
75647     but null.  Within Emacs, a list of environment variables and their
75648     values is kept in the variable ‘process-environment’.
75649
75650          (getenv "USER")
75651               ⇒ "lewis"
75652
75653     The shell command ‘printenv’ prints all or part of the environment:
75654
75655          bash$ printenv
75656          PATH=/usr/local/bin:/usr/bin:/bin
75657          USER=lewis
75658          TERM=xterm
75659          SHELL=/bin/bash
75660          HOME=/home/lewis
75661          ...
75662
75663 -- Command: setenv variable &optional value substitute
75664     This command sets the value of the environment variable named
75665     VARIABLE to VALUE.  VARIABLE should be a string.  Internally, Emacs
75666     Lisp can handle any string.  However, normally VARIABLE should be a
75667     valid shell identifier, that is, a sequence of letters, digits and
75668     underscores, starting with a letter or underscore.  Otherwise,
75669     errors may occur if subprocesses of Emacs try to access the value
75670     of VARIABLE.  If VALUE is omitted or ‘nil’ (or, interactively, with
75671     a prefix argument), ‘setenv’ removes VARIABLE from the environment.
75672     Otherwise, VALUE should be a string.
75673
75674     If the optional argument SUBSTITUTE is non-‘nil’, Emacs calls the
75675     function ‘substitute-env-vars’ to expand any environment variables
75676     in VALUE.
75677
75678     ‘setenv’ works by modifying ‘process-environment’; binding that
75679     variable with ‘let’ is also reasonable practice.
75680
75681     ‘setenv’ returns the new value of VARIABLE, or ‘nil’ if it removed
75682     VARIABLE from the environment.
75683
75684 -- Variable: process-environment
75685     This variable is a list of strings, each describing one environment
75686     variable.  The functions ‘getenv’ and ‘setenv’ work by means of
75687     this variable.
75688
75689          process-environment
75690          ⇒ ("PATH=/usr/local/bin:/usr/bin:/bin"
75691              "USER=lewis"
75692              "TERM=xterm"
75693              "SHELL=/bin/bash"
75694              "HOME=/home/lewis"
75695              ...)
75696
75697     If ‘process-environment’ contains multiple elements that specify
75698     the same environment variable, the first of these elements
75699     specifies the variable, and the others are ignored.
75700
75701 -- Variable: initial-environment
75702     This variable holds the list of environment variables Emacs
75703     inherited from its parent process when Emacs started.
75704
75705 -- Variable: path-separator
75706     This variable holds a string that says which character separates
75707     directories in a search path (as found in an environment variable).
75708     Its value is ‘":"’ for Unix and GNU systems, and ‘";"’ for MS
75709     systems.
75710
75711 -- Function: parse-colon-path path
75712     This function takes a search path string such as the value of the
75713     ‘PATH’ environment variable, and splits it at the separators,
75714     returning a list of directories.  ‘nil’ in this list means the
75715     current directory.  Although the function’s name says “colon”, it
75716     actually uses the value of ‘path-separator’.
75717
75718          (parse-colon-path ":/foo:/bar")
75719               ⇒ (nil "/foo/" "/bar/")
75720
75721 -- Variable: invocation-name
75722     This variable holds the program name under which Emacs was invoked.
75723     The value is a string, and does not include a directory name.
75724
75725 -- Variable: invocation-directory
75726     This variable holds the directory in which the Emacs executable was
75727     located when it was run, or ‘nil’ if that directory cannot be
75728     determined.
75729
75730 -- Variable: installation-directory
75731     If non-‘nil’, this is a directory within which to look for the
75732     ‘lib-src’ and ‘etc’ subdirectories.  In an installed Emacs, it is
75733     normally ‘nil’.  It is non-‘nil’ when Emacs can’t find those
75734     directories in their standard installed locations, but can find
75735     them in a directory related somehow to the one containing the Emacs
75736     executable (i.e., ‘invocation-directory’).
75737
75738 -- Function: load-average &optional use-float
75739     This function returns the current 1-minute, 5-minute, and 15-minute
75740     system load averages, in a list.  The load average indicates the
75741     number of processes trying to run on the system.
75742
75743     By default, the values are integers that are 100 times the system
75744     load averages, but if USE-FLOAT is non-‘nil’, then they are
75745     returned as floating-point numbers without multiplying by 100.
75746
75747     If it is impossible to obtain the load average, this function
75748     signals an error.  On some platforms, access to load averages
75749     requires installing Emacs as setuid or setgid so that it can read
75750     kernel information, and that usually isn’t advisable.
75751
75752     If the 1-minute load average is available, but the 5- or 15-minute
75753     averages are not, this function returns a shortened list containing
75754     the available averages.
75755
75756          (load-average)
75757               ⇒ (169 48 36)
75758          (load-average t)
75759               ⇒ (1.69 0.48 0.36)
75760
75761     The shell command ‘uptime’ returns similar information.
75762
75763 -- Function: emacs-pid
75764     This function returns the process ID of the Emacs process, as an
75765     integer.
75766
75767 -- Variable: tty-erase-char
75768     This variable holds the erase character that was selected in the
75769     system’s terminal driver, before Emacs was started.
75770
75771
75772File: elisp.info,  Node: User Identification,  Next: Time of Day,  Prev: System Environment,  Up: System Interface
75773
7577440.4 User Identification
75775========================
75776
75777 -- Variable: init-file-user
75778     This variable says which user’s init files should be used by
75779     Emacs—or ‘nil’ if none.  ‘""’ stands for the user who originally
75780     logged in.  The value reflects command-line options such as ‘-q’ or
75781     ‘-u USER’.
75782
75783     Lisp packages that load files of customizations, or any other sort
75784     of user profile, should obey this variable in deciding where to
75785     find it.  They should load the profile of the user name found in
75786     this variable.  If ‘init-file-user’ is ‘nil’, meaning that the
75787     ‘-q’, ‘-Q’, or ‘-batch’ option was used, then Lisp packages should
75788     not load any customization files or user profile.
75789
75790 -- User Option: user-mail-address
75791     This holds the email address of the user who is using Emacs.
75792
75793 -- Function: user-login-name &optional uid
75794     This function returns the name under which the user is logged in.
75795     It uses the environment variables ‘LOGNAME’ or ‘USER’ if either is
75796     set.  Otherwise, the value is based on the effective UID, not the
75797     real UID.
75798
75799     If you specify UID (a number), the result is the user name that
75800     corresponds to UID, or ‘nil’ if there is no such user.
75801
75802 -- Function: user-real-login-name
75803     This function returns the user name corresponding to Emacs’s real
75804     UID.  This ignores the effective UID, and the environment variables
75805     ‘LOGNAME’ and ‘USER’.
75806
75807 -- Function: user-full-name &optional uid
75808     This function returns the full name of the logged-in user—or the
75809     value of the environment variable ‘NAME’, if that is set.
75810
75811     If the Emacs process’s user-id does not correspond to any known
75812     user (and provided ‘NAME’ is not set), the result is ‘"unknown"’.
75813
75814     If UID is non-‘nil’, then it should be a number (a user-id) or a
75815     string (a login name).  Then ‘user-full-name’ returns the full name
75816     corresponding to that user-id or login name.  If you specify a
75817     user-id or login name that isn’t defined, it returns ‘nil’.
75818
75819   The symbols ‘user-login-name’, ‘user-real-login-name’ and
75820‘user-full-name’ are variables as well as functions.  The functions
75821return the same values that the variables hold.  These variables allow
75822you to fake out Emacs by telling the functions what to return.  The
75823variables are also useful for constructing frame titles (*note Frame
75824Titles::).
75825
75826 -- Function: user-real-uid
75827     This function returns the real UID of the user.
75828
75829 -- Function: user-uid
75830     This function returns the effective UID of the user.
75831
75832 -- Function: group-gid
75833     This function returns the effective GID of the Emacs process.
75834
75835 -- Function: group-real-gid
75836     This function returns the real GID of the Emacs process.
75837
75838 -- Function: system-users
75839     This function returns a list of strings, listing the user names on
75840     the system.  If Emacs cannot retrieve this information, the return
75841     value is a list containing just the value of
75842     ‘user-real-login-name’.
75843
75844 -- Function: system-groups
75845     This function returns a list of strings, listing the names of user
75846     groups on the system.  If Emacs cannot retrieve this information,
75847     the return value is ‘nil’.
75848
75849 -- Function: group-name gid
75850     This function returns the group name that corresponds to the
75851     numeric group ID GID, or ‘nil’ if there is no such group.
75852
75853
75854File: elisp.info,  Node: Time of Day,  Next: Time Zone Rules,  Prev: User Identification,  Up: System Interface
75855
7585640.5 Time of Day
75857================
75858
75859This section explains how to determine the current time and time zone.
75860
75861   Many functions like ‘current-time’ and ‘file-attributes’ return “Lisp
75862timestamp” values that count seconds, and that can represent absolute
75863time by counting seconds since the “epoch” of 1970-01-01 00:00:00 UTC.
75864
75865   Although traditionally Lisp timestamps were integer pairs, their form
75866has evolved and programs ordinarily should not depend on the current
75867default form.  If your program needs a particular timestamp form, you
75868can use the ‘time-convert’ function to convert it to the needed form.
75869*Note Time Conversion::.
75870
75871   There are currently three forms of Lisp timestamps, each of which
75872represents a number of seconds:
75873
75874   • An integer.  Although this is the simplest form, it cannot
75875     represent subsecond timestamps.
75876
75877   • A pair of integers ‘(TICKS . HZ)’, where HZ is positive.  This
75878     represents TICKS/HZ seconds, which is the same time as plain TICKS
75879     if HZ is 1.  A common value for HZ is 1000000000, for a
75880     nanosecond-resolution clock.(1)
75881
75882   • A list of four integers ‘(HIGH LOW MICRO PICO)’, where 0≤LOW<65536,
75883     0≤MICRO<1000000, and 0≤PICO<1000000.  This represents the number of
75884     seconds using the formula: HIGH * 2**16 + LOW + MICRO * 10**−6 +
75885     PICO * 10**−12.  In some cases, functions may default to returning
75886     two- or three-element lists, with omitted MICRO and PICO components
75887     defaulting to zero.  On all current machines PICO is a multiple of
75888     1000, but this may change as higher-resolution clocks become
75889     available.
75890
75891   Function arguments, e.g., the TIME argument to ‘current-time-string’,
75892accept a more-general “time value” format, which can be a Lisp
75893timestamp, ‘nil’ for the current time, a single floating-point number
75894for seconds, or a list ‘(HIGH LOW MICRO)’ or ‘(HIGH LOW)’ that is a
75895truncated list timestamp with missing elements taken to be zero.
75896
75897   Time values can be converted to and from calendrical and other forms.
75898Some of these conversions rely on operating system functions that limit
75899the range of possible time values, and signal an error such as
75900‘"Specified time is not representable"’ if the limits are exceeded.  For
75901instance, a system may not support years before 1970, or years before
759021901, or years far in the future.  You can convert a time value into a
75903human-readable string using ‘format-time-string’, into a Lisp timestamp
75904using ‘time-convert’, and into other forms using ‘decode-time’ and
75905‘float-time’.  These functions are described in the following sections.
75906
75907 -- Function: current-time-string &optional time zone
75908     This function returns the current time and date as a human-readable
75909     string.  The format does not vary for the initial part of the
75910     string, which contains the day of week, month, day of month, and
75911     time of day in that order: the number of characters used for these
75912     fields is always the same, although (unless you require English
75913     weekday or month abbreviations regardless of locale) it is
75914     typically more convenient to use ‘format-time-string’ than to
75915     extract fields from the output of ‘current-time-string’, as the
75916     year might not have exactly four digits, and additional information
75917     may some day be added at the end.
75918
75919     The argument TIME, if given, specifies a time to format, instead of
75920     the current time.  The optional argument ZONE defaults to the
75921     current time zone rule.  *Note Time Zone Rules::.  The operating
75922     system limits the range of time and zone values.
75923
75924          (current-time-string)
75925               ⇒ "Fri Nov  1 15:59:49 2019"
75926
75927 -- Function: current-time
75928     This function returns the current time as a Lisp timestamp.
75929     Although the timestamp takes the form ‘(HIGH LOW MICRO PICO)’ in
75930     the current Emacs release, this is planned to change in a future
75931     Emacs version.  You can use the ‘time-convert’ function to convert
75932     a timestamp to some other form.  *Note Time Conversion::.
75933
75934 -- Function: float-time &optional time
75935     This function returns the current time as a floating-point number
75936     of seconds since the epoch.  The optional argument TIME, if given,
75937     specifies a time to convert instead of the current time.
75938
75939     _Warning_: Since the result is floating point, it may not be exact.
75940     Do not use this function if precise time stamps are required.  For
75941     example, on typical systems ‘(float-time '(1 . 10))’ displays as
75942     ‘0.1’ but is slightly greater than 1/10.
75943
75944     ‘time-to-seconds’ is an alias for this function.
75945
75946   ---------- Footnotes ----------
75947
75948   (1) Currently HZ should be at least 65536 to avoid compatibility
75949warnings when the timestamp is passed to standard functions, as previous
75950versions of Emacs would interpret such a timestamps differently due to
75951backward-compatibility concerns.  These warnings are intended to be
75952removed in a future Emacs version.
75953
75954
75955File: elisp.info,  Node: Time Zone Rules,  Next: Time Conversion,  Prev: Time of Day,  Up: System Interface
75956
7595740.6 Time Zone Rules
75958====================
75959
75960The default time zone is determined by the ‘TZ’ environment variable.
75961*Note System Environment::.  For example, you can tell Emacs to default
75962to Universal Time with ‘(setenv "TZ" "UTC0")’.  If ‘TZ’ is not in the
75963environment, Emacs uses system wall clock time, which is a
75964platform-dependent default time zone.
75965
75966   The set of supported ‘TZ’ strings is system-dependent.  GNU and many
75967other systems support the tzdata database, e.g., ‘"America/New_York"’
75968specifies the time zone and daylight saving time history for locations
75969near New York City.  GNU and most other systems support POSIX-style ‘TZ’
75970strings, e.g., ‘"EST+5EDT,M4.1.0/2,M10.5.0/2"’ specifies the rules used
75971in New York from 1987 through 2006.  All systems support the string
75972‘"UTC0"’ meaning Universal Time.
75973
75974   Functions that convert to and from local time accept an optional
75975“time zone rule” argument, which specifies the conversion’s time zone
75976and daylight saving time history.  If the time zone rule is omitted or
75977‘nil’, the conversion uses Emacs’s default time zone.  If it is ‘t’, the
75978conversion uses Universal Time.  If it is ‘wall’, the conversion uses
75979the system wall clock time.  If it is a string, the conversion uses the
75980time zone rule equivalent to setting ‘TZ’ to that string.  If it is a
75981list (OFFSET ABBR), where OFFSET is an integer number of seconds east of
75982Universal Time and ABBR is a string, the conversion uses a fixed time
75983zone with the given offset and abbreviation.  An integer OFFSET is
75984treated as if it were (OFFSET ABBR), where ABBR is a numeric
75985abbreviation on POSIX-compatible platforms and is unspecified on
75986MS-Windows.
75987
75988 -- Function: current-time-zone &optional time zone
75989     This function returns a list describing the time zone that the user
75990     is in.
75991
75992     The value has the form ‘(OFFSET ABBR)’.  Here OFFSET is an integer
75993     giving the number of seconds ahead of Universal Time (east of
75994     Greenwich).  A negative value means west of Greenwich.  The second
75995     element, ABBR, is a string giving an abbreviation for the time
75996     zone, e.g., ‘"CST"’ for China Standard Time or for U.S. Central
75997     Standard Time.  Both elements can change when daylight saving time
75998     begins or ends; if the user has specified a time zone that does not
75999     use a seasonal time adjustment, then the value is constant through
76000     time.
76001
76002     If the operating system doesn’t supply all the information
76003     necessary to compute the value, the unknown elements of the list
76004     are ‘nil’.
76005
76006     The argument TIME, if given, specifies a time value to analyze
76007     instead of the current time.  The optional argument ZONE defaults
76008     to the current time zone rule.  The operating system limits the
76009     range of time and zone values.
76010
76011
76012File: elisp.info,  Node: Time Conversion,  Next: Time Parsing,  Prev: Time Zone Rules,  Up: System Interface
76013
7601440.7 Time Conversion
76015====================
76016
76017These functions convert time values (*note Time of Day::) to Lisp
76018timestamps, or into calendrical information and vice versa.
76019
76020   Many 32-bit operating systems are limited to system times containing
7602132 bits of information in their seconds component; these systems
76022typically handle only the times from 1901-12-13 20:45:52 through
760232038-01-19 03:14:07 Universal Time.  However, 64-bit and some 32-bit
76024operating systems have larger seconds components, and can represent
76025times far in the past or future.
76026
76027   Calendrical conversion functions always use the Gregorian calendar,
76028even for dates before the Gregorian calendar was introduced.  Year
76029numbers count the number of years since the year 1 BC, and do not skip
76030zero as traditional Gregorian years do; for example, the year number −37
76031represents the Gregorian year 38 BC.
76032
76033 -- Function: time-convert time &optional form
76034     This function converts a time value into a Lisp timestamp.
76035
76036     The optional FORM argument specifies the timestamp form to be
76037     returned.  If FORM is the symbol ‘integer’, this function returns
76038     an integer count of seconds.  If FORM is a positive integer, it
76039     specifies a clock frequency and this function returns an
76040     integer-pair timestamp ‘(TICKS . FORM)’.(1)  If FORM is ‘t’, this
76041     function treats it as a positive integer suitable for representing
76042     the timestamp; for example, it is treated as 1000000000 if TIME is
76043     nil and the platform timestamp has nanosecond resolution.  If FORM
76044     is ‘list’, this function returns an integer list ‘(HIGH LOW MICRO
76045     PICO)’.  Although an omitted or ‘nil’ FORM currently acts like
76046     ‘list’, this is planned to change in a future Emacs version, so
76047     callers requiring list timestamps should pass ‘list’ explicitly.
76048
76049     If TIME is infinite or a NaN, this function signals an error.
76050     Otherwise, if TIME cannot be represented exactly, conversion
76051     truncates it toward minus infinity.  When FORM is ‘t’, conversion
76052     is always exact so no truncation occurs, and the returned clock
76053     resolution is no less than that of TIME.  By way of contrast,
76054     ‘float-time’ can convert any Lisp time value without signaling an
76055     error, although the result might not be exact.  *Note Time of
76056     Day::.
76057
76058     For efficiency this function might return a value that is ‘eq’ to
76059     TIME, or that otherwise shares structure with TIME.
76060
76061     Although ‘(time-convert nil nil)’ is equivalent to
76062     ‘(current-time)’, the latter may be a bit faster.
76063
76064          (setq a (time-convert nil t))
76065          ⇒ (1564826753904873156 . 1000000000)
76066          (time-convert a 100000)
76067          ⇒ (156482675390487 . 100000)
76068          (time-convert a 'integer)
76069          ⇒ 1564826753
76070          (time-convert a 'list)
76071          ⇒ (23877 23681 904873 156000)
76072
76073 -- Function: decode-time &optional time zone form
76074     This function converts a time value into calendrical information.
76075     If you don’t specify TIME, it decodes the current time, and
76076     similarly ZONE defaults to the current time zone rule.  *Note Time
76077     Zone Rules::.  The operating system limits the range of time and
76078     zone values.
76079
76080     The FORM argument controls the form of the returned SECONDS
76081     element, as described below.  The return value is a list of nine
76082     elements, as follows:
76083
76084          (SECONDS MINUTES HOUR DAY MONTH YEAR DOW DST UTCOFF)
76085
76086     Here is what the elements mean:
76087
76088     SECONDS
76089          The number of seconds past the minute, with form described
76090          below.
76091     MINUTES
76092          The number of minutes past the hour, as an integer between 0
76093          and 59.
76094     HOUR
76095          The hour of the day, as an integer between 0 and 23.
76096     DAY
76097          The day of the month, as an integer between 1 and 31.
76098     MONTH
76099          The month of the year, as an integer between 1 and 12.
76100     YEAR
76101          The year, an integer typically greater than 1900.
76102     DOW
76103          The day of week, as an integer between 0 and 6, where 0 stands
76104          for Sunday.
76105     DST
76106          ‘t’ if daylight saving time is effect, ‘nil’ if it is not in
76107          effect, and −1 if this information is not available.
76108     UTCOFF
76109          An integer indicating the Universal Time offset in seconds,
76110          i.e., the number of seconds east of Greenwich.
76111
76112     The SECONDS element is a Lisp timestamp that is nonnegative and
76113     less than 61; it is less than 60 except during positive leap
76114     seconds (assuming the operating system supports leap seconds).  If
76115     the optional FORM argument is ‘t’, SECONDS uses the same precision
76116     as TIME; if FORM is ‘integer’, SECONDS is truncated to an integer.
76117     For example, if TIME is the timestamp ‘(1566009571321 . 1000)’,
76118     which represents 2019-08-17 02:39:31.321 UTC on typical systems
76119     that lack leap seconds, then ‘(decode-time TIME t t)’ returns
76120     ‘((31321 . 1000) 39 2 17 8 2019 6 nil 0)’, whereas ‘(decode-time
76121     TIME t 'integer)’ returns ‘(31 39 2 17 8 2019 6 nil 0)’.  If FORM
76122     is omitted or ‘nil’, it currently defaults to ‘integer’ but this
76123     default may change in future Emacs releases, so callers requiring a
76124     particular form should specify FORM.
76125
76126     *Common Lisp Note:* Common Lisp has different meanings for DOW and
76127     UTCOFF, and its SECOND is an integer between 0 and 59 inclusive.
76128
76129     To access (or alter) the elements in the time value, the
76130     ‘decoded-time-second’, ‘decoded-time-minute’, ‘decoded-time-hour’,
76131     ‘decoded-time-day’, ‘decoded-time-month’, ‘decoded-time-year’,
76132     ‘decoded-time-weekday’, ‘decoded-time-dst’ and ‘decoded-time-zone’
76133     accessors can be used.
76134
76135     For instance, to increase the year in a decoded time, you could
76136     say:
76137
76138          (setf (decoded-time-year decoded-time)
76139                (+ (decoded-time-year decoded-time) 4))
76140
76141     Also see the following function.
76142
76143 -- Function: decoded-time-add time delta
76144     This function takes a decoded time structure and adds DELTA (also a
76145     decoded time structure) to it.  Elements in DELTA that are ‘nil’
76146     are ignored.
76147
76148     For instance, if you want “same time next month”, you could say:
76149
76150          (let ((time (decode-time nil nil t))
76151                (delta (make-decoded-time :month 2)))
76152             (encode-time (decoded-time-add time delta)))
76153
76154     If this date doesn’t exist (if you’re running this on January 31st,
76155     for instance), then the date will be shifted back until you get a
76156     valid date (which will be February 28th or 29th, depending).
76157
76158     Fields are added in a most to least significant order, so if the
76159     adjustment described above happens, it happens before adding days,
76160     hours, minutes or seconds.
76161
76162     The values in DELTA can be negative to subtract values instead.
76163
76164     The return value is a decoded time structure.
76165
76166 -- Function: make-decoded-time &key second minute hour day month year
76167          dst zone
76168     Return a decoded time structure with only the given keywords filled
76169     out, leaving the rest ‘nil’.  For instance, to get a structure that
76170     represents “two months”, you could say:
76171
76172          (make-decoded-time :month 2)
76173
76174 -- Function: encode-time time &rest obsolescent-arguments
76175     This function converts TIME to a Lisp timestamp.  It can act as the
76176     inverse of ‘decode-time’.
76177
76178     Ordinarily the first argument is a list ‘(SECOND MINUTE HOUR DAY
76179     MONTH YEAR IGNORED DST ZONE)’ that specifies a decoded time in the
76180     style of ‘decode-time’, so that ‘(encode-time (decode-time ...))’
76181     works.  For the meanings of these list members, see the table under
76182     ‘decode-time’.
76183
76184     As an obsolescent calling convention, this function can be given
76185     six or more arguments.  The first six arguments SECOND, MINUTE,
76186     HOUR, DAY, MONTH, and YEAR specify most of the components of a
76187     decoded time.  If there are more than six arguments the _last_
76188     argument is used as ZONE and any other extra arguments are ignored,
76189     so that ‘(apply #'encode-time (decode-time ...))’ works.  In this
76190     obsolescent convention, ZONE defaults to the current time zone rule
76191     (*note Time Zone Rules::), and DST is treated as if it was −1.
76192
76193     Year numbers less than 100 are not treated specially.  If you want
76194     them to stand for years above 1900, or years above 2000, you must
76195     alter them yourself before you call ‘encode-time’.  The operating
76196     system limits the range of time and zone values.
76197
76198     The ‘encode-time’ function acts as a rough inverse to
76199     ‘decode-time’.  For example, you can pass the output of the latter
76200     to the former as follows:
76201
76202          (encode-time (decode-time ...))
76203
76204     You can perform simple date arithmetic by using out-of-range values
76205     for SECONDS, MINUTES, HOUR, DAY, and MONTH; for example, day 0
76206     means the day preceding the given month.
76207
76208   ---------- Footnotes ----------
76209
76210   (1) Currently a positive integer FORM should be at least 65536 if the
76211returned value is intended to be given to standard functions expecting
76212Lisp timestamps.
76213
76214
76215File: elisp.info,  Node: Time Parsing,  Next: Processor Run Time,  Prev: Time Conversion,  Up: System Interface
76216
7621740.8 Parsing and Formatting Times
76218=================================
76219
76220These functions convert time values to text in a string, and vice versa.
76221Time values include ‘nil’, numbers, and Lisp timestamps (*note Time of
76222Day::).
76223
76224 -- Function: date-to-time string
76225     This function parses the time-string STRING and returns the
76226     corresponding Lisp timestamp.  The argument STRING should represent
76227     a date-time, and should be in one of the forms recognized by
76228     ‘parse-time-string’ (see below).  This function assumes Universal
76229     Time if STRING lacks explicit time zone information.  The operating
76230     system limits the range of time and zone values.
76231
76232 -- Function: parse-time-string string
76233     This function parses the time-string STRING into a list of the
76234     following form:
76235
76236          (SEC MIN HOUR DAY MON YEAR DOW DST TZ)
76237
76238     The format of this list is the same as what ‘decode-time’ accepts
76239     (*note Time Conversion::), and is described in more detail there.
76240     Any element that cannot be determined from the input will be set to
76241     ‘nil’.  The argument STRING should resemble an RFC 822 (or later)
76242     or ISO 8601 string, like “Fri, 25 Mar 2016 16:24:56 +0100” or
76243     “1998-09-12T12:21:54-0200”, but this function will attempt to parse
76244     less well-formed time strings as well.
76245
76246 -- Function: iso8601-parse string
76247     For a more strict function (that will error out upon invalid
76248     input), this function can be used instead.  It can parse all
76249     variants of the ISO 8601 standard, so in addition to the formats
76250     mentioned above, it also parses things like “1998W45-3” (week
76251     number) and “1998-245” (ordinal day number).  To parse durations,
76252     there’s ‘iso8601-parse-duration’, and to parse intervals, there’s
76253     ‘iso8601-parse-interval’.  All these functions return decoded time
76254     structures, except the final one, which returns three of them (the
76255     start, the end, and the duration).
76256
76257 -- Function: format-time-string format-string &optional time zone
76258
76259     This function converts TIME (or the current time, if TIME is
76260     omitted or ‘nil’) to a string according to FORMAT-STRING.  The
76261     conversion uses the time zone rule ZONE, which defaults to the
76262     current time zone rule.  *Note Time Zone Rules::.  The argument
76263     FORMAT-STRING may contain ‘%’-sequences which say to substitute
76264     parts of the time.  Here is a table of what the ‘%’-sequences mean:
76265
76266     ‘%a’
76267          This stands for the abbreviated name of the day of week.
76268     ‘%A’
76269          This stands for the full name of the day of week.
76270     ‘%b’
76271          This stands for the abbreviated name of the month.
76272     ‘%B’
76273          This stands for the full name of the month.
76274     ‘%c’
76275          This is a synonym for ‘%x %X’.
76276     ‘%C’
76277          This stands for the century, that is, the year divided by 100,
76278          truncated toward zero.  The default field width is 2.
76279     ‘%d’
76280          This stands for the day of month, zero-padded.
76281     ‘%D’
76282          This is a synonym for ‘%m/%d/%y’.
76283     ‘%e’
76284          This stands for the day of month, blank-padded.
76285     ‘%F’
76286          This stands for the ISO 8601 date format, which is like
76287          ‘%+4Y-%m-%d’ except that any flags or field width override the
76288          ‘+’ and (after subtracting 6) the ‘4’.
76289     ‘%g’
76290          This stands for the year corresponding to the ISO week within
76291          the century.
76292     ‘%G’
76293          This stands for the year corresponding to the ISO week.
76294     ‘%h’
76295          This is a synonym for ‘%b’.
76296     ‘%H’
76297          This stands for the hour (00–23).
76298     ‘%I’
76299          This stands for the hour (01–12).
76300     ‘%j’
76301          This stands for the day of the year (001–366).
76302     ‘%k’
76303          This stands for the hour (0–23), blank padded.
76304     ‘%l’
76305          This stands for the hour (1–12), blank padded.
76306     ‘%m’
76307          This stands for the month (01–12).
76308     ‘%M’
76309          This stands for the minute (00–59).
76310     ‘%n’
76311          This stands for a newline.
76312     ‘%N’
76313          This stands for the nanoseconds (000000000–999999999).  To ask
76314          for fewer digits, use ‘%3N’ for milliseconds, ‘%6N’ for
76315          microseconds, etc.  Any excess digits are discarded, without
76316          rounding.
76317     ‘%p’
76318          This stands for ‘AM’ or ‘PM’, as appropriate.
76319     ‘%q’
76320          This stands for the calendar quarter (1–4).
76321     ‘%r’
76322          This is a synonym for ‘%I:%M:%S %p’.
76323     ‘%R’
76324          This is a synonym for ‘%H:%M’.
76325     ‘%s’
76326          This stands for the integer number of seconds since the epoch.
76327     ‘%S’
76328          This stands for the second (00–59, or 00–60 on platforms that
76329          support leap seconds).
76330     ‘%t’
76331          This stands for a tab character.
76332     ‘%T’
76333          This is a synonym for ‘%H:%M:%S’.
76334     ‘%u’
76335          This stands for the numeric day of week (1–7).  Monday is day
76336          1.
76337     ‘%U’
76338          This stands for the week of the year (01–52), assuming that
76339          weeks start on Sunday.
76340     ‘%V’
76341          This stands for the week of the year according to ISO 8601.
76342     ‘%w’
76343          This stands for the numeric day of week (0–6).  Sunday is day
76344          0.
76345     ‘%W’
76346          This stands for the week of the year (01–52), assuming that
76347          weeks start on Monday.
76348     ‘%x’
76349          This has a locale-specific meaning.  In the default locale
76350          (named ‘C’), it is equivalent to ‘%D’.
76351     ‘%X’
76352          This has a locale-specific meaning.  In the default locale
76353          (named ‘C’), it is equivalent to ‘%T’.
76354     ‘%y’
76355          This stands for the year without century (00–99).
76356     ‘%Y’
76357          This stands for the year with century.
76358     ‘%Z’
76359          This stands for the time zone abbreviation (e.g., ‘EST’).
76360     ‘%z’
76361          This stands for the time zone numerical offset.  The ‘z’ can
76362          be preceded by one, two, or three colons; if plain ‘%z’ stands
76363          for ‘-0500’, then ‘%:z’ stands for ‘-05:00’, ‘%::z’ stands for
76364          ‘-05:00:00’, and ‘%:::z’ is like ‘%::z’ except it suppresses
76365          trailing instances of ‘:00’ so it stands for ‘-05’ in the same
76366          example.
76367     ‘%%’
76368          This stands for a single ‘%’.
76369
76370     One or more flag characters can appear immediately after the ‘%’.
76371     ‘0’ pads with zeros, ‘+’ pads with zeros and also puts ‘+’ before
76372     nonnegative year numbers with more than four digits, ‘_’ pads with
76373     blanks, ‘-’ suppresses padding, ‘^’ upper-cases letters, and ‘#’
76374     reverses the case of letters.
76375
76376     You can also specify the field width and type of padding for any of
76377     these ‘%’-sequences.  This works as in ‘printf’: you write the
76378     field width as digits in a ‘%’-sequence, after any flags.  For
76379     example, ‘%S’ specifies the number of seconds since the minute;
76380     ‘%03S’ means to pad this with zeros to 3 positions, ‘%_3S’ to pad
76381     with spaces to 3 positions.  Plain ‘%3S’ pads with zeros, because
76382     that is how ‘%S’ normally pads to two positions.
76383
76384     The characters ‘E’ and ‘O’ act as modifiers when used after any
76385     flags and field widths in a ‘%’-sequence.  ‘E’ specifies using the
76386     current locale’s alternative version of the date and time.  In a
76387     Japanese locale, for example, ‘%Ex’ might yield a date format based
76388     on the Japanese Emperors’ reigns.  ‘E’ is allowed in ‘%Ec’, ‘%EC’,
76389     ‘%Ex’, ‘%EX’, ‘%Ey’, and ‘%EY’.
76390
76391     ‘O’ means to use the current locale’s alternative representation of
76392     numbers, instead of the ordinary decimal digits.  This is allowed
76393     with most letters, all the ones that output numbers.
76394
76395     To help debug programs, unrecognized ‘%’-sequences stand for
76396     themselves and are output as-is.  Programs should not rely on this
76397     behavior, as future versions of Emacs may recognize new
76398     ‘%’-sequences as extensions.
76399
76400     This function uses the C library function ‘strftime’ (*note
76401     (libc)Formatting Calendar Time::) to do most of the work.  In order
76402     to communicate with that function, it first converts TIME and ZONE
76403     to internal form; the operating system limits the range of time and
76404     zone values.  This function also encodes FORMAT-STRING using the
76405     coding system specified by ‘locale-coding-system’ (*note
76406     Locales::); after ‘strftime’ returns the resulting string, this
76407     function decodes the string using that same coding system.
76408
76409 -- Function: format-seconds format-string seconds
76410     This function converts its argument SECONDS into a string of years,
76411     days, hours, etc., according to FORMAT-STRING.  The argument
76412     FORMAT-STRING may contain ‘%’-sequences which control the
76413     conversion.  Here is a table of what the ‘%’-sequences mean:
76414
76415     ‘%y’
76416     ‘%Y’
76417          The integer number of 365-day years.
76418     ‘%d’
76419     ‘%D’
76420          The integer number of days.
76421     ‘%h’
76422     ‘%H’
76423          The integer number of hours.
76424     ‘%m’
76425     ‘%M’
76426          The integer number of minutes.
76427     ‘%s’
76428     ‘%S’
76429          The integer number of seconds.
76430     ‘%z’
76431          Non-printing control flag.  When it is used, other specifiers
76432          must be given in the order of decreasing size, i.e., years
76433          before days, hours before minutes, etc.  Nothing will be
76434          produced in the result string to the left of ‘%z’ until the
76435          first non-zero conversion is encountered.  For example, the
76436          default format used by ‘emacs-uptime’ (*note emacs-uptime:
76437          Processor Run Time.) ‘"%Y, %D, %H, %M, %z%S"’ means that the
76438          number of seconds will always be produced, but years, days,
76439          hours, and minutes will only be shown if they are non-zero.
76440     ‘%%’
76441          Produces a literal ‘%’.
76442
76443     Upper-case format sequences produce the units in addition to the
76444     numbers, lower-case formats produce only the numbers.
76445
76446     You can also specify the field width by following the ‘%’ with a
76447     number; shorter numbers will be padded with blanks.  An optional
76448     period before the width requests zero-padding instead.  For
76449     example, ‘"%.3Y"’ might produce ‘"004 years"’.
76450
76451
76452File: elisp.info,  Node: Processor Run Time,  Next: Time Calculations,  Prev: Time Parsing,  Up: System Interface
76453
7645440.9 Processor Run time
76455=======================
76456
76457Emacs provides several functions and primitives that return time, both
76458elapsed and processor time, used by the Emacs process.
76459
76460 -- Command: emacs-uptime &optional format
76461     This function returns a string representing the Emacs “uptime”—the
76462     elapsed wall-clock time this instance of Emacs is running.  The
76463     string is formatted by ‘format-seconds’ according to the optional
76464     argument FORMAT.  For the available format descriptors, see *note
76465     format-seconds: Time Parsing.  If FORMAT is ‘nil’ or omitted, it
76466     defaults to ‘"%Y, %D, %H, %M, %z%S"’.
76467
76468     When called interactively, it prints the uptime in the echo area.
76469
76470 -- Function: get-internal-run-time
76471     This function returns the processor run time used by Emacs, as a
76472     Lisp timestamp (*note Time of Day::).
76473
76474     Note that the time returned by this function excludes the time
76475     Emacs was not using the processor, and if the Emacs process has
76476     several threads, the returned value is the sum of the processor
76477     times used up by all Emacs threads.
76478
76479     If the system doesn’t provide a way to determine the processor run
76480     time, ‘get-internal-run-time’ returns the same time as
76481     ‘current-time’.
76482
76483 -- Command: emacs-init-time
76484     This function returns the duration of the Emacs initialization
76485     (*note Startup Summary::) in seconds, as a string.  When called
76486     interactively, it prints the duration in the echo area.
76487
76488
76489File: elisp.info,  Node: Time Calculations,  Next: Timers,  Prev: Processor Run Time,  Up: System Interface
76490
7649140.10 Time Calculations
76492=======================
76493
76494These functions perform calendrical computations using time values
76495(*note Time of Day::).  As with any time value, a value of ‘nil’ for any
76496of their time-value arguments stands for the current system time, and a
76497single number stands for the number of seconds since the epoch.
76498
76499 -- Function: time-less-p t1 t2
76500     This returns ‘t’ if time value T1 is less than time value T2.  The
76501     result is ‘nil’ if either argument is a NaN.
76502
76503 -- Function: time-equal-p t1 t2
76504     This returns ‘t’ if T1 and T2 are equal time values.  The result is
76505     ‘nil’ if either argument is a NaN.
76506
76507 -- Function: time-subtract t1 t2
76508     This returns the time difference T1 − T2 between two time values,
76509     as a Lisp time value.  The result is exact and its clock resolution
76510     is no worse than the worse of its two arguments’ resolutions.  The
76511     result is floating-point only if it is infinite or a NaN.  If you
76512     need the difference in units of elapsed seconds, you can convert it
76513     with ‘time-convert’ or ‘float-time’.  *Note Time Conversion::.
76514
76515 -- Function: time-add t1 t2
76516     This returns the sum of two time values, using the same conversion
76517     rules as ‘time-subtract’.  One argument should represent a time
76518     difference rather than a point in time, as a time value that is
76519     often just a single number of elapsed seconds.  Here is how to add
76520     a number of seconds to a time value:
76521
76522          (time-add TIME SECONDS)
76523
76524 -- Function: time-to-days time-value
76525     This function returns the number of days between the beginning of
76526     year 1 and TIME-VALUE, assuming the default time zone.  The
76527     operating system limits the range of time and zone values.
76528
76529 -- Function: time-to-day-in-year time-value
76530     This returns the day number within the year corresponding to
76531     TIME-VALUE, assuming the default time zone.  The operating system
76532     limits the range of time and zone values.
76533
76534 -- Function: date-leap-year-p year
76535     This function returns ‘t’ if YEAR is a leap year.
76536
76537 -- Function: date-days-in-month year month
76538     Return the number of days in MONTH in YEAR.  For instance, February
76539     2020 has 29 days.
76540
76541 -- Function: date-ordinal-to-time year ordinal
76542     Return the date of ORDINAL in YEAR as a decoded time structure.
76543     For instance, the 120th day in 2004 is April 29th.
76544
76545
76546File: elisp.info,  Node: Timers,  Next: Idle Timers,  Prev: Time Calculations,  Up: System Interface
76547
7654840.11 Timers for Delayed Execution
76549==================================
76550
76551You can set up a “timer” to call a function at a specified future time
76552or after a certain length of idleness.  A timer is a special object that
76553stores the information about the next invocation times and the function
76554to invoke.
76555
76556 -- Function: timerp object
76557     This predicate function returns non-‘nil’ if ‘object’ is a timer.
76558
76559   Emacs cannot run timers at any arbitrary point in a Lisp program; it
76560can run them only when Emacs could accept output from a subprocess:
76561namely, while waiting or inside certain primitive functions such as
76562‘sit-for’ or ‘read-event’ which _can_ wait.  Therefore, a timer’s
76563execution may be delayed if Emacs is busy.  However, the time of
76564execution is very precise if Emacs is idle.
76565
76566   Emacs binds ‘inhibit-quit’ to ‘t’ before calling the timer function,
76567because quitting out of many timer functions can leave things in an
76568inconsistent state.  This is normally unproblematical because most timer
76569functions don’t do a lot of work.  Indeed, for a timer to call a
76570function that takes substantial time to run is likely to be annoying.
76571If a timer function needs to allow quitting, it should use
76572‘with-local-quit’ (*note Quitting::).  For example, if a timer function
76573calls ‘accept-process-output’ to receive output from an external
76574process, that call should be wrapped inside ‘with-local-quit’, to ensure
76575that ‘C-g’ works if the external process hangs.
76576
76577   It is usually a bad idea for timer functions to alter buffer
76578contents.  When they do, they usually should call ‘undo-boundary’ both
76579before and after changing the buffer, to separate the timer’s changes
76580from user commands’ changes and prevent a single undo entry from growing
76581to be quite large.
76582
76583   Timer functions should also avoid calling functions that cause Emacs
76584to wait, such as ‘sit-for’ (*note Waiting::).  This can lead to
76585unpredictable effects, since other timers (or even the same timer) can
76586run while waiting.  If a timer function needs to perform an action after
76587a certain time has elapsed, it can do this by scheduling a new timer.
76588
76589   If a timer function calls functions that can change the match data,
76590it should save and restore the match data.  *Note Saving Match Data::.
76591
76592 -- Command: run-at-time time repeat function &rest args
76593     This sets up a timer that calls the function FUNCTION with
76594     arguments ARGS at time TIME.  If REPEAT is a number (integer or
76595     floating point), the timer is scheduled to run again every REPEAT
76596     seconds after TIME.  If REPEAT is ‘nil’, the timer runs only once.
76597
76598     TIME may specify an absolute or a relative time.
76599
76600     Absolute times may be specified using a string with a limited
76601     variety of formats, and are taken to be times _today_, even if
76602     already in the past.  The recognized forms are ‘XXXX’, ‘X:XX’, or
76603     ‘XX:XX’ (military time), and ‘XXam’, ‘XXAM’, ‘XXpm’, ‘XXPM’,
76604     ‘XX:XXam’, ‘XX:XXAM’, ‘XX:XXpm’, or ‘XX:XXPM’.  A period can be
76605     used instead of a colon to separate the hour and minute parts.
76606
76607     To specify a relative time as a string, use numbers followed by
76608     units.  For example:
76609
76610     ‘1 min’
76611          denotes 1 minute from now.
76612     ‘1 min 5 sec’
76613          denotes 65 seconds from now.
76614     ‘1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year’
76615          denotes exactly 103 months, 123 days, and 10862 seconds from
76616          now.
76617
76618     For relative time values, Emacs considers a month to be exactly
76619     thirty days, and a year to be exactly 365.25 days.
76620
76621     Not all convenient formats are strings.  If TIME is a number
76622     (integer or floating point), that specifies a relative time
76623     measured in seconds.  The result of ‘encode-time’ can also be used
76624     to specify an absolute value for TIME.
76625
76626     In most cases, REPEAT has no effect on when _first_ call takes
76627     place—TIME alone specifies that.  There is one exception: if TIME
76628     is ‘t’, then the timer runs whenever the time is a multiple of
76629     REPEAT seconds after the epoch.  This is useful for functions like
76630     ‘display-time’.
76631
76632     The function ‘run-at-time’ returns a timer value that identifies
76633     the particular scheduled future action.  You can use this value to
76634     call ‘cancel-timer’ (see below).
76635
76636 -- Command: run-with-timer secs repeat function &rest args
76637     This is exactly the same as ‘run-at-time’ (so see that definition
76638     for an explanation of the parameters; SECS is passed as TIME to
76639     that function), but is meant to be used when the delay is specified
76640     in seconds.
76641
76642   A repeating timer nominally ought to run every REPEAT seconds, but
76643remember that any invocation of a timer can be late.  Lateness of one
76644repetition has no effect on the scheduled time of the next repetition.
76645For instance, if Emacs is busy computing for long enough to cover three
76646scheduled repetitions of the timer, and then starts to wait, it will
76647immediately call the timer function three times in immediate succession
76648(presuming no other timers trigger before or between them).  If you want
76649a timer to run again no less than N seconds after the last invocation,
76650don’t use the REPEAT argument.  Instead, the timer function should
76651explicitly reschedule the timer.
76652
76653 -- User Option: timer-max-repeats
76654     This variable’s value specifies the maximum number of times to
76655     repeat calling a timer function in a row, when many previously
76656     scheduled calls were unavoidably delayed.
76657
76658 -- Macro: with-timeout (seconds timeout-forms...) body...
76659     Execute BODY, but give up after SECONDS seconds.  If BODY finishes
76660     before the time is up, ‘with-timeout’ returns the value of the last
76661     form in BODY.  If, however, the execution of BODY is cut short by
76662     the timeout, then ‘with-timeout’ executes all the TIMEOUT-FORMS and
76663     returns the value of the last of them.
76664
76665     This macro works by setting a timer to run after SECONDS seconds.
76666     If BODY finishes before that time, it cancels the timer.  If the
76667     timer actually runs, it terminates execution of BODY, then executes
76668     TIMEOUT-FORMS.
76669
76670     Since timers can run within a Lisp program only when the program
76671     calls a primitive that can wait, ‘with-timeout’ cannot stop
76672     executing BODY while it is in the midst of a computation—only when
76673     it calls one of those primitives.  So use ‘with-timeout’ only with
76674     a BODY that waits for input, not one that does a long computation.
76675
76676   The function ‘y-or-n-p-with-timeout’ provides a simple way to use a
76677timer to avoid waiting too long for an answer.  *Note Yes-or-No
76678Queries::.
76679
76680 -- Function: cancel-timer timer
76681     This cancels the requested action for TIMER, which should be a
76682     timer—usually, one previously returned by ‘run-at-time’ or
76683     ‘run-with-idle-timer’.  This cancels the effect of that call to one
76684     of these functions; the arrival of the specified time will not
76685     cause anything special to happen.
76686
76687   The ‘list-timers’ command lists all the currently active timers.
76688There’s only one command available in the buffer displayed: ‘c’
76689(‘timer-list-cancel’) that will cancel the timer on the line under
76690point.
76691
76692
76693File: elisp.info,  Node: Idle Timers,  Next: Terminal Input,  Prev: Timers,  Up: System Interface
76694
7669540.12 Idle Timers
76696=================
76697
76698Here is how to set up a timer that runs when Emacs is idle for a certain
76699length of time.  Aside from how to set them up, idle timers work just
76700like ordinary timers.
76701
76702 -- Command: run-with-idle-timer secs repeat function &rest args
76703     Set up a timer which runs the next time Emacs is idle for SECS
76704     seconds.  The value of SECS may be a number or a value of the type
76705     returned by ‘current-idle-time’.
76706
76707     If REPEAT is ‘nil’, the timer runs just once, the first time Emacs
76708     remains idle for a long enough time.  More often REPEAT is
76709     non-‘nil’, which means to run the timer _each time_ Emacs remains
76710     idle for SECS seconds.
76711
76712     The function ‘run-with-idle-timer’ returns a timer value which you
76713     can use in calling ‘cancel-timer’ (*note Timers::).
76714
76715   Emacs becomes “idle” when it starts waiting for user input, and it
76716remains idle until the user provides some input.  If a timer is set for
76717five seconds of idleness, it runs approximately five seconds after Emacs
76718first becomes idle.  Even if REPEAT is non-‘nil’, this timer will not
76719run again as long as Emacs remains idle, because the duration of
76720idleness will continue to increase and will not go down to five seconds
76721again.
76722
76723   Emacs can do various things while idle: garbage collect, autosave or
76724handle data from a subprocess.  But these interludes during idleness do
76725not interfere with idle timers, because they do not reset the clock of
76726idleness to zero.  An idle timer set for 600 seconds will run when ten
76727minutes have elapsed since the last user command was finished, even if
76728subprocess output has been accepted thousands of times within those ten
76729minutes, and even if there have been garbage collections and autosaves.
76730
76731   When the user supplies input, Emacs becomes non-idle while executing
76732the input.  Then it becomes idle again, and all the idle timers that are
76733set up to repeat will subsequently run another time, one by one.
76734
76735   Do not write an idle timer function containing a loop which does a
76736certain amount of processing each time around, and exits when
76737‘(input-pending-p)’ is non-‘nil’.  This approach seems very natural but
76738has two problems:
76739
76740   • It blocks out all process output (since Emacs accepts process
76741     output only while waiting).
76742
76743   • It blocks out any idle timers that ought to run during that time.
76744
76745Similarly, do not write an idle timer function that sets up another idle
76746timer (including the same idle timer) with SECS argument less than or
76747equal to the current idleness time.  Such a timer will run almost
76748immediately, and continue running again and again, instead of waiting
76749for the next time Emacs becomes idle.  The correct approach is to
76750reschedule with an appropriate increment of the current value of the
76751idleness time, as described below.
76752
76753 -- Function: current-idle-time
76754     If Emacs is idle, this function returns the length of time Emacs
76755     has been idle, using the same format as ‘current-time’ (*note Time
76756     of Day::).
76757
76758     When Emacs is not idle, ‘current-idle-time’ returns ‘nil’.  This is
76759     a convenient way to test whether Emacs is idle.
76760
76761   The main use of ‘current-idle-time’ is when an idle timer function
76762wants to “take a break” for a while.  It can set up another idle timer
76763to call the same function again, after a few seconds more idleness.
76764Here’s an example:
76765
76766     (defvar my-resume-timer nil
76767       "Timer for `my-timer-function' to reschedule itself, or nil.")
76768
76769     (defun my-timer-function ()
76770       ;; If the user types a command while ‘my-resume-timer’
76771       ;; is active, the next time this function is called from
76772       ;; its main idle timer, deactivate ‘my-resume-timer’.
76773       (when my-resume-timer
76774         (cancel-timer my-resume-timer))
76775       ...DO THE WORK FOR A WHILE...
76776       (when TAKING-A-BREAK
76777         (setq my-resume-timer
76778               (run-with-idle-timer
76779                 ;; Compute an idle time BREAK-LENGTH
76780                 ;; more than the current value.
76781                 (time-add (current-idle-time) BREAK-LENGTH)
76782                 nil
76783                 'my-timer-function))))
76784
76785
76786File: elisp.info,  Node: Terminal Input,  Next: Terminal Output,  Prev: Idle Timers,  Up: System Interface
76787
7678840.13 Terminal Input
76789====================
76790
76791This section describes functions and variables for recording or
76792manipulating terminal input.  See *note Display::, for related
76793functions.
76794
76795* Menu:
76796
76797* Input Modes::         Options for how input is processed.
76798* Recording Input::     Saving histories of recent or all input events.
76799
76800
76801File: elisp.info,  Node: Input Modes,  Next: Recording Input,  Up: Terminal Input
76802
7680340.13.1 Input Modes
76804-------------------
76805
76806 -- Function: set-input-mode interrupt flow meta &optional quit-char
76807     This function sets the mode for reading keyboard input.  If
76808     INTERRUPT is non-‘nil’, then Emacs uses input interrupts.  If it is
76809     ‘nil’, then it uses CBREAK mode.  The default setting is
76810     system-dependent.  Some systems always use CBREAK mode regardless
76811     of what is specified.
76812
76813     When Emacs communicates directly with X, it ignores this argument
76814     and uses interrupts if that is the way it knows how to communicate.
76815
76816     If FLOW is non-‘nil’, then Emacs uses XON/XOFF (‘C-q’, ‘C-s’) flow
76817     control for output to the terminal.  This has no effect except in
76818     CBREAK mode.
76819
76820     The argument META controls support for input character codes above
76821     127.  If META is ‘t’, Emacs converts characters with the 8th bit
76822     set into Meta characters.  If META is ‘nil’, Emacs disregards the
76823     8th bit; this is necessary when the terminal uses it as a parity
76824     bit.  If META is neither ‘t’ nor ‘nil’, Emacs uses all 8 bits of
76825     input unchanged.  This is good for terminals that use 8-bit
76826     character sets.
76827
76828     If QUIT-CHAR is non-‘nil’, it specifies the character to use for
76829     quitting.  Normally this character is ‘C-g’.  *Note Quitting::.
76830
76831   The ‘current-input-mode’ function returns the input mode settings
76832Emacs is currently using.
76833
76834 -- Function: current-input-mode
76835     This function returns the current mode for reading keyboard input.
76836     It returns a list, corresponding to the arguments of
76837     ‘set-input-mode’, of the form ‘(INTERRUPT FLOW META QUIT)’ in
76838     which:
76839     INTERRUPT
76840          is non-‘nil’ when Emacs is using interrupt-driven input.  If
76841          ‘nil’, Emacs is using CBREAK mode.
76842     FLOW
76843          is non-‘nil’ if Emacs uses XON/XOFF (‘C-q’, ‘C-s’) flow
76844          control for output to the terminal.  This value is meaningful
76845          only when INTERRUPT is ‘nil’.
76846     META
76847          is ‘t’ if Emacs treats the eighth bit of input characters as
76848          the meta bit; ‘nil’ means Emacs clears the eighth bit of every
76849          input character; any other value means Emacs uses all eight
76850          bits as the basic character code.
76851     QUIT
76852          is the character Emacs currently uses for quitting, usually
76853          ‘C-g’.
76854
76855
76856File: elisp.info,  Node: Recording Input,  Prev: Input Modes,  Up: Terminal Input
76857
7685840.13.2 Recording Input
76859-----------------------
76860
76861 -- Function: recent-keys &optional include-cmds
76862     This function returns a vector containing the last 300 input events
76863     from the keyboard or mouse.  All input events are included, whether
76864     or not they were used as parts of key sequences.  Thus, you always
76865     get the last 300 input events, not counting events generated by
76866     keyboard macros.  (These are excluded because they are less
76867     interesting for debugging; it should be enough to see the events
76868     that invoked the macros.)
76869
76870     If INCLUDE-CMDS is non-‘nil’, complete key sequences in the result
76871     vector are interleaved with pseudo-events of the form ‘(nil .
76872     COMMAND)’, where COMMAND is the binding of the key sequence (*note
76873     Command Overview::).
76874
76875     A call to ‘clear-this-command-keys’ (*note Command Loop Info::)
76876     causes this function to return an empty vector immediately
76877     afterward.
76878
76879 -- Command: open-dribble-file filename
76880     This function opens a “dribble file” named FILENAME.  When a
76881     dribble file is open, each input event from the keyboard or mouse
76882     (but not those from keyboard macros) is written in that file.  A
76883     non-character event is expressed using its printed representation
76884     surrounded by ‘<...>’.  Be aware that sensitive information (such
76885     as passwords) may end up recorded in the dribble file.
76886
76887     You close the dribble file by calling this function with an
76888     argument of ‘nil’.
76889
76890   See also the ‘open-termscript’ function (*note Terminal Output::).
76891
76892
76893File: elisp.info,  Node: Terminal Output,  Next: Sound Output,  Prev: Terminal Input,  Up: System Interface
76894
7689540.14 Terminal Output
76896=====================
76897
76898The terminal output functions send output to a text terminal, or keep
76899track of output sent to the terminal.  The variable ‘baud-rate’ tells
76900you what Emacs thinks is the output speed of the terminal.
76901
76902 -- User Option: baud-rate
76903     This variable’s value is the output speed of the terminal, as far
76904     as Emacs knows.  Setting this variable does not change the speed of
76905     actual data transmission, but the value is used for calculations
76906     such as padding.
76907
76908     It also affects decisions about whether to scroll part of the
76909     screen or repaint on text terminals.  *Note Forcing Redisplay::,
76910     for the corresponding functionality on graphical terminals.
76911
76912     The value is measured in baud.
76913
76914   If you are running across a network, and different parts of the
76915network work at different baud rates, the value returned by Emacs may be
76916different from the value used by your local terminal.  Some network
76917protocols communicate the local terminal speed to the remote machine, so
76918that Emacs and other programs can get the proper value, but others do
76919not.  If Emacs has the wrong value, it makes decisions that are less
76920than optimal.  To fix the problem, set ‘baud-rate’.
76921
76922 -- Function: send-string-to-terminal string &optional terminal
76923     This function sends STRING to TERMINAL without alteration.  Control
76924     characters in STRING have terminal-dependent effects.  (If you need
76925     to display non-ASCII text on the terminal, encode it using one of
76926     the functions described in *note Explicit Encoding::.)  This
76927     function operates only on text terminals.  TERMINAL may be a
76928     terminal object, a frame, or ‘nil’ for the selected frame’s
76929     terminal.  In batch mode, STRING is sent to ‘stdout’ when TERMINAL
76930     is ‘nil’.
76931
76932     One use of this function is to define function keys on terminals
76933     that have downloadable function key definitions.  For example, this
76934     is how (on certain terminals) to define function key 4 to move
76935     forward four characters (by transmitting the characters ‘C-u C-f’
76936     to the computer):
76937
76938          (send-string-to-terminal "\eF4\^U\^F")
76939               ⇒ nil
76940
76941 -- Command: open-termscript filename
76942     This function is used to open a “termscript file” that will record
76943     all the characters sent by Emacs to the terminal.  It returns
76944     ‘nil’.  Termscript files are useful for investigating problems
76945     where Emacs garbles the screen, problems that are due to incorrect
76946     Termcap entries or to undesirable settings of terminal options more
76947     often than to actual Emacs bugs.  Once you are certain which
76948     characters were actually output, you can determine reliably whether
76949     they correspond to the Termcap specifications in use.
76950
76951          (open-termscript "../junk/termscript")
76952               ⇒ nil
76953
76954     You close the termscript file by calling this function with an
76955     argument of ‘nil’.
76956
76957     See also ‘open-dribble-file’ in *note Recording Input::.
76958
76959
76960File: elisp.info,  Node: Sound Output,  Next: X11 Keysyms,  Prev: Terminal Output,  Up: System Interface
76961
7696240.15 Sound Output
76963==================
76964
76965To play sound using Emacs, use the function ‘play-sound’.  Only certain
76966systems are supported; if you call ‘play-sound’ on a system which cannot
76967really do the job, it gives an error.
76968
76969   The sound must be stored as a file in RIFF-WAVE format (‘.wav’) or
76970Sun Audio format (‘.au’).
76971
76972 -- Function: play-sound sound
76973     This function plays a specified sound.  The argument, SOUND, has
76974     the form ‘(sound PROPERTIES...)’, where the PROPERTIES consist of
76975     alternating keywords (particular symbols recognized specially) and
76976     values corresponding to them.
76977
76978     Here is a table of the keywords that are currently meaningful in
76979     SOUND, and their meanings:
76980
76981     ‘:file FILE’
76982          This specifies the file containing the sound to play.  If the
76983          file name is not absolute, it is expanded against the
76984          directory ‘data-directory’.
76985
76986     ‘:data DATA’
76987          This specifies the sound to play without need to refer to a
76988          file.  The value, DATA, should be a string containing the same
76989          bytes as a sound file.  We recommend using a unibyte string.
76990
76991     ‘:volume VOLUME’
76992          This specifies how loud to play the sound.  It should be a
76993          number in the range of 0 to 1.  The default is to use whatever
76994          volume has been specified before.
76995
76996     ‘:device DEVICE’
76997          This specifies the system device on which to play the sound,
76998          as a string.  The default device is system-dependent.
76999
77000     Before actually playing the sound, ‘play-sound’ calls the functions
77001     in the list ‘play-sound-functions’.  Each function is called with
77002     one argument, SOUND.
77003
77004 -- Command: play-sound-file file &optional volume device
77005     This function is an alternative interface to playing a sound FILE
77006     specifying an optional VOLUME and DEVICE.
77007
77008 -- Variable: play-sound-functions
77009     A list of functions to be called before playing a sound.  Each
77010     function is called with one argument, a property list that
77011     describes the sound.
77012
77013
77014File: elisp.info,  Node: X11 Keysyms,  Next: Batch Mode,  Prev: Sound Output,  Up: System Interface
77015
7701640.16 Operating on X11 Keysyms
77017==============================
77018
77019To define system-specific X11 keysyms, set the variable
77020‘system-key-alist’.
77021
77022 -- Variable: system-key-alist
77023     This variable’s value should be an alist with one element for each
77024     system-specific keysym.  Each element has the form ‘(CODE .
77025     SYMBOL)’, where CODE is the numeric keysym code (not including the
77026     vendor-specific bit, −2**28), and SYMBOL is the name for the
77027     function key.
77028
77029     For example ‘(168 . mute-acute)’ defines a system-specific key
77030     (used by HP X servers) whose numeric code is −2**28 + 168.
77031
77032     It is not crucial to exclude from the alist the keysyms of other X
77033     servers; those do no harm, as long as they don’t conflict with the
77034     ones used by the X server actually in use.
77035
77036     The variable is always local to the current terminal, and cannot be
77037     buffer-local.  *Note Multiple Terminals::.
77038
77039   You can specify which keysyms Emacs should use for the Control, Meta,
77040Alt, Hyper, and Super modifiers by setting these variables:
77041
77042 -- Variable: x-ctrl-keysym
77043 -- Variable: x-alt-keysym
77044 -- Variable: x-meta-keysym
77045 -- Variable: x-hyper-keysym
77046 -- Variable: x-super-keysym
77047     The name of the keysym that should stand for the Control modifier
77048     (respectively, for Alt, Meta, Hyper, and Super).  For example, here
77049     is how to swap the Meta and Alt modifiers within Emacs:
77050          (setq x-alt-keysym 'meta)
77051          (setq x-meta-keysym 'alt)
77052
77053
77054File: elisp.info,  Node: Batch Mode,  Next: Session Management,  Prev: X11 Keysyms,  Up: System Interface
77055
7705640.17 Batch Mode
77057================
77058
77059The command-line option ‘-batch’ causes Emacs to run noninteractively.
77060In this mode, Emacs does not read commands from the terminal, it does
77061not alter the terminal modes, and it does not expect to be outputting to
77062an erasable screen.  The idea is that you specify Lisp programs to run;
77063when they are finished, Emacs should exit.  The way to specify the
77064programs to run is with ‘-l FILE’, which loads the library named FILE,
77065or ‘-f FUNCTION’, which calls FUNCTION with no arguments, or
77066‘--eval=FORM’.
77067
77068   Any Lisp program output that would normally go to the echo area,
77069either using ‘message’, or using ‘prin1’, etc., with ‘t’ as the stream
77070(*note Output Streams::), goes instead to Emacs’s standard descriptors
77071when in batch mode: ‘message’ writes to the standard error descriptor,
77072while ‘prin1’ and other print functions write to the standard output.
77073Similarly, input that would normally come from the minibuffer is read
77074from the standard input descriptor.  Thus, Emacs behaves much like a
77075noninteractive application program.  (The echo area output that Emacs
77076itself normally generates, such as command echoing, is suppressed
77077entirely.)
77078
77079   Non-ASCII text written to the standard output or error descriptors is
77080by default encoded using ‘locale-coding-system’ (*note Locales::) if it
77081is non-‘nil’; this can be overridden by binding
77082‘coding-system-for-write’ to a coding system of you choice (*note
77083Explicit Encoding::).
77084
77085 -- Variable: noninteractive
77086     This variable is non-‘nil’ when Emacs is running in batch mode.
77087
77088   If Emacs exits due to signaling an error in batch mode, the exit
77089status of the Emacs command is non-zero:
77090
77091     $ emacs -Q --batch --eval '(error "foo")'; echo $?
77092     foo
77093     255
77094
77095
77096File: elisp.info,  Node: Session Management,  Next: Desktop Notifications,  Prev: Batch Mode,  Up: System Interface
77097
7709840.18 Session Management
77099========================
77100
77101Emacs supports the X Session Management Protocol, which is used to
77102suspend and restart applications.  In the X Window System, a program
77103called the “session manager” is responsible for keeping track of the
77104applications that are running.  When the X server shuts down, the
77105session manager asks applications to save their state, and delays the
77106actual shutdown until they respond.  An application can also cancel the
77107shutdown.
77108
77109   When the session manager restarts a suspended session, it directs
77110these applications to individually reload their saved state.  It does
77111this by specifying a special command-line argument that says what saved
77112session to restore.  For Emacs, this argument is ‘--smid SESSION’.
77113
77114 -- Variable: emacs-save-session-functions
77115     Emacs supports saving state via a hook called
77116     ‘emacs-save-session-functions’.  Emacs runs this hook when the
77117     session manager tells it that the window system is shutting down.
77118     The functions are called with no arguments, and with the current
77119     buffer set to a temporary buffer.  Each function can use ‘insert’
77120     to add Lisp code to this buffer.  At the end, Emacs saves the
77121     buffer in a file, called the “session file”.
77122
77123     Subsequently, when the session manager restarts Emacs, it loads the
77124     session file automatically (*note Loading::).  This is performed by
77125     a function named ‘emacs-session-restore’, which is called during
77126     startup.  *Note Startup Summary::.
77127
77128     If a function in ‘emacs-save-session-functions’ returns non-‘nil’,
77129     Emacs tells the session manager to cancel the shutdown.
77130
77131   Here is an example that just inserts some text into ‘*scratch*’ when
77132Emacs is restarted by the session manager.
77133
77134     (add-hook 'emacs-save-session-functions 'save-yourself-test)
77135
77136     (defun save-yourself-test ()
77137       (insert "(save-current-buffer
77138       (switch-to-buffer \"*scratch*\")
77139       (insert \"I am restored\"))")
77140       nil)
77141
77142
77143File: elisp.info,  Node: Desktop Notifications,  Next: File Notifications,  Prev: Session Management,  Up: System Interface
77144
7714540.19 Desktop Notifications
77146===========================
77147
77148Emacs is able to send “notifications” on systems that support the
77149freedesktop.org Desktop Notifications Specification and on MS-Windows.
77150In order to use this functionality on POSIX hosts, Emacs must have been
77151compiled with D-Bus support, and the ‘notifications’ library must be
77152loaded.  *Note D-Bus: (dbus)Top.  The following function is supported
77153when D-Bus support is available:
77154
77155 -- Function: notifications-notify &rest params
77156     This function sends a notification to the desktop via D-Bus,
77157     consisting of the parameters specified by the PARAMS arguments.
77158     These arguments should consist of alternating keyword and value
77159     pairs.  The supported keywords and values are as follows:
77160
77161     ‘:bus BUS’
77162          The D-Bus bus.  This argument is needed only if a bus other
77163          than ‘:session’ shall be used.
77164
77165     ‘:title TITLE’
77166          The notification title.
77167
77168     ‘:body TEXT’
77169          The notification body text.  Depending on the implementation
77170          of the notification server, the text could contain HTML
77171          markups, like ‘"<b>bold text</b>"’, hyperlinks, or images.
77172          Special HTML characters must be encoded, as ‘"Contact
77173          &lt;postmaster@localhost&gt;!"’.
77174
77175     ‘:app-name NAME’
77176          The name of the application sending the notification.  The
77177          default is ‘notifications-application-name’.
77178
77179     ‘:replaces-id ID’
77180          The notification ID that this notification replaces.  ID must
77181          be the result of a previous ‘notifications-notify’ call.
77182
77183     ‘:app-icon ICON-FILE’
77184          The file name of the notification icon.  If set to ‘nil’, no
77185          icon is displayed.  The default is
77186          ‘notifications-application-icon’.
77187
77188     ‘:actions (KEY TITLE KEY TITLE ...)’
77189          A list of actions to be applied.  KEY and TITLE are both
77190          strings.  The default action (usually invoked by clicking the
77191          notification) should have a key named ‘"default"’.  The title
77192          can be anything, though implementations are free not to
77193          display it.
77194
77195     ‘:timeout TIMEOUT’
77196          The timeout time in milliseconds since the display of the
77197          notification at which the notification should automatically
77198          close.  If −1, the notification’s expiration time is dependent
77199          on the notification server’s settings, and may vary for the
77200          type of notification.  If 0, the notification never expires.
77201          Default value is −1.
77202
77203     ‘:urgency URGENCY’
77204          The urgency level.  It can be ‘low’, ‘normal’, or ‘critical’.
77205
77206     ‘:action-items’
77207          When this keyword is given, the TITLE string of the actions is
77208          interpreted as icon name.
77209
77210     ‘:category CATEGORY’
77211          The type of notification this is, a string.  See the Desktop
77212          Notifications Specification
77213          (https://developer.gnome.org/notification-spec/#categories)
77214          for a list of standard categories.
77215
77216     ‘:desktop-entry FILENAME’
77217          This specifies the name of the desktop filename representing
77218          the calling program, like ‘"emacs"’.
77219
77220     ‘:image-data (WIDTH HEIGHT ROWSTRIDE HAS-ALPHA BITS CHANNELS DATA)’
77221          This is a raw data image format that describes the width,
77222          height, rowstride, whether there is an alpha channel, bits per
77223          sample, channels and image data, respectively.
77224
77225     ‘:image-path PATH’
77226          This is represented either as a URI (‘file://’ is the only URI
77227          schema supported right now) or a name in a
77228          freedesktop.org-compliant icon theme from
77229          ‘$XDG_DATA_DIRS/icons’.
77230
77231     ‘:sound-file FILENAME’
77232          The path to a sound file to play when the notification pops
77233          up.
77234
77235     ‘:sound-name NAME’
77236          A themable named sound from the freedesktop.org sound naming
77237          specification from ‘$XDG_DATA_DIRS/sounds’, to play when the
77238          notification pops up.  Similar to the icon name, only for
77239          sounds.  An example would be ‘"message-new-instant"’.
77240
77241     ‘:suppress-sound’
77242          Causes the server to suppress playing any sounds, if it has
77243          that ability.
77244
77245     ‘:resident’
77246          When set the server will not automatically remove the
77247          notification when an action has been invoked.  The
77248          notification will remain resident in the server until it is
77249          explicitly removed by the user or by the sender.  This hint is
77250          likely only useful when the server has the ‘:persistence’
77251          capability.
77252
77253     ‘:transient’
77254          When set the server will treat the notification as transient
77255          and by-pass the server’s persistence capability, if it should
77256          exist.
77257
77258     ‘:x POSITION’
77259     ‘:y POSITION’
77260          Specifies the X, Y location on the screen that the
77261          notification should point to.  Both arguments must be used
77262          together.
77263
77264     ‘:on-action FUNCTION’
77265          Function to call when an action is invoked.  The notification
77266          ID and the KEY of the action are passed as arguments to the
77267          function.
77268
77269     ‘:on-close FUNCTION’
77270          Function to call when the notification has been closed by
77271          timeout or by the user.  The function receive the notification
77272          ID and the closing REASON as arguments:
77273
77274             • ‘expired’ if the notification has expired
77275             • ‘dismissed’ if the notification was dismissed by the user
77276             • ‘close-notification’ if the notification was closed by a
77277               call to ‘notifications-close-notification’
77278             • ‘undefined’ if the notification server hasn’t provided a
77279               reason
77280
77281     Which parameters are accepted by the notification server can be
77282     checked via ‘notifications-get-capabilities’.
77283
77284     This function returns a notification id, an integer, which can be
77285     used to manipulate the notification item with
77286     ‘notifications-close-notification’ or the ‘:replaces-id’ argument
77287     of another ‘notifications-notify’ call.  For example:
77288
77289          (defun my-on-action-function (id key)
77290            (message "Message %d, key \"%s\" pressed" id key))
77291               ⇒ my-on-action-function
77292
77293          (defun my-on-close-function (id reason)
77294            (message "Message %d, closed due to \"%s\"" id reason))
77295               ⇒ my-on-close-function
77296
77297          (notifications-notify
77298           :title "Title"
77299           :body "This is <b>important</b>."
77300           :actions '("Confirm" "I agree" "Refuse" "I disagree")
77301           :on-action 'my-on-action-function
77302           :on-close 'my-on-close-function)
77303               ⇒ 22
77304
77305          A message window opens on the desktop.  Press ``I agree''.
77306               ⇒ Message 22, key "Confirm" pressed
77307                  Message 22, closed due to "dismissed"
77308
77309 -- Function: notifications-close-notification id &optional bus
77310     This function closes a notification with identifier ID.  BUS can be
77311     a string denoting a D-Bus connection, the default is ‘:session’.
77312
77313 -- Function: notifications-get-capabilities &optional bus
77314     Returns the capabilities of the notification server, a list of
77315     symbols.  BUS can be a string denoting a D-Bus connection, the
77316     default is ‘:session’.  The following capabilities can be expected:
77317
77318     ‘:actions’
77319          The server will provide the specified actions to the user.
77320
77321     ‘:body’
77322          Supports body text.
77323
77324     ‘:body-hyperlinks’
77325          The server supports hyperlinks in the notifications.
77326
77327     ‘:body-images’
77328          The server supports images in the notifications.
77329
77330     ‘:body-markup’
77331          Supports markup in the body text.
77332
77333     ‘:icon-multi’
77334          The server will render an animation of all the frames in a
77335          given image array.
77336
77337     ‘:icon-static’
77338          Supports display of exactly 1 frame of any given image array.
77339          This value is mutually exclusive with ‘:icon-multi’.
77340
77341     ‘:persistence’
77342          The server supports persistence of notifications.
77343
77344     ‘:sound’
77345          The server supports sounds on notifications.
77346
77347     Further vendor-specific caps start with ‘:x-vendor’, like
77348     ‘:x-gnome-foo-cap’.
77349
77350 -- Function: notifications-get-server-information &optional bus
77351     Return information on the notification server, a list of strings.
77352     BUS can be a string denoting a D-Bus connection, the default is
77353     ‘:session’.  The returned list is ‘(NAME VENDOR VERSION
77354     SPEC-VERSION)’.
77355
77356     NAME
77357          The product name of the server.
77358
77359     VENDOR
77360          The vendor name.  For example, ‘"KDE"’, ‘"GNOME"’.
77361
77362     VERSION
77363          The server’s version number.
77364
77365     SPEC-VERSION
77366          The specification version the server is compliant with.
77367
77368     If SPEC_VERSION is ‘nil’, the server supports a specification prior
77369     to ‘"1.0"’.
77370
77371   When Emacs runs on MS-Windows as a GUI session, it supports a small
77372subset of the D-Bus notifications functionality via a native primitive:
77373
77374 -- Function: w32-notification-notify &rest params
77375     This function displays an MS-Windows tray notification as specified
77376     by PARAMS.  MS-Windows tray notifications are displayed in a
77377     balloon from an icon in the notification area of the taskbar.
77378
77379     Value is the integer unique ID of the notification that can be used
77380     to remove the notification using ‘w32-notification-close’,
77381     described below.  If the function fails, the return value is ‘nil’.
77382
77383     The arguments PARAMS are specified as keyword/value pairs.  All the
77384     parameters are optional, but if no parameters are specified, the
77385     function will do nothing and return ‘nil’.
77386
77387     The following parameters are supported:
77388
77389     ‘:icon ICON’
77390          Display ICON in the system tray.  If ICON is a string, it
77391          should specify a file name from which to load the icon; the
77392          specified file should be a ‘.ico’ Windows icon file.  If ICON
77393          is not a string, or if this parameter is not specified, the
77394          standard Emacs icon will be used.
77395
77396     ‘:tip TIP’
77397          Use TIP as the tooltip for the notification.  If TIP is a
77398          string, this is the text of a tooltip that will be shown when
77399          the mouse pointer hovers over the tray icon added by the
77400          notification.  If TIP is not a string, or if this parameter is
77401          not specified, the default tooltip text is ‘Emacs
77402          notification’.  The tooltip text can be up to 127 characters
77403          long (63 on Windows versions before W2K). Longer strings will
77404          be truncated.
77405
77406     ‘:level LEVEL’
77407          Notification severity level, one of ‘info’, ‘warning’, or
77408          ‘error’.  If given, the value determines the icon displayed to
77409          the left of the notification title, but only if the ‘:title’
77410          parameter (see below) is also specified and is a string.
77411
77412     ‘:title TITLE’
77413          The title of the notification.  If TITLE is a string, it is
77414          displayed in a larger font immediately above the body text.
77415          The title text can be up to 63 characters long; longer text
77416          will be truncated.
77417
77418     ‘:body BODY’
77419          The body of the notification.  If BODY is a string, it
77420          specifies the text of the notification message.  Use embedded
77421          newlines to control how the text is broken into lines.  The
77422          body text can be up to 255 characters long, and will be
77423          truncated if it’s longer.  Unlike with D-Bus, the body text
77424          should be plain text, with no markup.
77425
77426     Note that versions of Windows before W2K support only ‘:icon’ and
77427     ‘:tip’.  The other parameters can be passed, but they will be
77428     ignored on those old systems.
77429
77430     There can be at most one active notification at any given time.  An
77431     active notification must be removed by calling
77432     ‘w32-notification-close’ before a new one can be shown.
77433
77434   To remove the notification and its icon from the taskbar, use the
77435following function:
77436
77437 -- Function: w32-notification-close id
77438     This function removes the tray notification given by its unique ID.
77439
77440
77441File: elisp.info,  Node: File Notifications,  Next: Dynamic Libraries,  Prev: Desktop Notifications,  Up: System Interface
77442
7744340.20 Notifications on File Changes
77444===================================
77445
77446Several operating systems support watching of filesystems for changes of
77447files.  If configured properly, Emacs links a respective library like
77448‘inotify’, ‘kqueue’, ‘gfilenotify’, or ‘w32notify’ statically.  These
77449libraries enable watching of filesystems on the local machine.
77450
77451   It is also possible to watch filesystems on remote machines, *note
77452Remote Files: (emacs)Remote Files. This does not depend on one of the
77453libraries linked to Emacs.
77454
77455   Since all these libraries emit different events on notified file
77456changes, there is the Emacs library ‘filenotify’ which provides a
77457unified interface.  Lisp programs that want to receive file
77458notifications should always use this library in preference to the native
77459ones.
77460
77461 -- Function: file-notify-add-watch file flags callback
77462     Add a watch for filesystem events pertaining to FILE.  This
77463     arranges for filesystem events pertaining to FILE to be reported to
77464     Emacs.
77465
77466     The returned value is a descriptor for the added watch.  Its type
77467     depends on the underlying library, it cannot be assumed to be an
77468     integer as in the example below.  It should be used for comparison
77469     by ‘equal’ only.
77470
77471     If the FILE cannot be watched for some reason, this function
77472     signals a ‘file-notify-error’ error.
77473
77474     Sometimes, mounted filesystems cannot be watched for file changes.
77475     This is not detected by this function, a non-‘nil’ return value
77476     does not guarantee that changes on FILE will be notified.
77477
77478     FLAGS is a list of conditions to set what will be watched for.  It
77479     can include the following symbols:
77480
77481     ‘change’
77482          watch for file changes
77483     ‘attribute-change’
77484          watch for file attribute changes, like permissions or
77485          modification time
77486
77487     If FILE is a directory, changes for all files in that directory
77488     will be notified.  This does not work recursively.
77489
77490     When any event happens, Emacs will call the CALLBACK function
77491     passing it a single argument EVENT, which is of the form
77492
77493          (DESCRIPTOR ACTION FILE [FILE1])
77494
77495     DESCRIPTOR is the same object as the one returned by this function.
77496     ACTION is the description of the event.  It could be any one of the
77497     following symbols:
77498
77499     ‘created’
77500          FILE was created
77501     ‘deleted’
77502          FILE was deleted
77503     ‘changed’
77504          FILE’s contents has changed; with ‘w32notify’ library, reports
77505          attribute changes as well
77506     ‘renamed’
77507          FILE has been renamed to FILE1
77508     ‘attribute-changed’
77509          a FILE attribute was changed
77510     ‘stopped’
77511          watching FILE has been stopped
77512
77513     Note that the ‘w32notify’ library does not report
77514     ‘attribute-changed’ events.  When some file’s attribute, like
77515     permissions or modification time, has changed, this library reports
77516     a ‘changed’ event.  Likewise, the ‘kqueue’ library does not report
77517     reliably file attribute changes when watching a directory.
77518
77519     The ‘stopped’ event reports, that watching the file has been
77520     stopped.  This could be because ‘file-notify-rm-watch’ was called
77521     (see below), or because the file being watched was deleted, or due
77522     to another error reported from the underlying library.
77523
77524     FILE and FILE1 are the name of the file(s) whose event is being
77525     reported.  For example:
77526
77527          (require 'filenotify)
77528               ⇒ filenotify
77529
77530          (defun my-notify-callback (event)
77531            (message "Event %S" event))
77532               ⇒ my-notify-callback
77533
77534          (file-notify-add-watch
77535            "/tmp" '(change attribute-change) 'my-notify-callback)
77536               ⇒ 35025468
77537
77538          (write-region "foo" nil "/tmp/foo")
77539               ⇒ Event (35025468 created "/tmp/.#foo")
77540                  Event (35025468 created "/tmp/foo")
77541                  Event (35025468 changed "/tmp/foo")
77542                  Event (35025468 deleted "/tmp/.#foo")
77543
77544          (write-region "bla" nil "/tmp/foo")
77545               ⇒ Event (35025468 created "/tmp/.#foo")
77546                  Event (35025468 changed "/tmp/foo")
77547                  Event (35025468 deleted "/tmp/.#foo")
77548
77549          (set-file-modes "/tmp/foo" (default-file-modes))
77550               ⇒ Event (35025468 attribute-changed "/tmp/foo")
77551
77552     Whether the action ‘renamed’ is returned, depends on the used watch
77553     library.  Otherwise, the actions ‘deleted’ and ‘created’ could be
77554     returned in a random order.
77555
77556          (rename-file "/tmp/foo" "/tmp/bla")
77557               ⇒ Event (35025468 renamed "/tmp/foo" "/tmp/bla")
77558
77559          (delete-file "/tmp/bla")
77560               ⇒ Event (35025468 deleted "/tmp/bla")
77561
77562 -- Function: file-notify-rm-watch descriptor
77563     Removes an existing file watch specified by its DESCRIPTOR.
77564     DESCRIPTOR should be an object returned by ‘file-notify-add-watch’.
77565
77566 -- Function: file-notify-valid-p descriptor
77567     Checks a watch specified by its DESCRIPTOR for validity.
77568     DESCRIPTOR should be an object returned by ‘file-notify-add-watch’.
77569
77570     A watch can become invalid if the file or directory it watches is
77571     deleted, or if the watcher thread exits abnormally for any other
77572     reason.  Removing the watch by calling ‘file-notify-rm-watch’ also
77573     makes it invalid.
77574
77575          (make-directory "/tmp/foo")
77576               ⇒ Event (35025468 created "/tmp/foo")
77577
77578          (setq desc
77579                (file-notify-add-watch
77580                  "/tmp/foo" '(change) 'my-notify-callback))
77581               ⇒ 11359632
77582
77583          (file-notify-valid-p desc)
77584               ⇒ t
77585
77586          (write-region "bla" nil "/tmp/foo/bla")
77587               ⇒ Event (11359632 created "/tmp/foo/.#bla")
77588                  Event (11359632 created "/tmp/foo/bla")
77589                  Event (11359632 changed "/tmp/foo/bla")
77590                  Event (11359632 deleted "/tmp/foo/.#bla")
77591
77592          ;; Deleting a file in the directory doesn't invalidate the watch.
77593          (delete-file "/tmp/foo/bla")
77594               ⇒ Event (11359632 deleted "/tmp/foo/bla")
77595
77596          (write-region "bla" nil "/tmp/foo/bla")
77597               ⇒ Event (11359632 created "/tmp/foo/.#bla")
77598                  Event (11359632 created "/tmp/foo/bla")
77599                  Event (11359632 changed "/tmp/foo/bla")
77600                  Event (11359632 deleted "/tmp/foo/.#bla")
77601
77602          ;; Deleting the directory invalidates the watch.
77603          ;; Events arrive for different watch descriptors.
77604          (delete-directory "/tmp/foo" 'recursive)
77605               ⇒ Event (35025468 deleted "/tmp/foo")
77606                  Event (11359632 deleted "/tmp/foo/bla")
77607                  Event (11359632 deleted "/tmp/foo")
77608                  Event (11359632 stopped "/tmp/foo")
77609
77610          (file-notify-valid-p desc)
77611               ⇒ nil
77612
77613
77614File: elisp.info,  Node: Dynamic Libraries,  Next: Security Considerations,  Prev: File Notifications,  Up: System Interface
77615
7761640.21 Dynamically Loaded Libraries
77617==================================
77618
77619A “dynamically loaded library” is a library that is loaded on demand,
77620when its facilities are first needed.  Emacs supports such on-demand
77621loading of support libraries for some of its features.
77622
77623 -- Variable: dynamic-library-alist
77624     This is an alist of dynamic libraries and external library files
77625     implementing them.
77626
77627     Each element is a list of the form ‘(LIBRARY FILES...)’, where the
77628     ‘car’ is a symbol representing a supported external library, and
77629     the rest are strings giving alternate filenames for that library.
77630
77631     Emacs tries to load the library from the files in the order they
77632     appear in the list; if none is found, the Emacs session won’t have
77633     access to that library, and the features it provides will be
77634     unavailable.
77635
77636     Image support on some platforms uses this facility.  Here’s an
77637     example of setting this variable for supporting images on
77638     MS-Windows:
77639
77640          (setq dynamic-library-alist
77641                '((xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll")
77642                  (png "libpng12d.dll" "libpng12.dll" "libpng.dll"
77643                       "libpng13d.dll" "libpng13.dll")
77644                  (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll"
77645                        "jpeg.dll")
77646                  (tiff "libtiff3.dll" "libtiff.dll")
77647                  (gif "giflib4.dll" "libungif4.dll" "libungif.dll")
77648                  (svg "librsvg-2-2.dll")
77649                  (gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
77650                  (glib "libglib-2.0-0.dll")
77651                  (gobject "libgobject-2.0-0.dll")))
77652
77653     Note that image types ‘pbm’ and ‘xbm’ do not need entries in this
77654     variable because they do not depend on external libraries and are
77655     always available in Emacs.
77656
77657     Also note that this variable is not meant to be a generic facility
77658     for accessing external libraries; only those already known by Emacs
77659     can be loaded through it.
77660
77661     This variable is ignored if the given LIBRARY is statically linked
77662     into Emacs.
77663
77664
77665File: elisp.info,  Node: Security Considerations,  Prev: Dynamic Libraries,  Up: System Interface
77666
7766740.22 Security Considerations
77668=============================
77669
77670Like any application, Emacs can be run in a secure environment, where
77671the operating system enforces rules about access and the like.  With
77672some care, Emacs-based applications can also be part of a security
77673perimeter that checks such rules.  Although the default settings for
77674Emacs work well for a typical software development environment, they may
77675require adjustment in environments containing untrusted users that may
77676include attackers.  Here is a compendium of security issues that may be
77677helpful if you are developing such applications.  It is by no means
77678complete; it is intended to give you an idea of the security issues
77679involved, rather than to be a security checklist.
77680
77681File local variables
77682     A file that Emacs visits can contain variable settings that affect
77683     the buffer visiting that file; *Note File Local Variables::.
77684     Similarly, a directory can specify local variable values common to
77685     all files in that directory; see *note Directory Local Variables::.
77686     Although Emacs takes some effort to protect against misuse of these
77687     variables, a security hole can be created merely by a package
77688     setting ‘safe-local-variable’ too optimistically, a problem that is
77689     all too common.  To disable this feature for both files and
77690     directories, set ‘enable-local-variables’ to ‘nil’.
77691
77692Access control
77693     Although Emacs normally respects access permissions of the
77694     underlying operating system, in some cases it handles accesses
77695     specially.  For example, file names can have handlers that treat
77696     the files specially, with their own access checking.  *Note Magic
77697     File Names::.  Also, a buffer can be read-only even if the
77698     corresponding file is writable, and vice versa, which can result in
77699     messages such as ‘File passwd is write-protected; try to save
77700     anyway? (yes or no)’.  *Note Read Only Buffers::.
77701
77702Authentication
77703     Emacs has several functions that deal with passwords, e.g.,
77704     ‘read-passwd’.  *Note Reading a Password::.  Although these
77705     functions do not attempt to broadcast passwords to the world, their
77706     implementations are not proof against determined attackers with
77707     access to Emacs internals.  For example, even if Elisp code uses
77708     ‘clear-string’ to scrub a password from its memory after using it,
77709     remnants of the password may still reside in the garbage-collected
77710     free list.  *Note Modifying Strings::.
77711
77712Code injection
77713     Emacs can send commands to many other applications, and
77714     applications should take care that strings sent as operands of
77715     these commands are not misinterpreted as directives.  For example,
77716     when using a shell command to rename a file A to B, do not simply
77717     use the string ‘mv A B’, because either file name might start with
77718     ‘-’, or might contain shell metacharacters like ‘;’.  Although
77719     functions like ‘shell-quote-argument’ can help avoid this sort of
77720     problem, they are not panaceas; for example, on a POSIX platform
77721     ‘shell-quote-argument’ quotes shell metacharacters but not leading
77722     ‘-’.  On MS-Windows, quoting for ‘%’ assumes none of the
77723     environment variables have ‘^’ in their name.  *Note Shell
77724     Arguments::.  Typically it is safer to use ‘call-process’ than a
77725     subshell.  *Note Synchronous Processes::.  And it is safer yet to
77726     use builtin Emacs functions; for example, use ‘(rename-file "A" "B"
77727     t)’ instead of invoking ‘mv’.  *Note Changing Files::.
77728
77729Coding systems
77730     Emacs attempts to infer the coding systems of the files and network
77731     connections it accesses.  *Note Coding Systems::.  If Emacs infers
77732     incorrectly, or if the other parties to the network connection
77733     disagree with Emacs’s inferences, the resulting system could be
77734     unreliable.  Also, even when it infers correctly, Emacs often can
77735     use bytes that other programs cannot.  For example, although to
77736     Emacs the null byte is just a character like any other, many other
77737     applications treat it as a string terminator and mishandle strings
77738     or files containing null bytes.
77739
77740Environment and configuration variables
77741     POSIX specifies several environment variables that can affect how
77742     Emacs behaves.  Any environment variable whose name consists
77743     entirely of uppercase ASCII letters, digits, and the underscore may
77744     affect the internal behavior of Emacs.  Emacs uses several such
77745     variables, e.g., ‘EMACSLOADPATH’.  *Note Library Search::.  On some
77746     platforms some environment variables (e.g., ‘PATH’,
77747     ‘POSIXLY_CORRECT’, ‘SHELL’, ‘TMPDIR’) need to have
77748     properly-configured values in order to get standard behavior for
77749     any utility Emacs might invoke.  Even seemingly-benign variables
77750     like ‘TZ’ may have security implications.  *Note System
77751     Environment::.
77752
77753     Emacs has customization and other variables with similar
77754     considerations.  For example, if the variable ‘shell-file-name’
77755     specifies a shell with nonstandard behavior, an Emacs-based
77756     application may misbehave.
77757
77758Installation
77759     When Emacs is installed, if the installation directory hierarchy
77760     can be modified by untrusted users, the application cannot be
77761     trusted.  This applies also to the directory hierarchies of the
77762     programs that Emacs uses, and of the files that Emacs reads and
77763     writes.
77764
77765Network access
77766     Emacs often accesses the network, and you may want to configure it
77767     to avoid network accesses that it would normally do.  For example,
77768     unless you set ‘tramp-mode’ to ‘nil’, file names using a certain
77769     syntax are interpreted as being network files, and are retrieved
77770     across the network.  *Note The Tramp Manual: (tramp)Top.
77771
77772Race conditions
77773     Emacs applications have the same sort of race-condition issues that
77774     other applications do.  For example, even when ‘(file-readable-p
77775     "foo.txt")’ returns ‘t’, it could be that ‘foo.txt’ is unreadable
77776     because some other program changed the file’s permissions between
77777     the call to ‘file-readable-p’ and now.  *Note Testing
77778     Accessibility::.
77779
77780Resource limits
77781     When Emacs exhausts memory or other operating system resources, its
77782     behavior can be less reliable, in that computations that ordinarily
77783     run to completion may abort back to the top level.  This may cause
77784     Emacs to neglect operations that it normally would have done.
77785
77786
77787File: elisp.info,  Node: Packaging,  Next: Antinews,  Prev: System Interface,  Up: Top
77788
7778941 Preparing Lisp code for distribution
77790***************************************
77791
77792Emacs provides a standard way to distribute Emacs Lisp code to users.  A
77793“package” is a collection of one or more files, formatted and bundled in
77794such a way that users can easily download, install, uninstall, and
77795upgrade it.
77796
77797   The following sections describe how to create a package, and how to
77798put it in a “package archive” for others to download.  *Note
77799(emacs)Packages::, for a description of user-level features of the
77800packaging system.
77801
77802* Menu:
77803
77804* Packaging Basics::        The basic concepts of Emacs Lisp packages.
77805* Simple Packages::         How to package a single .el file.
77806* Multi-file Packages::     How to package multiple files.
77807* Package Archives::        Maintaining package archives.
77808* Archive Web Server::      Interfacing to an archive web server.
77809
77810
77811File: elisp.info,  Node: Packaging Basics,  Next: Simple Packages,  Up: Packaging
77812
7781341.1 Packaging Basics
77814=====================
77815
77816A package is either a “simple package” or a “multi-file package”.  A
77817simple package is stored in a package archive as a single Emacs Lisp
77818file, while a multi-file package is stored as a tar file (containing
77819multiple Lisp files, and possibly non-Lisp files such as a manual).
77820
77821   In ordinary usage, the difference between simple packages and
77822multi-file packages is relatively unimportant; the Package Menu
77823interface makes no distinction between them.  However, the procedure for
77824creating them differs, as explained in the following sections.
77825
77826   Each package (whether simple or multi-file) has certain “attributes”:
77827
77828Name
77829     A short word (e.g., ‘auctex’).  This is usually also the symbol
77830     prefix used in the program (*note Coding Conventions::).
77831
77832Version
77833     A version number, in a form that the function ‘version-to-list’
77834     understands (e.g., ‘11.86’).  Each release of a package should be
77835     accompanied by an increase in the version number so that it will be
77836     recognized as an upgrade by users querying the package archive.
77837
77838Brief description
77839     This is shown when the package is listed in the Package Menu.  It
77840     should occupy a single line, ideally in 36 characters or less.
77841
77842Long description
77843     This is shown in the buffer created by ‘C-h P’
77844     (‘describe-package’), following the package’s brief description and
77845     installation status.  It normally spans multiple lines, and should
77846     fully describe the package’s capabilities and how to begin using it
77847     once it is installed.
77848
77849Dependencies
77850     A list of other packages (possibly including minimal acceptable
77851     version numbers) on which this package depends.  The list may be
77852     empty, meaning this package has no dependencies.  Otherwise,
77853     installing this package also automatically installs its
77854     dependencies, recursively; if any dependency cannot be found, the
77855     package cannot be installed.
77856
77857   Installing a package, either via the command ‘package-install-file’,
77858or via the Package Menu, creates a subdirectory of ‘package-user-dir’
77859named ‘NAME-VERSION’, where NAME is the package’s name and VERSION its
77860version (e.g., ‘~/.emacs.d/elpa/auctex-11.86/’).  We call this the
77861package’s “content directory”.  It is where Emacs puts the package’s
77862contents (the single Lisp file for a simple package, or the files
77863extracted from a multi-file package).
77864
77865   Emacs then searches every Lisp file in the content directory for
77866autoload magic comments (*note Autoload::).  These autoload definitions
77867are saved to a file named ‘NAME-autoloads.el’ in the content directory.
77868They are typically used to autoload the principal user commands defined
77869in the package, but they can also perform other tasks, such as adding an
77870element to ‘auto-mode-alist’ (*note Auto Major Mode::).  Note that a
77871package typically does _not_ autoload every function and variable
77872defined within it—only the handful of commands typically called to begin
77873using the package.  Emacs then byte-compiles every Lisp file in the
77874package.
77875
77876   After installation, the installed package is “loaded”: Emacs adds the
77877package’s content directory to ‘load-path’, and evaluates the autoload
77878definitions in ‘NAME-autoloads.el’.
77879
77880   Whenever Emacs starts up, it automatically calls the function
77881‘package-activate-all’ to make installed packages available to the
77882current session.  This is done after loading the early init file, but
77883before loading the regular init file (*note Startup Summary::).
77884Packages are not automatically made available if the user option
77885‘package-enable-at-startup’ is set to ‘nil’ in the early init file.
77886
77887 -- Function: package-activate-all
77888     This function makes the packages available to the current session.
77889     The user option ‘package-load-list’ specifies which packages to
77890     make available; by default, all installed packages are made
77891     available.  *Note (emacs)Package Installation::.
77892
77893     In most cases, you should not need to call ‘package-activate-all’,
77894     as this is done automatically during startup.  Simply make sure to
77895     put any code that should run before ‘package-activate-all’ in the
77896     early init file, and any code that should run after it in the
77897     primary init file (*note (emacs)Init File::).
77898
77899 -- Command: package-initialize &optional no-activate
77900     This function initializes Emacs’ internal record of which packages
77901     are installed, and then calls ‘package-activate-all’.
77902
77903     The optional argument NO-ACTIVATE, if non-‘nil’, causes Emacs to
77904     update its record of installed packages without actually making
77905     them available.
77906
77907
77908File: elisp.info,  Node: Simple Packages,  Next: Multi-file Packages,  Prev: Packaging Basics,  Up: Packaging
77909
7791041.2 Simple Packages
77911====================
77912
77913A simple package consists of a single Emacs Lisp source file.  The file
77914must conform to the Emacs Lisp library header conventions (*note Library
77915Headers::).  The package’s attributes are taken from the various
77916headers, as illustrated by the following example:
77917
77918     ;;; superfrobnicator.el --- Frobnicate and bifurcate flanges
77919
77920     ;; Copyright (C) 2011 Free Software Foundation, Inc.
77921
77922     ;; Author: J. R. Hacker <jrh@example.com>
77923     ;; Version: 1.3
77924     ;; Package-Requires: ((flange "1.0"))
77925     ;; Keywords: multimedia, hypermedia
77926     ;; URL: https://example.com/jrhacker/superfrobnicate
77927
77928     ...
77929
77930     ;;; Commentary:
77931
77932     ;; This package provides a minor mode to frobnicate and/or
77933     ;; bifurcate any flanges you desire.  To activate it, just type
77934     ...
77935
77936     ;;;###autoload
77937     (define-minor-mode superfrobnicator-mode
77938     ...
77939
77940   The name of the package is the same as the base name of the file, as
77941written on the first line.  Here, it is ‘superfrobnicator’.
77942
77943   The brief description is also taken from the first line.  Here, it is
77944‘Frobnicate and bifurcate flanges’.
77945
77946   The version number comes from the ‘Package-Version’ header, if it
77947exists, or from the ‘Version’ header otherwise.  One or the other _must_
77948be present.  Here, the version number is 1.3.
77949
77950   If the file has a ‘;;; Commentary:’ section, this section is used as
77951the long description.  (When displaying the description, Emacs omits the
77952‘;;; Commentary:’ line, as well as the leading comment characters in the
77953commentary itself.)
77954
77955   If the file has a ‘Package-Requires’ header, that is used as the
77956package dependencies.  In the above example, the package depends on the
77957‘flange’ package, version 1.0 or higher.  *Note Library Headers::, for a
77958description of the ‘Package-Requires’ header.  If the header is omitted,
77959the package has no dependencies.
77960
77961   The ‘Keywords’ and ‘URL’ headers are optional, but recommended.  The
77962command ‘describe-package’ uses these to add links to its output.  The
77963‘Keywords’ header should contain at least one standard keyword from the
77964‘finder-known-keywords’ list.
77965
77966   The file ought to also contain one or more autoload magic comments,
77967as explained in *note Packaging Basics::.  In the above example, a magic
77968comment autoloads ‘superfrobnicator-mode’.
77969
77970   *Note Package Archives::, for an explanation of how to add a
77971single-file package to a package archive.
77972
77973
77974File: elisp.info,  Node: Multi-file Packages,  Next: Package Archives,  Prev: Simple Packages,  Up: Packaging
77975
7797641.3 Multi-file Packages
77977========================
77978
77979A multi-file package is less convenient to create than a single-file
77980package, but it offers more features: it can include multiple Emacs Lisp
77981files, an Info manual, and other file types (such as images).
77982
77983   Prior to installation, a multi-file package is stored in a package
77984archive as a tar file.  The tar file must be named ‘NAME-VERSION.tar’,
77985where NAME is the package name and VERSION is the version number.  Its
77986contents, once extracted, must all appear in a directory named
77987‘NAME-VERSION’, the “content directory” (*note Packaging Basics::).
77988Files may also extract into subdirectories of the content directory.
77989
77990   One of the files in the content directory must be named
77991NAME-pkg.el’.  It must contain a single Lisp form, consisting of a call
77992to the function ‘define-package’, described below.  This defines the
77993package’s attributes: version, brief description, and requirements.
77994
77995   For example, if we distribute version 1.3 of the superfrobnicator as
77996a multi-file package, the tar file would be ‘superfrobnicator-1.3.tar’.
77997Its contents would extract into the directory ‘superfrobnicator-1.3’,
77998and one of these would be the file ‘superfrobnicator-pkg.el’.
77999
78000 -- Function: define-package name version &optional docstring
78001          requirements
78002     This function defines a package.  NAME is the package name, a
78003     string.  VERSION is the version, as a string of a form that can be
78004     understood by the function ‘version-to-list’.  DOCSTRING is the
78005     brief description.
78006
78007     REQUIREMENTS is a list of required packages and their versions.
78008     Each element in this list should have the form ‘(DEP-NAME
78009     DEP-VERSION)’, where DEP-NAME is a symbol whose name is the
78010     dependency’s package name, and DEP-VERSION is the dependency’s
78011     version (a string).
78012
78013   If the content directory contains a file named ‘README’, this file is
78014used as the long description (overriding any ‘;;; Commentary:’ section).
78015
78016   If the content directory contains a file named ‘dir’, this is assumed
78017to be an Info directory file made with ‘install-info’.  *Note Invoking
78018install-info: (texinfo)Invoking install-info.  The relevant Info files
78019should also be present in the content directory.  In this case, Emacs
78020will automatically add the content directory to ‘Info-directory-list’
78021when the package is activated.
78022
78023   Do not include any ‘.elc’ files in the package.  Those are created
78024when the package is installed.  Note that there is no way to control the
78025order in which files are byte-compiled.
78026
78027   Do not include any file named ‘NAME-autoloads.el’.  This file is
78028reserved for the package’s autoload definitions (*note Packaging
78029Basics::).  It is created automatically when the package is installed,
78030by searching all the Lisp files in the package for autoload magic
78031comments.
78032
78033   If the multi-file package contains auxiliary data files (such as
78034images), the package’s Lisp code can refer to these files via the
78035variable ‘load-file-name’ (*note Loading::).  Here is an example:
78036
78037     (defconst superfrobnicator-base (file-name-directory load-file-name))
78038
78039     (defun superfrobnicator-fetch-image (file)
78040       (expand-file-name file superfrobnicator-base))
78041
78042
78043File: elisp.info,  Node: Package Archives,  Next: Archive Web Server,  Prev: Multi-file Packages,  Up: Packaging
78044
7804541.4 Creating and Maintaining Package Archives
78046==============================================
78047
78048Via the Package Menu, users may download packages from “package
78049archives”.  Such archives are specified by the variable
78050‘package-archives’, whose default value contains a single entry: the
78051archive hosted by the GNU project at <https://elpa.gnu.org>.  This
78052section describes how to set up and maintain a package archive.
78053
78054 -- User Option: package-archives
78055     The value of this variable is an alist of package archives
78056     recognized by the Emacs package manager.
78057
78058     Each alist element corresponds to one archive, and should have the
78059     form ‘(ID . LOCATION)’, where ID is the name of the archive (a
78060     string) and LOCATION is its “base location” (a string).
78061
78062     If the base location starts with ‘http:’ or ‘https:’, it is treated
78063     as an HTTP(S) URL, and packages are downloaded from this archive
78064     via HTTP(S) (as is the case for the default GNU archive).
78065
78066     Otherwise, the base location should be a directory name.  In this
78067     case, Emacs retrieves packages from this archive via ordinary file
78068     access.  Such local archives are mainly useful for testing.
78069
78070   A package archive is simply a directory in which the package files,
78071and associated files, are stored.  If you want the archive to be
78072reachable via HTTP, this directory must be accessible to a web server;
78073*Note Archive Web Server::.
78074
78075   A convenient way to set up and update a package archive is via the
78076‘package-x’ library.  This is included with Emacs, but not loaded by
78077default; type ‘M-x load-library <RET> package-x <RET>’ to load it, or
78078add ‘(require 'package-x)’ to your init file.  *Note Lisp Libraries:
78079(emacs)Lisp Libraries.
78080
78081After you create an archive, remember that it is not accessible in the
78082Package Menu interface unless it is in ‘package-archives’.
78083
78084   Maintaining a public package archive entails a degree of
78085responsibility.  When Emacs users install packages from your archive,
78086those packages can cause Emacs to run arbitrary code with the
78087permissions of the installing user.  (This is true for Emacs code in
78088general, not just for packages.)  So you should ensure that your archive
78089is well-maintained and keep the hosting system secure.
78090
78091   One way to increase the security of your packages is to “sign” them
78092using a cryptographic key.  If you have generated a private/public gpg
78093key pair, you can use gpg to sign the package like this:
78094
78095     gpg -ba -o FILE.sig FILE
78096
78097For a single-file package, FILE is the package Lisp file; for a
78098multi-file package, it is the package tar file.  You can also sign the
78099archive’s contents file in the same way.  Make the ‘.sig’ files
78100available in the same location as the packages.  You should also make
78101your public key available for people to download; e.g., by uploading it
78102to a key server such as <https://pgp.mit.edu/>.  When people install
78103packages from your archive, they can use your public key to verify the
78104signatures.
78105
78106   A full explanation of these matters is outside the scope of this
78107manual.  For more information on cryptographic keys and signing, *note
78108GnuPG: (gnupg)Top.  Emacs comes with an interface to GNU Privacy Guard,
78109*note EasyPG: (epa)Top.
78110
78111
78112File: elisp.info,  Node: Archive Web Server,  Prev: Package Archives,  Up: Packaging
78113
7811441.5 Interfacing to an archive web server
78115=========================================
78116
78117A web server providing access to a package archive must support the
78118following queries:
78119
78120archive-contents
78121     Return a lisp form describing the archive contents.  The form is a
78122     list of ’package-desc’ structures (see ‘package.el’), except the
78123     first element of the list is the archive version.
78124
78125<package name>-readme.txt
78126     Return the long description of the package.
78127
78128<file name>.sig
78129     Return the signature for the file.
78130
78131<file name>
78132     Return the file.  This will be the tarball for a multi-file
78133     package, or the single file for a simple package.
78134
78135
78136File: elisp.info,  Node: Antinews,  Next: GNU Free Documentation License,  Prev: Packaging,  Up: Top
78137
78138Appendix A Emacs 26 Antinews
78139****************************
78140
78141For those users who live backwards in time, here is information about
78142downgrading to Emacs version 26.3.  We hope you will enjoy the greater
78143simplicity that results from the absence of many Emacs 27.2 features.
78144
78145   • Lisp objects are again implemented on the C level as integer types,
78146     not as pointers.  This might be a small step for Emacs Lisp users,
78147     but it’s a giant leap for the Emacs developers who work on the C
78148     level, since it is now again easy to print Lisp object in the
78149     debugger in the decimal format, which is so much easier for
78150     debugging.  It also makes calling Emacs functions from the debugger
78151     easier, and allows us to freely mix integers and Lisp objects in
78152     the C code.
78153
78154   • The test suite was removed from the distribution tarball.  We
78155     believe that tests need seldom if ever be run, certainly not by the
78156     end users.  Removing the tests from the tarball makes it much
78157     smaller, which is important since disk space becomes more and more
78158     at premium as you move back in time.
78159
78160   • Dynamic module support is disabled by default.  This both makes
78161     Emacs smaller (a worthy goal by itself), and removes the
78162     complications and additional complexity related with installing
78163     module support files and letting random shared objects an
78164     opportunity to be loaded into Emacs and mess with it.
78165
78166   • You now must activate any installed packages only after loading
78167     your init files.  That requires an explicit call to
78168     ‘package-initialize’ in your init file, which is a Good Thing, as
78169     it makes you think seriously where and indeed whether you’d like
78170     your packages to become available to your sessions.  Simplicity
78171     should tramp convenience!
78172
78173   • To reduce the amount of code in Emacs related to unimportant
78174     features, we’ve removed native rotation and resizing of images.
78175     You will have to build Emacs with ImageMagick if you want to resize
78176     or rotate images inside Emacs.  We don’t expect anyone to miss
78177     that.
78178
78179   • We’ve re-enabled color fonts usage by the XFT font back-end.  We
78180     consider the availability of these fonts more important than a
78181     random crash here and there, especially since the use of these
78182     fonts for displaying Emoji will become less and less important as
78183     we travel back in time, and will completely disappear in some past
78184     Emacs version.
78185
78186   • The function ‘network-interface-list’ can now return only IPv4
78187     addresses.  We consider the complexity introduced by IPv6 to be too
78188     much to be justified, and on the other hand its removal is the step
78189     in the right direction, given that IPv6 is expected to be
78190     completely removed as we move back in time.
78191
78192   • The limit on repetitions in regular expressions was reduced to
78193     2**15 − 1.  We envision that regular expressions will become more
78194     and more simple as we move towards the distant past.
78195
78196   • To simplify code and reduce complexity, we removed the capability
78197     of searching programs on remote hosts in ‘executable-find’.  If you
78198     really need this feature (why would you?), you can always write
78199     your own shell script and run it on the remote.
78200
78201   • The ‘:extend’ face attribute is no longer available; all faces have
78202     their background color extended by default past end of line.  This
78203     should significantly simplify face management and remove
78204     unnecessary code bloat, as well as make faces significantly simpler
78205     to understand and use.
78206
78207   • The predicates ‘display-blink-cursor-p’ and ‘display-symbol-keys-p’
78208     were deleted.  They are rarely if ever needed, and can easily be
78209     substituted by appropriate calls to old and proven APIs like
78210     ‘display-graphic-p’.  As an additional bonus, writing Lisp programs
78211     that depend on this functionality will make sure the programmer
78212     understands better what exactly is the required features of the
78213     display terminal.
78214
78215   • Relative directories in the value of the ‘HOME’ environment
78216     variable are once again interpreted relative to the
78217     ‘default-directory’ of the current buffer.  This is much simpler,
78218     and also allows ‘HOME’ to resolve to a different place in different
78219     buffers, which allows some interesting applications.
78220
78221     For the same reasons, ‘file-name-absolute-p’ now again considers
78222     ‘~foo’ an absolute file name, even if there’s no known user ‘foo’.
78223     This means a Lisp program which uses such file names will always
78224     work the same on any system, regardless of its known users.
78225
78226   • File-related primitives like ‘file-attributes’, ‘file-modes’,
78227     ‘file-newer-than-file-p’, and some others once again return ‘nil’
78228     when the underlying low-level APIs fail, instead of signaling an
78229     error.  We decided that functions which signal errors require more
78230     complex code from Lisp programs which use them, and found this
78231     complexity unjustified when returning ‘nil’ will do.
78232
78233   • Similarly, old-style backquotes no longer signal errors; they
78234     generate warnings instead.  You can remove error handling from
78235     programs that use backquotes.
78236
78237   • Formatting floating-point numbers has been sped up by letting the
78238     underlying implementation produce unpredictable values, instead of
78239     signaling errors when the number is too large to format correctly.
78240     We believe the Emacs Lisp programmers should always know what they
78241     are doing when they deal with floating-point values.
78242
78243   • The function ‘read-char-from-minibuffer’ was deleted.  We decided
78244     that ‘read-char’ should be enough for any Lisp program that needs
78245     to ask the user for a single-character input, in recognition of the
78246     fact that nothing makes Emacs Lisp hackers rejoice more than the
78247     need to sit down and write yet another interactive
78248     question-and-answer function, and make it optimal for each specific
78249     case.  Consequently, no history is provided for such responses (why
78250     would someone want history of single-key strokes, anyway?).
78251
78252   • The function ‘ngettext’ was deleted.  Non-English languages will
78253     become less and less widespread, let alone useful, as you move back
78254     in time, so we took this small step in that direction, and
78255     simplified Emacs as a nice bonus.
78256
78257   • Focus-change notifications on text-mode frames are no longer
78258     recognized or supported.  You can now safely disregard the
78259     possibility of receiving such notifications on TTY frames.  This is
78260     one small step on the long road of removing all non-character input
78261     events Emacs supports on TTY frames.
78262
78263   • Face specifications in ‘face-remapping-alist’ now have to be
78264     buffer-specific, without any differences between windows showing
78265     the same buffers.  This allowed us to remove a lot of unneeded code
78266     bloat from Emacs, and make the face handling much simpler.
78267
78268   • The ‘%o’ and ‘%x’ formats now always produce unsigned values, as
78269     you’d expect.  This allows you to reveal the underlying machine
78270     representation, which is different on each architecture, something
78271     we consider a valuable feature.
78272
78273   • We no longer highlight in ‘font-lock-warning-face’ symbols with
78274     confusable quote characters, such as U+2018.  Detecting them needed
78275     non-trivial amount of code, and we firmly believe that Lisp
78276     programmers always know what they are doing, and don’t need to be
78277     annoyed with typefaces that stand out and distract.
78278
78279   • The function ‘file-system-info’ was dropped on Posix platforms,
78280     since you can always invoke ‘df’ instead and parse its output.
78281
78282   • The functions that implement the ‘base64url’ encoding were removed,
78283     as they can always be emulated by suitable tweaking of the normal
78284     base-64 encoding.  No need to bloat Emacs and force Lisp
78285     programmers learn more interfaces on this account.
78286
78287   • As part of the ongoing quest for simplicity, many other functions
78288     and variables have been eliminated.
78289
78290
78291File: elisp.info,  Node: GNU Free Documentation License,  Next: GPL,  Prev: Antinews,  Up: Top
78292
78293Appendix B GNU Free Documentation License
78294*****************************************
78295
78296                     Version 1.3, 3 November 2008
78297
78298     Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
78299     <https://fsf.org/>
78300
78301     Everyone is permitted to copy and distribute verbatim copies
78302     of this license document, but changing it is not allowed.
78303
78304  0. PREAMBLE
78305
78306     The purpose of this License is to make a manual, textbook, or other
78307     functional and useful document “free” in the sense of freedom: to
78308     assure everyone the effective freedom to copy and redistribute it,
78309     with or without modifying it, either commercially or
78310     noncommercially.  Secondarily, this License preserves for the
78311     author and publisher a way to get credit for their work, while not
78312     being considered responsible for modifications made by others.
78313
78314     This License is a kind of “copyleft”, which means that derivative
78315     works of the document must themselves be free in the same sense.
78316     It complements the GNU General Public License, which is a copyleft
78317     license designed for free software.
78318
78319     We have designed this License in order to use it for manuals for
78320     free software, because free software needs free documentation: a
78321     free program should come with manuals providing the same freedoms
78322     that the software does.  But this License is not limited to
78323     software manuals; it can be used for any textual work, regardless
78324     of subject matter or whether it is published as a printed book.  We
78325     recommend this License principally for works whose purpose is
78326     instruction or reference.
78327
78328  1. APPLICABILITY AND DEFINITIONS
78329
78330     This License applies to any manual or other work, in any medium,
78331     that contains a notice placed by the copyright holder saying it can
78332     be distributed under the terms of this License.  Such a notice
78333     grants a world-wide, royalty-free license, unlimited in duration,
78334     to use that work under the conditions stated herein.  The
78335     “Document”, below, refers to any such manual or work.  Any member
78336     of the public is a licensee, and is addressed as “you”.  You accept
78337     the license if you copy, modify or distribute the work in a way
78338     requiring permission under copyright law.
78339
78340     A “Modified Version” of the Document means any work containing the
78341     Document or a portion of it, either copied verbatim, or with
78342     modifications and/or translated into another language.
78343
78344     A “Secondary Section” is a named appendix or a front-matter section
78345     of the Document that deals exclusively with the relationship of the
78346     publishers or authors of the Document to the Document’s overall
78347     subject (or to related matters) and contains nothing that could
78348     fall directly within that overall subject.  (Thus, if the Document
78349     is in part a textbook of mathematics, a Secondary Section may not
78350     explain any mathematics.)  The relationship could be a matter of
78351     historical connection with the subject or with related matters, or
78352     of legal, commercial, philosophical, ethical or political position
78353     regarding them.
78354
78355     The “Invariant Sections” are certain Secondary Sections whose
78356     titles are designated, as being those of Invariant Sections, in the
78357     notice that says that the Document is released under this License.
78358     If a section does not fit the above definition of Secondary then it
78359     is not allowed to be designated as Invariant.  The Document may
78360     contain zero Invariant Sections.  If the Document does not identify
78361     any Invariant Sections then there are none.
78362
78363     The “Cover Texts” are certain short passages of text that are
78364     listed, as Front-Cover Texts or Back-Cover Texts, in the notice
78365     that says that the Document is released under this License.  A
78366     Front-Cover Text may be at most 5 words, and a Back-Cover Text may
78367     be at most 25 words.
78368
78369     A “Transparent” copy of the Document means a machine-readable copy,
78370     represented in a format whose specification is available to the
78371     general public, that is suitable for revising the document
78372     straightforwardly with generic text editors or (for images composed
78373     of pixels) generic paint programs or (for drawings) some widely
78374     available drawing editor, and that is suitable for input to text
78375     formatters or for automatic translation to a variety of formats
78376     suitable for input to text formatters.  A copy made in an otherwise
78377     Transparent file format whose markup, or absence of markup, has
78378     been arranged to thwart or discourage subsequent modification by
78379     readers is not Transparent.  An image format is not Transparent if
78380     used for any substantial amount of text.  A copy that is not
78381     “Transparent” is called “Opaque”.
78382
78383     Examples of suitable formats for Transparent copies include plain
78384     ASCII without markup, Texinfo input format, LaTeX input format,
78385     SGML or XML using a publicly available DTD, and standard-conforming
78386     simple HTML, PostScript or PDF designed for human modification.
78387     Examples of transparent image formats include PNG, XCF and JPG.
78388     Opaque formats include proprietary formats that can be read and
78389     edited only by proprietary word processors, SGML or XML for which
78390     the DTD and/or processing tools are not generally available, and
78391     the machine-generated HTML, PostScript or PDF produced by some word
78392     processors for output purposes only.
78393
78394     The “Title Page” means, for a printed book, the title page itself,
78395     plus such following pages as are needed to hold, legibly, the
78396     material this License requires to appear in the title page.  For
78397     works in formats which do not have any title page as such, “Title
78398     Page” means the text near the most prominent appearance of the
78399     work’s title, preceding the beginning of the body of the text.
78400
78401     The “publisher” means any person or entity that distributes copies
78402     of the Document to the public.
78403
78404     A section “Entitled XYZ” means a named subunit of the Document
78405     whose title either is precisely XYZ or contains XYZ in parentheses
78406     following text that translates XYZ in another language.  (Here XYZ
78407     stands for a specific section name mentioned below, such as
78408     “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.)
78409     To “Preserve the Title” of such a section when you modify the
78410     Document means that it remains a section “Entitled XYZ” according
78411     to this definition.
78412
78413     The Document may include Warranty Disclaimers next to the notice
78414     which states that this License applies to the Document.  These
78415     Warranty Disclaimers are considered to be included by reference in
78416     this License, but only as regards disclaiming warranties: any other
78417     implication that these Warranty Disclaimers may have is void and
78418     has no effect on the meaning of this License.
78419
78420  2. VERBATIM COPYING
78421
78422     You may copy and distribute the Document in any medium, either
78423     commercially or noncommercially, provided that this License, the
78424     copyright notices, and the license notice saying this License
78425     applies to the Document are reproduced in all copies, and that you
78426     add no other conditions whatsoever to those of this License.  You
78427     may not use technical measures to obstruct or control the reading
78428     or further copying of the copies you make or distribute.  However,
78429     you may accept compensation in exchange for copies.  If you
78430     distribute a large enough number of copies you must also follow the
78431     conditions in section 3.
78432
78433     You may also lend copies, under the same conditions stated above,
78434     and you may publicly display copies.
78435
78436  3. COPYING IN QUANTITY
78437
78438     If you publish printed copies (or copies in media that commonly
78439     have printed covers) of the Document, numbering more than 100, and
78440     the Document’s license notice requires Cover Texts, you must
78441     enclose the copies in covers that carry, clearly and legibly, all
78442     these Cover Texts: Front-Cover Texts on the front cover, and
78443     Back-Cover Texts on the back cover.  Both covers must also clearly
78444     and legibly identify you as the publisher of these copies.  The
78445     front cover must present the full title with all words of the title
78446     equally prominent and visible.  You may add other material on the
78447     covers in addition.  Copying with changes limited to the covers, as
78448     long as they preserve the title of the Document and satisfy these
78449     conditions, can be treated as verbatim copying in other respects.
78450
78451     If the required texts for either cover are too voluminous to fit
78452     legibly, you should put the first ones listed (as many as fit
78453     reasonably) on the actual cover, and continue the rest onto
78454     adjacent pages.
78455
78456     If you publish or distribute Opaque copies of the Document
78457     numbering more than 100, you must either include a machine-readable
78458     Transparent copy along with each Opaque copy, or state in or with
78459     each Opaque copy a computer-network location from which the general
78460     network-using public has access to download using public-standard
78461     network protocols a complete Transparent copy of the Document, free
78462     of added material.  If you use the latter option, you must take
78463     reasonably prudent steps, when you begin distribution of Opaque
78464     copies in quantity, to ensure that this Transparent copy will
78465     remain thus accessible at the stated location until at least one
78466     year after the last time you distribute an Opaque copy (directly or
78467     through your agents or retailers) of that edition to the public.
78468
78469     It is requested, but not required, that you contact the authors of
78470     the Document well before redistributing any large number of copies,
78471     to give them a chance to provide you with an updated version of the
78472     Document.
78473
78474  4. MODIFICATIONS
78475
78476     You may copy and distribute a Modified Version of the Document
78477     under the conditions of sections 2 and 3 above, provided that you
78478     release the Modified Version under precisely this License, with the
78479     Modified Version filling the role of the Document, thus licensing
78480     distribution and modification of the Modified Version to whoever
78481     possesses a copy of it.  In addition, you must do these things in
78482     the Modified Version:
78483
78484       A. Use in the Title Page (and on the covers, if any) a title
78485          distinct from that of the Document, and from those of previous
78486          versions (which should, if there were any, be listed in the
78487          History section of the Document).  You may use the same title
78488          as a previous version if the original publisher of that
78489          version gives permission.
78490
78491       B. List on the Title Page, as authors, one or more persons or
78492          entities responsible for authorship of the modifications in
78493          the Modified Version, together with at least five of the
78494          principal authors of the Document (all of its principal
78495          authors, if it has fewer than five), unless they release you
78496          from this requirement.
78497
78498       C. State on the Title page the name of the publisher of the
78499          Modified Version, as the publisher.
78500
78501       D. Preserve all the copyright notices of the Document.
78502
78503       E. Add an appropriate copyright notice for your modifications
78504          adjacent to the other copyright notices.
78505
78506       F. Include, immediately after the copyright notices, a license
78507          notice giving the public permission to use the Modified
78508          Version under the terms of this License, in the form shown in
78509          the Addendum below.
78510
78511       G. Preserve in that license notice the full lists of Invariant
78512          Sections and required Cover Texts given in the Document’s
78513          license notice.
78514
78515       H. Include an unaltered copy of this License.
78516
78517       I. Preserve the section Entitled “History”, Preserve its Title,
78518          and add to it an item stating at least the title, year, new
78519          authors, and publisher of the Modified Version as given on the
78520          Title Page.  If there is no section Entitled “History” in the
78521          Document, create one stating the title, year, authors, and
78522          publisher of the Document as given on its Title Page, then add
78523          an item describing the Modified Version as stated in the
78524          previous sentence.
78525
78526       J. Preserve the network location, if any, given in the Document
78527          for public access to a Transparent copy of the Document, and
78528          likewise the network locations given in the Document for
78529          previous versions it was based on.  These may be placed in the
78530          “History” section.  You may omit a network location for a work
78531          that was published at least four years before the Document
78532          itself, or if the original publisher of the version it refers
78533          to gives permission.
78534
78535       K. For any section Entitled “Acknowledgements” or “Dedications”,
78536          Preserve the Title of the section, and preserve in the section
78537          all the substance and tone of each of the contributor
78538          acknowledgements and/or dedications given therein.
78539
78540       L. Preserve all the Invariant Sections of the Document, unaltered
78541          in their text and in their titles.  Section numbers or the
78542          equivalent are not considered part of the section titles.
78543
78544       M. Delete any section Entitled “Endorsements”.  Such a section
78545          may not be included in the Modified Version.
78546
78547       N. Do not retitle any existing section to be Entitled
78548          “Endorsements” or to conflict in title with any Invariant
78549          Section.
78550
78551       O. Preserve any Warranty Disclaimers.
78552
78553     If the Modified Version includes new front-matter sections or
78554     appendices that qualify as Secondary Sections and contain no
78555     material copied from the Document, you may at your option designate
78556     some or all of these sections as invariant.  To do this, add their
78557     titles to the list of Invariant Sections in the Modified Version’s
78558     license notice.  These titles must be distinct from any other
78559     section titles.
78560
78561     You may add a section Entitled “Endorsements”, provided it contains
78562     nothing but endorsements of your Modified Version by various
78563     parties—for example, statements of peer review or that the text has
78564     been approved by an organization as the authoritative definition of
78565     a standard.
78566
78567     You may add a passage of up to five words as a Front-Cover Text,
78568     and a passage of up to 25 words as a Back-Cover Text, to the end of
78569     the list of Cover Texts in the Modified Version.  Only one passage
78570     of Front-Cover Text and one of Back-Cover Text may be added by (or
78571     through arrangements made by) any one entity.  If the Document
78572     already includes a cover text for the same cover, previously added
78573     by you or by arrangement made by the same entity you are acting on
78574     behalf of, you may not add another; but you may replace the old
78575     one, on explicit permission from the previous publisher that added
78576     the old one.
78577
78578     The author(s) and publisher(s) of the Document do not by this
78579     License give permission to use their names for publicity for or to
78580     assert or imply endorsement of any Modified Version.
78581
78582  5. COMBINING DOCUMENTS
78583
78584     You may combine the Document with other documents released under
78585     this License, under the terms defined in section 4 above for
78586     modified versions, provided that you include in the combination all
78587     of the Invariant Sections of all of the original documents,
78588     unmodified, and list them all as Invariant Sections of your
78589     combined work in its license notice, and that you preserve all
78590     their Warranty Disclaimers.
78591
78592     The combined work need only contain one copy of this License, and
78593     multiple identical Invariant Sections may be replaced with a single
78594     copy.  If there are multiple Invariant Sections with the same name
78595     but different contents, make the title of each such section unique
78596     by adding at the end of it, in parentheses, the name of the
78597     original author or publisher of that section if known, or else a
78598     unique number.  Make the same adjustment to the section titles in
78599     the list of Invariant Sections in the license notice of the
78600     combined work.
78601
78602     In the combination, you must combine any sections Entitled
78603     “History” in the various original documents, forming one section
78604     Entitled “History”; likewise combine any sections Entitled
78605     “Acknowledgements”, and any sections Entitled “Dedications”.  You
78606     must delete all sections Entitled “Endorsements.”
78607
78608  6. COLLECTIONS OF DOCUMENTS
78609
78610     You may make a collection consisting of the Document and other
78611     documents released under this License, and replace the individual
78612     copies of this License in the various documents with a single copy
78613     that is included in the collection, provided that you follow the
78614     rules of this License for verbatim copying of each of the documents
78615     in all other respects.
78616
78617     You may extract a single document from such a collection, and
78618     distribute it individually under this License, provided you insert
78619     a copy of this License into the extracted document, and follow this
78620     License in all other respects regarding verbatim copying of that
78621     document.
78622
78623  7. AGGREGATION WITH INDEPENDENT WORKS
78624
78625     A compilation of the Document or its derivatives with other
78626     separate and independent documents or works, in or on a volume of a
78627     storage or distribution medium, is called an “aggregate” if the
78628     copyright resulting from the compilation is not used to limit the
78629     legal rights of the compilation’s users beyond what the individual
78630     works permit.  When the Document is included in an aggregate, this
78631     License does not apply to the other works in the aggregate which
78632     are not themselves derivative works of the Document.
78633
78634     If the Cover Text requirement of section 3 is applicable to these
78635     copies of the Document, then if the Document is less than one half
78636     of the entire aggregate, the Document’s Cover Texts may be placed
78637     on covers that bracket the Document within the aggregate, or the
78638     electronic equivalent of covers if the Document is in electronic
78639     form.  Otherwise they must appear on printed covers that bracket
78640     the whole aggregate.
78641
78642  8. TRANSLATION
78643
78644     Translation is considered a kind of modification, so you may
78645     distribute translations of the Document under the terms of section
78646     4.  Replacing Invariant Sections with translations requires special
78647     permission from their copyright holders, but you may include
78648     translations of some or all Invariant Sections in addition to the
78649     original versions of these Invariant Sections.  You may include a
78650     translation of this License, and all the license notices in the
78651     Document, and any Warranty Disclaimers, provided that you also
78652     include the original English version of this License and the
78653     original versions of those notices and disclaimers.  In case of a
78654     disagreement between the translation and the original version of
78655     this License or a notice or disclaimer, the original version will
78656     prevail.
78657
78658     If a section in the Document is Entitled “Acknowledgements”,
78659     “Dedications”, or “History”, the requirement (section 4) to
78660     Preserve its Title (section 1) will typically require changing the
78661     actual title.
78662
78663  9. TERMINATION
78664
78665     You may not copy, modify, sublicense, or distribute the Document
78666     except as expressly provided under this License.  Any attempt
78667     otherwise to copy, modify, sublicense, or distribute it is void,
78668     and will automatically terminate your rights under this License.
78669
78670     However, if you cease all violation of this License, then your
78671     license from a particular copyright holder is reinstated (a)
78672     provisionally, unless and until the copyright holder explicitly and
78673     finally terminates your license, and (b) permanently, if the
78674     copyright holder fails to notify you of the violation by some
78675     reasonable means prior to 60 days after the cessation.
78676
78677     Moreover, your license from a particular copyright holder is
78678     reinstated permanently if the copyright holder notifies you of the
78679     violation by some reasonable means, this is the first time you have
78680     received notice of violation of this License (for any work) from
78681     that copyright holder, and you cure the violation prior to 30 days
78682     after your receipt of the notice.
78683
78684     Termination of your rights under this section does not terminate
78685     the licenses of parties who have received copies or rights from you
78686     under this License.  If your rights have been terminated and not
78687     permanently reinstated, receipt of a copy of some or all of the
78688     same material does not give you any rights to use it.
78689
78690  10. FUTURE REVISIONS OF THIS LICENSE
78691
78692     The Free Software Foundation may publish new, revised versions of
78693     the GNU Free Documentation License from time to time.  Such new
78694     versions will be similar in spirit to the present version, but may
78695     differ in detail to address new problems or concerns.  See
78696     <https://www.gnu.org/licenses/>.
78697
78698     Each version of the License is given a distinguishing version
78699     number.  If the Document specifies that a particular numbered
78700     version of this License “or any later version” applies to it, you
78701     have the option of following the terms and conditions either of
78702     that specified version or of any later version that has been
78703     published (not as a draft) by the Free Software Foundation.  If the
78704     Document does not specify a version number of this License, you may
78705     choose any version ever published (not as a draft) by the Free
78706     Software Foundation.  If the Document specifies that a proxy can
78707     decide which future versions of this License can be used, that
78708     proxy’s public statement of acceptance of a version permanently
78709     authorizes you to choose that version for the Document.
78710
78711  11. RELICENSING
78712
78713     “Massive Multiauthor Collaboration Site” (or “MMC Site”) means any
78714     World Wide Web server that publishes copyrightable works and also
78715     provides prominent facilities for anybody to edit those works.  A
78716     public wiki that anybody can edit is an example of such a server.
78717     A “Massive Multiauthor Collaboration” (or “MMC”) contained in the
78718     site means any set of copyrightable works thus published on the MMC
78719     site.
78720
78721     “CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0
78722     license published by Creative Commons Corporation, a not-for-profit
78723     corporation with a principal place of business in San Francisco,
78724     California, as well as future copyleft versions of that license
78725     published by that same organization.
78726
78727     “Incorporate” means to publish or republish a Document, in whole or
78728     in part, as part of another Document.
78729
78730     An MMC is “eligible for relicensing” if it is licensed under this
78731     License, and if all works that were first published under this
78732     License somewhere other than this MMC, and subsequently
78733     incorporated in whole or in part into the MMC, (1) had no cover
78734     texts or invariant sections, and (2) were thus incorporated prior
78735     to November 1, 2008.
78736
78737     The operator of an MMC Site may republish an MMC contained in the
78738     site under CC-BY-SA on the same site at any time before August 1,
78739     2009, provided the MMC is eligible for relicensing.
78740
78741ADDENDUM: How to use this License for your documents
78742====================================================
78743
78744To use this License in a document you have written, include a copy of
78745the License in the document and put the following copyright and license
78746notices just after the title page:
78747
78748       Copyright (C)  YEAR  YOUR NAME.
78749       Permission is granted to copy, distribute and/or modify this document
78750       under the terms of the GNU Free Documentation License, Version 1.3
78751       or any later version published by the Free Software Foundation;
78752       with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
78753       Texts.  A copy of the license is included in the section entitled ``GNU
78754       Free Documentation License''.
78755
78756   If you have Invariant Sections, Front-Cover Texts and Back-Cover
78757Texts, replace the “with...Texts.” line with this:
78758
78759         with the Invariant Sections being LIST THEIR TITLES, with
78760         the Front-Cover Texts being LIST, and with the Back-Cover Texts
78761         being LIST.
78762
78763   If you have Invariant Sections without Cover Texts, or some other
78764combination of the three, merge those two alternatives to suit the
78765situation.
78766
78767   If your document contains nontrivial examples of program code, we
78768recommend releasing these examples in parallel under your choice of free
78769software license, such as the GNU General Public License, to permit
78770their use in free software.
78771
78772
78773File: elisp.info,  Node: GPL,  Next: Tips,  Prev: GNU Free Documentation License,  Up: Top
78774
78775Appendix C GNU General Public License
78776*************************************
78777
78778                        Version 3, 29 June 2007
78779
78780     Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
78781
78782     Everyone is permitted to copy and distribute verbatim copies of this
78783     license document, but changing it is not allowed.
78784
78785Preamble
78786========
78787
78788The GNU General Public License is a free, copyleft license for software
78789and other kinds of works.
78790
78791   The licenses for most software and other practical works are designed
78792to take away your freedom to share and change the works.  By contrast,
78793the GNU General Public License is intended to guarantee your freedom to
78794share and change all versions of a program—to make sure it remains free
78795software for all its users.  We, the Free Software Foundation, use the
78796GNU General Public License for most of our software; it applies also to
78797any other work released this way by its authors.  You can apply it to
78798your programs, too.
78799
78800   When we speak of free software, we are referring to freedom, not
78801price.  Our General Public Licenses are designed to make sure that you
78802have the freedom to distribute copies of free software (and charge for
78803them if you wish), that you receive source code or can get it if you
78804want it, that you can change the software or use pieces of it in new
78805free programs, and that you know you can do these things.
78806
78807   To protect your rights, we need to prevent others from denying you
78808these rights or asking you to surrender the rights.  Therefore, you have
78809certain responsibilities if you distribute copies of the software, or if
78810you modify it: responsibilities to respect the freedom of others.
78811
78812   For example, if you distribute copies of such a program, whether
78813gratis or for a fee, you must pass on to the recipients the same
78814freedoms that you received.  You must make sure that they, too, receive
78815or can get the source code.  And you must show them these terms so they
78816know their rights.
78817
78818   Developers that use the GNU GPL protect your rights with two steps:
78819(1) assert copyright on the software, and (2) offer you this License
78820giving you legal permission to copy, distribute and/or modify it.
78821
78822   For the developers’ and authors’ protection, the GPL clearly explains
78823that there is no warranty for this free software.  For both users’ and
78824authors’ sake, the GPL requires that modified versions be marked as
78825changed, so that their problems will not be attributed erroneously to
78826authors of previous versions.
78827
78828   Some devices are designed to deny users access to install or run
78829modified versions of the software inside them, although the manufacturer
78830can do so.  This is fundamentally incompatible with the aim of
78831protecting users’ freedom to change the software.  The systematic
78832pattern of such abuse occurs in the area of products for individuals to
78833use, which is precisely where it is most unacceptable.  Therefore, we
78834have designed this version of the GPL to prohibit the practice for those
78835products.  If such problems arise substantially in other domains, we
78836stand ready to extend this provision to those domains in future versions
78837of the GPL, as needed to protect the freedom of users.
78838
78839   Finally, every program is threatened constantly by software patents.
78840States should not allow patents to restrict development and use of
78841software on general-purpose computers, but in those that do, we wish to
78842avoid the special danger that patents applied to a free program could
78843make it effectively proprietary.  To prevent this, the GPL assures that
78844patents cannot be used to render the program non-free.
78845
78846   The precise terms and conditions for copying, distribution and
78847modification follow.
78848
78849TERMS AND CONDITIONS
78850====================
78851
78852  0. Definitions.
78853
78854     “This License” refers to version 3 of the GNU General Public
78855     License.
78856
78857     “Copyright” also means copyright-like laws that apply to other
78858     kinds of works, such as semiconductor masks.
78859
78860     “The Program” refers to any copyrightable work licensed under this
78861     License.  Each licensee is addressed as “you”.  “Licensees” and
78862     “recipients” may be individuals or organizations.
78863
78864     To “modify” a work means to copy from or adapt all or part of the
78865     work in a fashion requiring copyright permission, other than the
78866     making of an exact copy.  The resulting work is called a “modified
78867     version” of the earlier work or a work “based on” the earlier work.
78868
78869     A “covered work” means either the unmodified Program or a work
78870     based on the Program.
78871
78872     To “propagate” a work means to do anything with it that, without
78873     permission, would make you directly or secondarily liable for
78874     infringement under applicable copyright law, except executing it on
78875     a computer or modifying a private copy.  Propagation includes
78876     copying, distribution (with or without modification), making
78877     available to the public, and in some countries other activities as
78878     well.
78879
78880     To “convey” a work means any kind of propagation that enables other
78881     parties to make or receive copies.  Mere interaction with a user
78882     through a computer network, with no transfer of a copy, is not
78883     conveying.
78884
78885     An interactive user interface displays “Appropriate Legal Notices”
78886     to the extent that it includes a convenient and prominently visible
78887     feature that (1) displays an appropriate copyright notice, and (2)
78888     tells the user that there is no warranty for the work (except to
78889     the extent that warranties are provided), that licensees may convey
78890     the work under this License, and how to view a copy of this
78891     License.  If the interface presents a list of user commands or
78892     options, such as a menu, a prominent item in the list meets this
78893     criterion.
78894
78895  1. Source Code.
78896
78897     The “source code” for a work means the preferred form of the work
78898     for making modifications to it.  “Object code” means any non-source
78899     form of a work.
78900
78901     A “Standard Interface” means an interface that either is an
78902     official standard defined by a recognized standards body, or, in
78903     the case of interfaces specified for a particular programming
78904     language, one that is widely used among developers working in that
78905     language.
78906
78907     The “System Libraries” of an executable work include anything,
78908     other than the work as a whole, that (a) is included in the normal
78909     form of packaging a Major Component, but which is not part of that
78910     Major Component, and (b) serves only to enable use of the work with
78911     that Major Component, or to implement a Standard Interface for
78912     which an implementation is available to the public in source code
78913     form.  A “Major Component”, in this context, means a major
78914     essential component (kernel, window system, and so on) of the
78915     specific operating system (if any) on which the executable work
78916     runs, or a compiler used to produce the work, or an object code
78917     interpreter used to run it.
78918
78919     The “Corresponding Source” for a work in object code form means all
78920     the source code needed to generate, install, and (for an executable
78921     work) run the object code and to modify the work, including scripts
78922     to control those activities.  However, it does not include the
78923     work’s System Libraries, or general-purpose tools or generally
78924     available free programs which are used unmodified in performing
78925     those activities but which are not part of the work.  For example,
78926     Corresponding Source includes interface definition files associated
78927     with source files for the work, and the source code for shared
78928     libraries and dynamically linked subprograms that the work is
78929     specifically designed to require, such as by intimate data
78930     communication or control flow between those subprograms and other
78931     parts of the work.
78932
78933     The Corresponding Source need not include anything that users can
78934     regenerate automatically from other parts of the Corresponding
78935     Source.
78936
78937     The Corresponding Source for a work in source code form is that
78938     same work.
78939
78940  2. Basic Permissions.
78941
78942     All rights granted under this License are granted for the term of
78943     copyright on the Program, and are irrevocable provided the stated
78944     conditions are met.  This License explicitly affirms your unlimited
78945     permission to run the unmodified Program.  The output from running
78946     a covered work is covered by this License only if the output, given
78947     its content, constitutes a covered work.  This License acknowledges
78948     your rights of fair use or other equivalent, as provided by
78949     copyright law.
78950
78951     You may make, run and propagate covered works that you do not
78952     convey, without conditions so long as your license otherwise
78953     remains in force.  You may convey covered works to others for the
78954     sole purpose of having them make modifications exclusively for you,
78955     or provide you with facilities for running those works, provided
78956     that you comply with the terms of this License in conveying all
78957     material for which you do not control copyright.  Those thus making
78958     or running the covered works for you must do so exclusively on your
78959     behalf, under your direction and control, on terms that prohibit
78960     them from making any copies of your copyrighted material outside
78961     their relationship with you.
78962
78963     Conveying under any other circumstances is permitted solely under
78964     the conditions stated below.  Sublicensing is not allowed; section
78965     10 makes it unnecessary.
78966
78967  3. Protecting Users’ Legal Rights From Anti-Circumvention Law.
78968
78969     No covered work shall be deemed part of an effective technological
78970     measure under any applicable law fulfilling obligations under
78971     article 11 of the WIPO copyright treaty adopted on 20 December
78972     1996, or similar laws prohibiting or restricting circumvention of
78973     such measures.
78974
78975     When you convey a covered work, you waive any legal power to forbid
78976     circumvention of technological measures to the extent such
78977     circumvention is effected by exercising rights under this License
78978     with respect to the covered work, and you disclaim any intention to
78979     limit operation or modification of the work as a means of
78980     enforcing, against the work’s users, your or third parties’ legal
78981     rights to forbid circumvention of technological measures.
78982
78983  4. Conveying Verbatim Copies.
78984
78985     You may convey verbatim copies of the Program’s source code as you
78986     receive it, in any medium, provided that you conspicuously and
78987     appropriately publish on each copy an appropriate copyright notice;
78988     keep intact all notices stating that this License and any
78989     non-permissive terms added in accord with section 7 apply to the
78990     code; keep intact all notices of the absence of any warranty; and
78991     give all recipients a copy of this License along with the Program.
78992
78993     You may charge any price or no price for each copy that you convey,
78994     and you may offer support or warranty protection for a fee.
78995
78996  5. Conveying Modified Source Versions.
78997
78998     You may convey a work based on the Program, or the modifications to
78999     produce it from the Program, in the form of source code under the
79000     terms of section 4, provided that you also meet all of these
79001     conditions:
79002
79003       a. The work must carry prominent notices stating that you
79004          modified it, and giving a relevant date.
79005
79006       b. The work must carry prominent notices stating that it is
79007          released under this License and any conditions added under
79008          section 7.  This requirement modifies the requirement in
79009          section 4 to “keep intact all notices”.
79010
79011       c. You must license the entire work, as a whole, under this
79012          License to anyone who comes into possession of a copy.  This
79013          License will therefore apply, along with any applicable
79014          section 7 additional terms, to the whole of the work, and all
79015          its parts, regardless of how they are packaged.  This License
79016          gives no permission to license the work in any other way, but
79017          it does not invalidate such permission if you have separately
79018          received it.
79019
79020       d. If the work has interactive user interfaces, each must display
79021          Appropriate Legal Notices; however, if the Program has
79022          interactive interfaces that do not display Appropriate Legal
79023          Notices, your work need not make them do so.
79024
79025     A compilation of a covered work with other separate and independent
79026     works, which are not by their nature extensions of the covered
79027     work, and which are not combined with it such as to form a larger
79028     program, in or on a volume of a storage or distribution medium, is
79029     called an “aggregate” if the compilation and its resulting
79030     copyright are not used to limit the access or legal rights of the
79031     compilation’s users beyond what the individual works permit.
79032     Inclusion of a covered work in an aggregate does not cause this
79033     License to apply to the other parts of the aggregate.
79034
79035  6. Conveying Non-Source Forms.
79036
79037     You may convey a covered work in object code form under the terms
79038     of sections 4 and 5, provided that you also convey the
79039     machine-readable Corresponding Source under the terms of this
79040     License, in one of these ways:
79041
79042       a. Convey the object code in, or embodied in, a physical product
79043          (including a physical distribution medium), accompanied by the
79044          Corresponding Source fixed on a durable physical medium
79045          customarily used for software interchange.
79046
79047       b. Convey the object code in, or embodied in, a physical product
79048          (including a physical distribution medium), accompanied by a
79049          written offer, valid for at least three years and valid for as
79050          long as you offer spare parts or customer support for that
79051          product model, to give anyone who possesses the object code
79052          either (1) a copy of the Corresponding Source for all the
79053          software in the product that is covered by this License, on a
79054          durable physical medium customarily used for software
79055          interchange, for a price no more than your reasonable cost of
79056          physically performing this conveying of source, or (2) access
79057          to copy the Corresponding Source from a network server at no
79058          charge.
79059
79060       c. Convey individual copies of the object code with a copy of the
79061          written offer to provide the Corresponding Source.  This
79062          alternative is allowed only occasionally and noncommercially,
79063          and only if you received the object code with such an offer,
79064          in accord with subsection 6b.
79065
79066       d. Convey the object code by offering access from a designated
79067          place (gratis or for a charge), and offer equivalent access to
79068          the Corresponding Source in the same way through the same
79069          place at no further charge.  You need not require recipients
79070          to copy the Corresponding Source along with the object code.
79071          If the place to copy the object code is a network server, the
79072          Corresponding Source may be on a different server (operated by
79073          you or a third party) that supports equivalent copying
79074          facilities, provided you maintain clear directions next to the
79075          object code saying where to find the Corresponding Source.
79076          Regardless of what server hosts the Corresponding Source, you
79077          remain obligated to ensure that it is available for as long as
79078          needed to satisfy these requirements.
79079
79080       e. Convey the object code using peer-to-peer transmission,
79081          provided you inform other peers where the object code and
79082          Corresponding Source of the work are being offered to the
79083          general public at no charge under subsection 6d.
79084
79085     A separable portion of the object code, whose source code is
79086     excluded from the Corresponding Source as a System Library, need
79087     not be included in conveying the object code work.
79088
79089     A “User Product” is either (1) a “consumer product”, which means
79090     any tangible personal property which is normally used for personal,
79091     family, or household purposes, or (2) anything designed or sold for
79092     incorporation into a dwelling.  In determining whether a product is
79093     a consumer product, doubtful cases shall be resolved in favor of
79094     coverage.  For a particular product received by a particular user,
79095     “normally used” refers to a typical or common use of that class of
79096     product, regardless of the status of the particular user or of the
79097     way in which the particular user actually uses, or expects or is
79098     expected to use, the product.  A product is a consumer product
79099     regardless of whether the product has substantial commercial,
79100     industrial or non-consumer uses, unless such uses represent the
79101     only significant mode of use of the product.
79102
79103     “Installation Information” for a User Product means any methods,
79104     procedures, authorization keys, or other information required to
79105     install and execute modified versions of a covered work in that
79106     User Product from a modified version of its Corresponding Source.
79107     The information must suffice to ensure that the continued
79108     functioning of the modified object code is in no case prevented or
79109     interfered with solely because modification has been made.
79110
79111     If you convey an object code work under this section in, or with,
79112     or specifically for use in, a User Product, and the conveying
79113     occurs as part of a transaction in which the right of possession
79114     and use of the User Product is transferred to the recipient in
79115     perpetuity or for a fixed term (regardless of how the transaction
79116     is characterized), the Corresponding Source conveyed under this
79117     section must be accompanied by the Installation Information.  But
79118     this requirement does not apply if neither you nor any third party
79119     retains the ability to install modified object code on the User
79120     Product (for example, the work has been installed in ROM).
79121
79122     The requirement to provide Installation Information does not
79123     include a requirement to continue to provide support service,
79124     warranty, or updates for a work that has been modified or installed
79125     by the recipient, or for the User Product in which it has been
79126     modified or installed.  Access to a network may be denied when the
79127     modification itself materially and adversely affects the operation
79128     of the network or violates the rules and protocols for
79129     communication across the network.
79130
79131     Corresponding Source conveyed, and Installation Information
79132     provided, in accord with this section must be in a format that is
79133     publicly documented (and with an implementation available to the
79134     public in source code form), and must require no special password
79135     or key for unpacking, reading or copying.
79136
79137  7. Additional Terms.
79138
79139     “Additional permissions” are terms that supplement the terms of
79140     this License by making exceptions from one or more of its
79141     conditions.  Additional permissions that are applicable to the
79142     entire Program shall be treated as though they were included in
79143     this License, to the extent that they are valid under applicable
79144     law.  If additional permissions apply only to part of the Program,
79145     that part may be used separately under those permissions, but the
79146     entire Program remains governed by this License without regard to
79147     the additional permissions.
79148
79149     When you convey a copy of a covered work, you may at your option
79150     remove any additional permissions from that copy, or from any part
79151     of it.  (Additional permissions may be written to require their own
79152     removal in certain cases when you modify the work.)  You may place
79153     additional permissions on material, added by you to a covered work,
79154     for which you have or can give appropriate copyright permission.
79155
79156     Notwithstanding any other provision of this License, for material
79157     you add to a covered work, you may (if authorized by the copyright
79158     holders of that material) supplement the terms of this License with
79159     terms:
79160
79161       a. Disclaiming warranty or limiting liability differently from
79162          the terms of sections 15 and 16 of this License; or
79163
79164       b. Requiring preservation of specified reasonable legal notices
79165          or author attributions in that material or in the Appropriate
79166          Legal Notices displayed by works containing it; or
79167
79168       c. Prohibiting misrepresentation of the origin of that material,
79169          or requiring that modified versions of such material be marked
79170          in reasonable ways as different from the original version; or
79171
79172       d. Limiting the use for publicity purposes of names of licensors
79173          or authors of the material; or
79174
79175       e. Declining to grant rights under trademark law for use of some
79176          trade names, trademarks, or service marks; or
79177
79178       f. Requiring indemnification of licensors and authors of that
79179          material by anyone who conveys the material (or modified
79180          versions of it) with contractual assumptions of liability to
79181          the recipient, for any liability that these contractual
79182          assumptions directly impose on those licensors and authors.
79183
79184     All other non-permissive additional terms are considered “further
79185     restrictions” within the meaning of section 10.  If the Program as
79186     you received it, or any part of it, contains a notice stating that
79187     it is governed by this License along with a term that is a further
79188     restriction, you may remove that term.  If a license document
79189     contains a further restriction but permits relicensing or conveying
79190     under this License, you may add to a covered work material governed
79191     by the terms of that license document, provided that the further
79192     restriction does not survive such relicensing or conveying.
79193
79194     If you add terms to a covered work in accord with this section, you
79195     must place, in the relevant source files, a statement of the
79196     additional terms that apply to those files, or a notice indicating
79197     where to find the applicable terms.
79198
79199     Additional terms, permissive or non-permissive, may be stated in
79200     the form of a separately written license, or stated as exceptions;
79201     the above requirements apply either way.
79202
79203  8. Termination.
79204
79205     You may not propagate or modify a covered work except as expressly
79206     provided under this License.  Any attempt otherwise to propagate or
79207     modify it is void, and will automatically terminate your rights
79208     under this License (including any patent licenses granted under the
79209     third paragraph of section 11).
79210
79211     However, if you cease all violation of this License, then your
79212     license from a particular copyright holder is reinstated (a)
79213     provisionally, unless and until the copyright holder explicitly and
79214     finally terminates your license, and (b) permanently, if the
79215     copyright holder fails to notify you of the violation by some
79216     reasonable means prior to 60 days after the cessation.
79217
79218     Moreover, your license from a particular copyright holder is
79219     reinstated permanently if the copyright holder notifies you of the
79220     violation by some reasonable means, this is the first time you have
79221     received notice of violation of this License (for any work) from
79222     that copyright holder, and you cure the violation prior to 30 days
79223     after your receipt of the notice.
79224
79225     Termination of your rights under this section does not terminate
79226     the licenses of parties who have received copies or rights from you
79227     under this License.  If your rights have been terminated and not
79228     permanently reinstated, you do not qualify to receive new licenses
79229     for the same material under section 10.
79230
79231  9. Acceptance Not Required for Having Copies.
79232
79233     You are not required to accept this License in order to receive or
79234     run a copy of the Program.  Ancillary propagation of a covered work
79235     occurring solely as a consequence of using peer-to-peer
79236     transmission to receive a copy likewise does not require
79237     acceptance.  However, nothing other than this License grants you
79238     permission to propagate or modify any covered work.  These actions
79239     infringe copyright if you do not accept this License.  Therefore,
79240     by modifying or propagating a covered work, you indicate your
79241     acceptance of this License to do so.
79242
79243  10. Automatic Licensing of Downstream Recipients.
79244
79245     Each time you convey a covered work, the recipient automatically
79246     receives a license from the original licensors, to run, modify and
79247     propagate that work, subject to this License.  You are not
79248     responsible for enforcing compliance by third parties with this
79249     License.
79250
79251     An “entity transaction” is a transaction transferring control of an
79252     organization, or substantially all assets of one, or subdividing an
79253     organization, or merging organizations.  If propagation of a
79254     covered work results from an entity transaction, each party to that
79255     transaction who receives a copy of the work also receives whatever
79256     licenses to the work the party’s predecessor in interest had or
79257     could give under the previous paragraph, plus a right to possession
79258     of the Corresponding Source of the work from the predecessor in
79259     interest, if the predecessor has it or can get it with reasonable
79260     efforts.
79261
79262     You may not impose any further restrictions on the exercise of the
79263     rights granted or affirmed under this License.  For example, you
79264     may not impose a license fee, royalty, or other charge for exercise
79265     of rights granted under this License, and you may not initiate
79266     litigation (including a cross-claim or counterclaim in a lawsuit)
79267     alleging that any patent claim is infringed by making, using,
79268     selling, offering for sale, or importing the Program or any portion
79269     of it.
79270
79271  11. Patents.
79272
79273     A “contributor” is a copyright holder who authorizes use under this
79274     License of the Program or a work on which the Program is based.
79275     The work thus licensed is called the contributor’s “contributor
79276     version”.
79277
79278     A contributor’s “essential patent claims” are all patent claims
79279     owned or controlled by the contributor, whether already acquired or
79280     hereafter acquired, that would be infringed by some manner,
79281     permitted by this License, of making, using, or selling its
79282     contributor version, but do not include claims that would be
79283     infringed only as a consequence of further modification of the
79284     contributor version.  For purposes of this definition, “control”
79285     includes the right to grant patent sublicenses in a manner
79286     consistent with the requirements of this License.
79287
79288     Each contributor grants you a non-exclusive, worldwide,
79289     royalty-free patent license under the contributor’s essential
79290     patent claims, to make, use, sell, offer for sale, import and
79291     otherwise run, modify and propagate the contents of its contributor
79292     version.
79293
79294     In the following three paragraphs, a “patent license” is any
79295     express agreement or commitment, however denominated, not to
79296     enforce a patent (such as an express permission to practice a
79297     patent or covenant not to sue for patent infringement).  To “grant”
79298     such a patent license to a party means to make such an agreement or
79299     commitment not to enforce a patent against the party.
79300
79301     If you convey a covered work, knowingly relying on a patent
79302     license, and the Corresponding Source of the work is not available
79303     for anyone to copy, free of charge and under the terms of this
79304     License, through a publicly available network server or other
79305     readily accessible means, then you must either (1) cause the
79306     Corresponding Source to be so available, or (2) arrange to deprive
79307     yourself of the benefit of the patent license for this particular
79308     work, or (3) arrange, in a manner consistent with the requirements
79309     of this License, to extend the patent license to downstream
79310     recipients.  “Knowingly relying” means you have actual knowledge
79311     that, but for the patent license, your conveying the covered work
79312     in a country, or your recipient’s use of the covered work in a
79313     country, would infringe one or more identifiable patents in that
79314     country that you have reason to believe are valid.
79315
79316     If, pursuant to or in connection with a single transaction or
79317     arrangement, you convey, or propagate by procuring conveyance of, a
79318     covered work, and grant a patent license to some of the parties
79319     receiving the covered work authorizing them to use, propagate,
79320     modify or convey a specific copy of the covered work, then the
79321     patent license you grant is automatically extended to all
79322     recipients of the covered work and works based on it.
79323
79324     A patent license is “discriminatory” if it does not include within
79325     the scope of its coverage, prohibits the exercise of, or is
79326     conditioned on the non-exercise of one or more of the rights that
79327     are specifically granted under this License.  You may not convey a
79328     covered work if you are a party to an arrangement with a third
79329     party that is in the business of distributing software, under which
79330     you make payment to the third party based on the extent of your
79331     activity of conveying the work, and under which the third party
79332     grants, to any of the parties who would receive the covered work
79333     from you, a discriminatory patent license (a) in connection with
79334     copies of the covered work conveyed by you (or copies made from
79335     those copies), or (b) primarily for and in connection with specific
79336     products or compilations that contain the covered work, unless you
79337     entered into that arrangement, or that patent license was granted,
79338     prior to 28 March 2007.
79339
79340     Nothing in this License shall be construed as excluding or limiting
79341     any implied license or other defenses to infringement that may
79342     otherwise be available to you under applicable patent law.
79343
79344  12. No Surrender of Others’ Freedom.
79345
79346     If conditions are imposed on you (whether by court order, agreement
79347     or otherwise) that contradict the conditions of this License, they
79348     do not excuse you from the conditions of this License.  If you
79349     cannot convey a covered work so as to satisfy simultaneously your
79350     obligations under this License and any other pertinent obligations,
79351     then as a consequence you may not convey it at all.  For example,
79352     if you agree to terms that obligate you to collect a royalty for
79353     further conveying from those to whom you convey the Program, the
79354     only way you could satisfy both those terms and this License would
79355     be to refrain entirely from conveying the Program.
79356
79357  13. Use with the GNU Affero General Public License.
79358
79359     Notwithstanding any other provision of this License, you have
79360     permission to link or combine any covered work with a work licensed
79361     under version 3 of the GNU Affero General Public License into a
79362     single combined work, and to convey the resulting work.  The terms
79363     of this License will continue to apply to the part which is the
79364     covered work, but the special requirements of the GNU Affero
79365     General Public License, section 13, concerning interaction through
79366     a network will apply to the combination as such.
79367
79368  14. Revised Versions of this License.
79369
79370     The Free Software Foundation may publish revised and/or new
79371     versions of the GNU General Public License from time to time.  Such
79372     new versions will be similar in spirit to the present version, but
79373     may differ in detail to address new problems or concerns.
79374
79375     Each version is given a distinguishing version number.  If the
79376     Program specifies that a certain numbered version of the GNU
79377     General Public License “or any later version” applies to it, you
79378     have the option of following the terms and conditions either of
79379     that numbered version or of any later version published by the Free
79380     Software Foundation.  If the Program does not specify a version
79381     number of the GNU General Public License, you may choose any
79382     version ever published by the Free Software Foundation.
79383
79384     If the Program specifies that a proxy can decide which future
79385     versions of the GNU General Public License can be used, that
79386     proxy’s public statement of acceptance of a version permanently
79387     authorizes you to choose that version for the Program.
79388
79389     Later license versions may give you additional or different
79390     permissions.  However, no additional obligations are imposed on any
79391     author or copyright holder as a result of your choosing to follow a
79392     later version.
79393
79394  15. Disclaimer of Warranty.
79395
79396     THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
79397     APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE
79398     COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS”
79399     WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
79400     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
79401     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE
79402     RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
79403     SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
79404     NECESSARY SERVICING, REPAIR OR CORRECTION.
79405
79406  16. Limitation of Liability.
79407
79408     IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
79409     WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES
79410     AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
79411     DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
79412     CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
79413     THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
79414     BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
79415     PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
79416     PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
79417     THE POSSIBILITY OF SUCH DAMAGES.
79418
79419  17. Interpretation of Sections 15 and 16.
79420
79421     If the disclaimer of warranty and limitation of liability provided
79422     above cannot be given local legal effect according to their terms,
79423     reviewing courts shall apply local law that most closely
79424     approximates an absolute waiver of all civil liability in
79425     connection with the Program, unless a warranty or assumption of
79426     liability accompanies a copy of the Program in return for a fee.
79427
79428END OF TERMS AND CONDITIONS
79429===========================
79430
79431How to Apply These Terms to Your New Programs
79432=============================================
79433
79434If you develop a new program, and you want it to be of the greatest
79435possible use to the public, the best way to achieve this is to make it
79436free software which everyone can redistribute and change under these
79437terms.
79438
79439   To do so, attach the following notices to the program.  It is safest
79440to attach them to the start of each source file to most effectively
79441state the exclusion of warranty; and each file should have at least the
79442“copyright” line and a pointer to where the full notice is found.
79443
79444     ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
79445     Copyright (C) YEAR NAME OF AUTHOR
79446
79447     This program is free software: you can redistribute it and/or modify
79448     it under the terms of the GNU General Public License as published by
79449     the Free Software Foundation, either version 3 of the License, or (at
79450     your option) any later version.
79451
79452     This program is distributed in the hope that it will be useful, but
79453     WITHOUT ANY WARRANTY; without even the implied warranty of
79454     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
79455     General Public License for more details.
79456
79457     You should have received a copy of the GNU General Public License
79458     along with this program.  If not, see <https://www.gnu.org/licenses/>.
79459
79460   Also add information on how to contact you by electronic and paper
79461mail.
79462
79463   If the program does terminal interaction, make it output a short
79464notice like this when it starts in an interactive mode:
79465
79466     PROGRAM Copyright (C) YEAR NAME OF AUTHOR
79467     This program comes with ABSOLUTELY NO WARRANTY; for details type ‘show w’.
79468     This is free software, and you are welcome to redistribute it
79469     under certain conditions; type ‘show c’ for details.
79470
79471   The hypothetical commands ‘show w’ and ‘show c’ should show the
79472appropriate parts of the General Public License.  Of course, your
79473program’s commands might be different; for a GUI interface, you would
79474use an “about box”.
79475
79476   You should also get your employer (if you work as a programmer) or
79477school, if any, to sign a “copyright disclaimer” for the program, if
79478necessary.  For more information on this, and how to apply and follow
79479the GNU GPL, see <https://www.gnu.org/licenses/>.
79480
79481   The GNU General Public License does not permit incorporating your
79482program into proprietary programs.  If your program is a subroutine
79483library, you may consider it more useful to permit linking proprietary
79484applications with the library.  If this is what you want to do, use the
79485GNU Lesser General Public License instead of this License.  But first,
79486please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
79487
79488
79489File: elisp.info,  Node: Tips,  Next: GNU Emacs Internals,  Prev: GPL,  Up: Top
79490
79491Appendix D Tips and Conventions
79492*******************************
79493
79494This chapter describes no additional features of Emacs Lisp.  Instead it
79495gives advice on making effective use of the features described in the
79496previous chapters, and describes conventions Emacs Lisp programmers
79497should follow.
79498
79499   You can automatically check some of the conventions described below
79500by running the command ‘M-x checkdoc <RET>’ when visiting a Lisp file.
79501It cannot check all of the conventions, and not all the warnings it
79502gives necessarily correspond to problems, but it is worth examining them
79503all.  Alternatively, use the command ‘M-x checkdoc-current-buffer <RET>’
79504to check the conventions in the current buffer, or ‘checkdoc-file’ when
79505you want to check a file in batch mode, e.g., with a command run by
79506‘M-x compile <RET>’.
79507
79508* Menu:
79509
79510* Coding Conventions::        Conventions for clean and robust programs.
79511* Key Binding Conventions::   Which keys should be bound by which programs.
79512* Programming Tips::          Making Emacs code fit smoothly in Emacs.
79513* Compilation Tips::          Making compiled code run fast.
79514* Warning Tips::              Turning off compiler warnings.
79515* Documentation Tips::        Writing readable documentation strings.
79516* Comment Tips::              Conventions for writing comments.
79517* Library Headers::           Standard headers for library packages.
79518
79519
79520File: elisp.info,  Node: Coding Conventions,  Next: Key Binding Conventions,  Up: Tips
79521
79522D.1 Emacs Lisp Coding Conventions
79523=================================
79524
79525Here are conventions that you should follow when writing Emacs Lisp code
79526intended for widespread use:
79527
79528   • Simply loading a package should not change Emacs’s editing
79529     behavior.  Include a command or commands to enable and disable the
79530     feature, or to invoke it.
79531
79532     This convention is mandatory for any file that includes custom
79533     definitions.  If fixing such a file to follow this convention
79534     requires an incompatible change, go ahead and make the incompatible
79535     change; don’t postpone it.
79536
79537   • You should choose a short word to distinguish your program from
79538     other Lisp programs.  The names of all global symbols in your
79539     program, that is the names of variables, constants, and functions,
79540     should begin with that chosen prefix.  Separate the prefix from the
79541     rest of the name with a hyphen, ‘-’.  This practice helps avoid
79542     name conflicts, since all global variables in Emacs Lisp share the
79543     same name space, and all functions share another name space(1).
79544     Use two hyphens to separate prefix and name if the symbol is not
79545     meant to be used by other packages.
79546
79547     Occasionally, for a command name intended for users to use, it is
79548     more convenient if some words come before the package’s name
79549     prefix.  For example, it is our convention to have commands that
79550     list objects named as ‘list-SOMETHING’, e.g., a package called
79551     ‘frob’ could have a command ‘list-frobs’, when its other global
79552     symbols begin with ‘frob-’.  Also, constructs that define
79553     functions, variables, etc., work better if they start with ‘defun’
79554     or ‘defvar’, so put the name prefix later on in the name.
79555
79556     This recommendation applies even to names for traditional Lisp
79557     primitives that are not primitives in Emacs Lisp—such as
79558     ‘copy-list’.  Believe it or not, there is more than one plausible
79559     way to define ‘copy-list’.  Play it safe; append your name prefix
79560     to produce a name like ‘foo-copy-list’ or ‘mylib-copy-list’
79561     instead.
79562
79563     If you write a function that you think ought to be added to Emacs
79564     under a certain name, such as ‘twiddle-files’, don’t call it by
79565     that name in your program.  Call it ‘mylib-twiddle-files’ in your
79566     program, and send mail to ‘bug-gnu-emacs@gnu.org’ suggesting we add
79567     it to Emacs.  If and when we do, we can change the name easily
79568     enough.
79569
79570     If one prefix is insufficient, your package can use two or three
79571     alternative common prefixes, so long as they make sense.
79572
79573   • We recommend enabling ‘lexical-binding’ in new code, and converting
79574     existing Emacs Lisp code to enable ‘lexical-binding’ if it doesn’t
79575     already.  *Note Using Lexical Binding::.
79576
79577   • Put a call to ‘provide’ at the end of each separate Lisp file.
79578     *Note Named Features::.
79579
79580   • If a file requires certain other Lisp programs to be loaded
79581     beforehand, then the comments at the beginning of the file should
79582     say so.  Also, use ‘require’ to make sure they are loaded.  *Note
79583     Named Features::.
79584
79585   • If a file FOO uses a macro defined in another file BAR, but does
79586     not use any functions or variables defined in BAR, then FOO should
79587     contain the following expression:
79588
79589          (eval-when-compile (require 'BAR))
79590
79591     This tells Emacs to load BAR just before byte-compiling FOO, so
79592     that the macro definition is available during compilation.  Using
79593     ‘eval-when-compile’ avoids loading BAR when the compiled version of
79594     FOO is _used_.  It should be called before the first use of the
79595     macro in the file.  *Note Compiling Macros::.
79596
79597   • Avoid loading additional libraries at run time unless they are
79598     really needed.  If your file simply cannot work without some other
79599     library, then just ‘require’ that library at the top-level and be
79600     done with it.  But if your file contains several independent
79601     features, and only one or two require the extra library, then
79602     consider putting ‘require’ statements inside the relevant functions
79603     rather than at the top-level.  Or use ‘autoload’ statements to load
79604     the extra library when needed.  This way people who don’t use those
79605     aspects of your file do not need to load the extra library.
79606
79607   • If you need Common Lisp extensions, use the ‘cl-lib’ library rather
79608     than the old ‘cl’ library.  The latter does not use a clean
79609     namespace (i.e., its definitions do not start with a ‘cl-’ prefix).
79610     If your package loads ‘cl’ at run time, that could cause name
79611     clashes for users who don’t use that package.
79612
79613     There is no problem with using the ‘cl’ package at _compile_ time,
79614     with ‘(eval-when-compile (require 'cl))’.  That’s sufficient for
79615     using the macros in the ‘cl’ package, because the compiler expands
79616     them before generating the byte-code.  It is still better to use
79617     the more modern ‘cl-lib’ in this case, though.
79618
79619   • When defining a major mode, please follow the major mode
79620     conventions.  *Note Major Mode Conventions::.
79621
79622   • When defining a minor mode, please follow the minor mode
79623     conventions.  *Note Minor Mode Conventions::.
79624
79625   • If the purpose of a function is to tell you whether a certain
79626     condition is true or false, give the function a name that ends in
79627     ‘p’ (which stands for “predicate”).  If the name is one word, add
79628     just ‘p’; if the name is multiple words, add ‘-p’.  Examples are
79629     ‘framep’ and ‘frame-live-p’.  We recommend to avoid using this ‘-p’
79630     suffix in boolean variable names, unless the variable is bound to a
79631     predicate function; instead, use a ‘-flag’ suffix or names like
79632     ‘is-foo’.
79633
79634   • If the purpose of a variable is to store a single function, give it
79635     a name that ends in ‘-function’.  If the purpose of a variable is
79636     to store a list of functions (i.e., the variable is a hook), please
79637     follow the naming conventions for hooks.  *Note Hooks::.
79638
79639   • If loading the file adds functions to hooks, define a function
79640     ‘FEATURE-unload-function’, where FEATURE is the name of the feature
79641     the package provides, and make it undo any such changes.  Using
79642     ‘unload-feature’ to unload the file will run this function.  *Note
79643     Unloading::.
79644
79645   • It is a bad idea to define aliases for the Emacs primitives.
79646     Normally you should use the standard names instead.  The case where
79647     an alias may be useful is where it facilitates backwards
79648     compatibility or portability.
79649
79650   • If a package needs to define an alias or a new function for
79651     compatibility with some other version of Emacs, name it with the
79652     package prefix, not with the raw name with which it occurs in the
79653     other version.  Here is an example from Gnus, which provides many
79654     examples of such compatibility issues.
79655
79656          (defalias 'gnus-point-at-bol
79657            (if (fboundp 'point-at-bol)
79658                'point-at-bol
79659              'line-beginning-position))
79660
79661   • Redefining or advising an Emacs primitive is a bad idea.  It may do
79662     the right thing for a particular program, but there is no telling
79663     what other programs might break as a result.
79664
79665   • It is likewise a bad idea for one Lisp package to advise a function
79666     in another Lisp package (*note Advising Functions::).
79667
79668   • Avoid using ‘eval-after-load’ and ‘with-eval-after-load’ in
79669     libraries and packages (*note Hooks for Loading::).  This feature
79670     is meant for personal customizations; using it in a Lisp program is
79671     unclean, because it modifies the behavior of another Lisp file in a
79672     way that’s not visible in that file.  This is an obstacle for
79673     debugging, much like advising a function in the other package.
79674
79675   • If a file does replace any of the standard functions or library
79676     programs of Emacs, prominent comments at the beginning of the file
79677     should say which functions are replaced, and how the behavior of
79678     the replacements differs from that of the originals.
79679
79680   • Constructs that define a function or variable should be macros, not
79681     functions, and their names should start with ‘define-’.  The macro
79682     should receive the name to be defined as the first argument.  That
79683     will help various tools find the definition automatically.  Avoid
79684     constructing the names in the macro itself, since that would
79685     confuse these tools.
79686
79687   • In some other systems there is a convention of choosing variable
79688     names that begin and end with ‘*’.  We don’t use that convention in
79689     Emacs Lisp, so please don’t use it in your programs.  (Emacs uses
79690     such names only for special-purpose buffers.)  People will find
79691     Emacs more coherent if all libraries use the same conventions.
79692
79693   • The default file coding system for Emacs Lisp source files is UTF-8
79694     (*note Text Representations::).  In the rare event that your
79695     program contains characters which are _not_ in UTF-8, you should
79696     specify an appropriate coding system in the source file’s ‘-*-’
79697     line or local variables list.  *Note Local Variables in Files:
79698     (emacs)File Variables.
79699
79700   • Indent the file using the default indentation parameters.
79701
79702   • Don’t make a habit of putting close-parentheses on lines by
79703     themselves; Lisp programmers find this disconcerting.
79704
79705   • Please put a copyright notice and copying permission notice on the
79706     file if you distribute copies.  *Note Library Headers::.
79707
79708   ---------- Footnotes ----------
79709
79710   (1) The benefits of a Common Lisp-style package system are considered
79711not to outweigh the costs.
79712
79713
79714File: elisp.info,  Node: Key Binding Conventions,  Next: Programming Tips,  Prev: Coding Conventions,  Up: Tips
79715
79716D.2 Key Binding Conventions
79717===========================
79718
79719   • Many special major modes, like Dired, Info, Compilation, and Occur,
79720     are designed to handle read-only text that contains “hyper-links”.
79721     Such a major mode should redefine ‘mouse-2’ and <RET> to follow the
79722     links.  It should also set up a ‘follow-link’ condition, so that
79723     the link obeys ‘mouse-1-click-follows-link’.  *Note Clickable
79724     Text::.  *Note Buttons::, for an easy method of implementing such
79725     clickable links.
79726
79727   • Don’t define ‘C-c LETTER’ as a key in Lisp programs.  Sequences
79728     consisting of ‘C-c’ and a letter (either upper or lower case) are
79729     reserved for users; they are the *only* sequences reserved for
79730     users, so do not block them.
79731
79732     Changing all the Emacs major modes to respect this convention was a
79733     lot of work; abandoning this convention would make that work go to
79734     waste, and inconvenience users.  Please comply with it.
79735
79736   • Function keys <F5> through <F9> without modifier keys are also
79737     reserved for users to define.
79738
79739   • Sequences consisting of ‘C-c’ followed by a control character or a
79740     digit are reserved for major modes.
79741
79742   • Sequences consisting of ‘C-c’ followed by ‘{’, ‘}’, ‘<’, ‘>’, ‘:’
79743     or ‘;’ are also reserved for major modes.
79744
79745   • Sequences consisting of ‘C-c’ followed by any other ASCII
79746     punctuation or symbol character are allocated for minor modes.
79747     Using them in a major mode is not absolutely prohibited, but if you
79748     do that, the major mode binding may be shadowed from time to time
79749     by minor modes.
79750
79751   • Don’t bind ‘C-h’ following any prefix character (including ‘C-c’).
79752     If you don’t bind ‘C-h’, it is automatically available as a help
79753     character for listing the subcommands of the prefix character.
79754
79755   • Don’t bind a key sequence ending in <ESC> except following another
79756     <ESC>.  (That is, it is OK to bind a sequence ending in ‘<ESC>
79757     <ESC>’.)
79758
79759     The reason for this rule is that a non-prefix binding for <ESC> in
79760     any context prevents recognition of escape sequences as function
79761     keys in that context.
79762
79763   • Similarly, don’t bind a key sequence ending in ‘C-g’, since that is
79764     commonly used to cancel a key sequence.
79765
79766   • Anything that acts like a temporary mode or state that the user can
79767     enter and leave should define ‘<ESC> <ESC>’ or ‘<ESC> <ESC> <ESC>’
79768     as a way to escape.
79769
79770     For a state that accepts ordinary Emacs commands, or more generally
79771     any kind of state in which <ESC> followed by a function key or
79772     arrow key is potentially meaningful, then you must not define
79773     ‘<ESC> <ESC>’, since that would preclude recognizing an escape
79774     sequence after <ESC>.  In these states, you should define ‘<ESC>
79775     <ESC> <ESC>’ as the way to escape.  Otherwise, define ‘<ESC> <ESC>’
79776     instead.
79777
79778
79779File: elisp.info,  Node: Programming Tips,  Next: Compilation Tips,  Prev: Key Binding Conventions,  Up: Tips
79780
79781D.3 Emacs Programming Tips
79782==========================
79783
79784Following these conventions will make your program fit better into Emacs
79785when it runs.
79786
79787   • Don’t use ‘next-line’ or ‘previous-line’ in programs; nearly
79788     always, ‘forward-line’ is more convenient as well as more
79789     predictable and robust.  *Note Text Lines::.
79790
79791   • Don’t call functions that set the mark, unless setting the mark is
79792     one of the intended features of your program.  The mark is a
79793     user-level feature, so it is incorrect to change the mark except to
79794     supply a value for the user’s benefit.  *Note The Mark::.
79795
79796     In particular, don’t use any of these functions:
79797
79798        • ‘beginning-of-buffer’, ‘end-of-buffer’
79799        • ‘replace-string’, ‘replace-regexp’
79800        • ‘insert-file’, ‘insert-buffer’
79801
79802     If you just want to move point, or replace a certain string, or
79803     insert a file or buffer’s contents, without any of the other
79804     features intended for interactive users, you can replace these
79805     functions with one or two lines of simple Lisp code.
79806
79807   • Use lists rather than vectors, except when there is a particular
79808     reason to use a vector.  Lisp has more facilities for manipulating
79809     lists than for vectors, and working with lists is usually more
79810     convenient.
79811
79812     Vectors are advantageous for tables that are substantial in size
79813     and are accessed in random order (not searched front to back),
79814     provided there is no need to insert or delete elements (only lists
79815     allow that).
79816
79817   • The recommended way to show a message in the echo area is with the
79818     ‘message’ function, not ‘princ’.  *Note The Echo Area::.
79819
79820   • When you encounter an error condition, call the function ‘error’
79821     (or ‘signal’).  The function ‘error’ does not return.  *Note
79822     Signaling Errors::.
79823
79824     Don’t use ‘message’, ‘throw’, ‘sleep-for’, or ‘beep’ to report
79825     errors.
79826
79827   • An error message should start with a capital letter but should not
79828     end with a period.
79829
79830   • A question asked in the minibuffer with ‘yes-or-no-p’ or ‘y-or-n-p’
79831     should start with a capital letter and end with ‘? ’.
79832
79833   • When you mention a default value in a minibuffer prompt, put it and
79834     the word ‘default’ inside parentheses.  It should look like this:
79835
79836          Enter the answer (default 42):
79837
79838   • In ‘interactive’, if you use a Lisp expression to produce a list of
79839     arguments, don’t try to provide the correct default values for
79840     region or position arguments.  Instead, provide ‘nil’ for those
79841     arguments if they were not specified, and have the function body
79842     compute the default value when the argument is ‘nil’.  For
79843     instance, write this:
79844
79845          (defun foo (pos)
79846            (interactive
79847             (list (if SPECIFIED SPECIFIED-POS)))
79848            (unless pos (setq pos DEFAULT-POS))
79849            ...)
79850
79851     rather than this:
79852
79853          (defun foo (pos)
79854            (interactive
79855             (list (if SPECIFIED SPECIFIED-POS
79856                       DEFAULT-POS)))
79857            ...)
79858
79859     This is so that repetition of the command will recompute these
79860     defaults based on the current circumstances.
79861
79862     You do not need to take such precautions when you use interactive
79863     specs ‘d’, ‘m’ and ‘r’, because they make special arrangements to
79864     recompute the argument values on repetition of the command.
79865
79866   • Many commands that take a long time to execute display a message
79867     that says something like ‘Operating...’ when they start, and change
79868     it to ‘Operating...done’ when they finish.  Please keep the style
79869     of these messages uniform: _no_ space around the ellipsis, and _no_
79870     period after ‘done’.  *Note Progress::, for an easy way to generate
79871     such messages.
79872
79873   • Try to avoid using recursive edits.  Instead, do what the Rmail ‘e’
79874     command does: use a new local keymap that contains a command
79875     defined to switch back to the old local keymap.  Or simply switch
79876     to another buffer and let the user switch back at will.  *Note
79877     Recursive Editing::.
79878
79879
79880File: elisp.info,  Node: Compilation Tips,  Next: Warning Tips,  Prev: Programming Tips,  Up: Tips
79881
79882D.4 Tips for Making Compiled Code Fast
79883======================================
79884
79885Here are ways of improving the execution speed of byte-compiled Lisp
79886programs.
79887
79888   • Profile your program, to find out where the time is being spent.
79889     *Note Profiling::.
79890
79891   • Use iteration rather than recursion whenever possible.  Function
79892     calls are slow in Emacs Lisp even when a compiled function is
79893     calling another compiled function.
79894
79895   • Using the primitive list-searching functions ‘memq’, ‘member’,
79896     ‘assq’, or ‘assoc’ is even faster than explicit iteration.  It can
79897     be worth rearranging a data structure so that one of these
79898     primitive search functions can be used.
79899
79900   • Certain built-in functions are handled specially in byte-compiled
79901     code, avoiding the need for an ordinary function call.  It is a
79902     good idea to use these functions rather than alternatives.  To see
79903     whether a function is handled specially by the compiler, examine
79904     its ‘byte-compile’ property.  If the property is non-‘nil’, then
79905     the function is handled specially.
79906
79907     For example, the following input will show you that ‘aref’ is
79908     compiled specially (*note Array Functions::):
79909
79910          (get 'aref 'byte-compile)
79911               ⇒ byte-compile-two-args
79912
79913     Note that in this case (and many others), you must first load the
79914     ‘bytecomp’ library, which defines the ‘byte-compile’ property.
79915
79916   • If calling a small function accounts for a substantial part of your
79917     program’s running time, make the function inline.  This eliminates
79918     the function call overhead.  Since making a function inline reduces
79919     the flexibility of changing the program, don’t do it unless it
79920     gives a noticeable speedup in something slow enough that users care
79921     about the speed.  *Note Inline Functions::.
79922
79923
79924File: elisp.info,  Node: Warning Tips,  Next: Documentation Tips,  Prev: Compilation Tips,  Up: Tips
79925
79926D.5 Tips for Avoiding Compiler Warnings
79927=======================================
79928
79929   • Try to avoid compiler warnings about undefined free variables, by
79930     adding dummy ‘defvar’ definitions for these variables, like this:
79931
79932          (defvar foo)
79933
79934     Such a definition has no effect except to tell the compiler not to
79935     warn about uses of the variable ‘foo’ in this file.
79936
79937   • Similarly, to avoid a compiler warning about an undefined function
79938     that you know _will_ be defined, use a ‘declare-function’ statement
79939     (*note Declaring Functions::).
79940
79941   • If you use many functions, macros, and variables from a certain
79942     file, you can add a ‘require’ (*note require: Named Features.) for
79943     that package to avoid compilation warnings for them, like this:
79944
79945          (require 'foo)
79946
79947     If you need only macros from some file, you can require it only at
79948     compile time (*note Eval During Compile::).  For instance,
79949
79950          (eval-when-compile
79951            (require 'foo))
79952
79953   • If you bind a variable in one function, and use it or set it in
79954     another function, the compiler warns about the latter function
79955     unless the variable has a definition.  But adding a definition
79956     would be unclean if the variable has a short name, since Lisp
79957     packages should not define short variable names.  The right thing
79958     to do is to rename this variable to start with the name prefix used
79959     for the other functions and variables in your package.
79960
79961   • The last resort for avoiding a warning, when you want to do
79962     something that is usually a mistake but you know is not a mistake
79963     in your usage, is to put it inside ‘with-no-warnings’.  *Note
79964     Compiler Errors::.
79965
79966
79967File: elisp.info,  Node: Documentation Tips,  Next: Comment Tips,  Prev: Warning Tips,  Up: Tips
79968
79969D.6 Tips for Documentation Strings
79970==================================
79971
79972Here are some tips and conventions for the writing of documentation
79973strings.  You can check many of these conventions by running the command
79974‘M-x checkdoc-minor-mode’.
79975
79976   • Every command, function, or variable intended for users to know
79977     about should have a documentation string.
79978
79979   • An internal variable or subroutine of a Lisp program might as well
79980     have a documentation string.  Documentation strings take up very
79981     little space in a running Emacs.
79982
79983   • Format the documentation string so that it fits in an Emacs window
79984     on an 80-column screen.  It is a good idea for most lines to be no
79985     wider than 60 characters.  The first line should not be wider than
79986     67 characters or it will look bad in the output of ‘apropos’.
79987
79988     You can fill the text if that looks good.  Emacs Lisp mode fills
79989     documentation strings to the width specified by
79990     ‘emacs-lisp-docstring-fill-column’.  However, you can sometimes
79991     make a documentation string much more readable by adjusting its
79992     line breaks with care.  Use blank lines between sections if the
79993     documentation string is long.
79994
79995   • The first line of the documentation string should consist of one or
79996     two complete sentences that stand on their own as a summary.  ‘M-x
79997     apropos’ displays just the first line, and if that line’s contents
79998     don’t stand on their own, the result looks bad.  In particular,
79999     start the first line with a capital letter and end it with a
80000     period.
80001
80002     For a function, the first line should briefly answer the question,
80003     “What does this function do?” For a variable, the first line should
80004     briefly answer the question, “What does this value mean?”
80005
80006     Don’t limit the documentation string to one line; use as many lines
80007     as you need to explain the details of how to use the function or
80008     variable.  Please use complete sentences for the rest of the text
80009     too.
80010
80011   • When the user tries to use a disabled command, Emacs displays just
80012     the first paragraph of its documentation string—everything through
80013     the first blank line.  If you wish, you can choose which
80014     information to include before the first blank line so as to make
80015     this display useful.
80016
80017   • The first line should mention all the important arguments of the
80018     function, and should mention them in the order that they are
80019     written in a function call.  If the function has many arguments,
80020     then it is not feasible to mention them all in the first line; in
80021     that case, the first line should mention the first few arguments,
80022     including the most important arguments.
80023
80024   • When a function’s documentation string mentions the value of an
80025     argument of the function, use the argument name in capital letters
80026     as if it were a name for that value.  Thus, the documentation
80027     string of the function ‘eval’ refers to its first argument as
80028     ‘FORM’, because the actual argument name is ‘form’:
80029
80030          Evaluate FORM and return its value.
80031
80032     Also write metasyntactic variables in capital letters, such as when
80033     you show the decomposition of a list or vector into subunits, some
80034     of which may vary.  ‘KEY’ and ‘VALUE’ in the following example
80035     illustrate this practice:
80036
80037          The argument TABLE should be an alist whose elements
80038          have the form (KEY . VALUE).  Here, KEY is ...
80039
80040   • Never change the case of a Lisp symbol when you mention it in a doc
80041     string.  If the symbol’s name is ‘foo’, write “foo”, not “Foo”
80042     (which is a different symbol).
80043
80044     This might appear to contradict the policy of writing function
80045     argument values, but there is no real contradiction; the argument
80046     _value_ is not the same thing as the _symbol_ that the function
80047     uses to hold the value.
80048
80049     If this puts a lower-case letter at the beginning of a sentence and
80050     that annoys you, rewrite the sentence so that the symbol is not at
80051     the start of it.
80052
80053   • Do not start or end a documentation string with whitespace.
80054
80055   • *Do not* indent subsequent lines of a documentation string so that
80056     the text is lined up in the source code with the text of the first
80057     line.  This looks nice in the source code, but looks bizarre when
80058     users view the documentation.  Remember that the indentation before
80059     the starting double-quote is not part of the string!
80060
80061   • When a documentation string refers to a Lisp symbol, write it as it
80062     would be printed (which usually means in lower case), surrounding
80063     it with curved single quotes (‘..’).  There are two exceptions:
80064     write ‘t’ and ‘nil’ without surrounding punctuation.  For example:
80065
80066           CODE can be ‘lambda’, nil, or t.
80067
80068     *Note (emacs)Quotation Marks::, for how to enter curved single
80069     quotes.
80070
80071     Documentation strings can also use an older single-quoting
80072     convention, which quotes symbols with grave accent ` and apostrophe
80073     ': `like-this' rather than ‘like-this’.  This older convention was
80074     designed for now-obsolete displays in which grave accent and
80075     apostrophe were mirror images.  Documentation using this convention
80076     is converted to the user’s preferred format when it is copied into
80077     a help buffer.  *Note Keys in Documentation::.
80078
80079     Help mode automatically creates a hyperlink when a documentation
80080     string uses a single-quoted symbol name, if the symbol has either a
80081     function or a variable definition.  You do not need to do anything
80082     special to make use of this feature.  However, when a symbol has
80083     both a function definition and a variable definition, and you want
80084     to refer to just one of them, you can specify which one by writing
80085     one of the words ‘variable’, ‘option’, ‘function’, or ‘command’,
80086     immediately before the symbol name.  (Case makes no difference in
80087     recognizing these indicator words.)  For example, if you write
80088
80089          This function sets the variable `buffer-file-name'.
80090
80091     then the hyperlink will refer only to the variable documentation of
80092     ‘buffer-file-name’, and not to its function documentation.
80093
80094     If a symbol has a function definition and/or a variable definition,
80095     but those are irrelevant to the use of the symbol that you are
80096     documenting, you can write the words ‘symbol’ or ‘program’ before
80097     the symbol name to prevent making any hyperlink.  For example,
80098
80099          If the argument KIND-OF-RESULT is the symbol `list',
80100          this function returns a list of all the objects
80101          that satisfy the criterion.
80102
80103     does not make a hyperlink to the documentation, irrelevant here, of
80104     the function ‘list’.
80105
80106     Normally, no hyperlink is made for a variable without variable
80107     documentation.  You can force a hyperlink for such variables by
80108     preceding them with one of the words ‘variable’ or ‘option’.
80109
80110     Hyperlinks for faces are only made if the face name is preceded or
80111     followed by the word ‘face’.  In that case, only the face
80112     documentation will be shown, even if the symbol is also defined as
80113     a variable or as a function.
80114
80115     To make a hyperlink to Info documentation, write the single-quoted
80116     name of the Info node (or anchor), preceded by ‘info node’, ‘Info
80117     node’, ‘info anchor’ or ‘Info anchor’.  The Info file name defaults
80118     to ‘emacs’.  For example,
80119
80120          See Info node `Font Lock' and Info node `(elisp)Font Lock Basics'.
80121
80122     Finally, to create a hyperlink to URLs, write the single-quoted
80123     URL, preceded by ‘URL’.  For example,
80124
80125          The home page for the GNU project has more information (see URL
80126          `https://www.gnu.org/').
80127
80128   • Don’t write key sequences directly in documentation strings.
80129     Instead, use the ‘\\[...]’ construct to stand for them.  For
80130     example, instead of writing ‘C-f’, write the construct
80131     ‘\\[forward-char]’.  When Emacs displays the documentation string,
80132     it substitutes whatever key is currently bound to ‘forward-char’.
80133     (This is normally ‘C-f’, but it may be some other character if the
80134     user has moved key bindings.)  *Note Keys in Documentation::.
80135
80136   • In documentation strings for a major mode, you will want to refer
80137     to the key bindings of that mode’s local map, rather than global
80138     ones.  Therefore, use the construct ‘\\<...>’ once in the
80139     documentation string to specify which key map to use.  Do this
80140     before the first use of ‘\\[...]’.  The text inside the ‘\\<...>’
80141     should be the name of the variable containing the local keymap for
80142     the major mode.
80143
80144     It is not practical to use ‘\\[...]’ very many times, because
80145     display of the documentation string will become slow.  So use this
80146     to describe the most important commands in your major mode, and
80147     then use ‘\\{...}’ to display the rest of the mode’s keymap.
80148
80149   • For consistency, phrase the verb in the first sentence of a
80150     function’s documentation string as an imperative—for instance, use
80151     “Return the cons of A and B.” in preference to “Returns the cons of
80152     A and B.” Usually it looks good to do likewise for the rest of the
80153     first paragraph.  Subsequent paragraphs usually look better if each
80154     sentence is indicative and has a proper subject.
80155
80156   • The documentation string for a function that is a yes-or-no
80157     predicate should start with words such as “Return t if”, to
80158     indicate explicitly what constitutes truth.  The word “return”
80159     avoids starting the sentence with lower-case “t”, which could be
80160     somewhat distracting.
80161
80162   • Write documentation strings in the active voice, not the passive,
80163     and in the present tense, not the future.  For instance, use
80164     “Return a list containing A and B.” instead of “A list containing A
80165     and B will be returned.”
80166
80167   • Avoid using the word “cause” (or its equivalents) unnecessarily.
80168     Instead of, “Cause Emacs to display text in boldface”, write just
80169     “Display text in boldface”.
80170
80171   • Avoid using “iff” (a mathematics term meaning “if and only if”),
80172     since many people are unfamiliar with it and mistake it for a typo.
80173     In most cases, the meaning is clear with just “if”.  Otherwise, try
80174     to find an alternate phrasing that conveys the meaning.
80175
80176   • Try to avoid using abbreviations such as “e.g.” (for “for
80177     example”), “i.e.” (for “that is”), “no.” (for “number”), “c.f.80178     (for “in contrast to”) and “w.r.t.” (for “with respect to”) as much
80179     as possible.  It is almost always clearer and easier to read the
80180     expanded version.(1)
80181
80182   • When a command is meaningful only in a certain mode or situation,
80183     do mention that in the documentation string.  For example, the
80184     documentation of ‘dired-find-file’ is:
80185
80186          In Dired, visit the file or directory named on this line.
80187
80188   • When you define a variable that represents an option users might
80189     want to set, use ‘defcustom’.  *Note Defining Variables::.
80190
80191   • The documentation string for a variable that is a yes-or-no flag
80192     should start with words such as “Non-nil means”, to make it clear
80193     that all non-‘nil’ values are equivalent and indicate explicitly
80194     what ‘nil’ and non-‘nil’ mean.
80195
80196   • If a line in a documentation string begins with an
80197     open-parenthesis, consider writing a backslash before the
80198     open-parenthesis, like this:
80199
80200          The argument FOO can be either a number
80201          \(a buffer position) or a string (a file name).
80202
80203     This avoids a bug in Emacs versions older than 27.1, where the ‘(’
80204     was treated as the start of a defun (*note Defuns: (emacs)Defuns.).
80205     If you do not anticipate anyone editing your code with older Emacs
80206     versions, there is no need for this work-around.
80207
80208   ---------- Footnotes ----------
80209
80210   (1) We do use these occasionally, but try not to overdo it.
80211
80212
80213File: elisp.info,  Node: Comment Tips,  Next: Library Headers,  Prev: Documentation Tips,  Up: Tips
80214
80215D.7 Tips on Writing Comments
80216============================
80217
80218We recommend these conventions for comments:
80219
80220‘;’
80221     Comments that start with a single semicolon, ‘;’, should all be
80222     aligned to the same column on the right of the source code.  Such
80223     comments usually explain how the code on that line does its job.
80224     For example:
80225
80226          (setq base-version-list                 ; There was a base
80227                (assoc (substring fn 0 start-vn)  ; version to which
80228                       file-version-assoc-list))  ; this looks like
80229                                                  ; a subversion.
80230
80231‘;;’
80232     Comments that start with two semicolons, ‘;;’, should be aligned to
80233     the same level of indentation as the code.  Such comments usually
80234     describe the purpose of the following lines or the state of the
80235     program at that point.  For example:
80236
80237          (prog1 (setq auto-fill-function
80238                       ...
80239                       ...
80240            ;; Update mode line.
80241            (force-mode-line-update)))
80242
80243     We also normally use two semicolons for comments outside functions.
80244
80245          ;; This Lisp code is run in Emacs when it is to operate as
80246          ;; a server for other processes.
80247
80248     If a function has no documentation string, it should instead have a
80249     two-semicolon comment right before the function, explaining what
80250     the function does and how to call it properly.  Explain precisely
80251     what each argument means and how the function interprets its
80252     possible values.  It is much better to convert such comments to
80253     documentation strings, though.
80254
80255‘;;;’
80256     Comments that start with three semicolons, ‘;;;’, should start at
80257     the left margin.  We use them for comments which should be
80258     considered a heading by Outline minor mode.  By default, comments
80259     starting with at least three semicolons (followed by a single space
80260     and a non-whitespace character) are considered headings, comments
80261     starting with two or fewer are not.  Historically, triple-semicolon
80262     comments have also been used for commenting out lines within a
80263     function, but this use is discouraged.
80264
80265     When commenting out entire functions, use two semicolons.
80266
80267‘;;;;’
80268     Comments that start with four (or more) semicolons, ‘;;;;’, should
80269     be aligned to the left margin and are used for headings of major
80270     sections of a program.  For example:
80271
80272          ;;;; The kill ring
80273
80274     If you wish to have sub-headings under these heading, use more
80275     semicolons to nest these sub-headings.
80276
80277Generally speaking, the ‘M-;’ (‘comment-dwim’) command automatically
80278starts a comment of the appropriate type; or indents an existing comment
80279to the right place, depending on the number of semicolons.  *Note
80280Manipulating Comments: (emacs)Comments.
80281
80282
80283File: elisp.info,  Node: Library Headers,  Prev: Comment Tips,  Up: Tips
80284
80285D.8 Conventional Headers for Emacs Libraries
80286============================================
80287
80288Emacs has conventions for using special comments in Lisp libraries to
80289divide them into sections and give information such as who wrote them.
80290Using a standard format for these items makes it easier for tools (and
80291people) to extract the relevant information.  This section explains
80292these conventions, starting with an example:
80293
80294     ;;; foo.el --- Support for the Foo programming language  -*- lexical-binding: t; -*-
80295
80296     ;; Copyright (C) 2010-2021 Your Name
80297
80298     ;; Author: Your Name <yourname@example.com>
80299     ;; Maintainer: Someone Else <someone@example.com>
80300     ;; Created: 14 Jul 2010
80301     ;; Keywords: languages
80302     ;; URL: https://example.com/foo
80303
80304     ;; This file is not part of GNU Emacs.
80305
80306     ;; This file is free software...
80307     ...
80308     ;; along with this file.  If not, see <https://www.gnu.org/licenses/>.
80309
80310   The very first line should have this format:
80311
80312     ;;; FILENAME --- DESCRIPTION  -*- lexical-binding: t; -*-
80313
80314The description should be contained in one line.  If the file needs to
80315set more variables in the ‘-*-’ specification, add it after
80316‘lexical-binding’.  If this would make the first line too long, use a
80317Local Variables section at the end of the file.
80318
80319   The copyright notice usually lists your name (if you wrote the file).
80320If you have an employer who claims copyright on your work, you might
80321need to list them instead.  Do not say that the copyright holder is the
80322Free Software Foundation (or that the file is part of GNU Emacs) unless
80323your file has been accepted into the Emacs distribution.  For more
80324information on the form of copyright and license notices, see the guide
80325on the GNU website (https://www.gnu.org/licenses/gpl-howto.html).
80326
80327   After the copyright notice come several “header comment” lines, each
80328beginning with ‘;; HEADER-NAME:’.  Here is a table of the conventional
80329possibilities for HEADER-NAME:
80330
80331‘Author’
80332     This line states the name and email address of at least the
80333     principal author of the library.  If there are multiple authors,
80334     list them on continuation lines led by ‘;;’ and a tab or at least
80335     two spaces.  We recommend including a contact email address, of the
80336     form ‘<...>’.  For example:
80337
80338          ;; Author: Your Name <yourname@example.com>
80339          ;;      Someone Else <someone@example.com>
80340          ;;      Another Person <another@example.com>
80341
80342‘Maintainer’
80343     This header has the same format as the Author header.  It lists the
80344     person(s) who currently maintain(s) the file (respond to bug
80345     reports, etc.).
80346
80347     If there is no maintainer line, the person(s) in the Author field
80348     is/are presumed to be the maintainers.  Some files in Emacs use
80349     ‘emacs-devel@gnu.org’ for the maintainer, which means the author is
80350     no longer responsible for the file, and that it is maintained as
80351     part of Emacs.
80352
80353‘Created’
80354     This optional line gives the original creation date of the file,
80355     and is for historical interest only.
80356
80357‘Version’
80358     If you wish to record version numbers for the individual Lisp
80359     program, put them in this line.  Lisp files distributed with Emacs
80360     generally do not have a ‘Version’ header, since the version number
80361     of Emacs itself serves the same purpose.  If you are distributing a
80362     collection of multiple files, we recommend not writing the version
80363     in every file, but only the main one.
80364
80365‘Keywords’
80366     This line lists keywords for the ‘finder-by-keyword’ help command.
80367     Please use that command to see a list of the meaningful keywords.
80368     The command ‘M-x checkdoc-package-keywords <RET>’ will find and
80369     display any keywords that are not in ‘finder-known-keywords’.  If
80370     you set the variable ‘checkdoc-package-keywords-flag’ non-‘nil’,
80371     checkdoc commands will include the keyword verification in its
80372     checks.
80373
80374     This field is how people will find your package when they’re
80375     looking for things by topic.  To separate the keywords, you can use
80376     spaces, commas, or both.
80377
80378     The name of this field is unfortunate, since people often assume it
80379     is the place to write arbitrary keywords that describe their
80380     package, rather than just the relevant Finder keywords.
80381
80382‘Homepage’
80383‘URL’
80384     These lines state the homepage of the library.
80385
80386‘Package-Version’
80387     If ‘Version’ is not suitable for use by the package manager, then a
80388     package can define ‘Package-Version’; it will be used instead.
80389     This is handy if ‘Version’ is an RCS id or something else that
80390     cannot be parsed by ‘version-to-list’.  *Note Packaging Basics::.
80391
80392‘Package-Requires’
80393     If this exists, it names packages on which the current package
80394     depends for proper operation.  *Note Packaging Basics::.  This is
80395     used by the package manager both at download time (to ensure that a
80396     complete set of packages is downloaded) and at activation time (to
80397     ensure that a package is only activated if all its dependencies
80398     have been).
80399
80400     Its format is a list of lists on a single line.  The ‘car’ of each
80401     sub-list is the name of a package, as a symbol.  The ‘cadr’ of each
80402     sub-list is the minimum acceptable version number, as a string that
80403     can be parsed by ‘version-to-list’.  An entry that lacks a version
80404     (i.e., an entry which is just a symbol, or a sub-list of one
80405     element) is equivalent to entry with version "0".  For instance:
80406
80407          ;; Package-Requires: ((gnus "1.0") (bubbles "2.7.2") cl-lib (seq))
80408
80409     The package code automatically defines a package named ‘emacs’ with
80410     the version number of the currently running Emacs.  This can be
80411     used to require a minimal version of Emacs for a package.
80412
80413   Just about every Lisp library ought to have the ‘Author’ and
80414‘Keywords’ header comment lines.  Use the others if they are
80415appropriate.  You can also put in header lines with other header
80416names—they have no standard meanings, so they can’t do any harm.
80417
80418   We use additional stylized comments to subdivide the contents of the
80419library file.  These should be separated from anything else by blank
80420lines.  Here is a table of them:
80421
80422‘;;; Commentary:’
80423     This begins introductory comments that explain how the library
80424     works.  It should come right after the copying permissions,
80425     terminated by a ‘Change Log’, ‘History’ or ‘Code’ comment line.
80426     This text is used by the Finder package, so it should make sense in
80427     that context.
80428
80429‘;;; Change Log:’
80430     This begins an optional log of changes to the file over time.
80431     Don’t put too much information in this section—it is better to keep
80432     the detailed logs in a version control system (as Emacs does) or in
80433     a separate ‘ChangeLog’ file.  ‘History’ is an alternative to
80434     ‘Change Log’.
80435
80436‘;;; Code:’
80437     This begins the actual code of the program.
80438
80439‘;;; FILENAME ends here’
80440     This is the “footer line”; it appears at the very end of the file.
80441     Its purpose is to enable people to detect truncated versions of the
80442     file from the lack of a footer line.
80443
80444
80445File: elisp.info,  Node: GNU Emacs Internals,  Next: Standard Errors,  Prev: Tips,  Up: Top
80446
80447Appendix E GNU Emacs Internals
80448******************************
80449
80450This chapter describes how the runnable Emacs executable is dumped with
80451the preloaded Lisp libraries in it, how storage is allocated, and some
80452internal aspects of GNU Emacs that may be of interest to C programmers.
80453
80454* Menu:
80455
80456* Building Emacs::      How the dumped Emacs is made.
80457* Pure Storage::        Kludge to make preloaded Lisp functions shareable.
80458* Garbage Collection::  Reclaiming space for Lisp objects no longer used.
80459* Stack-allocated Objects::    Temporary conses and strings on C stack.
80460* Memory Usage::        Info about total size of Lisp objects made so far.
80461* C Dialect::           What C variant Emacs is written in.
80462* Writing Emacs Primitives::   Writing C code for Emacs.
80463* Writing Dynamic Modules::    Writing loadable modules for Emacs.
80464* Object Internals::    Data formats of buffers, windows, processes.
80465* C Integer Types::     How C integer types are used inside Emacs.
80466
80467
80468File: elisp.info,  Node: Building Emacs,  Next: Pure Storage,  Up: GNU Emacs Internals
80469
80470E.1 Building Emacs
80471==================
80472
80473This section explains the steps involved in building the Emacs
80474executable.  You don’t have to know this material to build and install
80475Emacs, since the makefiles do all these things automatically.  This
80476information is pertinent to Emacs developers.
80477
80478   Building Emacs requires GNU Make version 3.81 or later.
80479
80480   Compilation of the C source files in the ‘src’ directory produces an
80481executable file called ‘temacs’, also called a “bare impure Emacs”.  It
80482contains the Emacs Lisp interpreter and I/O routines, but not the
80483editing commands.
80484
80485   The command ‘temacs -l loadup’ would run ‘temacs’ and direct it to
80486load ‘loadup.el’.  The ‘loadup’ library loads additional Lisp libraries,
80487which set up the normal Emacs editing environment.  After this step, the
80488Emacs executable is no longer “bare”.
80489
80490   Because it takes some time to load the standard Lisp files, the
80491‘temacs’ executable usually isn’t run directly by users.  Instead, one
80492of the last steps of building Emacs runs the command
80493‘temacs -batch -l loadup --temacs=DUMP-METHOD’.  The special option
80494‘--temacs’ tells ‘temacs’ how to record all the standard preloaded Lisp
80495functions and variables, so that when you subsequently run Emacs, it
80496will start much faster.  The ‘--temacs’ option requires an argument
80497DUMP-METHOD, which can be one of the following:
80498
80499‘pdump’
80500     Record the preloaded Lisp data in a “dump file”.  This method
80501     produces an additional data file which Emacs will load at startup.
80502     The produced dump file is usually called ‘emacs.pdmp’, and is
80503     installed in the Emacs ‘exec-directory’ (*note Help Functions::).
80504     This method is the most preferred one, as it does not require Emacs
80505     to employ any special techniques of memory allocation, which might
80506     get in the way of various memory-layout techniques used by modern
80507     systems to enhance security and privacy.
80508
80509‘pbootstrap’
80510     Like ‘pdump’, but used while “bootstrapping” Emacs, when no
80511     previous Emacs binary and no ‘*.elc’ byte-compiled Lisp files are
80512     available.  The produced dump file is usually named
80513bootstrap-emacs.pdmp’ in this case.
80514
80515‘dump’
80516     This method causes ‘temacs’ to dump out an executable program,
80517     called ‘emacs’, which has all the standard Lisp files already
80518     preloaded into it.  (The ‘-batch’ argument prevents ‘temacs’ from
80519     trying to initialize any of its data on the terminal, so that the
80520     tables of terminal information are empty in the dumped Emacs.)
80521     This method is also known as “unexec”, because it produces a
80522     program file from a running process, and thus is in some sense the
80523     opposite of executing a program to start a process.  Although this
80524     method was the way that Emacs traditionally saved its state, it is
80525     now deprecated.
80526
80527‘bootstrap’
80528     Like ‘dump’, but used when bootstrapping Emacs with the ‘unexec’
80529     method.
80530
80531   The dumped ‘emacs’ executable (also called a “pure” Emacs) is the one
80532which is installed.  If the portable dumper was used to build Emacs, the
80533‘emacs’ executable is actually an exact copy of ‘temacs’, and the
80534corresponding ‘emacs.pdmp’ file is installed as well.  The variable
80535‘preloaded-file-list’ stores a list of the preloaded Lisp files recorded
80536in the dump file or in the dumped Emacs executable.  If you port Emacs
80537to a new operating system, and are not able to implement dumping of any
80538kind, then Emacs must load ‘loadup.el’ each time it starts.
80539
80540   By default the dumped ‘emacs’ executable records details such as the
80541build time and host name.  Use the ‘--disable-build-details’ option of
80542‘configure’ to suppress these details, so that building and installing
80543Emacs twice from the same sources is more likely to result in identical
80544copies of Emacs.
80545
80546   You can specify additional files to preload by writing a library
80547named ‘site-load.el’ that loads them.  You may need to rebuild Emacs
80548with an added definition
80549
80550     #define SITELOAD_PURESIZE_EXTRA N
80551
80552to make N added bytes of pure space to hold the additional files; see
80553src/puresize.h’.  (Try adding increments of 20000 until it is big
80554enough.)  However, the advantage of preloading additional files
80555decreases as machines get faster.  On modern machines, it is usually not
80556advisable.
80557
80558   After ‘loadup.el’ reads ‘site-load.el’, it finds the documentation
80559strings for primitive and preloaded functions (and variables) in the
80560file ‘etc/DOC’ where they are stored, by calling ‘Snarf-documentation’
80561(*note Accessing Documentation: Definition of Snarf-documentation.).
80562
80563   You can specify other Lisp expressions to execute just before dumping
80564by putting them in a library named ‘site-init.el’.  This file is
80565executed after the documentation strings are found.
80566
80567   If you want to preload function or variable definitions, there are
80568three ways you can do this and make their documentation strings
80569accessible when you subsequently run Emacs:
80570
80571   • Arrange to scan these files when producing the ‘etc/DOC’ file, and
80572     load them with ‘site-load.el’.
80573
80574   • Load the files with ‘site-init.el’, then copy the files into the
80575     installation directory for Lisp files when you install Emacs.
80576
80577   • Specify a ‘nil’ value for ‘byte-compile-dynamic-docstrings’ as a
80578     local variable in each of these files, and load them with either
80579site-load.el’ or ‘site-init.el’.  (This method has the drawback
80580     that the documentation strings take up space in Emacs all the
80581     time.)
80582
80583   It is not advisable to put anything in ‘site-load.el’ or
80584site-init.el’ that would alter any of the features that users expect in
80585an ordinary unmodified Emacs.  If you feel you must override normal
80586features for your site, do it with ‘default.el’, so that users can
80587override your changes if they wish.  *Note Startup Summary::.  Note that
80588if either ‘site-load.el’ or ‘site-init.el’ changes ‘load-path’, the
80589changes will be lost after dumping.  *Note Library Search::.  To make a
80590permanent change to ‘load-path’, use the ‘--enable-locallisppath’ option
80591of ‘configure’.
80592
80593   In a package that can be preloaded, it is sometimes necessary (or
80594useful) to delay certain evaluations until Emacs subsequently starts up.
80595The vast majority of such cases relate to the values of customizable
80596variables.  For example, ‘tutorial-directory’ is a variable defined in
80597startup.el’, which is preloaded.  The default value is set based on
80598‘data-directory’.  The variable needs to access the value of
80599‘data-directory’ when Emacs starts, not when it is dumped, because the
80600Emacs executable has probably been installed in a different location
80601since it was dumped.
80602
80603 -- Function: custom-initialize-delay symbol value
80604     This function delays the initialization of SYMBOL to the next Emacs
80605     start.  You normally use this function by specifying it as the
80606     ‘:initialize’ property of a customizable variable.  (The argument
80607     VALUE is unused, and is provided only for compatibility with the
80608     form Custom expects.)
80609
80610   In the unlikely event that you need a more general functionality than
80611‘custom-initialize-delay’ provides, you can use ‘before-init-hook’
80612(*note Startup Summary::).
80613
80614 -- Function: dump-emacs-portable to-file &optional track-referrers
80615     This function dumps the current state of Emacs into a dump file
80616     TO-FILE, using the ‘pdump’ method.  Normally, the dump file is
80617     called ‘EMACS-NAME.dmp’, where EMACS-NAME is the name of the Emacs
80618     executable file.  The optional argument TRACK-REFERRERS, if
80619     non-‘nil’, causes the portable dumper to keep additional
80620     information to help track down the provenance of object types that
80621     are not yet supported by the ‘pdump’ method.
80622
80623     Although the portable dumper code can run on many platforms, the
80624     dump files that it produces are not portable—they can be loaded
80625     only by the Emacs executable that dumped them.
80626
80627     If you want to use this function in an Emacs that was already
80628     dumped, you must run Emacs with the ‘-batch’ option.
80629
80630 -- Function: dump-emacs to-file from-file
80631     This function dumps the current state of Emacs into an executable
80632     file TO-FILE, using the ‘unexec’ method.  It takes symbols from
80633     FROM-FILE (this is normally the executable file ‘temacs’).
80634
80635     This function cannot be used in an Emacs that was already dumped.
80636     This function is deprecated, and by default Emacs is built without
80637     ‘unexec’ support so this function is not available.
80638
80639 -- Function: pdumper-stats
80640     If the current Emacs session restored its state from a dump file,
80641     this function returns information about the dump file and the time
80642     it took to restore the Emacs state.  The value is an alist
80643     ‘((dumped-with-pdumper . t) (load-time . TIME) (dump-file-name . FILE))’,
80644     where FILE is the name of the dump file, and TIME is the time in
80645     seconds it took to restore the state from the dump file.  If the
80646     current session was not restored from a dump file, the value is
80647     nil.
80648
80649
80650File: elisp.info,  Node: Pure Storage,  Next: Garbage Collection,  Prev: Building Emacs,  Up: GNU Emacs Internals
80651
80652E.2 Pure Storage
80653================
80654
80655Emacs Lisp uses two kinds of storage for user-created Lisp objects:
80656“normal storage” and “pure storage”.  Normal storage is where all the
80657new data created during an Emacs session are kept (*note Garbage
80658Collection::).  Pure storage is used for certain data in the preloaded
80659standard Lisp files—data that should never change during actual use of
80660Emacs.
80661
80662   Pure storage is allocated only while ‘temacs’ is loading the standard
80663preloaded Lisp libraries.  In the file ‘emacs’, it is marked as
80664read-only (on operating systems that permit this), so that the memory
80665space can be shared by all the Emacs jobs running on the machine at
80666once.  Pure storage is not expandable; a fixed amount is allocated when
80667Emacs is compiled, and if that is not sufficient for the preloaded
80668libraries, ‘temacs’ allocates dynamic memory for the part that didn’t
80669fit.  If Emacs will be dumped using the ‘pdump’ method (*note Building
80670Emacs::), the pure-space overflow is of no special importance (it just
80671means some of the preloaded stuff cannot be shared with other Emacs
80672jobs).  However, if Emacs will be dumped using the now obsolete ‘unexec’
80673method, the resulting image will work, but garbage collection (*note
80674Garbage Collection::) is disabled in this situation, causing a memory
80675leak.  Such an overflow normally won’t happen unless you try to preload
80676additional libraries or add features to the standard ones.  Emacs will
80677display a warning about the overflow when it starts, if it was dumped
80678using ‘unexec’.  If this happens, you should increase the compilation
80679parameter ‘SYSTEM_PURESIZE_EXTRA’ in the file ‘src/puresize.h’ and
80680rebuild Emacs.
80681
80682 -- Function: purecopy object
80683     This function makes a copy in pure storage of OBJECT, and returns
80684     it.  It copies a string by simply making a new string with the same
80685     characters, but without text properties, in pure storage.  It
80686     recursively copies the contents of vectors and cons cells.  It does
80687     not make copies of other objects such as symbols, but just returns
80688     them unchanged.  It signals an error if asked to copy markers.
80689
80690     This function is a no-op except while Emacs is being built and
80691     dumped; it is usually called only in preloaded Lisp files.
80692
80693 -- Variable: pure-bytes-used
80694     The value of this variable is the number of bytes of pure storage
80695     allocated so far.  Typically, in a dumped Emacs, this number is
80696     very close to the total amount of pure storage available—if it were
80697     not, we would preallocate less.
80698
80699 -- Variable: purify-flag
80700     This variable determines whether ‘defun’ should make a copy of the
80701     function definition in pure storage.  If it is non-‘nil’, then the
80702     function definition is copied into pure storage.
80703
80704     This flag is ‘t’ while loading all of the basic functions for
80705     building Emacs initially (allowing those functions to be shareable
80706     and non-collectible).  Dumping Emacs as an executable always writes
80707     ‘nil’ in this variable, regardless of the value it actually has
80708     before and after dumping.
80709
80710     You should not change this flag in a running Emacs.
80711
80712
80713File: elisp.info,  Node: Garbage Collection,  Next: Stack-allocated Objects,  Prev: Pure Storage,  Up: GNU Emacs Internals
80714
80715E.3 Garbage Collection
80716======================
80717
80718When a program creates a list or the user defines a new function (such
80719as by loading a library), that data is placed in normal storage.  If
80720normal storage runs low, then Emacs asks the operating system to
80721allocate more memory.  Different types of Lisp objects, such as symbols,
80722cons cells, small vectors, markers, etc., are segregated in distinct
80723blocks in memory.  (Large vectors, long strings, buffers and certain
80724other editing types, which are fairly large, are allocated in individual
80725blocks, one per object; small strings are packed into blocks of 8k
80726bytes, and small vectors are packed into blocks of 4k bytes).
80727
80728   Beyond the basic vector, a lot of objects like markers, overlays and
80729buffers are managed as if they were vectors.  The corresponding C data
80730structures include the ‘union vectorlike_header’ field whose ‘size’
80731member contains the subtype enumerated by ‘enum pvec_type’ and an
80732information about how many ‘Lisp_Object’ fields this structure contains
80733and what the size of the rest data is.  This information is needed to
80734calculate the memory footprint of an object, and used by the vector
80735allocation code while iterating over the vector blocks.
80736
80737   It is quite common to use some storage for a while, then release it
80738by (for example) killing a buffer or deleting the last pointer to an
80739object.  Emacs provides a “garbage collector” to reclaim this abandoned
80740storage.  The garbage collector operates by finding and marking all Lisp
80741objects that are still accessible to Lisp programs.  To begin with, it
80742assumes all the symbols, their values and associated function
80743definitions, and any data presently on the stack, are accessible.  Any
80744objects that can be reached indirectly through other accessible objects
80745are also accessible.
80746
80747   When marking is finished, all objects still unmarked are garbage.  No
80748matter what the Lisp program or the user does, it is impossible to refer
80749to them, since there is no longer a way to reach them.  Their space
80750might as well be reused, since no one will miss them.  The second
80751(sweep) phase of the garbage collector arranges to reuse them.
80752
80753   The sweep phase puts unused cons cells onto a “free list” for future
80754allocation; likewise for symbols and markers.  It compacts the
80755accessible strings so they occupy fewer 8k blocks; then it frees the
80756other 8k blocks.  Unreachable vectors from vector blocks are coalesced
80757to create largest possible free areas; if a free area spans a complete
807584k block, that block is freed.  Otherwise, the free area is recorded in
80759a free list array, where each entry corresponds to a free list of areas
80760of the same size.  Large vectors, buffers, and other large objects are
80761allocated and freed individually.
80762
80763     Common Lisp note: Unlike other Lisps, GNU Emacs Lisp does not call
80764     the garbage collector when the free list is empty.  Instead, it
80765     simply requests the operating system to allocate more storage, and
80766     processing continues until ‘gc-cons-threshold’ bytes have been
80767     used.
80768
80769     This means that you can make sure that the garbage collector will
80770     not run during a certain portion of a Lisp program by calling the
80771     garbage collector explicitly just before it (provided that portion
80772     of the program does not use so much space as to force a second
80773     garbage collection).
80774
80775 -- Command: garbage-collect
80776     This command runs a garbage collection, and returns information on
80777     the amount of space in use.  (Garbage collection can also occur
80778     spontaneously if you use more than ‘gc-cons-threshold’ bytes of
80779     Lisp data since the previous garbage collection.)
80780
80781     ‘garbage-collect’ returns a list with information on amount of
80782     space in use, where each entry has the form ‘(NAME SIZE USED)’ or
80783     ‘(NAME SIZE USED FREE)’.  In the entry, NAME is a symbol describing
80784     the kind of objects this entry represents, SIZE is the number of
80785     bytes used by each one, USED is the number of those objects that
80786     were found live in the heap, and optional FREE is the number of
80787     those objects that are not live but that Emacs keeps around for
80788     future allocations.  So an overall result is:
80789
80790          ((conses CONS-SIZE USED-CONSES FREE-CONSES)
80791           (symbols SYMBOL-SIZE USED-SYMBOLS FREE-SYMBOLS)
80792           (strings STRING-SIZE USED-STRINGS FREE-STRINGS)
80793           (string-bytes BYTE-SIZE USED-BYTES)
80794           (vectors VECTOR-SIZE USED-VECTORS)
80795           (vector-slots SLOT-SIZE USED-SLOTS FREE-SLOTS)
80796           (floats FLOAT-SIZE USED-FLOATS FREE-FLOATS)
80797           (intervals INTERVAL-SIZE USED-INTERVALS FREE-INTERVALS)
80798           (buffers BUFFER-SIZE USED-BUFFERS)
80799           (heap UNIT-SIZE TOTAL-SIZE FREE-SIZE))
80800
80801     Here is an example:
80802
80803          (garbage-collect)
80804                ⇒ ((conses 16 49126 8058) (symbols 48 14607 0)
80805                           (strings 32 2942 2607)
80806                           (string-bytes 1 78607) (vectors 16 7247)
80807                           (vector-slots 8 341609 29474) (floats 8 71 102)
80808                           (intervals 56 27 26) (buffers 944 8)
80809                           (heap 1024 11715 2678))
80810
80811     Below is a table explaining each element.  Note that last ‘heap’
80812     entry is optional and present only if an underlying ‘malloc’
80813     implementation provides ‘mallinfo’ function.
80814
80815     CONS-SIZE
80816          Internal size of a cons cell, i.e., ‘sizeof (struct
80817          Lisp_Cons)’.
80818
80819     USED-CONSES
80820          The number of cons cells in use.
80821
80822     FREE-CONSES
80823          The number of cons cells for which space has been obtained
80824          from the operating system, but that are not currently being
80825          used.
80826
80827     SYMBOL-SIZE
80828          Internal size of a symbol, i.e., ‘sizeof (struct
80829          Lisp_Symbol)’.
80830
80831     USED-SYMBOLS
80832          The number of symbols in use.
80833
80834     FREE-SYMBOLS
80835          The number of symbols for which space has been obtained from
80836          the operating system, but that are not currently being used.
80837
80838     STRING-SIZE
80839          Internal size of a string header, i.e., ‘sizeof (struct
80840          Lisp_String)’.
80841
80842     USED-STRINGS
80843          The number of string headers in use.
80844
80845     FREE-STRINGS
80846          The number of string headers for which space has been obtained
80847          from the operating system, but that are not currently being
80848          used.
80849
80850     BYTE-SIZE
80851          This is used for convenience and equals to ‘sizeof (char)’.
80852
80853     USED-BYTES
80854          The total size of all string data in bytes.
80855
80856     VECTOR-SIZE
80857          Size in bytes of a vector of length 1, including its header.
80858
80859     USED-VECTORS
80860          The number of vector headers allocated from the vector blocks.
80861
80862     SLOT-SIZE
80863          Internal size of a vector slot, always equal to ‘sizeof
80864          (Lisp_Object)’.
80865
80866     USED-SLOTS
80867          The number of slots in all used vectors.  Slot counts might
80868          include some or all overhead from vector headers, depending on
80869          the platform.
80870
80871     FREE-SLOTS
80872          The number of free slots in all vector blocks.
80873
80874     FLOAT-SIZE
80875          Internal size of a float object, i.e., ‘sizeof (struct
80876          Lisp_Float)’.  (Do not confuse it with the native platform
80877          ‘float’ or ‘double’.)
80878
80879     USED-FLOATS
80880          The number of floats in use.
80881
80882     FREE-FLOATS
80883          The number of floats for which space has been obtained from
80884          the operating system, but that are not currently being used.
80885
80886     INTERVAL-SIZE
80887          Internal size of an interval object, i.e., ‘sizeof (struct
80888          interval)’.
80889
80890     USED-INTERVALS
80891          The number of intervals in use.
80892
80893     FREE-INTERVALS
80894          The number of intervals for which space has been obtained from
80895          the operating system, but that are not currently being used.
80896
80897     BUFFER-SIZE
80898          Internal size of a buffer, i.e., ‘sizeof (struct buffer)’.
80899          (Do not confuse with the value returned by ‘buffer-size’
80900          function.)
80901
80902     USED-BUFFERS
80903          The number of buffer objects in use.  This includes killed
80904          buffers invisible to users, i.e., all buffers in ‘all_buffers’
80905          list.
80906
80907     UNIT-SIZE
80908          The unit of heap space measurement, always equal to 1024
80909          bytes.
80910
80911     TOTAL-SIZE
80912          Total heap size, in UNIT-SIZE units.
80913
80914     FREE-SIZE
80915          Heap space which is not currently used, in UNIT-SIZE units.
80916
80917     If there was overflow in pure space (*note Pure Storage::), and
80918     Emacs was dumped using the (now obsolete) ‘unexec’ method (*note
80919     Building Emacs::), then ‘garbage-collect’ returns ‘nil’, because a
80920     real garbage collection cannot be done in that case.
80921
80922 -- User Option: garbage-collection-messages
80923     If this variable is non-‘nil’, Emacs displays a message at the
80924     beginning and end of garbage collection.  The default value is
80925     ‘nil’.
80926
80927 -- Variable: post-gc-hook
80928     This is a normal hook that is run at the end of garbage collection.
80929     Garbage collection is inhibited while the hook functions run, so be
80930     careful writing them.
80931
80932 -- User Option: gc-cons-threshold
80933     The value of this variable is the number of bytes of storage that
80934     must be allocated for Lisp objects after one garbage collection in
80935     order to trigger another garbage collection.  You can use the
80936     result returned by ‘garbage-collect’ to get an information about
80937     size of the particular object type; space allocated to the contents
80938     of buffers does not count.
80939
80940     The initial threshold value is ‘GC_DEFAULT_THRESHOLD’, defined in
80941alloc.c’.  Since it’s defined in ‘word_size’ units, the value is
80942     400,000 for the default 32-bit configuration and 800,000 for the
80943     64-bit one.  If you specify a larger value, garbage collection will
80944     happen less often.  This reduces the amount of time spent garbage
80945     collecting, but increases total memory use.  You may want to do
80946     this when running a program that creates lots of Lisp data.
80947
80948     You can make collections more frequent by specifying a smaller
80949     value, down to 1/10th of ‘GC_DEFAULT_THRESHOLD’.  A value less than
80950     this minimum will remain in effect only until the subsequent
80951     garbage collection, at which time ‘garbage-collect’ will set the
80952     threshold back to the minimum.
80953
80954 -- User Option: gc-cons-percentage
80955     The value of this variable specifies the amount of consing before a
80956     garbage collection occurs, as a fraction of the current heap size.
80957     This criterion and ‘gc-cons-threshold’ apply in parallel, and
80958     garbage collection occurs only when both criteria are satisfied.
80959
80960     As the heap size increases, the time to perform a garbage
80961     collection increases.  Thus, it can be desirable to do them less
80962     frequently in proportion.
80963
80964   Control over the garbage collector via ‘gc-cons-threshold’ and
80965‘gc-cons-percentage’ is only approximate.  Although Emacs checks for
80966threshold exhaustion regularly, for efficiency reasons it does not do so
80967immediately after every change to the heap or to ‘gc-cons-threshold’ or
80968‘gc-cons-percentage’, so exhausting the threshold does not immediately
80969trigger garbage collection.  Also, for efficiency in threshold
80970calculations Emacs approximates the heap size, which counts the bytes
80971used by currently-accessible objects in the heap.
80972
80973   The value returned by ‘garbage-collect’ describes the amount of
80974memory used by Lisp data, broken down by data type.  By contrast, the
80975function ‘memory-limit’ provides information on the total amount of
80976memory Emacs is currently using.
80977
80978 -- Function: memory-limit
80979     This function returns an estimate of the total amount of bytes of
80980     virtual memory that Emacs is currently using, divided by 1024.  You
80981     can use this to get a general idea of how your actions affect the
80982     memory usage.
80983
80984 -- Variable: memory-full
80985     This variable is ‘t’ if Emacs is nearly out of memory for Lisp
80986     objects, and ‘nil’ otherwise.
80987
80988 -- Function: memory-use-counts
80989     This returns a list of numbers that count the number of objects
80990     created in this Emacs session.  Each of these counters increments
80991     for a certain kind of object.  See the documentation string for
80992     details.
80993
80994 -- Function: memory-info
80995     This functions returns an amount of total system memory and how
80996     much of it is free.  On an unsupported system, the value may be
80997     ‘nil’.
80998
80999 -- Variable: gcs-done
81000     This variable contains the total number of garbage collections done
81001     so far in this Emacs session.
81002
81003 -- Variable: gc-elapsed
81004     This variable contains the total number of seconds of elapsed time
81005     during garbage collection so far in this Emacs session, as a
81006     floating-point number.
81007
81008
81009File: elisp.info,  Node: Stack-allocated Objects,  Next: Memory Usage,  Prev: Garbage Collection,  Up: GNU Emacs Internals
81010
81011E.4 Stack-allocated Objects
81012===========================
81013
81014The garbage collector described above is used to manage data visible
81015from Lisp programs, as well as most of the data internally used by the
81016Lisp interpreter.  Sometimes it may be useful to allocate temporary
81017internal objects using the C stack of the interpreter.  This can help
81018performance, as stack allocation is typically faster than using heap
81019memory to allocate and the garbage collector to free.  The downside is
81020that using such objects after they are freed results in undefined
81021behavior, so uses should be well thought out and carefully debugged by
81022using the ‘GC_CHECK_MARKED_OBJECTS’ feature (see ‘src/alloc.c’).  In
81023particular, stack-allocated objects should never be made visible to user
81024Lisp code.
81025
81026   Currently, cons cells and strings can be allocated this way.  This is
81027implemented by C macros like ‘AUTO_CONS’ and ‘AUTO_STRING’ that define a
81028named ‘Lisp_Object’ with block lifetime.  These objects are not freed by
81029the garbage collector; instead, they have automatic storage duration,
81030i.e., they are allocated like local variables and are automatically
81031freed at the end of execution of the C block that defined the object.
81032
81033   For performance reasons, stack-allocated strings are limited to ASCII
81034characters, and many of these strings are immutable, i.e., calling
81035‘ASET’ on them produces undefined behavior.
81036
81037
81038File: elisp.info,  Node: Memory Usage,  Next: C Dialect,  Prev: Stack-allocated Objects,  Up: GNU Emacs Internals
81039
81040E.5 Memory Usage
81041================
81042
81043These functions and variables give information about the total amount of
81044memory allocation that Emacs has done, broken down by data type.  Note
81045the difference between these and the values returned by
81046‘garbage-collect’; those count objects that currently exist, but these
81047count the number or size of all allocations, including those for objects
81048that have since been freed.
81049
81050 -- Variable: cons-cells-consed
81051     The total number of cons cells that have been allocated so far in
81052     this Emacs session.
81053
81054 -- Variable: floats-consed
81055     The total number of floats that have been allocated so far in this
81056     Emacs session.
81057
81058 -- Variable: vector-cells-consed
81059     The total number of vector cells that have been allocated so far in
81060     this Emacs session.  This includes vector-like objects such as
81061     markers and overlays, plus certain objects not visible to users.
81062
81063 -- Variable: symbols-consed
81064     The total number of symbols that have been allocated so far in this
81065     Emacs session.
81066
81067 -- Variable: string-chars-consed
81068     The total number of string characters that have been allocated so
81069     far in this session.
81070
81071 -- Variable: intervals-consed
81072     The total number of intervals that have been allocated so far in
81073     this Emacs session.
81074
81075 -- Variable: strings-consed
81076     The total number of strings that have been allocated so far in this
81077     Emacs session.
81078
81079
81080File: elisp.info,  Node: C Dialect,  Next: Writing Emacs Primitives,  Prev: Memory Usage,  Up: GNU Emacs Internals
81081
81082E.6 C Dialect
81083=============
81084
81085The C part of Emacs is portable to C99 or later: C11-specific features
81086such as ‘<stdalign.h>’ and ‘_Noreturn’ are not used without a check,
81087typically at configuration time, and the Emacs build procedure provides
81088a substitute implementation if necessary.  Some C11 features, such as
81089anonymous structures and unions, are too difficult to emulate, so they
81090are avoided entirely.
81091
81092   At some point in the future the base C dialect will no doubt change
81093to C11.
81094
81095
81096File: elisp.info,  Node: Writing Emacs Primitives,  Next: Writing Dynamic Modules,  Prev: C Dialect,  Up: GNU Emacs Internals
81097
81098E.7 Writing Emacs Primitives
81099============================
81100
81101Lisp primitives are Lisp functions implemented in C.  The details of
81102interfacing the C function so that Lisp can call it are handled by a few
81103C macros.  The only way to really understand how to write new C code is
81104to read the source, but we can explain some things here.
81105
81106   An example of a special form is the definition of ‘or’, from
81107eval.c’.  (An ordinary function would have the same general
81108appearance.)
81109
81110     DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
81111            doc: /* Eval args until one of them yields non-nil,
81112     then return that value.
81113     The remaining args are not evalled at all.
81114     If all args return nil, return nil.
81115     usage: (or CONDITIONS...)  */)
81116       (Lisp_Object args)
81117     {
81118       Lisp_Object val = Qnil;
81119
81120       while (CONSP (args))
81121         {
81122           val = eval_sub (XCAR (args));
81123           if (!NILP (val))
81124             break;
81125           args = XCDR (args);
81126           maybe_quit ();
81127         }
81128
81129       return val;
81130     }
81131
81132   Let’s start with a precise explanation of the arguments to the
81133‘DEFUN’ macro.  Here is a template for them:
81134
81135     DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC)
81136
81137LNAME
81138     This is the name of the Lisp symbol to define as the function name;
81139     in the example above, it is ‘or’.
81140
81141FNAME
81142     This is the C function name for this function.  This is the name
81143     that is used in C code for calling the function.  The name is, by
81144     convention, ‘F’ prepended to the Lisp name, with all dashes (‘-’)
81145     in the Lisp name changed to underscores.  Thus, to call this
81146     function from C code, call ‘For’.
81147
81148SNAME
81149     This is a C variable name to use for a structure that holds the
81150     data for the subr object that represents the function in Lisp.
81151     This structure conveys the Lisp symbol name to the initialization
81152     routine that will create the symbol and store the subr object as
81153     its definition.  By convention, this name is always FNAME with ‘F’
81154     replaced with ‘S’.
81155
81156MIN
81157     This is the minimum number of arguments that the function requires.
81158     The function ‘or’ allows a minimum of zero arguments.
81159
81160MAX
81161     This is the maximum number of arguments that the function accepts,
81162     if there is a fixed maximum.  Alternatively, it can be ‘UNEVALLED’,
81163     indicating a special form that receives unevaluated arguments, or
81164     ‘MANY’, indicating an unlimited number of evaluated arguments (the
81165     equivalent of ‘&rest’).  Both ‘UNEVALLED’ and ‘MANY’ are macros.
81166     If MAX is a number, it must be more than MIN but less than 8.
81167
81168INTERACTIVE
81169     This is an interactive specification, a string such as might be
81170     used as the argument of ‘interactive’ in a Lisp function (*note
81171     Using Interactive::).  In the case of ‘or’, it is ‘0’ (a null
81172     pointer), indicating that ‘or’ cannot be called interactively.  A
81173     value of ‘""’ indicates a function that should receive no arguments
81174     when called interactively.  If the value begins with a ‘"(’, the
81175     string is evaluated as a Lisp form.  For example:
81176
81177          DEFUN ("foo", Ffoo, Sfoo, 0, 3,
81178                 "(list (read-char-by-name \"Insert character: \")\
81179                        (prefix-numeric-value current-prefix-arg)\
81180                        t)",
81181                 doc: /* ... */)
81182
81183DOC
81184     This is the documentation string.  It uses C comment syntax rather
81185     than C string syntax because comment syntax requires nothing
81186     special to include multiple lines.  The ‘doc:’ identifies the
81187     comment that follows as the documentation string.  The ‘/*’ and
81188     ‘*/’ delimiters that begin and end the comment are not part of the
81189     documentation string.
81190
81191     If the last line of the documentation string begins with the
81192     keyword ‘usage:’, the rest of the line is treated as the argument
81193     list for documentation purposes.  This way, you can use different
81194     argument names in the documentation string from the ones used in
81195     the C code.  ‘usage:’ is required if the function has an unlimited
81196     number of arguments.
81197
81198     Some primitives have multiple definitions, one per platform (e.g.,
81199     ‘x-create-frame’).  In such cases, rather than writing the same
81200     documentation string in each definition, only one definition has
81201     the actual documentation.  The others have placeholders beginning
81202     with ‘SKIP’, which are ignored by the function that parses the
81203     ‘DOC’ file.
81204
81205     All the usual rules for documentation strings in Lisp code (*note
81206     Documentation Tips::) apply to C code documentation strings too.
81207
81208     The documentation string can be followed by a list of C function
81209     attributes for the C function that implements the primitive, like
81210     this:
81211
81212          DEFUN ("bar", Fbar, Sbar, 0, UNEVALLED, 0
81213                 doc: /* ... */
81214                 attributes: ATTR1 ATTR2 ...)
81215
81216     You can specify more than a single attribute, one after the other.
81217     Currently, only the following attributes are recognized:
81218
81219     ‘noreturn’
81220          Declares the C function as one that never returns.  This
81221          corresponds to the C11 keyword ‘_Noreturn’ and to
81222          ‘__attribute__ ((__noreturn__))’ attribute of GCC (*note
81223          (gcc)Function Attributes::).
81224
81225     ‘const’
81226          Declares that the function does not examine any values except
81227          its arguments, and has no effects except the return value.
81228          This corresponds to ‘__attribute__ ((__const__))’ attribute of
81229          GCC.
81230
81231     ‘noinline’
81232          This corresponds to ‘__attribute__ ((__noinline__))’ attribute
81233          of GCC, which prevents the function from being considered for
81234          inlining.  This might be needed, e.g., to countermand effects
81235          of link-time optimizations on stack-based variables.
81236
81237   After the call to the ‘DEFUN’ macro, you must write the argument list
81238for the C function, including the types for the arguments.  If the
81239primitive accepts a fixed maximum number of Lisp arguments, there must
81240be one C argument for each Lisp argument, and each argument must be of
81241type ‘Lisp_Object’.  (Various macros and functions for creating values
81242of type ‘Lisp_Object’ are declared in the file ‘lisp.h’.)  If the
81243primitive is a special form, it must accept a Lisp list containing its
81244unevaluated Lisp arguments as a single argument of type ‘Lisp_Object’.
81245If the primitive has no upper limit on the number of evaluated Lisp
81246arguments, it must have exactly two C arguments: the first is the number
81247of Lisp arguments, and the second is the address of a block containing
81248their values.  These have types ‘ptrdiff_t’ and ‘Lisp_Object *’,
81249respectively.  Since ‘Lisp_Object’ can hold any Lisp object of any data
81250type, you can determine the actual data type only at run time; so if you
81251want a primitive to accept only a certain type of argument, you must
81252check the type explicitly using a suitable predicate (*note Type
81253Predicates::).
81254
81255   Within the function ‘For’ itself, the local variable ‘args’ refers to
81256objects controlled by Emacs’s stack-marking garbage collector.  Although
81257the garbage collector does not reclaim objects reachable from C
81258‘Lisp_Object’ stack variables, it may move some of the components of an
81259object, such as the contents of a string or the text of a buffer.
81260Therefore, functions that access these components must take care to
81261refetch their addresses after performing Lisp evaluation.  This means
81262that instead of keeping C pointers to string contents or buffer text,
81263the code should keep the buffer or string position, and recompute the C
81264pointer from the position after performing Lisp evaluation.  Lisp
81265evaluation can occur via calls to ‘eval_sub’ or ‘Feval’, either directly
81266or indirectly.
81267
81268   Note the call to ‘maybe_quit’ inside the loop: this function checks
81269whether the user pressed ‘C-g’, and if so, aborts the processing.  You
81270should do that in any loop that can potentially require a large number
81271of iterations; in this case, the list of arguments could be very long.
81272This increases Emacs responsiveness and improves user experience.
81273
81274   You must not use C initializers for static or global variables unless
81275the variables are never written once Emacs is dumped.  These variables
81276with initializers are allocated in an area of memory that becomes
81277read-only (on certain operating systems) as a result of dumping Emacs.
81278*Note Pure Storage::.
81279
81280   Defining the C function is not enough to make a Lisp primitive
81281available; you must also create the Lisp symbol for the primitive and
81282store a suitable subr object in its function cell.  The code looks like
81283this:
81284
81285     defsubr (&SNAME);
81286
81287Here SNAME is the name you used as the third argument to ‘DEFUN’.
81288
81289   If you add a new primitive to a file that already has Lisp primitives
81290defined in it, find the function (near the end of the file) named
81291‘syms_of_SOMETHING’, and add the call to ‘defsubr’ there.  If the file
81292doesn’t have this function, or if you create a new file, add to it a
81293‘syms_of_FILENAME’ (e.g., ‘syms_of_myfile’).  Then find the spot in
81294emacs.c’ where all of these functions are called, and add a call to
81295‘syms_of_FILENAME’ there.
81296
81297   The function ‘syms_of_FILENAME’ is also the place to define any C
81298variables that are to be visible as Lisp variables.  ‘DEFVAR_LISP’ makes
81299a C variable of type ‘Lisp_Object’ visible in Lisp.  ‘DEFVAR_INT’ makes
81300a C variable of type ‘int’ visible in Lisp with a value that is always
81301an integer.  ‘DEFVAR_BOOL’ makes a C variable of type ‘int’ visible in
81302Lisp with a value that is either ‘t’ or ‘nil’.  Note that variables
81303defined with ‘DEFVAR_BOOL’ are automatically added to the list
81304‘byte-boolean-vars’ used by the byte compiler.
81305
81306   These macros all expect three arguments:
81307
81308‘lname’
81309     The name of the variable to be used by Lisp programs.
81310‘vname’
81311     The name of the variable in the C sources.
81312‘doc’
81313     The documentation for the variable, as a C comment.  *Note
81314     Documentation Basics::, for more details.
81315
81316   By convention, when defining variables of a “native” type (‘int’ and
81317‘bool’), the name of the C variable is the name of the Lisp variable
81318with ‘-’ replaced by ‘_’.  When the variable has type ‘Lisp_Object’, the
81319convention is to also prefix the C variable name with ‘V’.  i.e.
81320
81321     DEFVAR_INT ("my-int-variable", my_int_variable,
81322                doc: /* An integer variable.  */);
81323
81324     DEFVAR_LISP ("my-lisp-variable", Vmy_lisp_variable,
81325                doc: /* A Lisp variable.  */);
81326
81327   There are situations in Lisp where you need to refer to the symbol
81328itself rather than the value of that symbol.  One such case is when
81329temporarily overriding the value of a variable, which in Lisp is done
81330with ‘let’.  In C sources, this is done by defining a corresponding,
81331constant symbol, and using ‘specbind’.  By convention,
81332‘Qmy_lisp_variable’ corresponds to ‘Vmy_lisp_variable’; to define it,
81333use the ‘DEFSYM’ macro.  i.e.
81334
81335     DEFSYM (Qmy_lisp_variable, "my-lisp-variable");
81336
81337   To perform the actual binding:
81338
81339     specbind (Qmy_lisp_variable, Qt);
81340
81341   In Lisp symbols sometimes need to be quoted, to achieve the same
81342effect in C you again use the corresponding constant symbol
81343‘Qmy_lisp_variable’.  For example, when creating a buffer-local variable
81344(*note Buffer-Local Variables::) in Lisp you would write:
81345
81346     (make-variable-buffer-local 'my-lisp-variable)
81347
81348   In C the corresponding code uses ‘Fmake_variable_buffer_local’ in
81349combination with ‘DEFSYM’, i.e.
81350
81351     DEFSYM (Qmy_lisp_variable, "my-lisp-variable");
81352     Fmake_variable_buffer_local (Qmy_lisp_variable);
81353
81354   If you want to make a Lisp variable that is defined in C behave like
81355one declared with ‘defcustom’, add an appropriate entry to
81356cus-start.el’.  *Note Variable Definitions::, for a description of the
81357format to use.
81358
81359   If you directly define a file-scope C variable of type ‘Lisp_Object’,
81360you must protect it from garbage-collection by calling ‘staticpro’ in
81361‘syms_of_FILENAME’, like this:
81362
81363     staticpro (&VARIABLE);
81364
81365   Here is another example function, with more complicated arguments.
81366This comes from the code in ‘window.c’, and it demonstrates the use of
81367macros and functions to manipulate Lisp objects.
81368
81369     DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
81370            Scoordinates_in_window_p, 2, 2, 0,
81371            doc: /* Return non-nil if COORDINATES are in WINDOW.
81372       ...
81373       or `right-margin' is returned.  */)
81374       (register Lisp_Object coordinates, Lisp_Object window)
81375     {
81376       struct window *w;
81377       struct frame *f;
81378       int x, y;
81379       Lisp_Object lx, ly;
81380
81381       w = decode_live_window (window);
81382       f = XFRAME (w->frame);
81383       CHECK_CONS (coordinates);
81384       lx = Fcar (coordinates);
81385       ly = Fcdr (coordinates);
81386       CHECK_NUMBER (lx);
81387       CHECK_NUMBER (ly);
81388       x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
81389       y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
81390
81391       switch (coordinates_in_window (w, x, y))
81392         {
81393         case ON_NOTHING:            /* NOT in window at all.  */
81394           return Qnil;
81395
81396         ...
81397
81398         case ON_MODE_LINE:          /* In mode line of window.  */
81399           return Qmode_line;
81400
81401         ...
81402
81403         case ON_SCROLL_BAR:         /* On scroll-bar of window.  */
81404           /* Historically we are supposed to return nil in this case.  */
81405           return Qnil;
81406
81407         default:
81408           emacs_abort ();
81409         }
81410     }
81411
81412   Note that C code cannot call functions by name unless they are
81413defined in C.  The way to call a function written in Lisp is to use
81414‘Ffuncall’, which embodies the Lisp function ‘funcall’.  Since the Lisp
81415function ‘funcall’ accepts an unlimited number of arguments, in C it
81416takes two: the number of Lisp-level arguments, and a one-dimensional
81417array containing their values.  The first Lisp-level argument is the
81418Lisp function to call, and the rest are the arguments to pass to it.
81419
81420   The C functions ‘call0’, ‘call1’, ‘call2’, and so on, provide handy
81421ways to call a Lisp function conveniently with a fixed number of
81422arguments.  They work by calling ‘Ffuncall’.
81423
81424eval.c’ is a very good file to look through for examples; ‘lisp.h81425contains the definitions for some important macros and functions.
81426
81427   If you define a function which is side-effect free or pure, give it a
81428non-‘nil’ ‘side-effect-free’ or ‘pure’ property, respectively (*note
81429Standard Properties::).
81430
81431
81432File: elisp.info,  Node: Writing Dynamic Modules,  Next: Object Internals,  Prev: Writing Emacs Primitives,  Up: GNU Emacs Internals
81433
81434E.8 Writing Dynamically-Loaded Modules
81435======================================
81436
81437This section describes the Emacs module API and how to use it as part of
81438writing extension modules for Emacs.  The module API is defined in the C
81439programming language, therefore the description and the examples in this
81440section assume the module is written in C.  For other programming
81441languages, you will need to use the appropriate bindings, interfaces and
81442facilities for calling C code.  Emacs C code requires a C99 or later
81443compiler (*note C Dialect::), and so the code examples in this section
81444also follow that standard.
81445
81446   Writing a module and integrating it into Emacs comprises the
81447following tasks:
81448
81449   • Writing initialization code for the module.
81450
81451   • Writing one or more module functions.
81452
81453   • Communicating values and objects between Emacs and your module
81454     functions.
81455
81456   • Handling of error conditions and nonlocal exits.
81457
81458The following subsections describe these tasks and the API itself in
81459more detail.
81460
81461   Once your module is written, compile it to produce a shared library,
81462according to the conventions of the underlying platform.  Then place the
81463shared library in a directory mentioned in ‘load-path’ (*note Library
81464Search::), where Emacs will find it.
81465
81466   If you wish to verify the conformance of a module to the Emacs
81467dynamic module API, invoke Emacs with the ‘--module-assertions’ option.
81468*Note (emacs)Initial Options::.
81469
81470* Menu:
81471
81472* Module Initialization::
81473* Module Functions::
81474* Module Values::
81475* Module Misc::
81476* Module Nonlocal::
81477
81478
81479File: elisp.info,  Node: Module Initialization,  Next: Module Functions,  Up: Writing Dynamic Modules
81480
81481E.8.1 Module Initialization Code
81482--------------------------------
81483
81484Begin your module by including the header file ‘emacs-module.h’ and
81485defining the GPL compatibility symbol:
81486
81487     #include <emacs-module.h>
81488
81489     int plugin_is_GPL_compatible;
81490
81491   The ‘emacs-module.h’ file is installed into your system’s include
81492tree as part of the Emacs installation.  Alternatively, you can find it
81493in the Emacs source tree.
81494
81495   Next, write an initialization function for the module.
81496
81497 -- Function: int emacs_module_init (struct emacs_runtime *RUNTIME)
81498     Emacs calls this function when it loads a module.  If a module does
81499     not export a function named ‘emacs_module_init’, trying to load the
81500     module will signal an error.  The initialization function should
81501     return zero if the initialization succeeds, non-zero otherwise.  In
81502     the latter case, Emacs will signal an error, and the loading of the
81503     module will fail.  If the user presses ‘C-g’ during the
81504     initialization, Emacs ignores the return value of the
81505     initialization function and quits (*note Quitting::).  (If needed,
81506     you can catch user quitting inside the initialization function,
81507     *note should_quit::.)
81508
81509     The argument RUNTIME is a pointer to a C ‘struct’ that includes 2
81510     public fields: ‘size’, which provides the size of the structure in
81511     bytes; and ‘get_environment’, which provides a pointer to a
81512     function that allows the module initialization function access to
81513     the Emacs environment object and its interfaces.
81514
81515     The initialization function should perform whatever initialization
81516     is required for the module.  In addition, it can perform the
81517     following tasks:
81518
81519     Compatibility verification
81520          A module can verify that the Emacs executable which loads the
81521          module is compatible with the module, by comparing the ‘size’
81522          member of the RUNTIME structure with the value compiled into
81523          the module:
81524
81525               int
81526               emacs_module_init (struct emacs_runtime *ert)
81527               {
81528                 if (ert->size < sizeof (*ert))
81529                   return 1;
81530               }
81531
81532          If the size of the runtime object passed to the module is
81533          smaller than what it expects, it means the module was compiled
81534          for an Emacs version newer (later) than the one which attempts
81535          to load it, i.e. the module might be incompatible with the
81536          Emacs binary.
81537
81538          In addition, a module can verify the compatibility of the
81539          module API with what the module expects.  The following sample
81540          code assumes it is part of the ‘emacs_module_init’ function
81541          shown above:
81542
81543                 emacs_env *env = ert->get_environment (ert);
81544                 if (env->size < sizeof (*env))
81545                   return 2;
81546
81547          This calls the ‘get_environment’ function using the pointer
81548          provided in the ‘runtime’ structure to retrieve a pointer to
81549          the API’s “environment”, a C ‘struct’ which also has a ‘size’
81550          field holding the size of the structure in bytes.
81551
81552          Finally, you can write a module that will work with older
81553          versions of Emacs, by comparing the size of the environment
81554          passed by Emacs with known sizes, like this:
81555
81556                 emacs_env *env = ert->get_environment (ert);
81557                 if (env->size >= sizeof (struct emacs_env_26))
81558                   emacs_version = 26;  /* Emacs 26 or later.  */
81559                 else if (env->size >= sizeof (struct emacs_env_25))
81560                   emacs_version = 25;
81561                 else
81562                   return 2; /* Unknown or unsupported version.  */
81563
81564          This works because later Emacs versions always _add_ members
81565          to the environment, never _remove_ any members, so the size
81566          can only grow with new Emacs releases.  Given the version of
81567          Emacs, the module can use only the parts of the module API
81568          that existed in that version, since those parts are identical
81569          in later versions.
81570
81571emacs-module.h’ defines a preprocessor macro
81572          ‘EMACS_MAJOR_VERSION’.  It expands to an integer literal which
81573          is the latest major version of Emacs supported by the header.
81574          *Note Version Info::.  Note that the value of
81575          ‘EMACS_MAJOR_VERSION’ is a compile-time constant and does not
81576          represent the version of Emacs that is currently running and
81577          has loaded your module.  If you want your module to be
81578          compatible with various versions of ‘emacs-module.h’ as well
81579          as various versions of Emacs, you can use conditional
81580          compilation based on ‘EMACS_MAJOR_VERSION’.
81581
81582          We recommend that modules always perform the compatibility
81583          verification, unless they do their job entirely in the
81584          initialization function, and don’t access any Lisp objects or
81585          use any Emacs functions accessible through the environment
81586          structure.
81587
81588     Binding module functions to Lisp symbols
81589          This gives the module functions names so that Lisp code could
81590          call it by that name.  We describe how to do this in *note
81591          Module Functions:: below.
81592
81593
81594File: elisp.info,  Node: Module Functions,  Next: Module Values,  Prev: Module Initialization,  Up: Writing Dynamic Modules
81595
81596E.8.2 Writing Module Functions
81597------------------------------
81598
81599The main reason for writing an Emacs module is to make additional
81600functions available to Lisp programs that load the module.  This
81601subsection describes how to write such “module functions”.
81602
81603   A module function has the following general form and signature:
81604
81605 -- Function: emacs_value module_func (emacs_env *ENV, ptrdiff_t NARGS,
81606          emacs_value *ARGS, void *DATA)
81607     The ENV argument provides a pointer to the API environment, needed
81608     to access Emacs objects and functions.  The NARGS argument is the
81609     required number of arguments, which can be zero (see
81610     ‘make_function’ below for more flexible specification of the
81611     argument number), and ARGS is a pointer to the array of the
81612     function arguments.  The argument DATA points to additional data
81613     required by the function, which was arranged when ‘make_function’
81614     (see below) was called to create an Emacs function from
81615     ‘module_func’.
81616
81617     Module functions use the type ‘emacs_value’ to communicate Lisp
81618     objects between Emacs and the module (*note Module Values::).  The
81619     API, described below and in the following subsections, provides
81620     facilities for conversion between basic C data types and the
81621     corresponding ‘emacs_value’ objects.
81622
81623     A module function always returns a value.  If the function returns
81624     normally, the Lisp code which called it will see the Lisp object
81625     corresponding to the ‘emacs_value’ value the function returned.
81626     However, if the user typed ‘C-g’, or if the module function or its
81627     callees signaled an error or exited nonlocally (*note Module
81628     Nonlocal::), Emacs will ignore the returned value and quit or throw
81629     as it does when Lisp code encounters the same situations.
81630
81631   After writing your C code for a module function, you should make a
81632Lisp function object from it using the ‘make_function’ function, whose
81633pointer is provided in the environment (recall that the pointer to the
81634environment is returned by ‘get_environment’).  This is normally done in
81635the module initialization function (*note module initialization
81636function::), after verifying the API compatibility.
81637
81638 -- Function: emacs_value make_function (emacs_env *ENV, ptrdiff_t
81639          MIN_ARITY, ptrdiff_t MAX_ARITY, subr FUNC, const char
81640          *DOCSTRING, void *DATA)
81641     This returns an Emacs function created from the C function FUNC,
81642     whose signature is as described for ‘module_func’ above (assumed
81643     here to be ‘typedef’’ed as ‘subr’).  The arguments MIN_ARITY and
81644     MAX_ARITY specify the minimum and maximum number of arguments that
81645     FUNC can accept.  The MAX_ARITY argument can have the special value
81646     ‘emacs_variadic_function’, which makes the function accept an
81647     unlimited number of arguments, like the ‘&rest’ keyword in Lisp
81648     (*note Argument List::).
81649
81650     The argument DATA is a way to arrange for arbitrary additional data
81651     to be passed to FUNC when it is called.  Whatever pointer is passed
81652     to ‘make_function’ will be passed unaltered to FUNC.
81653
81654     The argument DOCSTRING specifies the documentation string for the
81655     function.  It should be either an ASCII string, or a UTF-8 encoded
81656     non-ASCII string, or a ‘NULL’ pointer; in the latter case the
81657     function will have no documentation.  The documentation string can
81658     end with a line that specifies the advertised calling convention,
81659     see *note Function Documentation::.
81660
81661     Since every module function must accept the pointer to the
81662     environment as its first argument, the call to ‘make_function’
81663     could be made from any module function, but you will normally want
81664     to do that from the module initialization function, so that all the
81665     module functions are known to Emacs once the module is loaded.
81666
81667   Finally, you should bind the Lisp function to a symbol, so that Lisp
81668code could call your function by name.  For that, use the module API
81669function ‘intern’ (*note intern::) whose pointer is also provided in the
81670environment that module functions can access.
81671
81672   Combining the above steps, code that arranges for a C function
81673‘module_func’ to be callable as ‘module-func’ from Lisp will look like
81674this, as part of the module initialization function:
81675
81676      emacs_env *env = ert->get_environment (ert);
81677      emacs_value func = env->make_function (env, min_arity, max_arity,
81678                                             module_func, docstring, data);
81679      emacs_value symbol = env->intern (env, "module-func");
81680      emacs_value args[] = {symbol, func};
81681      env->funcall (env, env->intern (env, "defalias"), 2, args);
81682
81683This makes the symbol ‘module-func’ known to Emacs by calling
81684‘env->intern’, then invokes ‘defalias’ from Emacs to bind the function
81685to that symbol.  Note that it is possible to use ‘fset’ instead of
81686‘defalias’; the differences are described in *note defalias: Defining
81687Functions.
81688
81689   Module functions including the ‘emacs_module_init’ function (*note
81690module initialization function::) may only interact with Emacs by
81691calling environment functions from some live ‘emacs_env’ pointer while
81692being called directly or indirectly from Emacs.  In other words, if a
81693module function wants to call Lisp functions or Emacs primitives,
81694convert ‘emacs_value’ objects to and from C datatypes (*note Module
81695Values::), or interact with Emacs in any other way, some call from Emacs
81696to ‘emacs_module_init’ or to a module function must be in the call
81697stack.  Module function may not interact with Emacs while garbage
81698collection is running; *note Garbage Collection::.  They may only
81699interact with Emacs from Lisp interpreter threads (including the main
81700thread) created by Emacs; *note Threads::.  The ‘--module-assertions’
81701command-line option can detect some violations of the above
81702requirements.  *Note (emacs)Initial Options::.
81703
81704   Using the module API, it is possible to define more complex function
81705and data types: interactive functions, inline functions, macros, etc.
81706However, the resulting C code will be cumbersome and hard to read.
81707Therefore, we recommend that you limit the module code which creates
81708functions and data structures to the absolute minimum, and leave the
81709rest for a Lisp package that will accompany your module, because doing
81710these additional tasks in Lisp is much easier, and will produce a much
81711more readable code.  For example, given a module function ‘module-func’
81712defined as above, one way of making an interactive command ‘module-cmd’
81713based on it is with the following simple Lisp wrapper:
81714
81715     (defun module-cmd (&rest args)
81716       "Documentation string for the command."
81717       (interactive SPEC)
81718       (apply 'module-func args))
81719
81720   The Lisp package which goes with your module could then load the
81721module using the ‘load’ primitive (*note Dynamic Modules::) when the
81722package is loaded into Emacs.
81723
81724
81725File: elisp.info,  Node: Module Values,  Next: Module Misc,  Prev: Module Functions,  Up: Writing Dynamic Modules
81726
81727E.8.3 Conversion Between Lisp and Module Values
81728-----------------------------------------------
81729
81730With very few exceptions, most modules need to exchange data with Lisp
81731programs that call them: accept arguments to module functions and return
81732values from module functions.  For this purpose, the module API provides
81733the ‘emacs_value’ type, which represents Emacs Lisp objects communicated
81734via the API; it is the functional equivalent of the ‘Lisp_Object’ type
81735used in Emacs C primitives (*note Writing Emacs Primitives::).  This
81736section describes the parts of the module API that allow to create
81737‘emacs_value’ objects corresponding to basic Lisp data types, and how to
81738access from C data in ‘emacs_value’ objects that correspond to Lisp
81739objects.
81740
81741   All of the functions described below are actually _function pointers_
81742provided via the pointer to the environment which every module function
81743accepts.  Therefore, module code should call these functions through the
81744environment pointer, like this:
81745
81746     emacs_env *env;  /* the environment pointer */
81747     env->some_function (arguments...);
81748
81749The ‘emacs_env’ pointer will usually come from the first argument to the
81750module function, or from the call to ‘get_environment’ if you need the
81751environment in the module initialization function.
81752
81753   Most of the functions described below became available in Emacs 25,
81754the first Emacs release that supported dynamic modules.  For the few
81755functions that became available in later Emacs releases, we mention the
81756first Emacs version that supported them.
81757
81758   The following API functions extract values of various C data types
81759from ‘emacs_value’ objects.  They all raise the ‘wrong-type-argument’
81760error condition (*note Type Predicates::) if the argument ‘emacs_value’
81761object is not of the type expected by the function.  *Note Module
81762Nonlocal::, for details of how signaling errors works in Emacs modules,
81763and how to catch error conditions inside the module before they are
81764reported to Emacs.  The API function ‘type_of’ (*note type_of: Module
81765Misc.) can be used to obtain the type of a ‘emacs_value’ object.
81766
81767 -- Function: intmax_t extract_integer (emacs_env *ENV, emacs_value ARG)
81768     This function returns the value of a Lisp integer specified by ARG.
81769     The C data type of the return value, ‘intmax_t’, is the widest
81770     integer data type supported by the C compiler, typically
81771     ‘long long’.  If the value of ARG doesn’t fit into an ‘intmax_t’,
81772     the function signals an error using the error symbol
81773     ‘overflow-error’.
81774
81775 -- Function: bool extract_big_integer (emacs_env *ENV, emacs_value ARG,
81776          int *SIGN, ptrdiff_t *COUNT, emacs_limb_t *MAGNITUDE)
81777     This function, which is available since Emacs 27, extracts the
81778     integer value of ARG.  The value of ARG must be an integer (fixnum
81779     or bignum).  If SIGN is not ‘NULL’, it stores the sign of ARG (-1,
81780     0, or +1) into ‘*sign’.  The magnitude is stored into MAGNITUDE as
81781     follows.  If COUNT and MAGNITUDE are both non-‘NULL’, then
81782     MAGNITUDE must point to an array of at least ‘*count’ ‘unsigned
81783     long’ elements.  If MAGNITUDE is large enough to hold the magnitude
81784     of ARG, then this function writes the magnitude into the MAGNITUDE
81785     array in little-endian form, stores the number of array elements
81786     written into ‘*count’, and returns ‘true’.  If MAGNITUDE is not
81787     large enough, it stores the required array size into ‘*count’,
81788     signals an error, and returns ‘false’.  If COUNT is not ‘NULL’ and
81789     MAGNITUDE is ‘NULL’, then the function stores the required array
81790     size into ‘*count’ and returns ‘true’.
81791
81792     Emacs guarantees that the maximum required value of ‘*count’ never
81793     exceeds ‘min (PTRDIFF_MAX, SIZE_MAX) / sizeof (emacs_limb_t)’, so
81794     you can use ‘malloc (*count * sizeof *magnitude)’ to allocate the
81795     ‘magnitude’ array without worrying about integer overflow in the
81796     size calculation.
81797
81798 -- Type alias: emacs_limb_t
81799     This is an unsigned integer type, used as the element type for the
81800     magnitude arrays for the big integer conversion functions.  The
81801     type is guaranteed to have unique object representations, i.e., no
81802     padding bits.
81803
81804 -- Macro: EMACS_LIMB_MAX
81805     This macro expands to a constant expression specifying the maximum
81806     possible value for an ‘emacs_limb_t’ object.  The expression is
81807     suitable for use in ‘#if’.
81808
81809 -- Function: double extract_float (emacs_env *ENV, emacs_value ARG)
81810     This function returns the value of a Lisp float specified by ARG,
81811     as a C ‘double’ value.
81812
81813 -- Function: struct timespec extract_time (emacs_env *ENV, emacs_value
81814          TIME)
81815     This function, which is available since Emacs 27, interprets TIME
81816     as an Emacs Lisp time value and returns the corresponding ‘struct
81817     timespec’.  *Note Time of Day::.  ‘struct timespec’ represents a
81818     timestamp with nanosecond precision.  It has the following members:
81819
81820     ‘time_t tv_sec’
81821          Whole number of seconds.
81822     ‘long tv_nsec’
81823          Fractional seconds as a number of nanoseconds.  For timestamps
81824          returned by ‘extract_time’, this is always nonnegative and
81825          less than one billion.  (Although POSIX requires the type of
81826          ‘tv_nsec’ to be ‘long’, the type is ‘long long’ on some
81827          nonstandard platforms.)
81828
81829     *Note (libc)Elapsed Time::.
81830
81831     If TIME has higher precision than nanoseconds, then this function
81832     truncates it to nanosecond precision towards negative infinity.
81833     This function signals an error if TIME (truncated to nanoseconds)
81834     cannot be represented by ‘struct timespec’.  For example, if
81835     ‘time_t’ is a 32-bit integer type, then a TIME value of ten billion
81836     seconds would signal an error, but a TIME value of 600 picoseconds
81837     would get truncated to zero.
81838
81839     If you need to deal with time values that are not representable by
81840     ‘struct timespec’, or if you want higher precision, call the Lisp
81841     function ‘encode-time’ and work with its return value.  *Note Time
81842     Conversion::.
81843
81844 -- Function: bool copy_string_contents (emacs_env *ENV, emacs_value
81845          ARG, char *BUF, ptrdiff_t *LEN)
81846     This function stores the UTF-8 encoded text of a Lisp string
81847     specified by ARG in the array of ‘char’ pointed by BUF, which
81848     should have enough space to hold at least ‘*LEN’ bytes, including
81849     the terminating null byte.  The argument LEN must not be a ‘NULL’
81850     pointer, and, when the function is called, it should point to a
81851     value that specifies the size of BUF in bytes.
81852
81853     If the buffer size specified by ‘*LEN’ is large enough to hold the
81854     string’s text, the function stores in ‘*LEN’ the actual number of
81855     bytes copied to BUF, including the terminating null byte, and
81856     returns ‘true’.  If the buffer is too small, the function raises
81857     the ‘args-out-of-range’ error condition, stores the required number
81858     of bytes in ‘*LEN’, and returns ‘false’.  *Note Module Nonlocal::,
81859     for how to handle pending error conditions.
81860
81861     The argument BUF can be a ‘NULL’ pointer, in which case the
81862     function stores in ‘*LEN’ the number of bytes required for storing
81863     the contents of ARG, and returns ‘true’.  This is how you can
81864     determine the size of BUF needed to store a particular string:
81865     first call ‘copy_string_contents’ with ‘NULL’ as BUF, then allocate
81866     enough memory to hold the number of bytes stored by the function in
81867     ‘*LEN’, and call the function again with non-‘NULL’ BUF to actually
81868     perform the text copying.
81869
81870 -- Function: emacs_value vec_get (emacs_env *ENV, emacs_value VECTOR,
81871          ptrdiff_t INDEX)
81872     This function returns the element of VECTOR at INDEX.  The INDEX of
81873     the first vector element is zero.  The function raises the
81874     ‘args-out-of-range’ error condition if the value of INDEX is
81875     invalid.  To extract C data from the value the function returns,
81876     use the other extraction functions described here, as appropriate
81877     for the Lisp data type stored in that element of the vector.
81878
81879 -- Function: ptrdiff_t vec_size (emacs_env *ENV, emacs_value VECTOR)
81880     This function returns the number of elements in VECTOR.
81881
81882 -- Function: void vec_set (emacs_env *ENV, emacs_value VECTOR,
81883          ptrdiff_t INDEX, emacs_value VALUE)
81884     This function stores VALUE in the element of VECTOR whose index is
81885     INDEX.  It raises the ‘args-out-of-range’ error condition if the
81886     value of INDEX is invalid.
81887
81888   The following API functions create ‘emacs_value’ objects from basic C
81889data types.  They all return the created ‘emacs_value’ object.
81890
81891 -- Function: emacs_value make_integer (emacs_env *ENV, intmax_t N)
81892     This function takes an integer argument N and returns the
81893     corresponding ‘emacs_value’ object.  It returns either a fixnum or
81894     a bignum depending on whether the value of N is inside the limits
81895     set by ‘most-negative-fixnum’ and ‘most-positive-fixnum’ (*note
81896     Integer Basics::).
81897
81898 -- Function: emacs_value make_big_integer (emacs_env *ENV, int sign,
81899          ptrdiff_t count, const emacs_limb_t *magnitude)
81900     This function, which is available since Emacs 27, takes an
81901     arbitrary-sized integer argument and returns a corresponding
81902     ‘emacs_value’ object.  The SIGN argument gives the sign of the
81903     return value.  If SIGN is nonzero, then MAGNITUDE must point to an
81904     array of at least COUNT elements specifying the little-endian
81905     magnitude of the return value.
81906
81907   The following example uses the GNU Multiprecision Library (GMP) to
81908calculate the next probable prime after a given integer.  *Note
81909(gmp)Top::, for a general overview of GMP, and *note (gmp)Integer Import
81910and Export:: for how to convert the ‘magnitude’ array to and from GMP
81911‘mpz_t’ values.
81912
81913     #include <emacs-module.h>
81914     int plugin_is_GPL_compatible;
81915
81916     #include <assert.h>
81917     #include <limits.h>
81918     #include <stdint.h>
81919     #include <stdlib.h>
81920     #include <string.h>
81921
81922     #include <gmp.h>
81923
81924     static void
81925     memory_full (emacs_env *env)
81926     {
81927       static const char message[] = "Memory exhausted";
81928       emacs_value data = env->make_string (env, message,
81929                                            strlen (message));
81930       env->non_local_exit_signal
81931         (env, env->intern (env, "error"),
81932          env->funcall (env, env->intern (env, "list"), 1, &data));
81933     }
81934
81935     enum
81936     {
81937       order = -1, endian = 0, nails = 0,
81938       limb_size = sizeof (emacs_limb_t),
81939       max_nlimbs = ((SIZE_MAX < PTRDIFF_MAX ? SIZE_MAX : PTRDIFF_MAX)
81940                     / limb_size)
81941     };
81942
81943     static bool
81944     extract_big_integer (emacs_env *env, emacs_value arg, mpz_t result)
81945     {
81946       ptrdiff_t nlimbs;
81947       bool ok = env->extract_big_integer (env, arg, NULL, &nlimbs, NULL);
81948       if (!ok)
81949         return false;
81950       assert (0 < nlimbs && nlimbs <= max_nlimbs);
81951       emacs_limb_t *magnitude = malloc (nlimbs * limb_size);
81952       if (magnitude == NULL)
81953         {
81954           memory_full (env);
81955           return false;
81956         }
81957       int sign;
81958       ok = env->extract_big_integer (env, arg, &sign, &nlimbs, magnitude);
81959       assert (ok);
81960       mpz_import (result, nlimbs, order, limb_size, endian, nails, magnitude);
81961       free (magnitude);
81962       if (sign < 0)
81963         mpz_neg (result, result);
81964       return true;
81965     }
81966
81967     static emacs_value
81968     make_big_integer (emacs_env *env, const mpz_t value)
81969     {
81970       size_t nbits = mpz_sizeinbase (value, 2);
81971       int bitsperlimb = CHAR_BIT * limb_size - nails;
81972       size_t nlimbs = nbits / bitsperlimb + (nbits % bitsperlimb != 0);
81973       emacs_limb_t *magnitude
81974         = nlimbs <= max_nlimbs ? malloc (nlimbs * limb_size) : NULL;
81975       if (magnitude == NULL)
81976         {
81977           memory_full (env);
81978           return NULL;
81979         }
81980       size_t written;
81981       mpz_export (magnitude, &written, order, limb_size, endian, nails, value);
81982       assert (written == nlimbs);
81983       assert (nlimbs <= PTRDIFF_MAX);
81984       emacs_value result = env->make_big_integer (env, mpz_sgn (value),
81985                                                   nlimbs, magnitude);
81986       free (magnitude);
81987       return result;
81988     }
81989
81990     static emacs_value
81991     next_prime (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
81992                 void *data)
81993     {
81994       assert (nargs == 1);
81995       mpz_t p;
81996       mpz_init (p);
81997       extract_big_integer (env, args[0], p);
81998       mpz_nextprime (p, p);
81999       emacs_value result = make_big_integer (env, p);
82000       mpz_clear (p);
82001       return result;
82002     }
82003
82004     int
82005     emacs_module_init (struct emacs_runtime *ert)
82006     {
82007       emacs_env *env = ert->get_environment (ert);
82008       emacs_value symbol = env->intern (env, "next-prime");
82009       emacs_value func
82010         = env->make_function (env, 1, 1, next_prime, NULL, NULL);
82011       emacs_value args[] = {symbol, func};
82012       env->funcall (env, env->intern (env, "defalias"), 2, args);
82013       return 0;
82014     }
82015
82016 -- Function: emacs_value make_float (emacs_env *ENV, double D)
82017     This function takes a ‘double’ argument D and returns the
82018     corresponding Emacs floating-point value.
82019
82020 -- Function: emacs_value make_time (emacs_env *ENV, struct timespec
82021          TIME)
82022     This function, which is available since Emacs 27, takes a ‘struct
82023     timespec’ argument TIME and returns the corresponding Emacs
82024     timestamp as a pair ‘(TICKS . HZ)’.  *Note Time of Day::.  The
82025     return value represents exactly the same timestamp as TIME: all
82026     input values are representable, and there is never a loss of
82027     precision.  ‘TIME.tv_sec’ and ‘TIME.tv_nsec’ can be arbitrary
82028     values.  In particular, there’s no requirement that TIME be
82029     normalized.  This means that ‘TIME.tv_nsec’ can be negative or
82030     larger than 999,999,999.
82031
82032 -- Function: emacs_value make_string (emacs_env *ENV, const char *STR,
82033          ptrdiff_t STRLEN)
82034     This function creates an Emacs string from C text string pointed by
82035     STR whose length in bytes, not including the terminating null byte,
82036     is STRLEN.  The original string in STR can be either an ASCII
82037     string or a UTF-8 encoded non-ASCII string; it can include embedded
82038     null bytes, and doesn’t have to end in a terminating null byte at
82039     ‘STR[STRLEN]’.  The function raises the ‘overflow-error’ error
82040     condition if STRLEN is negative or exceeds the maximum length of an
82041     Emacs string.
82042
82043   The API does not provide functions to manipulate Lisp data
82044structures, for example, create lists with ‘cons’ and ‘list’ (*note
82045Building Lists::), extract list members with ‘car’ and ‘cdr’ (*note List
82046Elements::), create vectors with ‘vector’ (*note Vector Functions::),
82047etc.  For these, use ‘intern’ and ‘funcall’, described in the next
82048subsection, to call the corresponding Lisp functions.
82049
82050   Normally, ‘emacs_value’ objects have a rather short lifetime: it ends
82051when the ‘emacs_env’ pointer used for their creation goes out of scope.
82052Occasionally, you may need to create “global references”: ‘emacs_value’
82053objects that live as long as you wish.  Use the following two functions
82054to manage such objects.
82055
82056 -- Function: emacs_value make_global_ref (emacs_env *ENV, emacs_value
82057          VALUE)
82058     This function returns a global reference for VALUE.
82059
82060 -- Function: void free_global_ref (emacs_env *ENV, emacs_value
82061          GLOBAL_VALUE)
82062     This function frees the GLOBAL_VALUE previously created by
82063     ‘make_global_ref’.  The GLOBAL_VALUE is no longer valid after the
82064     call.  Your module code should pair each call to ‘make_global_ref’
82065     with the corresponding ‘free_global_ref’.
82066
82067   An alternative to keeping around C data structures that need to be
82068passed to module functions later is to create “user pointer” objects.  A
82069user pointer, or ‘user-ptr’, object is a Lisp object that encapsulates a
82070C pointer and can have an associated finalizer function, which is called
82071when the object is garbage-collected (*note Garbage Collection::).  The
82072module API provides functions to create and access ‘user-ptr’ objects.
82073These functions raise the ‘wrong-type-argument’ error condition if they
82074are called on ‘emacs_value’ that doesn’t represent a ‘user-ptr’ object.
82075
82076 -- Function: emacs_value make_user_ptr (emacs_env *ENV, emacs_finalizer
82077          FIN, void *PTR)
82078     This function creates and returns a ‘user-ptr’ object which wraps
82079     the C pointer PTR.  The finalizer function FIN can be a ‘NULL’
82080     pointer (meaning no finalizer), or it can be a function of the
82081     following signature:
82082
82083          typedef void (*emacs_finalizer) (void *PTR);
82084
82085     If FIN is not a ‘NULL’ pointer, it will be called with the PTR as
82086     the argument when the ‘user-ptr’ object is garbage-collected.
82087     Don’t run any expensive code in a finalizer, because GC must finish
82088     quickly to keep Emacs responsive.
82089
82090 -- Function: void *get_user_ptr (emacs_env *ENV, emacs_value val)
82091     This function extracts the C pointer from the Lisp object
82092     represented by VAL.
82093
82094 -- Function: void set_user_ptr (emacs_env *ENV, emacs_value VALUE, void
82095          *PTR)
82096     This function sets the C pointer embedded in the ‘user-ptr’ object
82097     represented by VALUE to PTR.
82098
82099 -- Function: emacs_finalizer get_user_finalizer (emacs_env *ENV,
82100          emacs_value val)
82101     This function returns the finalizer of the ‘user-ptr’ object
82102     represented by VAL, or ‘NULL’ if it doesn’t have a finalizer.
82103
82104 -- Function: void set_user_finalizer (emacs_env *ENV, emacs_value VAL,
82105          emacs_finalizer FIN)
82106     This function changes the finalizer of the ‘user-ptr’ object
82107     represented by VAL to be FIN.  If FIN is a ‘NULL’ pointer, the
82108     ‘user-ptr’ object will have no finalizer.
82109
82110
82111File: elisp.info,  Node: Module Misc,  Next: Module Nonlocal,  Prev: Module Values,  Up: Writing Dynamic Modules
82112
82113E.8.4 Miscellaneous Convenience Functions for Modules
82114-----------------------------------------------------
82115
82116This subsection describes a few convenience functions provided by the
82117module API.  Like the functions described in previous subsections, all
82118of them are actually function pointers, and need to be called via the
82119‘emacs_env’ pointer.  Description of functions that were introduced
82120after Emacs 25 calls out the first version where they became available.
82121
82122 -- Function: bool eq (emacs_env *ENV, emacs_value VAL1, emacs_value
82123          VAL2)
82124     This function returns ‘true’ if the Lisp objects represented by
82125     VAL1 and VAL2 are identical, ‘false’ otherwise.  This is the same
82126     as the Lisp function ‘eq’ (*note Equality Predicates::), but avoids
82127     the need to intern the objects represented by the arguments.
82128
82129     There are no API functions for other equality predicates, so you
82130     will need to use ‘intern’ and ‘funcall’, described below, to
82131     perform more complex equality tests.
82132
82133 -- Function: bool is_not_nil (emacs_env *ENV, emacs_value VAL)
82134     This function tests whether the Lisp object represented by VAL is
82135     non-‘nil’; it returns ‘true’ or ‘false’ accordingly.
82136
82137     Note that you could implement an equivalent test by using ‘intern’
82138     to get an ‘emacs_value’ representing ‘nil’, then use ‘eq’,
82139     described above, to test for equality.  But using this function is
82140     more convenient.
82141
82142 -- Function: emacs_value type_of (emacs_env *ENV, emacs_value ‘object’)
82143     This function returns the type of OBJECT as a value that represents
82144     a symbol: ‘string’ for a string, ‘integer’ for an integer,
82145     ‘process’ for a process, etc.  *Note Type Predicates::.  You can
82146     use ‘intern’ and ‘eq’ to compare against known type symbols, if
82147     your code needs to depend on the object type.
82148
82149 -- Function: emacs_value intern (emacs_env *ENV, const char *name)
82150     This function returns an interned Emacs symbol whose name is NAME,
82151     which should be an ASCII null-terminated string.  It creates a new
82152     symbol if one does not already exist.
82153
82154     Together with ‘funcall’, described below, this function provides a
82155     means for invoking any Lisp-callable Emacs function, provided that
82156     its name is a pure ASCII string.  For example, here’s how to intern
82157     a symbol whose name ‘name_str’ is non-ASCII, by calling the more
82158     powerful Emacs ‘intern’ function (*note Creating Symbols::):
82159
82160          emacs_value fintern = env->intern (env, "intern");
82161          emacs_value sym_name =
82162            env->make_string (env, name_str, strlen (name_str));
82163          emacs_value intern_args[] = { sym_name, env->intern (env, "nil") };
82164          emacs_value symbol = env->funcall (env, fintern, 2, intern_args);
82165
82166 -- Function: emacs_value funcall (emacs_env *ENV, emacs_value FUNC,
82167          ptrdiff_t NARGS, emacs_value *ARGS)
82168     This function calls the specified FUNC passing it NARGS arguments
82169     from the array pointed to by ARGS.  The argument FUNC can be a
82170     function symbol (e.g., returned by ‘intern’ described above), a
82171     module function returned by ‘make_function’ (*note Module
82172     Functions::), a subroutine written in C, etc.  If NARGS is zero,
82173     ARGS can be a ‘NULL’ pointer.
82174
82175     The function returns the value that FUNC returned.
82176
82177   If your module includes potentially long-running code, it is a good
82178idea to check from time to time in that code whether the user wants to
82179quit, e.g., by typing ‘C-g’ (*note Quitting::).  The following function,
82180which is available since Emacs 26.1, is provided for that purpose.
82181
82182 -- Function: bool should_quit (emacs_env *ENV)
82183     This function returns ‘true’ if the user wants to quit.  In that
82184     case, we recommend that your module function aborts any on-going
82185     processing and returns as soon as possible.  In most cases, use
82186     ‘process_input’ instead.
82187
82188   To process input events in addition to checking whether the user
82189wants to quit, use the following function, which is available since
82190Emacs 27.1.
82191
82192 -- Function: enum emacs_process_input_result process_input (emacs_env
82193          *ENV)
82194     This function processes pending input events.  It returns
82195     ‘emacs_process_input_quit’ if the user wants to quit or an error
82196     occurred while processing signals.  In that case, we recommend that
82197     your module function aborts any on-going processing and returns as
82198     soon as possible.  If the module code may continue running,
82199     ‘process_input’ returns ‘emacs_process_input_continue’.  The return
82200     value is ‘emacs_process_input_continue’ if and only if there is no
82201     pending nonlocal exit in ‘env’.  If the module continues after
82202     calling ‘process_input’, global state such as variable values and
82203     buffer content may have been modified in arbitrary ways.
82204
82205
82206File: elisp.info,  Node: Module Nonlocal,  Prev: Module Misc,  Up: Writing Dynamic Modules
82207
82208E.8.5 Nonlocal Exits in Modules
82209-------------------------------
82210
82211Emacs Lisp supports nonlocal exits, whereby program control is
82212transferred from one point in a program to another remote point.  *Note
82213Nonlocal Exits::.  Thus, Lisp functions called by your module might exit
82214nonlocally by calling ‘signal’ or ‘throw’, and your module functions
82215must handle such nonlocal exits properly.  Such handling is needed
82216because C programs will not automatically release resources and perform
82217other cleanups in these cases; your module code must itself do it.  The
82218module API provides facilities for that, described in this subsection.
82219They are generally available since Emacs 25; those of them that became
82220available in later releases explicitly call out the first Emacs version
82221where they became part of the API.
82222
82223   When some Lisp code called by a module function signals an error or
82224throws, the nonlocal exit is trapped, and the pending exit and its
82225associated data are stored in the environment.  Whenever a nonlocal exit
82226is pending in the environment, any module API function called with a
82227pointer to that environment will return immediately without any
82228processing (the functions ‘non_local_exit_check’, ‘non_local_exit_get’,
82229and ‘non_local_exit_clear’ are exceptions from this rule).  If your
82230module function then does nothing and returns to Emacs, a pending
82231nonlocal exit will cause Emacs to act on it: signal an error or throw to
82232the corresponding ‘catch’.
82233
82234   So the simplest “handling” of nonlocal exits in module functions is
82235to do nothing special and let the rest of your code to run as if nothing
82236happened.  However, this can cause two classes of problems:
82237
82238   − Your module function might use uninitialized or undefined values,
82239     since API functions return immediately without producing the
82240     expected results.
82241
82242   − Your module might leak resources, because it might not have the
82243     opportunity to release them.
82244
82245   Therefore, we recommend that your module functions check for nonlocal
82246exit conditions and recover from them, using the functions described
82247below.
82248
82249 -- Function: enum emacs_funcall_exit non_local_exit_check (emacs_env
82250          *ENV)
82251     This function returns the kind of nonlocal exit condition stored in
82252     ENV.  The possible values are:
82253
82254     ‘emacs_funcall_exit_return’
82255          The last API function exited normally.
82256     ‘emacs_funcall_exit_signal’
82257          The last API function signaled an error.
82258     ‘emacs_funcall_exit_throw’
82259          The last API function exited via ‘throw’.
82260
82261 -- Function: enum emacs_funcall_exit non_local_exit_get (emacs_env
82262          *ENV, emacs_value *SYMBOL, emacs_value *DATA)
82263     This function returns the kind of nonlocal exit condition stored in
82264     ENV, like ‘non_local_exit_check’ does, but it also returns the full
82265     information about the nonlocal exit, if any.  If the return value
82266     is ‘emacs_funcall_exit_signal’, the function stores the error
82267     symbol in ‘*SYMBOL’ and the error data in ‘*DATA’ (*note Signaling
82268     Errors::).  If the return value is ‘emacs_funcall_exit_throw’, the
82269     function stores the ‘catch’ tag symbol in ‘*SYMBOL’ and the ‘throw’
82270     value in ‘*DATA’.  The function doesn’t store anything in memory
82271     pointed by these arguments when the return value is
82272     ‘emacs_funcall_exit_return’.
82273
82274   You should check nonlocal exit conditions where it matters: before
82275you allocated some resource or after you allocated a resource that might
82276need freeing, or where a failure means further processing is impossible
82277or infeasible.
82278
82279   Once your module function detected that a nonlocal exit is pending,
82280it can either return to Emacs (after performing the necessary local
82281cleanup), or it can attempt to recover from the nonlocal exit.  The
82282following API functions will help with these tasks.
82283
82284 -- Function: void non_local_exit_clear (emacs_env *ENV)
82285     This function clears the pending nonlocal exit conditions and data
82286     from ENV.  After calling it, the module API functions will work
82287     normally.  Use this function if your module function can recover
82288     from nonlocal exits of the Lisp functions it calls and continue,
82289     and also before calling any of the following two functions (or any
82290     other API functions, if you want them to perform their intended
82291     processing when a nonlocal exit is pending).
82292
82293 -- Function: void non_local_exit_throw (emacs_env *ENV, emacs_value
82294          TAG, emacs_value VALUE)
82295     This function throws to the Lisp ‘catch’ symbol represented by TAG,
82296     passing it VALUE as the value to return.  Your module function
82297     should in general return soon after calling this function.  One use
82298     of this function is when you want to re-throw a non-local exit from
82299     one of the called API or Lisp functions.
82300
82301 -- Function: void non_local_exit_signal (emacs_env *ENV, emacs_value
82302          ERROR, emacs_value DATA)
82303     This function signals the error represented by ERROR with the
82304     specified error data DATA.  The module function should return soon
82305     after calling this function.  This function could be useful, e.g.,
82306     for signaling errors from module functions to Emacs.
82307
82308
82309File: elisp.info,  Node: Object Internals,  Next: C Integer Types,  Prev: Writing Dynamic Modules,  Up: GNU Emacs Internals
82310
82311E.9 Object Internals
82312====================
82313
82314Emacs Lisp provides a rich set of the data types.  Some of them, like
82315cons cells, integers and strings, are common to nearly all Lisp
82316dialects.  Some others, like markers and buffers, are quite special and
82317needed to provide the basic support to write editor commands in Lisp.
82318To implement such a variety of object types and provide an efficient way
82319to pass objects between the subsystems of an interpreter, there is a set
82320of C data structures and a special type to represent the pointers to all
82321of them, which is known as “tagged pointer”.
82322
82323   In C, the tagged pointer is an object of type ‘Lisp_Object’.  Any
82324initialized variable of such a type always holds the value of one of the
82325following basic data types: integer, symbol, string, cons cell, float,
82326or vectorlike object.  Each of these data types has the corresponding
82327tag value.  All tags are enumerated by ‘enum Lisp_Type’ and placed into
82328a 3-bit bitfield of the ‘Lisp_Object’.  The rest of the bits is the
82329value itself.  Integers are immediate, i.e., directly represented by
82330those “value bits”, and all other objects are represented by the C
82331pointers to a corresponding object allocated from the heap.  Width of
82332the ‘Lisp_Object’ is platform- and configuration-dependent: usually it’s
82333equal to the width of an underlying platform pointer (i.e., 32-bit on a
8233432-bit machine and 64-bit on a 64-bit one), but also there is a special
82335configuration where ‘Lisp_Object’ is 64-bit but all pointers are 32-bit.
82336The latter trick was designed to overcome the limited range of values
82337for Lisp integers on a 32-bit system by using 64-bit ‘long long’ type
82338for ‘Lisp_Object’.
82339
82340   The following C data structures are defined in ‘lisp.h’ to represent
82341the basic data types beyond integers:
82342
82343‘struct Lisp_Cons’
82344     Cons cell, an object used to construct lists.
82345
82346‘struct Lisp_String’
82347     String, the basic object to represent a sequence of characters.
82348
82349‘struct Lisp_Vector’
82350     Array, a fixed-size set of Lisp objects which may be accessed by an
82351     index.
82352
82353‘struct Lisp_Symbol’
82354     Symbol, the unique-named entity commonly used as an identifier.
82355
82356‘struct Lisp_Float’
82357     Floating-point value.
82358
82359   These types are the first-class citizens of an internal type system.
82360Since the tag space is limited, all other types are the subtypes of
82361‘Lisp_Vectorlike’.  Vector subtypes are enumerated by ‘enum pvec_type’,
82362and nearly all complex objects like windows, buffers, frames, and
82363processes fall into this category.
82364
82365   Below there is a description of a few subtypes of ‘Lisp_Vectorlike’.
82366Buffer object represents the text to display and edit.  Window is the
82367part of display structure which shows the buffer or is used as a
82368container to recursively place other windows on the same frame.  (Do not
82369confuse Emacs Lisp window object with the window as an entity managed by
82370the user interface system like X; in Emacs terminology, the latter is
82371called frame.)  Finally, process object is used to manage the
82372subprocesses.
82373
82374* Menu:
82375
82376* Buffer Internals::    Components of a buffer structure.
82377* Window Internals::    Components of a window structure.
82378* Process Internals::   Components of a process structure.
82379
82380
82381File: elisp.info,  Node: Buffer Internals,  Next: Window Internals,  Up: Object Internals
82382
82383E.9.1 Buffer Internals
82384----------------------
82385
82386Two structures (see ‘buffer.h’) are used to represent buffers in C.  The
82387‘buffer_text’ structure contains fields describing the text of a buffer;
82388the ‘buffer’ structure holds other fields.  In the case of indirect
82389buffers, two or more ‘buffer’ structures reference the same
82390‘buffer_text’ structure.
82391
82392   Here are some of the fields in ‘struct buffer_text’:
82393
82394‘beg’
82395     The address of the buffer contents.  The buffer contents is a
82396     linear C array of ‘char’, with the gap somewhere in its midst.
82397
82398‘gpt’
82399‘gpt_byte’
82400     The character and byte positions of the buffer gap.  *Note Buffer
82401     Gap::.
82402
82403‘z’
82404‘z_byte’
82405     The character and byte positions of the end of the buffer text.
82406
82407‘gap_size’
82408     The size of buffer’s gap.  *Note Buffer Gap::.
82409
82410‘modiff’
82411‘save_modiff’
82412‘chars_modiff’
82413‘overlay_modiff’
82414     These fields count the number of buffer-modification events
82415     performed in this buffer.  ‘modiff’ is incremented after each
82416     buffer-modification event, and is never otherwise changed;
82417     ‘save_modiff’ contains the value of ‘modiff’ the last time the
82418     buffer was visited or saved; ‘chars_modiff’ counts only
82419     modifications to the characters in the buffer, ignoring all other
82420     kinds of changes (such as text properties); and ‘overlay_modiff’
82421     counts only modifications to the buffer’s overlays.
82422
82423‘beg_unchanged’
82424‘end_unchanged’
82425     The number of characters at the start and end of the text that are
82426     known to be unchanged since the last complete redisplay.
82427
82428‘unchanged_modified’
82429‘overlay_unchanged_modified’
82430     The values of ‘modiff’ and ‘overlay_modiff’, respectively, after
82431     the last complete redisplay.  If their current values match
82432     ‘modiff’ or ‘overlay_modiff’, that means ‘beg_unchanged’ and
82433     ‘end_unchanged’ contain no useful information.
82434
82435‘markers’
82436     The markers that refer to this buffer.  This is actually a single
82437     marker, and successive elements in its marker “chain” (a linked
82438     list) are the other markers referring to this buffer text.
82439
82440‘intervals’
82441     The interval tree which records the text properties of this buffer.
82442
82443   Some of the fields of ‘struct buffer’ are:
82444
82445‘header’
82446     A header of type ‘union vectorlike_header’ is common to all
82447     vectorlike objects.
82448
82449‘own_text’
82450     A ‘struct buffer_text’ structure that ordinarily holds the buffer
82451     contents.  In indirect buffers, this field is not used.
82452
82453‘text’
82454     A pointer to the ‘buffer_text’ structure for this buffer.  In an
82455     ordinary buffer, this is the ‘own_text’ field above.  In an
82456     indirect buffer, this is the ‘own_text’ field of the base buffer.
82457
82458‘next’
82459     A pointer to the next buffer, in the chain of all buffers,
82460     including killed buffers.  This chain is used only for allocation
82461     and garbage collection, in order to collect killed buffers
82462     properly.
82463
82464‘pt’
82465‘pt_byte’
82466     The character and byte positions of point in a buffer.
82467
82468‘begv’
82469‘begv_byte’
82470     The character and byte positions of the beginning of the accessible
82471     range of text in the buffer.
82472
82473‘zv’
82474‘zv_byte’
82475     The character and byte positions of the end of the accessible range
82476     of text in the buffer.
82477
82478‘base_buffer’
82479     In an indirect buffer, this points to the base buffer.  In an
82480     ordinary buffer, it is null.
82481
82482‘local_flags’
82483     This field contains flags indicating that certain variables are
82484     local in this buffer.  Such variables are declared in the C code
82485     using ‘DEFVAR_PER_BUFFER’, and their buffer-local bindings are
82486     stored in fields in the buffer structure itself.  (Some of these
82487     fields are described in this table.)
82488
82489‘modtime’
82490     The modification time of the visited file.  It is set when the file
82491     is written or read.  Before writing the buffer into a file, this
82492     field is compared to the modification time of the file to see if
82493     the file has changed on disk.  *Note Buffer Modification::.
82494
82495‘auto_save_modified’
82496     The time when the buffer was last auto-saved.
82497
82498‘last_window_start’
82499     The ‘window-start’ position in the buffer as of the last time the
82500     buffer was displayed in a window.
82501
82502‘clip_changed’
82503     This flag indicates that narrowing has changed in the buffer.
82504     *Note Narrowing::.
82505
82506‘prevent_redisplay_optimizations_p’
82507     This flag indicates that redisplay optimizations should not be used
82508     to display this buffer.
82509
82510‘overlay_center’
82511     This field holds the current overlay center position.  *Note
82512     Managing Overlays::.
82513
82514‘overlays_before’
82515‘overlays_after’
82516     These fields hold, respectively, a list of overlays that end at or
82517     before the current overlay center, and a list of overlays that end
82518     after the current overlay center.  *Note Managing Overlays::.
82519     ‘overlays_before’ is sorted in order of decreasing end position,
82520     and ‘overlays_after’ is sorted in order of increasing beginning
82521     position.
82522
82523‘name’
82524     A Lisp string that names the buffer.  It is guaranteed to be
82525     unique.  *Note Buffer Names::.  This and the following fields have
82526     their names in the C struct definition end in a ‘_’ to indicate
82527     that they should not be accessed directly, but via the ‘BVAR’
82528     macro, like this:
82529
82530            Lisp_Object buf_name = BVAR (buffer, name);
82531
82532‘save_length’
82533     The length of the file this buffer is visiting, when last read or
82534     saved.  It can have 2 special values: −1 means auto-saving was
82535     turned off in this buffer, and −2 means don’t turn off auto-saving
82536     if buffer text shrinks a lot.  This and other fields concerned with
82537     saving are not kept in the ‘buffer_text’ structure because indirect
82538     buffers are never saved.
82539
82540‘directory’
82541     The directory for expanding relative file names.  This is the value
82542     of the buffer-local variable ‘default-directory’ (*note File Name
82543     Expansion::).
82544
82545‘filename’
82546     The name of the file visited in this buffer, or ‘nil’.  This is the
82547     value of the buffer-local variable ‘buffer-file-name’ (*note Buffer
82548     File Name::).
82549
82550‘undo_list’
82551‘backed_up’
82552‘auto_save_file_name’
82553‘auto_save_file_format’
82554‘read_only’
82555‘file_format’
82556‘file_truename’
82557‘invisibility_spec’
82558‘display_count’
82559‘display_time’
82560     These fields store the values of Lisp variables that are
82561     automatically buffer-local (*note Buffer-Local Variables::), whose
82562     corresponding variable names have the additional prefix ‘buffer-’
82563     and have underscores replaced with dashes.  For instance,
82564     ‘undo_list’ stores the value of ‘buffer-undo-list’.
82565
82566‘mark’
82567     The mark for the buffer.  The mark is a marker, hence it is also
82568     included on the list ‘markers’.  *Note The Mark::.
82569
82570‘local_var_alist’
82571     The association list describing the buffer-local variable bindings
82572     of this buffer, not including the built-in buffer-local bindings
82573     that have special slots in the buffer object.  (Those slots are
82574     omitted from this table.)  *Note Buffer-Local Variables::.
82575
82576‘major_mode’
82577     Symbol naming the major mode of this buffer, e.g., ‘lisp-mode’.
82578
82579‘mode_name’
82580     Pretty name of the major mode, e.g., ‘"Lisp"’.
82581
82582‘keymap’
82583‘abbrev_table’
82584‘syntax_table’
82585‘category_table’
82586‘display_table’
82587     These fields store the buffer’s local keymap (*note Keymaps::),
82588     abbrev table (*note Abbrev Tables::), syntax table (*note Syntax
82589     Tables::), category table (*note Categories::), and display table
82590     (*note Display Tables::).
82591
82592‘downcase_table’
82593‘upcase_table’
82594‘case_canon_table’
82595     These fields store the conversion tables for converting text to
82596     lower case, upper case, and for canonicalizing text for case-fold
82597     search.  *Note Case Tables::.
82598
82599‘minor_modes’
82600     An alist of the minor modes of this buffer.
82601
82602‘pt_marker’
82603‘begv_marker’
82604‘zv_marker’
82605     These fields are only used in an indirect buffer, or in a buffer
82606     that is the base of an indirect buffer.  Each holds a marker that
82607     records ‘pt’, ‘begv’, and ‘zv’ respectively, for this buffer when
82608     the buffer is not current.
82609
82610‘mode_line_format’
82611‘header_line_format’
82612‘case_fold_search’
82613‘tab_width’
82614‘fill_column’
82615‘left_margin’
82616‘auto_fill_function’
82617‘truncate_lines’
82618‘word_wrap’
82619‘ctl_arrow’
82620‘bidi_display_reordering’
82621‘bidi_paragraph_direction’
82622‘selective_display’
82623‘selective_display_ellipses’
82624‘overwrite_mode’
82625‘abbrev_mode’
82626‘mark_active’
82627‘enable_multibyte_characters’
82628‘buffer_file_coding_system’
82629‘cache_long_line_scans’
82630‘point_before_scroll’
82631‘left_fringe_width’
82632‘right_fringe_width’
82633‘fringes_outside_margins’
82634‘scroll_bar_width’
82635‘indicate_empty_lines’
82636‘indicate_buffer_boundaries’
82637‘fringe_indicator_alist’
82638‘fringe_cursor_alist’
82639‘scroll_up_aggressively’
82640‘scroll_down_aggressively’
82641‘cursor_type’
82642‘cursor_in_non_selected_windows’
82643     These fields store the values of Lisp variables that are
82644     automatically buffer-local (*note Buffer-Local Variables::), whose
82645     corresponding variable names have underscores replaced with dashes.
82646     For instance, ‘mode_line_format’ stores the value of
82647     ‘mode-line-format’.
82648
82649‘last_selected_window’
82650     This is the last window that was selected with this buffer in it,
82651     or ‘nil’ if that window no longer displays this buffer.
82652
82653
82654File: elisp.info,  Node: Window Internals,  Next: Process Internals,  Prev: Buffer Internals,  Up: Object Internals
82655
82656E.9.2 Window Internals
82657----------------------
82658
82659The fields of a window (for a complete list, see the definition of
82660‘struct window’ in ‘window.h’) include:
82661
82662‘frame’
82663     The frame that this window is on, as a Lisp object.
82664
82665‘mini’
82666     Non-zero if this window is a minibuffer window, a window showing
82667     the minibuffer or the echo area.
82668
82669‘pseudo_window_p’
82670     Non-zero if this window is a “pseudo window”.  A pseudo window is
82671     either a window used to display the menu bar or the tool bar (when
82672     Emacs uses toolkits that don’t display their own menu bar and tool
82673     bar) or the tab bar or a window showing a tooltip on a tooltip
82674     frame.  Pseudo windows are in general not accessible from Lisp
82675     code.
82676
82677‘parent’
82678     Internally, Emacs arranges windows in a tree; each group of
82679     siblings has a parent window whose area includes all the siblings.
82680     This field points to the window’s parent in that tree, as a Lisp
82681     object.  For the root window of the tree and a minibuffer window
82682     this is always ‘nil’.
82683
82684     Parent windows do not display buffers, and play little role in
82685     display except to shape their child windows.  Emacs Lisp programs
82686     cannot directly manipulate parent windows; they operate on the
82687     windows at the leaves of the tree, which actually display buffers.
82688
82689‘contents’
82690     For a leaf window and windows showing a tooltip, this is the
82691     buffer, as a Lisp object, that the window is displaying.  For an
82692     internal (“parent”) window, this is its first child window.  For a
82693     pseudo window showing a menu or tool bar this is ‘nil’.  It is also
82694     ‘nil’ for a window that has been deleted.
82695
82696‘next’
82697‘prev’
82698     The next and previous sibling of this window as Lisp objects.
82699     ‘next’ is ‘nil’ if the window is the right-most or bottom-most in
82700     its group; ‘prev’ is ‘nil’ if it is the left-most or top-most in
82701     its group.  Whether the sibling is left/right or up/down is
82702     determined by the ‘horizontal’ field of the sibling’s parent: if
82703     it’s non-zero, the siblings are arranged horizontally.
82704
82705     As a special case, ‘next’ of a frame’s root window points to the
82706     frame’s minibuffer window, provided this is not a minibuffer-only
82707     or minibuffer-less frame.  On such frames ‘prev’ of the minibuffer
82708     window points to that frame’s root window.  In any other case, the
82709     root window’s ‘next’ and the minibuffer window’s (if present)
82710     ‘prev’ fields are ‘nil’.
82711
82712‘left_col’
82713     The left-hand edge of the window, measured in columns, relative to
82714     the leftmost column (column 0) of the window’s native frame.
82715
82716‘top_line’
82717     The top edge of the window, measured in lines, relative to the
82718     topmost line (line 0) of the window’s native frame.
82719
82720‘pixel_left’
82721‘pixel_top’
82722     The left-hand and top edges of this window, measured in pixels,
82723     relative to the top-left corner (0, 0) of the window’s native
82724     frame.
82725
82726‘total_cols’
82727‘total_lines’
82728     The total width and height of the window, measured in columns and
82729     lines respectively.  The values include scroll bars and fringes,
82730     dividers and/or the separator line on the right of the window (if
82731     any).
82732
82733‘pixel_width;’
82734‘pixel_height;’
82735     The total width and height of the window measured in pixels.
82736
82737‘start’
82738     A marker pointing to the position in the buffer that is the first
82739     character (in the logical order, *note Bidirectional Display::)
82740     displayed in the window.
82741
82742‘pointm’
82743     This is the value of point in the current buffer when this window
82744     is selected; when it is not selected, it retains its previous
82745     value.
82746
82747‘old_pointm’
82748     The value of ‘pointm’ at the last redisplay time.
82749
82750‘force_start’
82751     If this flag is non-‘nil’, it says that the window has been
82752     scrolled explicitly by the Lisp program, and the value of the
82753     window’s ‘start’ was set for redisplay to honor.  This affects what
82754     the next redisplay does if point is off the screen: instead of
82755     scrolling the window to show the text around point, it moves point
82756     to a location that is on the screen.
82757
82758‘optional_new_start’
82759     This is similar to ‘force_start’, but the next redisplay will only
82760     obey it if point stays visible.
82761
82762‘start_at_line_beg’
82763     Non-‘nil’ means current value of ‘start’ was the beginning of a
82764     line when it was chosen.
82765
82766‘use_time’
82767     This is the last time that the window was selected.  The function
82768     ‘get-lru-window’ uses this field.
82769
82770‘sequence_number’
82771     A unique number assigned to this window when it was created.
82772
82773‘last_modified’
82774     The ‘modiff’ field of the window’s buffer, as of the last time a
82775     redisplay completed in this window.
82776
82777‘last_overlay_modified’
82778     The ‘overlay_modiff’ field of the window’s buffer, as of the last
82779     time a redisplay completed in this window.
82780
82781‘last_point’
82782     The buffer’s value of point, as of the last time a redisplay
82783     completed in this window.
82784
82785‘last_had_star’
82786     A non-zero value means the window’s buffer was modified when the
82787     window was last updated.
82788
82789‘vertical_scroll_bar_type’
82790‘horizontal_scroll_bar_type’
82791     The types of this window’s vertical and horizontal scroll bars.
82792
82793‘scroll_bar_width’
82794‘scroll_bar_height’
82795     The width of this window’s vertical scroll bar and the height of
82796     this window’s horizontal scroll bar, in pixels.
82797
82798‘left_margin_cols’
82799‘right_margin_cols’
82800     The widths of the left and right margins in this window.  A value
82801     of zero means no margin.
82802
82803‘left_fringe_width’
82804‘right_fringe_width’
82805     The pixel widths of the left and right fringes in this window.  A
82806     value of −1 means use the values of the frame.
82807
82808‘fringes_outside_margins’
82809     A non-zero value means the fringes outside the display margins;
82810     othersize they are between the margin and the text.
82811
82812‘window_end_pos’
82813     This is computed as ‘z’ minus the buffer position of the last glyph
82814     in the current matrix of the window.  The value is only valid if
82815     ‘window_end_valid’ is non-zero.
82816
82817‘window_end_bytepos’
82818     The byte position corresponding to ‘window_end_pos’.
82819
82820‘window_end_vpos’
82821     The window-relative vertical position of the line containing
82822     ‘window_end_pos’.
82823
82824‘window_end_valid’
82825     This field is set to a non-zero value if ‘window_end_pos’ and
82826     ‘window_end_vpos’ are truly valid.  This is zero if nontrivial
82827     redisplay is pre-empted, since in that case the display that
82828     ‘window_end_pos’ was computed for did not get onto the screen.
82829
82830‘cursor’
82831     A structure describing where the cursor is in this window.
82832
82833‘last_cursor_vpos’
82834     The window-relative vertical position of the line showing the
82835     cursor as of the last redisplay that finished.
82836
82837‘phys_cursor’
82838     A structure describing where the cursor of this window physically
82839     is.
82840
82841‘phys_cursor_type’
82842‘phys_cursor_height’
82843‘phys_cursor_width’
82844     The type, height, and width of the cursor that was last displayed
82845     on this window.
82846
82847‘phys_cursor_on_p’
82848     This field is non-zero if the cursor is physically on.
82849
82850‘cursor_off_p’
82851     Non-zero means the cursor in this window is logically off.  This is
82852     used for blinking the cursor.
82853
82854‘last_cursor_off_p’
82855     This field contains the value of ‘cursor_off_p’ as of the time of
82856     the last redisplay.
82857
82858‘must_be_updated_p’
82859     This is set to 1 during redisplay when this window must be updated.
82860
82861‘hscroll’
82862     This is the number of columns that the display in the window is
82863     scrolled horizontally to the left.  Normally, this is 0.  When only
82864     the current line is hscrolled, this describes how much the current
82865     line is scrolled.
82866
82867‘min_hscroll’
82868     Minimum value of ‘hscroll’, set by the user via
82869     ‘set-window-hscroll’ (*note Horizontal Scrolling::).  When only the
82870     current line is hscrolled, this describes the horizontal scrolling
82871     of lines other than the current one.
82872
82873‘vscroll’
82874     Vertical scroll amount, in pixels.  Normally, this is 0.
82875
82876‘dedicated’
82877     Non-‘nil’ if this window is dedicated to its buffer.
82878
82879‘combination_limit’
82880     This window’s combination limit, meaningful only for a parent
82881     window.  If this is ‘t’, then it is not allowed to delete this
82882     window and recombine its child windows with other siblings of this
82883     window.
82884
82885‘window_parameters’
82886     The alist of this window’s parameters.
82887
82888‘display_table’
82889     The window’s display table, or ‘nil’ if none is specified for it.
82890
82891‘update_mode_line’
82892     Non-zero means this window’s mode line needs to be updated.
82893
82894‘mode_line_height’
82895‘header_line_height’
82896     The height in pixels of the mode line and the header line, or −1 if
82897     not known.
82898
82899‘base_line_number’
82900     The line number of a certain position in the buffer, or zero.  This
82901     is used for displaying the line number of point in the mode line.
82902
82903‘base_line_pos’
82904     The position in the buffer for which the line number is known, or
82905     zero meaning none is known.  If it is −1, don’t display the line
82906     number as long as the window shows that buffer.
82907
82908‘column_number_displayed’
82909     The column number currently displayed in this window’s mode line,
82910     or −1 if column numbers are not being displayed.
82911
82912‘current_matrix’
82913‘desired_matrix’
82914     Glyph matrices describing the current and desired display of this
82915     window.
82916
82917
82918File: elisp.info,  Node: Process Internals,  Prev: Window Internals,  Up: Object Internals
82919
82920E.9.3 Process Internals
82921-----------------------
82922
82923The fields of a process (for a complete list, see the definition of
82924‘struct Lisp_Process’ in ‘process.h’) include:
82925
82926‘name’
82927     A Lisp string, the name of the process.
82928
82929‘command’
82930     A list containing the command arguments that were used to start
82931     this process.  For a network or serial process, it is ‘nil’ if the
82932     process is running or ‘t’ if the process is stopped.
82933
82934‘filter’
82935     A Lisp function used to accept output from the process.
82936
82937‘sentinel’
82938     A Lisp function called whenever the state of the process changes.
82939
82940‘buffer’
82941     The associated buffer of the process.
82942
82943‘pid’
82944     An integer, the operating system’s process ID.  Pseudo-processes
82945     such as network or serial connections use a value of 0.
82946
82947‘childp’
82948     A flag, ‘t’ if this is really a child process.  For a network or
82949     serial connection, it is a plist based on the arguments to
82950     ‘make-network-process’ or ‘make-serial-process’.
82951
82952‘mark’
82953     A marker indicating the position of the end of the last output from
82954     this process inserted into the buffer.  This is often but not
82955     always the end of the buffer.
82956
82957‘kill_without_query’
82958     If this is non-zero, killing Emacs while this process is still
82959     running does not ask for confirmation about killing the process.
82960
82961‘raw_status’
82962     The raw process status, as returned by the ‘wait’ system call.
82963
82964‘status’
82965     The process status, as ‘process-status’ should return it.  This is
82966     a Lisp symbol, a cons cell, or a list.
82967
82968‘tick’
82969‘update_tick’
82970     If these two fields are not equal, a change in the status of the
82971     process needs to be reported, either by running the sentinel or by
82972     inserting a message in the process buffer.
82973
82974‘pty_flag’
82975     Non-zero if communication with the subprocess uses a pty; zero if
82976     it uses a pipe.
82977
82978‘infd’
82979     The file descriptor for input from the process.
82980
82981‘outfd’
82982     The file descriptor for output to the process.
82983
82984‘tty_name’
82985     The name of the terminal that the subprocess is using, or ‘nil’ if
82986     it is using pipes.
82987
82988‘decode_coding_system’
82989     Coding-system for decoding the input from this process.
82990
82991‘decoding_buf’
82992     A working buffer for decoding.
82993
82994‘decoding_carryover’
82995     Size of carryover in decoding.
82996
82997‘encode_coding_system’
82998     Coding-system for encoding the output to this process.
82999
83000‘encoding_buf’
83001     A working buffer for encoding.
83002
83003‘inherit_coding_system_flag’
83004     Flag to set ‘coding-system’ of the process buffer from the coding
83005     system used to decode process output.
83006
83007‘type’
83008     Symbol indicating the type of process: ‘real’, ‘network’, ‘serial’.
83009
83010
83011File: elisp.info,  Node: C Integer Types,  Prev: Object Internals,  Up: GNU Emacs Internals
83012
83013E.10 C Integer Types
83014====================
83015
83016Here are some guidelines for use of integer types in the Emacs C source
83017code.  These guidelines sometimes give competing advice; common sense is
83018advised.
83019
83020   • Avoid arbitrary limits.  For example, avoid ‘int len = strlen (s);’
83021     unless the length of ‘s’ is required for other reasons to fit in
83022     ‘int’ range.
83023
83024   • Do not assume that signed integer arithmetic wraps around on
83025     overflow.  This is no longer true of Emacs porting targets: signed
83026     integer overflow has undefined behavior in practice, and can dump
83027     core or even cause earlier or later code to behave illogically.
83028     Unsigned overflow does wrap around reliably, modulo a power of two.
83029
83030   • Prefer signed types to unsigned, as code gets confusing when signed
83031     and unsigned types are combined.  Many other guidelines assume that
83032     types are signed; in the rarer cases where unsigned types are
83033     needed, similar advice may apply to the unsigned counterparts
83034     (e.g., ‘size_t’ instead of ‘ptrdiff_t’, or ‘uintptr_t’ instead of
83035     ‘intptr_t’).
83036
83037   • Prefer ‘int’ for Emacs character codes, in the range 0 .. 0x3FFFFF.
83038     More generally, prefer ‘int’ for integers known to be in ‘int’
83039     range, e.g., screen column counts.
83040
83041   • Prefer ‘ptrdiff_t’ for sizes, i.e., for integers bounded by the
83042     maximum size of any individual C object or by the maximum number of
83043     elements in any C array.  This is part of Emacs’s general
83044     preference for signed types.  Using ‘ptrdiff_t’ limits objects to
83045     ‘PTRDIFF_MAX’ bytes, but larger objects would cause trouble anyway
83046     since they would break pointer subtraction, so this does not impose
83047     an arbitrary limit.
83048
83049   • Avoid ‘ssize_t’ except when communicating to low-level APIs that
83050     have ‘ssize_t’-related limitations.  Although it’s equivalent to
83051     ‘ptrdiff_t’ on typical platforms, ‘ssize_t’ is occasionally
83052     narrower, so using it for size-related calculations could overflow.
83053     Also, ‘ptrdiff_t’ is more ubiquitous and better-standardized, has
83054     standard ‘printf’ formats, and is the basis for Emacs’s internal
83055     size-overflow checking.  When using ‘ssize_t’, please note that
83056     POSIX requires support only for values in the range −1 ..
83057     ‘SSIZE_MAX’.
83058
83059   • Normally, prefer ‘intptr_t’ for internal representations of
83060     pointers, or for integers bounded only by the number of objects
83061     that can exist at any given time or by the total number of bytes
83062     that can be allocated.  However, prefer ‘uintptr_t’ to represent
83063     pointer arithmetic that could cross page boundaries.  For example,
83064     on a machine with a 32-bit address space an array could cross the
83065     0x7fffffff/0x80000000 boundary, which would cause an integer
83066     overflow when adding 1 to ‘(intptr_t) 0x7fffffff’.
83067
83068   • Prefer the Emacs-defined type ‘EMACS_INT’ for representing values
83069     converted to or from Emacs Lisp fixnums, as fixnum arithmetic is
83070     based on ‘EMACS_INT’.
83071
83072   • When representing a system value (such as a file size or a count of
83073     seconds since the Epoch), prefer the corresponding system type
83074     (e.g., ‘off_t’, ‘time_t’).  Do not assume that a system type is
83075     signed, unless this assumption is known to be safe.  For example,
83076     although ‘off_t’ is always signed, ‘time_t’ need not be.
83077
83078   • Prefer ‘intmax_t’ for representing values that might be any signed
83079     integer value.  A ‘printf’-family function can print such a value
83080     via a format like ‘"%"PRIdMAX’.
83081
83082   • Prefer ‘bool’, ‘false’ and ‘true’ for booleans.  Using ‘bool’ can
83083     make programs easier to read and a bit faster than using ‘int’.
83084     Although it is also OK to use ‘int’, ‘0’ and ‘1’, this older style
83085     is gradually being phased out.  When using ‘bool’, respect the
83086     limitations of the replacement implementation of ‘bool’, as
83087     documented in the source file ‘lib/stdbool.in.h’.  In particular,
83088     boolean bitfields should be of type ‘bool_bf’, not ‘bool’, so that
83089     they work correctly even when compiling Objective C with standard
83090     GCC.
83091
83092   • In bitfields, prefer ‘unsigned int’ or ‘signed int’ to ‘int’, as
83093     ‘int’ is less portable: it might be signed, and might not be.
83094     Single-bit bit fields should be ‘unsigned int’ or ‘bool_bf’ so that
83095     their values are 0 or 1.
83096
83097
83098File: elisp.info,  Node: Standard Errors,  Next: Standard Keymaps,  Prev: GNU Emacs Internals,  Up: Top
83099
83100Appendix F Standard Errors
83101**************************
83102
83103Here is a list of the more important error symbols in standard Emacs,
83104grouped by concept.  The list includes each symbol’s message and a cross
83105reference to a description of how the error can occur.
83106
83107   Each error symbol has a set of parent error conditions that is a list
83108of symbols.  Normally this list includes the error symbol itself and the
83109symbol ‘error’.  Occasionally it includes additional symbols, which are
83110intermediate classifications, narrower than ‘error’ but broader than a
83111single error symbol.  For example, all the errors in accessing files
83112have the condition ‘file-error’.  If we do not say here that a certain
83113error symbol has additional error conditions, that means it has none.
83114
83115   As a special exception, the error symbol ‘quit’ does not have the
83116condition ‘error’, because quitting is not considered an error.
83117
83118   Most of these error symbols are defined in C (mainly ‘data.c’), but
83119some are defined in Lisp.  For example, the file ‘userlock.el’ defines
83120the ‘file-locked’ and ‘file-supersession’ errors.  Several of the
83121specialized Lisp libraries distributed with Emacs define their own error
83122symbols.  We do not attempt to list of all those here.
83123
83124   *Note Errors::, for an explanation of how errors are generated and
83125handled.
83126
83127‘error’
83128     The message is ‘error’.  *Note Errors::.
83129
83130‘quit’
83131     The message is ‘Quit’.  *Note Quitting::.
83132
83133‘args-out-of-range’
83134     The message is ‘Args out of range’.  This happens when trying to
83135     access an element beyond the range of a sequence, buffer, or other
83136     container-like object.  *Note Sequences Arrays Vectors::, and see
83137     *note Text::.
83138
83139‘arith-error’
83140     The message is ‘Arithmetic error’.  This occurs when trying to
83141     perform integer division by zero.  *Note Numeric Conversions::, and
83142     see *note Arithmetic Operations::.
83143
83144‘beginning-of-buffer’
83145     The message is ‘Beginning of buffer’.  *Note Character Motion::.
83146
83147‘buffer-read-only’
83148     The message is ‘Buffer is read-only’.  *Note Read Only Buffers::.
83149
83150‘circular-list’
83151     The message is ‘List contains a loop’.  This happens when a
83152     circular structure is encountered.  *Note Circular Objects::.
83153
83154‘cl-assertion-failed’
83155     The message is ‘Assertion failed’.  This happens when the
83156     ‘cl-assert’ macro fails a test.  *Note (cl)Assertions::.
83157
83158‘coding-system-error’
83159     The message is ‘Invalid coding system’.  *Note Lisp and Coding
83160     Systems::.
83161
83162‘cyclic-function-indirection’
83163     The message is ‘Symbol's chain of function indirections contains a
83164     loop’.  *Note Function Indirection::.
83165
83166‘cyclic-variable-indirection’
83167     The message is ‘Symbol's chain of variable indirections contains a
83168     loop’.  *Note Variable Aliases::.
83169
83170‘dbus-error’
83171     The message is ‘D-Bus error’.  *Note (dbus)Errors and Events::.
83172
83173‘end-of-buffer’
83174     The message is ‘End of buffer’.  *Note Character Motion::.
83175
83176‘end-of-file’
83177     The message is ‘End of file during parsing’.  Note that this is not
83178     a subcategory of ‘file-error’, because it pertains to the Lisp
83179     reader, not to file I/O.  *Note Input Functions::.
83180
83181‘file-already-exists’
83182     This is a subcategory of ‘file-error’.  *Note Writing to Files::.
83183
83184‘file-date-error’
83185     This is a subcategory of ‘file-error’.  It occurs when ‘copy-file’
83186     tries and fails to set the last-modification time of the output
83187     file.  *Note Changing Files::.
83188
83189‘file-error’
83190     We do not list the error-strings of this error and its
83191     subcategories, because the error message is normally constructed
83192     from the data items alone when the error condition ‘file-error’ is
83193     present.  Thus, the error-strings are not very relevant.  However,
83194     these error symbols do have ‘error-message’ properties, and if no
83195     data is provided, the ‘error-message’ property _is_ used.  *Note
83196     Files::.
83197
83198‘file-missing’
83199     This is a subcategory of ‘file-error’.  It occurs when an operation
83200     attempts to act on a file that is missing.  *Note Changing Files::.
83201
83202‘compression-error’
83203     This is a subcategory of ‘file-error’, which results from problems
83204     handling a compressed file.  *Note How Programs Do Loading::.
83205
83206‘file-locked’
83207     This is a subcategory of ‘file-error’.  *Note File Locks::.
83208
83209‘file-supersession’
83210     This is a subcategory of ‘file-error’.  *Note Modification Time::.
83211
83212‘file-notify-error’
83213     This is a subcategory of ‘file-error’.  It happens, when a file
83214     could not be watched for changes.  *Note File Notifications::.
83215
83216‘ftp-error’
83217     This is a subcategory of ‘file-error’, which results from problems
83218     in accessing a remote file using ftp.  *Note (emacs)Remote Files::.
83219
83220‘invalid-function’
83221     The message is ‘Invalid function’.  *Note Function Indirection::.
83222
83223‘invalid-read-syntax’
83224     The message is usually ‘Invalid read syntax’.  *Note Printed
83225     Representation::.  This error can also be raised by commands like
83226     ‘eval-expression’ when there’s text following an expression.  In
83227     that case, the message is ‘Trailing garbage following expression’.
83228
83229‘invalid-regexp’
83230     The message is ‘Invalid regexp’.  *Note Regular Expressions::.
83231
83232‘mark-inactive’
83233     The message is ‘The mark is not active now’.  *Note The Mark::.
83234
83235‘no-catch’
83236     The message is ‘No catch for tag’.  *Note Catch and Throw::.
83237
83238‘range-error’
83239     The message is ‘Arithmetic range error’.
83240
83241‘overflow-error’
83242     The message is ‘Arithmetic overflow error’.  This is a subcategory
83243     of ‘range-error’.  This can happen with integers exceeding the
83244     ‘integer-width’ limit.  *Note Integer Basics::.
83245
83246‘scan-error’
83247     The message is ‘Scan error’.  This happens when certain
83248     syntax-parsing functions find invalid syntax or mismatched
83249     parentheses.  Conventionally raised with three argument: a
83250     human-readable error message, the start of the obstacle that cannot
83251     be moved over, and the end of the obstacle.  *Note List Motion::,
83252     and see *note Parsing Expressions::.
83253
83254‘search-failed’
83255     The message is ‘Search failed’.  *Note Searching and Matching::.
83256
83257‘setting-constant’
83258     The message is ‘Attempt to set a constant symbol’.  This happens
83259     when attempting to assign values to ‘nil’, ‘t’,
83260     ‘most-positive-fixnum’, ‘most-negative-fixnum’, and keyword
83261     symbols.  It also happens when attempting to assign values to
83262     ‘enable-multibyte-characters’ and some other symbols whose direct
83263     assignment is not allowed for some reason.  *Note Constant
83264     Variables::.
83265
83266‘text-read-only’
83267     The message is ‘Text is read-only’.  This is a subcategory of
83268     ‘buffer-read-only’.  *Note Special Properties::.
83269
83270‘undefined-color’
83271     The message is ‘Undefined color’.  *Note Color Names::.
83272
83273‘user-error’
83274     The message is the empty string.  *Note Signaling Errors::.
83275
83276‘user-search-failed’
83277     This is like ‘search-failed’, but doesn’t trigger the debugger,
83278     like ‘user-error’.  *Note Signaling Errors::, and see *note
83279     Searching and Matching::.  This is used for searching in Info
83280     files, see *note (info)Search Text::.
83281
83282‘void-function’
83283     The message is ‘Symbol's function definition is void’.  *Note
83284     Function Cells::.
83285
83286‘void-variable’
83287     The message is ‘Symbol's value as variable is void’.  *Note
83288     Accessing Variables::.
83289
83290‘wrong-number-of-arguments’
83291     The message is ‘Wrong number of arguments’.  *Note Argument List::.
83292
83293‘wrong-type-argument’
83294     The message is ‘Wrong type argument’.  *Note Type Predicates::.
83295
83296‘unknown-image-type’
83297     The message is ‘Cannot determine image type’.  *Note Images::.
83298
83299
83300File: elisp.info,  Node: Standard Keymaps,  Next: Standard Hooks,  Prev: Standard Errors,  Up: Top
83301
83302Appendix G Standard Keymaps
83303***************************
83304
83305In this section we list some of the more general keymaps.  Many of these
83306exist when Emacs is first started, but some are loaded only when the
83307respective feature is accessed.
83308
83309   There are many other, more specialized, maps than these; in
83310particular those associated with major and minor modes.  The minibuffer
83311uses several keymaps (*note Completion Commands::).  For more details on
83312keymaps, *note Keymaps::.
83313
83314‘2C-mode-map’
83315     A sparse keymap for subcommands of the prefix ‘C-x 6’.
83316     *Note Two-Column Editing: (emacs)Two-Column.
83317
83318‘abbrev-map’
83319     A sparse keymap for subcommands of the prefix ‘C-x a’.
83320     *Note (emacs)Defining Abbrevs::.
83321
83322‘button-buffer-map’
83323     A sparse keymap useful for buffers containing buffers.
83324     You may want to use this as a parent keymap.  *Note Buttons::.
83325
83326‘button-map’
83327     A sparse keymap used by buttons.
83328
83329‘ctl-x-4-map’
83330     A sparse keymap for subcommands of the prefix ‘C-x 4’.
83331
83332‘ctl-x-5-map’
83333     A sparse keymap for subcommands of the prefix ‘C-x 5’.
83334
83335‘ctl-x-map’
83336     A full keymap for ‘C-x’ commands.
83337
83338‘ctl-x-r-map’
83339     A sparse keymap for subcommands of the prefix ‘C-x r’.
83340     *Note (emacs)Registers::.
83341
83342‘esc-map’
83343     A full keymap for <ESC> (or <Meta>) commands.
83344
83345‘facemenu-keymap’
83346     A sparse keymap used for the ‘M-o’ prefix key.
83347
83348‘function-key-map’
83349     The parent keymap of all ‘local-function-key-map’ (q.v.) instances.
83350
83351‘global-map’
83352     The full keymap containing default global key bindings.
83353     Modes should not modify the Global map.
83354
83355‘goto-map’
83356     A sparse keymap used for the ‘M-g’ prefix key.
83357
83358‘help-map’
83359     A sparse keymap for the keys following the help character ‘C-h’.
83360     *Note Help Functions::.
83361
83362‘Helper-help-map’
83363     A full keymap used by the help utility package.
83364     It has the same keymap in its value cell and in its function cell.
83365
83366‘input-decode-map’
83367     The keymap for translating keypad and function keys.
83368     If there are none, then it contains an empty sparse keymap.  *Note
83369     Translation Keymaps::.
83370
83371‘key-translation-map’
83372     A keymap for translating keys.  This one overrides ordinary key
83373     bindings, unlike ‘local-function-key-map’.  *Note Translation
83374     Keymaps::.
83375
83376‘kmacro-keymap’
83377     A sparse keymap for keys that follows the ‘C-x C-k’ prefix search.
83378     *Note (emacs)Keyboard Macros::.
83379
83380‘local-function-key-map’
83381     The keymap for translating key sequences to preferred alternatives.
83382     If there are none, then it contains an empty sparse keymap.  *Note
83383     Translation Keymaps::.
83384
83385‘menu-bar-file-menu’
83386‘menu-bar-edit-menu’
83387‘menu-bar-options-menu’
83388‘global-buffers-menu-map’
83389‘menu-bar-tools-menu’
83390‘menu-bar-help-menu’
83391     These keymaps display the main, top-level menus in the menu bar.
83392     Some of them contain sub-menus.  For example, the Edit menu
83393     contains ‘menu-bar-search-menu’, etc.  *Note Menu Bar::.
83394
83395‘minibuffer-inactive-mode-map’
83396     A full keymap used in the minibuffer when it is not active.
83397     *Note Editing in the Minibuffer: (emacs)Minibuffer Edit.
83398
83399‘mode-line-coding-system-map’
83400‘mode-line-input-method-map’
83401‘mode-line-column-line-number-mode-map’
83402     These keymaps control various areas of the mode line.
83403     *Note Mode Line Format::.
83404
83405‘mode-specific-map’
83406     The keymap for characters following ‘C-c’.  Note, this is in the
83407     global map.  This map is not actually mode-specific: its name was
83408     chosen to be informative in ‘C-h b’ (‘display-bindings’), where it
83409     describes the main use of the ‘C-c’ prefix key.
83410
83411‘mouse-appearance-menu-map’
83412     A sparse keymap used for the ‘S-mouse-1’ key.
83413
83414‘mule-keymap’
83415     The global keymap used for the ‘C-x <RET>’ prefix key.
83416
83417‘narrow-map’
83418     A sparse keymap for subcommands of the prefix ‘C-x n’.
83419
83420‘prog-mode-map’
83421     The keymap used by Prog mode.
83422     *Note Basic Major Modes::.
83423
83424‘query-replace-map’
83425‘multi-query-replace-map’
83426     A sparse keymap used for responses in ‘query-replace’ and related
83427     commands; also for ‘y-or-n-p’ and ‘map-y-or-n-p’.  The functions
83428     that use this map do not support prefix keys; they look up one
83429     event at a time.  ‘multi-query-replace-map’ extends
83430     ‘query-replace-map’ for multi-buffer replacements.  *Note
83431     query-replace-map: Search and Replace.
83432
83433‘search-map’
83434     A sparse keymap that provides global bindings for search-related
83435     commands.
83436
83437‘special-mode-map’
83438     The keymap used by Special mode.
83439     *Note Basic Major Modes::.
83440
83441‘tab-prefix-map’
83442     The global keymap used for the ‘C-x t’ prefix key for tab-bar
83443     related commands.
83444     *Note (emacs)Tab Bars::.
83445
83446‘tab-bar-map’
83447     The keymap defining the contents of the tab bar.
83448     *Note (emacs)Tab Bars::.
83449
83450‘tool-bar-map’
83451     The keymap defining the contents of the tool bar.
83452     *Note Tool Bar::.
83453
83454‘universal-argument-map’
83455     A sparse keymap used while processing ‘C-u’.
83456     *Note Prefix Command Arguments::.
83457
83458‘vc-prefix-map’
83459     The global keymap used for the ‘C-x v’ prefix key.
83460
83461‘x-alternatives-map’
83462     A sparse keymap used to map certain keys under graphical frames.
83463     The function ‘x-setup-function-keys’ uses this.
83464
83465
83466File: elisp.info,  Node: Standard Hooks,  Next: Index,  Prev: Standard Keymaps,  Up: Top
83467
83468Appendix H Standard Hooks
83469*************************
83470
83471The following is a list of some hook variables that let you provide
83472functions to be called from within Emacs on suitable occasions.
83473
83474   Most of these variables have names ending with ‘-hook’.  They are
83475“normal hooks”, run by means of ‘run-hooks’.  The value of such a hook
83476is a list of functions; the functions are called with no arguments and
83477their values are completely ignored.  The recommended way to put a new
83478function on such a hook is to call ‘add-hook’.  *Note Hooks::, for more
83479information about using hooks.
83480
83481   The variables whose names end in ‘-functions’ are usually “abnormal
83482hooks” (some old code may also use the deprecated ‘-hooks’ suffix);
83483their values are lists of functions, but these functions are called in a
83484special way (they are passed arguments, or their return values are
83485used).  The variables whose names end in ‘-function’ have single
83486functions as their values.
83487
83488   This is not an exhaustive list, it only covers the more general
83489hooks.  For example, every major mode defines a hook named
83490‘MODENAME-mode-hook’.  The major mode command runs this normal hook with
83491‘run-mode-hooks’ as the very last thing it does.  *Note Mode Hooks::.
83492Most minor modes have mode hooks too.
83493
83494   A special feature allows you to specify expressions to evaluate if
83495and when a file is loaded (*note Hooks for Loading::).  That feature is
83496not exactly a hook, but does a similar job.
83497
83498‘activate-mark-hook’
83499‘deactivate-mark-hook’
83500     *Note The Mark::.
83501
83502‘after-change-functions’
83503‘before-change-functions’
83504‘first-change-hook’
83505     *Note Change Hooks::.
83506
83507‘after-change-major-mode-hook’
83508‘change-major-mode-after-body-hook’
83509     *Note Mode Hooks::.
83510
83511‘after-init-hook’
83512‘before-init-hook’
83513‘emacs-startup-hook’
83514‘window-setup-hook’
83515     *Note Init File::.
83516
83517‘after-insert-file-functions’
83518‘write-region-annotate-functions’
83519‘write-region-post-annotation-function’
83520     *Note Format Conversion::.
83521
83522‘after-make-frame-functions’
83523‘before-make-frame-hook’
83524‘server-after-make-frame-hook’
83525     *Note Creating Frames::.
83526
83527‘after-save-hook’
83528‘before-save-hook’
83529‘write-contents-functions’
83530‘write-file-functions’
83531     *Note Saving Buffers::.
83532
83533‘after-setting-font-hook’
83534     Hook run after a frame’s font changes.
83535
83536‘auto-save-hook’
83537     *Note Auto-Saving::.
83538
83539‘before-hack-local-variables-hook’
83540‘hack-local-variables-hook’
83541     *Note File Local Variables::.
83542
83543‘buffer-access-fontify-functions’
83544     *Note Lazy Properties::.
83545
83546‘buffer-list-update-hook’
83547     Hook run when the buffer list changes (*note Buffer List::).
83548
83549‘buffer-quit-function’
83550     Function to call to quit the current buffer.
83551
83552‘change-major-mode-hook’
83553     *Note Creating Buffer-Local::.
83554
83555‘comint-password-function’
83556     This abnormal hook permits a derived mode to supply a password for
83557     the underlying command interpreter without prompting the user.
83558
83559‘command-line-functions’
83560     *Note Command-Line Arguments::.
83561
83562‘delayed-warnings-hook’
83563     The command loop runs this soon after ‘post-command-hook’ (q.v.).
83564
83565‘focus-in-hook’
83566‘focus-out-hook’
83567     *Note Input Focus::.
83568
83569‘delete-frame-functions’
83570‘after-delete-frame-functions’
83571     *Note Deleting Frames::.
83572
83573‘delete-terminal-functions’
83574     *Note Multiple Terminals::.
83575
83576‘pop-up-frame-function’
83577‘split-window-preferred-function’
83578     *Note Choosing Window Options::.
83579
83580‘echo-area-clear-hook’
83581     *Note Echo Area Customization::.
83582
83583‘find-file-hook’
83584‘find-file-not-found-functions’
83585     *Note Visiting Functions::.
83586
83587‘font-lock-extend-after-change-region-function’
83588     *Note Region to Refontify::.
83589
83590‘font-lock-extend-region-functions’
83591     *Note Multiline Font Lock::.
83592
83593‘font-lock-fontify-buffer-function’
83594‘font-lock-fontify-region-function’
83595‘font-lock-mark-block-function’
83596‘font-lock-unfontify-buffer-function’
83597‘font-lock-unfontify-region-function’
83598     *Note Other Font Lock Variables::.
83599
83600‘fontification-functions’
83601     *Note Automatic Face Assignment: Auto Faces.
83602
83603‘frame-auto-hide-function’
83604     *Note Quitting Windows::.
83605
83606‘quit-window-hook’
83607     *Note Quitting Windows::.
83608
83609‘kill-buffer-hook’
83610‘kill-buffer-query-functions’
83611     *Note Killing Buffers::.
83612
83613‘kill-emacs-hook’
83614‘kill-emacs-query-functions’
83615     *Note Killing Emacs::.
83616
83617‘menu-bar-update-hook’
83618     *Note Menu Bar::.
83619
83620‘minibuffer-setup-hook’
83621‘minibuffer-exit-hook’
83622     *Note Minibuffer Misc::.
83623
83624‘mouse-leave-buffer-hook’
83625     Hook run when about to switch windows with a mouse command.
83626
83627‘mouse-position-function’
83628     *Note Mouse Position::.
83629
83630‘prefix-command-echo-keystrokes-functions’
83631     An abnormal hook run by prefix commands (such as ‘C-u’) which
83632     should return a string describing the current prefix state.  For
83633     example, ‘C-u’ produces ‘C-u-’ and ‘C-u 1 2 3-’.  Each hook
83634     function is called with no arguments and should return a string
83635     describing the current prefix state, or ‘nil’ if there’s no prefix
83636     state.  *Note Prefix Command Arguments::.
83637
83638‘prefix-command-preserve-state-hook’
83639     Hook run when a prefix command needs to preserve the prefix by
83640     passing the current prefix command state to the next command.  For
83641     example, ‘C-u’ needs to pass the state to the next command when the
83642     user types ‘C-u -’ or follows ‘C-u’ with a digit.
83643
83644‘pre-redisplay-functions’
83645     Hook run in each window just before redisplaying it.  *Note Forcing
83646     Redisplay::.
83647
83648‘post-command-hook’
83649‘pre-command-hook’
83650     *Note Command Overview::.
83651
83652‘post-gc-hook’
83653     *Note Garbage Collection::.
83654
83655‘post-self-insert-hook’
83656     *Note Keymaps and Minor Modes::.
83657
83658‘suspend-hook’
83659‘suspend-resume-hook’
83660‘suspend-tty-functions’
83661‘resume-tty-functions’
83662     *Note Suspending Emacs::.
83663
83664‘syntax-begin-function’
83665‘syntax-propertize-extend-region-functions’
83666‘syntax-propertize-function’
83667‘font-lock-syntactic-face-function’
83668     *Note Syntactic Font Lock::.  *Note Syntax Properties::.
83669
83670‘temp-buffer-setup-hook’
83671‘temp-buffer-show-function’
83672‘temp-buffer-show-hook’
83673     *Note Temporary Displays::.
83674
83675‘tty-setup-hook’
83676     *Note Terminal-Specific::.
83677
83678‘window-configuration-change-hook’
83679‘window-scroll-functions’
83680‘window-size-change-functions’
83681     *Note Window Hooks::.
83682
83683
83684File: elisp.info,  Node: Index,  Prev: Standard Hooks,  Up: Top
83685
83686Index
83687*****
83688
83689�[index�]
83690* Menu:
83691
83692* " in printing:                         Output Functions.    (line   9)
83693* " in strings:                          Syntax for Strings.  (line   6)
83694* ## read syntax:                        Symbol Type.         (line  57)
83695* #$:                                    Docs and Compilation.
83696                                                              (line  37)
83697* #' syntax:                             Anonymous Functions. (line  57)
83698* #( read syntax:                        Text Props and Strings.
83699                                                              (line   6)
83700* #@COUNT:                               Docs and Compilation.
83701                                                              (line  37)
83702* #COLON read syntax:                    Symbol Type.         (line  57)
83703* #N# read syntax:                       Circular Objects.    (line   6)
83704* #N= read syntax:                       Circular Objects.    (line   6)
83705* #^ read syntax:                        Char-Table Type.     (line  14)
83706* $ in display:                          Truncation.          (line   6)
83707* $ in regexp:                           Regexp Special.      (line 185)
83708* %:                                     Arithmetic Operations.
83709                                                              (line 106)
83710* % in format:                           Formatting Strings.  (line  41)
83711* & in replacement:                      Replacing Match.     (line  41)
83712* &optional:                             Argument List.       (line  18)
83713* &rest:                                 Argument List.       (line  18)
83714* ' for quoting:                         Quoting.             (line  17)
83715* ( in regexp:                           Regexp Backslash.    (line  45)
83716* (?: in regexp:                         Regexp Backslash.    (line  67)
83717* (...) in lists:                        Cons Cell Type.      (line  25)
83718* ) in regexp:                           Regexp Backslash.    (line  45)
83719* *:                                     Arithmetic Operations.
83720                                                              (line  62)
83721* * in interactive:                      Using Interactive.   (line  67)
83722* * in regexp:                           Regexp Special.      (line  16)
83723* * in rx:                               Rx Constructs.       (line  69)
83724* ** in rx:                              Rx Constructs.       (line 102)
83725* *? in rx:                              Rx Constructs.       (line  81)
83726* *get_user_ptr:                         Module Values.       (line 368)
83727* *scratch*:                             Auto Major Mode.     (line  79)
83728* +:                                     Arithmetic Operations.
83729                                                              (line  37)
83730* + in regexp:                           Regexp Special.      (line  45)
83731* + in rx:                               Rx Constructs.       (line  73)
83732* +? in rx:                              Rx Constructs.       (line  85)
83733* , (with backquote):                    Backquote.           (line  16)
83734* ,@ (with backquote):                   Backquote.           (line  29)
83735* -:                                     Arithmetic Operations.
83736                                                              (line  48)
83737* --disable-build-details option to configure: Building Emacs.
83738                                                              (line  74)
83739* --enable-locallisppath option to configure: Building Emacs. (line 117)
83740* --temacs option, and dumping method:   Building Emacs.      (line  23)
83741* –enable-profiling option of configure: Profiling.           (line  55)
83742* . in lists:                            Dotted Pair Notation.
83743                                                              (line   6)
83744* . in regexp:                           Regexp Special.      (line  10)
83745* .#, lock file names:                   File Locks.          (line   6)
83746* .emacs:                                Init File.           (line   6)
83747* /:                                     Arithmetic Operations.
83748                                                              (line  73)
83749* /=:                                    Comparison of Numbers.
83750                                                              (line  53)
83751* /dev/tty:                              Serial Ports.        (line   6)
83752* 0+ in rx:                              Rx Constructs.       (line  54)
83753* 1+:                                    Arithmetic Operations.
83754                                                              (line  13)
83755* 1+ in rx:                              Rx Constructs.       (line  59)
83756* 1-:                                    Arithmetic Operations.
83757                                                              (line  34)
83758* 1value:                                Test Coverage.       (line  25)
83759* 2C-mode-map:                           Prefix Keys.         (line  38)
83760* 2D box:                                Face Attributes.     (line 117)
83761* 3D box:                                Face Attributes.     (line 117)
83762* : in rx:                               Rx Constructs.       (line  27)
83763* :deferred, JSONRPC keyword:            JSONRPC deferred requests.
83764                                                              (line  16)
83765* :notification-dispatcher:              JSONRPC Overview.    (line  20)
83766* :request-dispatcher:                   JSONRPC Overview.    (line  20)
83767* ; for commenting:                      Comments.            (line   6)
83768* <:                                     Comparison of Numbers.
83769                                                              (line  57)
83770* <=:                                    Comparison of Numbers.
83771                                                              (line  61)
83772* =:                                     Comparison of Numbers.
83773                                                              (line  42)
83774* = in rx:                               Rx Constructs.       (line  93)
83775* >:                                     Comparison of Numbers.
83776                                                              (line  65)
83777* >=:                                    Comparison of Numbers.
83778                                                              (line  69)
83779* >= in rx:                              Rx Constructs.       (line  98)
83780* ? in character constant:               Basic Char Syntax.   (line   6)
83781* ? in minibuffer:                       Text from Minibuffer.
83782                                                              (line 250)
83783* ? in regexp:                           Regexp Special.      (line  51)
83784* ? in rx:                               Rx Constructs.       (line  77)
83785* ?? in rx:                              Rx Constructs.       (line  89)
83786* @ in interactive:                      Using Interactive.   (line  70)
83787* [ in regexp:                           Regexp Special.      (line  69)
83788* [...] (Edebug):                        Specification List.  (line 134)
83789* \ in character constant:               General Escape Syntax.
83790                                                              (line  10)
83791* \ in display:                          Truncation.          (line   6)
83792* \ in printing:                         Output Functions.    (line   9)
83793* \ in regexp:                           Regexp Special.      (line 196)
83794* \ in replacement:                      Replacing Match.     (line  50)
83795* \ in strings:                          Syntax for Strings.  (line   6)
83796* \ in symbols:                          Symbol Type.         (line  23)
83797* \' in regexp:                          Regexp Backslash.    (line 163)
83798* \( in strings:                         List Motion.         (line  81)
83799* \< in regexp:                          Regexp Backslash.    (line 184)
83800* \= in regexp:                          Regexp Backslash.    (line 167)
83801* \> in regexp:                          Regexp Backslash.    (line 189)
83802* \a:                                    Basic Char Syntax.   (line  27)
83803* \b:                                    Basic Char Syntax.   (line  27)
83804* \b in regexp:                          Regexp Backslash.    (line 171)
83805* \B in regexp:                          Regexp Backslash.    (line 180)
83806* \e:                                    Basic Char Syntax.   (line  27)
83807* \f:                                    Basic Char Syntax.   (line  27)
83808* \n:                                    Basic Char Syntax.   (line  27)
83809* \n in print:                           Output Variables.    (line  17)
83810* \N in replacement:                     Replacing Match.     (line  44)
83811* \r:                                    Basic Char Syntax.   (line  27)
83812* \s:                                    Basic Char Syntax.   (line  27)
83813* \s in regexp:                          Regexp Backslash.    (line 130)
83814* \S in regexp:                          Regexp Backslash.    (line 138)
83815* \t:                                    Basic Char Syntax.   (line  27)
83816* \v:                                    Basic Char Syntax.   (line  27)
83817* \w in regexp:                          Regexp Backslash.    (line 123)
83818* \W in regexp:                          Regexp Backslash.    (line 127)
83819* \_< in regexp:                         Regexp Backslash.    (line 194)
83820* \_> in regexp:                         Regexp Backslash.    (line 200)
83821* \` in regexp:                          Regexp Backslash.    (line 159)
83822* ] in regexp:                           Regexp Special.      (line  69)
83823* ^ in interactive:                      Using Interactive.   (line  75)
83824* ^ in regexp:                           Regexp Special.      (line 154)
83825* `:                                     Backquote.           (line   6)
83826* ‘ (list substitution):                 Backquote.           (line   6)
83827* | in regexp:                           Regexp Backslash.    (line  12)
83828* | in rx:                               Rx Constructs.       (line  34)
83829* abbrev:                                Abbrevs.             (line   6)
83830* abbrev properties:                     Abbrev Properties.   (line   6)
83831* abbrev table properties:               Abbrev Table Properties.
83832                                                              (line   6)
83833* abbrev tables:                         Abbrev Tables.       (line   6)
83834* abbrev tables in modes:                Major Mode Conventions.
83835                                                              (line 126)
83836* abbrev-all-caps:                       Abbrev Expansion.    (line  59)
83837* abbrev-expand-function:                Abbrev Expansion.    (line  97)
83838* abbrev-expansion:                      Abbrev Expansion.    (line  18)
83839* abbrev-file-name:                      Abbrev Files.        (line  16)
83840* abbrev-get:                            Abbrev Properties.   (line  13)
83841* abbrev-insert:                         Abbrev Expansion.    (line  39)
83842* abbrev-map:                            Standard Keymaps.    (line  20)
83843* abbrev-minor-mode-table-alist:         Standard Abbrev Tables.
83844                                                              (line  20)
83845* abbrev-prefix-mark:                    Abbrev Expansion.    (line  48)
83846* abbrev-put:                            Abbrev Properties.   (line  10)
83847* abbrev-start-location:                 Abbrev Expansion.    (line  65)
83848* abbrev-start-location-buffer:          Abbrev Expansion.    (line  73)
83849* abbrev-symbol:                         Abbrev Expansion.    (line  11)
83850* abbrev-table-get:                      Abbrev Table Properties.
83851                                                              (line  13)
83852* abbrev-table-name-list:                Abbrev Tables.       (line  45)
83853* abbrev-table-p:                        Abbrev Tables.       (line  14)
83854* abbrev-table-put:                      Abbrev Table Properties.
83855                                                              (line  10)
83856* abbreviate-file-name:                  Directory Names.     (line  83)
83857* abbreviated file names:                Directory Names.     (line  83)
83858* abbrevs, looking up and expanding:     Abbrev Expansion.    (line   6)
83859* abbrevs-changed:                       Abbrev Files.        (line  36)
83860* abnormal hook:                         Hooks.               (line  33)
83861* abort-recursive-edit:                  Recursive Editing.   (line  92)
83862* aborting:                              Recursive Editing.   (line  32)
83863* abs:                                   Comparison of Numbers.
83864                                                              (line  89)
83865* absolute edges:                        Frame Layout.        (line 229)
83866* absolute file name:                    Relative File Names. (line   6)
83867* absolute frame edges:                  Frame Layout.        (line 229)
83868* absolute frame position:               Frame Layout.        (line 229)
83869* absolute position:                     Frame Layout.        (line 229)
83870* accept input from processes:           Accepting Output.    (line   6)
83871* accept-change-group:                   Atomic Changes.      (line  48)
83872* accept-process-output:                 Accepting Output.    (line  12)
83873* access control list:                   Extended Attributes. (line  14)
83874* access minibuffer contents:            Minibuffer Contents. (line   6)
83875* access-file:                           Testing Accessibility.
83876                                                              (line  69)
83877* accessibility of a file:               Testing Accessibility.
83878                                                              (line   6)
83879* accessible portion (of a buffer):      Narrowing.           (line   6)
83880* accessible-keymaps:                    Scanning Keymaps.    (line   9)
83881* accessing documentation strings:       Accessing Documentation.
83882                                                              (line   6)
83883* accessing hash tables:                 Hash Access.         (line   6)
83884* accessing plist properties:            Plist Access.        (line   6)
83885* ACL entries:                           Extended Attributes. (line  14)
83886* acos:                                  Math Functions.      (line  20)
83887* action (button property):              Button Properties.   (line  12)
83888* action alist for buffer display:       Buffer Display Action Alists.
83889                                                              (line   6)
83890* action function, for buffer display:   Buffer Display Action Functions.
83891                                                              (line   6)
83892* action, customization keyword:         Type Keywords.       (line  63)
83893* activate-change-group:                 Atomic Changes.      (line  39)
83894* activate-mark-hook:                    The Mark.            (line 174)
83895* active display table:                  Active Display Table.
83896                                                              (line   6)
83897* active keymap:                         Active Keymaps.      (line   6)
83898* active keymap, controlling:            Controlling Active Maps.
83899                                                              (line   6)
83900* active-minibuffer-window:              Minibuffer Windows.  (line  34)
83901* ad-activate:                           Porting Old Advice.  (line   6)
83902* adaptive-fill-first-line-regexp:       Adaptive Fill.       (line  62)
83903* adaptive-fill-function:                Adaptive Fill.       (line  75)
83904* adaptive-fill-mode:                    Adaptive Fill.       (line  12)
83905* adaptive-fill-regexp:                  Adaptive Fill.       (line  53)
83906* add-face-text-property:                Changing Properties. (line  89)
83907* add-function:                          Core Advising Primitives.
83908                                                              (line   6)
83909* add-hook:                              Setting Hooks.       (line  22)
83910* add-name-to-file:                      Changing Files.      (line  38)
83911* add-text-properties:                   Changing Properties. (line  23)
83912* add-to-history:                        Minibuffer History.  (line  57)
83913* add-to-invisibility-spec:              Invisible Text.      (line  63)
83914* add-to-list:                           List Variables.      (line  34)
83915* add-to-ordered-list:                   List Variables.      (line  72)
83916* add-variable-watcher:                  Watching Variables.  (line  15)
83917* address field of register:             Cons Cell Type.      (line   6)
83918* adjust-window-trailing-edge:           Resizing Windows.    (line  70)
83919* adjusting point:                       Adjusting Point.     (line   6)
83920* advertised binding:                    Keys in Documentation.
83921                                                              (line  67)
83922* advice, add and remove:                Core Advising Primitives.
83923                                                              (line   6)
83924* advice-add:                            Advising Named Functions.
83925                                                              (line  63)
83926* advice-eval-interactive-spec:          Core Advising Primitives.
83927                                                              (line  96)
83928* advice-function-mapc:                  Core Advising Primitives.
83929                                                              (line  91)
83930* advice-function-member-p:              Core Advising Primitives.
83931                                                              (line  86)
83932* advice-mapc:                           Advising Named Functions.
83933                                                              (line  77)
83934* advice-member-p:                       Advising Named Functions.
83935                                                              (line  72)
83936* advice-remove:                         Advising Named Functions.
83937                                                              (line  68)
83938* advices, porting from defadvice:       Porting Old Advice.  (line   6)
83939* advising functions:                    Advising Functions.  (line   6)
83940* advising named functions:              Advising Named Functions.
83941                                                              (line   6)
83942* AEAD cipher:                           GnuTLS Cryptography. (line   6)
83943* after-change-functions:                Change Hooks.        (line  23)
83944* after-change-major-mode-hook:          Mode Hooks.          (line  55)
83945* after-delete-frame-functions:          Deleting Frames.     (line  12)
83946* after-find-file:                       Subroutines of Visiting.
83947                                                              (line  32)
83948* after-focus-change-function:           Input Focus.         (line 166)
83949* after-init-hook:                       Init File.           (line  64)
83950* after-init-time:                       Startup Summary.     (line  93)
83951* after-insert-file-functions:           Format Conversion Piecemeal.
83952                                                              (line  78)
83953* after-load-functions:                  Hooks for Loading.   (line   9)
83954* after-make-frame-functions:            Creating Frames.     (line  45)
83955* after-revert-hook:                     Reverting.           (line  87)
83956* after-save-hook:                       Saving Buffers.      (line 148)
83957* after-setting-font-hook:               Standard Hooks.      (line  69)
83958* after-string (overlay property):       Overlay Properties.  (line 203)
83959* alias, for coding systems:             Coding System Basics.
83960                                                              (line  91)
83961* alias, for faces:                      Face Functions.      (line  33)
83962* alias, for functions:                  Defining Functions.  (line  55)
83963* alias, for variables:                  Variable Aliases.    (line   6)
83964* alist:                                 Association Lists.   (line   6)
83965* alist vs. plist:                       Plists and Alists.   (line   6)
83966* alist-get:                             Association Lists.   (line 124)
83967* all-completions:                       Basic Completion.    (line  96)
83968* all-threads:                           Basic Thread Functions.
83969                                                              (line  72)
83970* allow-no-window, a buffer display action alist entry: Buffer Display Action Alists.
83971                                                              (line 213)
83972* alnum character class, regexp:         Char Classes.        (line   6)
83973* alpha character class, regexp:         Char Classes.        (line   6)
83974* alpha, a frame parameter:              Font and Color Parameters.
83975                                                              (line  65)
83976* alt characters:                        Other Char Bits.     (line  16)
83977* alternatives, defining:                Generic Commands.    (line   6)
83978* amalgamating commands, and undo:       Undo.                (line  98)
83979* amalgamating-undo-limit:               Undo.                (line  98)
83980* and:                                   Combining Conditions.
83981                                                              (line  17)
83982* and in rx:                             Rx Constructs.       (line  28)
83983* animation:                             Multi-Frame Images.  (line   6)
83984* anonymous face:                        Faces.               (line  11)
83985* anonymous function:                    Anonymous Functions. (line   6)
83986* any in rx:                             Rx Constructs.       (line 123)
83987* anychar in rx:                         Rx Constructs.       (line 155)
83988* anything in rx:                        Rx Constructs.       (line 155)
83989* apostrophe for quoting:                Quoting.             (line  17)
83990* append:                                Building Lists.      (line  61)
83991* append-to-file:                        Writing to Files.    (line  11)
83992* apply:                                 Calling Functions.   (line  56)
83993* apply, and debugging:                  Internals of Debugger.
83994                                                              (line  86)
83995* apply-partially:                       Calling Functions.   (line  91)
83996* applying customizations:               Applying Customizations.
83997                                                              (line   6)
83998* apropos:                               Help Functions.      (line  11)
83999* archive web server:                    Archive Web Server.  (line   6)
84000* aref:                                  Array Functions.     (line  20)
84001* args, customization keyword:           Composite Types.     (line 289)
84002* argument:                              What Is a Function.  (line   6)
84003* argument binding:                      Argument List.       (line   6)
84004* argument lists, features:              Argument List.       (line   6)
84005* arguments for shell commands:          Shell Arguments.     (line   6)
84006* arguments, interactive entry:          Using Interactive.   (line   6)
84007* arguments, reading:                    Minibuffers.         (line   6)
84008* argv:                                  Command-Line Arguments.
84009                                                              (line  69)
84010* arith-error example:                   Handling Errors.     (line 155)
84011* arith-error in division:               Arithmetic Operations.
84012                                                              (line 101)
84013* arithmetic operations:                 Arithmetic Operations.
84014                                                              (line   6)
84015* arithmetic shift:                      Bitwise Operations.  (line  17)
84016* array:                                 Arrays.              (line   6)
84017* array elements:                        Array Functions.     (line  21)
84018* arrayp:                                Array Functions.     (line   9)
84019* ascii character class, regexp:         Char Classes.        (line   6)
84020* ASCII character codes:                 Character Type.      (line   6)
84021* ASCII control characters:              Usual Display.       (line  22)
84022* ascii-case-table:                      Case Tables.         (line  90)
84023* aset:                                  Array Functions.     (line  33)
84024* ash:                                   Bitwise Operations.  (line  16)
84025* asin:                                  Math Functions.      (line  15)
84026* ask-user-about-lock:                   File Locks.          (line  57)
84027* ask-user-about-supersession-threat:    Modification Time.   (line  73)
84028* asking the user questions:             Yes-or-No Queries.   (line   6)
84029* assoc:                                 Association Lists.   (line  58)
84030* assoc-default:                         Association Lists.   (line 170)
84031* assoc-delete-all:                      Association Lists.   (line 241)
84032* assoc-string:                          Text Comparison.     (line 241)
84033* association list:                      Association Lists.   (line   6)
84034* assq:                                  Association Lists.   (line  99)
84035* assq-delete-all:                       Association Lists.   (line 226)
84036* asynchronous subprocess:               Asynchronous Processes.
84037                                                              (line   6)
84038* atan:                                  Math Functions.      (line  25)
84039* atom:                                  List-related Predicates.
84040                                                              (line  15)
84041* atomic changes:                        Atomic Changes.      (line   6)
84042* atomic windows:                        Atomic Windows.      (line   6)
84043* atoms:                                 Cons Cell Type.      (line  22)
84044* attributes of text:                    Text Properties.     (line   6)
84045* Auto Fill mode:                        Auto Filling.        (line   6)
84046* auto-coding-alist:                     Default Coding Systems.
84047                                                              (line  51)
84048* auto-coding-functions:                 Default Coding Systems.
84049                                                              (line  97)
84050* auto-coding-regexp-alist:              Default Coding Systems.
84051                                                              (line  17)
84052* auto-fill-chars:                       Auto Filling.        (line  31)
84053* auto-fill-function:                    Auto Filling.        (line  15)
84054* auto-hide-function, a frame parameter: Frame Interaction Parameters.
84055                                                              (line  29)
84056* auto-hscroll-mode:                     Horizontal Scrolling.
84057                                                              (line  40)
84058* auto-lower, a frame parameter:         Management Parameters.
84059                                                              (line  19)
84060* auto-mode-alist:                       Auto Major Mode.     (line 103)
84061* auto-raise, a frame parameter:         Management Parameters.
84062                                                              (line  15)
84063* auto-raise-tool-bar-buttons:           Tool Bar.            (line 154)
84064* auto-resize-tool-bars:                 Tool Bar.            (line 142)
84065* auto-save-default:                     Auto-Saving.         (line 135)
84066* auto-save-file-name-p:                 Auto-Saving.         (line  32)
84067* auto-save-hook:                        Auto-Saving.         (line 132)
84068* auto-save-interval:                    Auto-Saving.         (line 113)
84069* auto-save-list-file-name:              Auto-Saving.         (line 190)
84070* auto-save-list-file-prefix:            Auto-Saving.         (line 207)
84071* auto-save-mode:                        Auto-Saving.         (line  22)
84072* auto-save-timeout:                     Auto-Saving.         (line 120)
84073* auto-save-visited-file-name:           Auto-Saving.         (line  86)
84074* auto-selection of window:              Mouse Window Auto-selection.
84075                                                              (line   6)
84076* auto-window-vscroll:                   Vertical Scrolling.  (line  52)
84077* autoload:                              Autoload.            (line  30)
84078* autoload <1>:                          Autoload.            (line   6)
84079* autoload by prefix:                    Autoload by Prefix.  (line   6)
84080* autoload cookie:                       Autoload.            (line 109)
84081* autoload cookie, and safe values of variable: File Local Variables.
84082                                                              (line 104)
84083* autoload errors:                       Autoload.            (line  95)
84084* autoload object:                       What Is a Function.  (line  88)
84085* autoload, when to use:                 When to Autoload.    (line   6)
84086* autoload-compute-prefixes:             Autoload by Prefix.  (line   6)
84087* autoload-do-load:                      Autoload.            (line 204)
84088* autoloadp:                             Autoload.            (line  88)
84089* automatic face assignment:             Auto Faces.          (line   6)
84090* automatically buffer-local:            Intro to Buffer-Local.
84091                                                              (line  39)
84092* back-to-indentation:                   Motion by Indent.    (line   9)
84093* background-color, a frame parameter:   Font and Color Parameters.
84094                                                              (line 100)
84095* background-mode, a frame parameter:    Font and Color Parameters.
84096                                                              (line  29)
84097* backing store:                         Display Feature Testing.
84098                                                              (line 116)
84099* backquote (list substitution):         Backquote.           (line   6)
84100* backquote-style patterns:              Backquote Patterns.  (line   6)
84101* backref in rx:                         Rx Constructs.       (line 373)
84102* backslash in character constants:      General Escape Syntax.
84103                                                              (line  10)
84104* backslash in regular expressions:      Regexp Backslash.    (line   6)
84105* backslash in strings:                  Syntax for Strings.  (line   6)
84106* backslash in symbols:                  Symbol Type.         (line  23)
84107* backspace:                             Basic Char Syntax.   (line  27)
84108* backtrace:                             Internals of Debugger.
84109                                                              (line  20)
84110* backtrace buffer:                      Backtraces.          (line   6)
84111* backtrace from emacsclient’s --eval:   Error Debugging.     (line  74)
84112* backtrace of thread:                   The Thread List.     (line  21)
84113* backtrace-debug:                       Internals of Debugger.
84114                                                              (line  92)
84115* backtrace-frame:                       Internals of Debugger.
84116                                                              (line 114)
84117* backtracking:                          Backtracking.        (line   6)
84118* backtracking and POSIX regular expressions: POSIX Regexps.  (line   6)
84119* backtracking and regular expressions:  Regexp Special.      (line  25)
84120* backup file:                           Backup Files.        (line   6)
84121* backup files, rename or copy:          Rename or Copy.      (line   6)
84122* backup-buffer:                         Making Backups.      (line   6)
84123* backup-by-copying:                     Rename or Copy.      (line  29)
84124* backup-by-copying-when-linked:         Rename or Copy.      (line  37)
84125* backup-by-copying-when-mismatch:       Rename or Copy.      (line  44)
84126* backup-by-copying-when-privileged-mismatch: Rename or Copy. (line  57)
84127* backup-directory-alist:                Making Backups.      (line  67)
84128* backup-enable-predicate:               Making Backups.      (line  43)
84129* backup-file-name-p:                    Backup Names.        (line  10)
84130* backup-inhibited:                      Making Backups.      (line  55)
84131* backups and auto-saving:               Backups and Auto-Saving.
84132                                                              (line   6)
84133* backward-button:                       Button Buffer Commands.
84134                                                              (line  42)
84135* backward-char:                         Character Motion.    (line  36)
84136* backward-delete-char-untabify:         Deletion.            (line  68)
84137* backward-delete-char-untabify-method:  Deletion.            (line  87)
84138* backward-list:                         List Motion.         (line  19)
84139* backward-prefix-chars:                 Motion and Syntax.   (line  34)
84140* backward-sexp:                         List Motion.         (line  60)
84141* backward-to-indentation:               Motion by Indent.    (line  14)
84142* backward-up-list:                      List Motion.         (line  34)
84143* backward-word:                         Word Motion.         (line  38)
84144* backward-word-strictly:                Word Motion.         (line  75)
84145* balance-windows:                       Resizing Windows.    (line 209)
84146* balance-windows-area:                  Resizing Windows.    (line 216)
84147* balanced parenthesis motion:           List Motion.         (line   6)
84148* balancing parentheses:                 Blinking.            (line   6)
84149* balancing window sizes:                Resizing Windows.    (line 209)
84150* barf-if-buffer-read-only:              Read Only Buffers.   (line  66)
84151* base 64 encoding:                      Base 64.             (line   6)
84152* base buffer:                           Indirect Buffers.    (line   6)
84153* base coding system:                    Coding System Basics.
84154                                                              (line  45)
84155* base direction of a paragraph:         Bidirectional Display.
84156                                                              (line  78)
84157* base for reading an integer:           Integer Basics.      (line  16)
84158* base location, package archive:        Package Archives.    (line  12)
84159* base remapping, faces:                 Face Remapping.      (line  46)
84160* base64-decode-region:                  Base 64.             (line  51)
84161* base64-decode-string:                  Base 64.             (line  62)
84162* base64-encode-region:                  Base 64.             (line  11)
84163* base64-encode-string:                  Base 64.             (line  32)
84164* base64url-encode-region:               Base 64.             (line  23)
84165* base64url-encode-string:               Base 64.             (line  43)
84166* basic code (of input character):       Keyboard Events.     (line  13)
84167* basic faces:                           Basic Faces.         (line   6)
84168* batch mode:                            Batch Mode.          (line   6)
84169* batch-byte-compile:                    Compilation Functions.
84170                                                              (line 125)
84171* baud, in serial connections:           Serial Ports.        (line 116)
84172* baud-rate:                             Terminal Output.     (line  10)
84173* beep:                                  Beeping.             (line  17)
84174* before point, insertion:               Insertion.           (line   6)
84175* before-change-functions:               Change Hooks.        (line  16)
84176* before-hack-local-variables-hook:      File Local Variables.
84177                                                              (line  83)
84178* before-init-hook:                      Init File.           (line  59)
84179* before-init-time:                      Startup Summary.     (line  22)
84180* before-make-frame-hook:                Creating Frames.     (line  42)
84181* before-revert-hook:                    Reverting.           (line  82)
84182* before-save-hook:                      Saving Buffers.      (line 141)
84183* before-string (overlay property):      Overlay Properties.  (line 198)
84184* beginning of line:                     Text Lines.          (line  54)
84185* beginning of line in regexp:           Regexp Special.      (line 172)
84186* beginning-of-buffer:                   Buffer End Motion.   (line  18)
84187* beginning-of-defun:                    List Motion.         (line  64)
84188* beginning-of-defun-function:           List Motion.         (line  88)
84189* beginning-of-line:                     Text Lines.          (line  14)
84190* bell:                                  Beeping.             (line   6)
84191* bell character:                        Basic Char Syntax.   (line  27)
84192* benchmark.el:                          Profiling.           (line  50)
84193* benchmarking:                          Profiling.           (line  50)
84194* best practices:                        Tips.                (line   6)
84195* bidi-display-reordering:               Bidirectional Display.
84196                                                              (line  32)
84197* bidi-find-overridden-directionality:   Bidirectional Display.
84198                                                              (line 238)
84199* bidi-paragraph-direction:              Bidirectional Display.
84200                                                              (line 118)
84201* bidi-paragraph-separate-re:            Bidirectional Display.
84202                                                              (line  98)
84203* bidi-paragraph-start-re:               Bidirectional Display.
84204                                                              (line  92)
84205* bidi-string-mark-left-to-right:        Bidirectional Display.
84206                                                              (line 188)
84207* bidirectional class of characters:     Character Properties.
84208                                                              (line  57)
84209* bidirectional display:                 Bidirectional Display.
84210                                                              (line   6)
84211* bidirectional reordering:              Bidirectional Display.
84212                                                              (line  17)
84213* big endian:                            Bindat Spec.         (line  13)
84214* bignum range:                          Integer Basics.      (line  96)
84215* bignump:                               Predicates on Numbers.
84216                                                              (line  13)
84217* binary coding system:                  Coding System Basics.
84218                                                              (line  62)
84219* binary I/O in batch mode:              Input Functions.     (line  60)
84220* bindat-get-field:                      Bindat Functions.    (line  19)
84221* bindat-ip-to-string:                   Bindat Functions.    (line  53)
84222* bindat-length:                         Bindat Functions.    (line  38)
84223* bindat-pack:                           Bindat Functions.    (line  42)
84224* bindat-unpack:                         Bindat Functions.    (line  10)
84225* binding arguments:                     Argument List.       (line   6)
84226* binding local variables:               Local Variables.     (line   6)
84227* binding of a key:                      Keymap Basics.       (line   6)
84228* bitmap-spec-p:                         Face Attributes.     (line 229)
84229* bitmaps, fringe:                       Fringe Bitmaps.      (line   6)
84230* bitwise arithmetic:                    Bitwise Operations.  (line   6)
84231* blink-cursor-alist:                    Cursor Parameters.   (line  56)
84232* blink-matching-delay:                  Blinking.            (line  22)
84233* blink-matching-open:                   Blinking.            (line  27)
84234* blink-matching-paren:                  Blinking.            (line  15)
84235* blink-matching-paren-distance:         Blinking.            (line  18)
84236* blink-paren-function:                  Blinking.            (line   9)
84237* blinking parentheses:                  Blinking.            (line   6)
84238* bobp:                                  Near Point.          (line  61)
84239* body height of a window:               Window Sizes.        (line 144)
84240* body of a window:                      Window Sizes.        (line  23)
84241* body of function:                      Lambda Components.   (line  37)
84242* body size of a window:                 Window Sizes.        (line 185)
84243* body width of a window:                Window Sizes.        (line 162)
84244* bol in rx:                             Rx Constructs.       (line 312)
84245* bolp:                                  Near Point.          (line  72)
84246* bool-vector:                           Bool-Vectors.        (line  21)
84247* bool-vector length:                    Sequence Functions.  (line  14)
84248* bool-vector-count-consecutive:         Bool-Vectors.        (line  61)
84249* bool-vector-count-population:          Bool-Vectors.        (line  66)
84250* bool-vector-exclusive-or:              Bool-Vectors.        (line  31)
84251* bool-vector-intersection:              Bool-Vectors.        (line  41)
84252* bool-vector-not:                       Bool-Vectors.        (line  51)
84253* bool-vector-p:                         Bool-Vectors.        (line  25)
84254* bool-vector-set-difference:            Bool-Vectors.        (line  46)
84255* bool-vector-subsetp:                   Bool-Vectors.        (line  56)
84256* bool-vector-union:                     Bool-Vectors.        (line  36)
84257* Bool-vectors:                          Bool-Vectors.        (line   6)
84258* boolean:                               nil and t.           (line   6)
84259* booleanp:                              nil and t.           (line  36)
84260* bootstrapping Emacs:                   Building Emacs.      (line  44)
84261* border-color, a frame parameter:       Font and Color Parameters.
84262                                                              (line 112)
84263* border-width, a frame parameter:       Layout Parameters.   (line   9)
84264* bos in rx:                             Rx Constructs.       (line 320)
84265* bot in rx:                             Rx Constructs.       (line 320)
84266* bottom dividers:                       Window Dividers.     (line   6)
84267* bottom-divider, prefix key:            Key Sequence Input.  (line  92)
84268* bottom-divider-width, a frame parameter: Layout Parameters. (line  51)
84269* bottom-visible, a frame parameter:     Mouse Dragging Parameters.
84270                                                              (line  44)
84271* boundp:                                Void Variables.      (line  56)
84272* bow in rx:                             Rx Constructs.       (line 332)
84273* box diagrams, for lists:               Box Diagrams.        (line   6)
84274* break:                                 Debugger.            (line   6)
84275* breakpoints (Edebug):                  Breakpoints.         (line   6)
84276* bucket (in obarray):                   Creating Symbols.    (line  11)
84277* buffer:                                Buffers.             (line   6)
84278* buffer boundaries, indicating:         Fringe Indicators.   (line  16)
84279* buffer contents:                       Text.                (line  23)
84280* buffer display:                        Displaying Buffers.  (line   6)
84281* buffer display action alist:           Buffer Display Action Alists.
84282                                                              (line   6)
84283* buffer display action function:        Buffer Display Action Functions.
84284                                                              (line   6)
84285* buffer display action functions, precedence: Precedence of Action Functions.
84286                                                              (line   6)
84287* buffer display conventions:            The Zen of Buffer Display.
84288                                                              (line   6)
84289* buffer display display action:         Choosing Window.     (line  12)
84290* buffer file name:                      Buffer File Name.    (line   6)
84291* buffer gap:                            Buffer Gap.          (line   6)
84292* buffer input stream:                   Input Streams.       (line  11)
84293* buffer internals:                      Buffer Internals.    (line   6)
84294* buffer list:                           Buffer List.         (line   6)
84295* buffer modification:                   Buffer Modification. (line   6)
84296* buffer names:                          Buffer Names.        (line   6)
84297* buffer output stream:                  Output Streams.      (line  11)
84298* buffer portion as string:              Buffer Contents.     (line   6)
84299* buffer position:                       Positions.           (line   6)
84300* buffer text notation:                  Buffer Text Notation.
84301                                                              (line   6)
84302* buffer, read-only:                     Read Only Buffers.   (line   6)
84303* buffer-access-fontified-property:      Lazy Properties.     (line  29)
84304* buffer-access-fontify-functions:       Lazy Properties.     (line  14)
84305* buffer-auto-save-file-format:          Format Conversion Round-Trip.
84306                                                              (line 153)
84307* buffer-auto-save-file-name:            Auto-Saving.         (line  14)
84308* buffer-backed-up:                      Making Backups.      (line  22)
84309* buffer-base-buffer:                    Indirect Buffers.    (line  60)
84310* buffer-chars-modified-tick:            Buffer Modification. (line  55)
84311* buffer-disable-undo:                   Maintaining Undo.    (line  26)
84312* buffer-display-count:                  Buffers and Windows. (line  42)
84313* buffer-display-table:                  Active Display Table.
84314                                                              (line  24)
84315* buffer-display-time:                   Buffers and Windows. (line  47)
84316* buffer-enable-undo:                    Maintaining Undo.    (line  16)
84317* buffer-end:                            Point.               (line  50)
84318* buffer-end in rx:                      Rx Constructs.       (line 324)
84319* buffer-file-coding-system:             Encoding and I/O.    (line  20)
84320* buffer-file-format:                    Format Conversion Round-Trip.
84321                                                              (line 107)
84322* buffer-file-name:                      Buffer File Name.    (line  22)
84323* buffer-file-name <1>:                  Buffer File Name.    (line  13)
84324* buffer-file-number:                    Buffer File Name.    (line  43)
84325* buffer-file-truename:                  Buffer File Name.    (line  37)
84326* buffer-hash:                           Checksum/Hash.       (line  64)
84327* buffer-invisibility-spec:              Invisible Text.      (line  34)
84328* buffer-list:                           Buffer List.         (line  28)
84329* buffer-list, a frame parameter:        Buffer Parameters.   (line  38)
84330* buffer-list-update-hook:               Buffer List.         (line 139)
84331* buffer-list-update-hook <1>:           Standard Hooks.      (line  82)
84332* buffer-live-p:                         Killing Buffers.     (line  98)
84333* buffer-local variables:                Buffer-Local Variables.
84334                                                              (line   6)
84335* buffer-local variables in modes:       Major Mode Conventions.
84336                                                              (line 156)
84337* buffer-local-value:                    Creating Buffer-Local.
84338                                                              (line 111)
84339* buffer-local-variables:                Creating Buffer-Local.
84340                                                              (line 117)
84341* buffer-modified-p:                     Buffer Modification. (line  22)
84342* buffer-modified-tick:                  Buffer Modification. (line  50)
84343* buffer-name:                           Buffer Names.        (line  18)
84344* buffer-name-history:                   Minibuffer History.  (line 102)
84345* buffer-narrowed-p:                     Narrowing.           (line  53)
84346* buffer-offer-save:                     Killing Buffers.     (line  80)
84347* buffer-predicate, a frame parameter:   Buffer Parameters.   (line  30)
84348* buffer-quit-function:                  Standard Hooks.      (line  85)
84349* buffer-read-only:                      Read Only Buffers.   (line  27)
84350* buffer-save-without-query:             Killing Buffers.     (line  92)
84351* buffer-saved-size:                     Auto-Saving.         (line 173)
84352* buffer-size:                           Point.               (line  54)
84353* buffer-stale-function:                 Reverting.           (line  99)
84354* buffer-start in rx:                    Rx Constructs.       (line 320)
84355* buffer-string:                         Buffer Contents.     (line  43)
84356* buffer-substring:                      Buffer Contents.     (line   9)
84357* buffer-substring-filters:              Buffer Contents.     (line 108)
84358* buffer-substring-no-properties:        Buffer Contents.     (line  38)
84359* buffer-substring-with-bidi-context:    Bidirectional Display.
84360                                                              (line 273)
84361* buffer-swap-text:                      Swapping Text.       (line  26)
84362* buffer-undo-list:                      Undo.                (line  15)
84363* bufferp:                               Buffer Basics.       (line  40)
84364* bufferpos-to-filepos:                  Text Representations.
84365                                                              (line  82)
84366* buffers to display on frame:           Buffer Parameters.   (line   6)
84367* buffers without undo information:      Buffer Names.        (line  12)
84368* buffers, controlled in windows:        Buffers and Windows. (line   6)
84369* buffers, creating:                     Creating Buffers.    (line   6)
84370* buffers, killing:                      Killing Buffers.     (line   6)
84371* bugs:                                  Caveats.             (line  27)
84372* bugs in this manual:                   Caveats.             (line   6)
84373* build details:                         Building Emacs.      (line  74)
84374* building Emacs:                        Building Emacs.      (line   6)
84375* building lists:                        Building Lists.      (line   6)
84376* built-in function:                     What Is a Function.  (line  37)
84377* bury-buffer:                           Buffer List.         (line 101)
84378* butlast:                               List Elements.       (line 153)
84379* button (button property):              Button Properties.   (line  57)
84380* button buffer commands:                Button Buffer Commands.
84381                                                              (line   6)
84382* button properties:                     Button Properties.   (line   6)
84383* button types:                          Button Types.        (line   6)
84384* button-activate:                       Manipulating Buttons.
84385                                                              (line  28)
84386* button-at:                             Manipulating Buttons.
84387                                                              (line  47)
84388* button-down event:                     Button-Down Events.  (line   6)
84389* button-end:                            Manipulating Buttons.
84390                                                              (line  19)
84391* button-face, customization keyword:    Type Keywords.       (line  66)
84392* button-get:                            Manipulating Buttons.
84393                                                              (line  22)
84394* button-has-type-p:                     Manipulating Buttons.
84395                                                              (line  43)
84396* button-label:                          Manipulating Buttons.
84397                                                              (line  37)
84398* button-prefix, customization keyword:  Type Keywords.       (line  71)
84399* button-put:                            Manipulating Buttons.
84400                                                              (line  25)
84401* button-start:                          Manipulating Buttons.
84402                                                              (line  16)
84403* button-suffix, customization keyword:  Type Keywords.       (line  71)
84404* button-type:                           Manipulating Buttons.
84405                                                              (line  40)
84406* button-type-get:                       Manipulating Buttons.
84407                                                              (line  55)
84408* button-type-put:                       Manipulating Buttons.
84409                                                              (line  52)
84410* button-type-subtype-p:                 Manipulating Buttons.
84411                                                              (line  58)
84412* buttons in buffers:                    Buttons.             (line   6)
84413* byte compilation:                      Byte Compilation.    (line   6)
84414* byte compiler warnings, how to avoid:  Warning Tips.        (line   6)
84415* byte packing and unpacking:            Byte Packing.        (line   6)
84416* byte to string:                        Converting Representations.
84417                                                              (line  59)
84418* byte-boolean-vars:                     Variables with Restricted Values.
84419                                                              (line  22)
84420* byte-boolean-vars <1>:                 Writing Emacs Primitives.
84421                                                              (line 202)
84422* byte-code:                             Byte Compilation.    (line   6)
84423* byte-code function:                    Byte-Code Objects.   (line   6)
84424* byte-code object:                      Byte-Code Objects.   (line   6)
84425* byte-code-function-p:                  What Is a Function.  (line 136)
84426* byte-compile:                          Compilation Functions.
84427                                                              (line  34)
84428* byte-compile-debug:                    Compilation Functions.
84429                                                              (line  11)
84430* byte-compile-dynamic:                  Dynamic Loading.     (line  48)
84431* byte-compile-dynamic-docstrings:       Docs and Compilation.
84432                                                              (line  23)
84433* byte-compile-error-on-warn:            Compiler Errors.     (line  87)
84434* byte-compile-file:                     Compilation Functions.
84435                                                              (line  75)
84436* byte-compiler errors:                  Compiler Errors.     (line   6)
84437* byte-compiler warnings:                Compiler Errors.     (line  21)
84438* byte-compiling macros:                 Compiling Macros.    (line   6)
84439* byte-compiling require:                Named Features.      (line  51)
84440* byte-recompile-directory:              Compilation Functions.
84441                                                              (line 105)
84442* byte-to-position:                      Text Representations.
84443                                                              (line  68)
84444* byte-to-string:                        Converting Representations.
84445                                                              (line  58)
84446* bytes:                                 Strings and Characters.
84447                                                              (line   6)
84448* bytesize, in serial connections:       Serial Ports.        (line 116)
84449* C programming language:                C Dialect.           (line   6)
84450* C-c:                                   Prefix Keys.         (line  21)
84451* C-g:                                   Quitting.            (line   6)
84452* C-h:                                   Prefix Keys.         (line  19)
84453* C-M-x:                                 Instrumenting.       (line  10)
84454* C-x:                                   Prefix Keys.         (line  27)
84455* C-x 4:                                 Prefix Keys.         (line  34)
84456* C-x 5:                                 Prefix Keys.         (line  36)
84457* C-x 6:                                 Prefix Keys.         (line  38)
84458* C-x C-a C-m:                           Edebug Execution Modes.
84459                                                              (line  67)
84460* C-x <RET>:                             Prefix Keys.         (line  31)
84461* C-x t:                                 Prefix Keys.         (line  40)
84462* C-x v:                                 Prefix Keys.         (line  43)
84463* C-x X =:                               Coverage Testing.    (line  23)
84464* caaaar:                                List Elements.       (line 146)
84465* caaadr:                                List Elements.       (line 146)
84466* caaar:                                 List Elements.       (line 146)
84467* caadar:                                List Elements.       (line 146)
84468* caaddr:                                List Elements.       (line 146)
84469* caadr:                                 List Elements.       (line 146)
84470* caar:                                  List Elements.       (line 133)
84471* cadaar:                                List Elements.       (line 146)
84472* cadadr:                                List Elements.       (line 146)
84473* cadar:                                 List Elements.       (line 146)
84474* caddar:                                List Elements.       (line 146)
84475* cadddr:                                List Elements.       (line 146)
84476* caddr:                                 List Elements.       (line 146)
84477* cadr:                                  List Elements.       (line 136)
84478* calendrical computations:              Time Calculations.   (line   6)
84479* calendrical information:               Time Conversion.     (line   6)
84480* call stack:                            Internals of Debugger.
84481                                                              (line  21)
84482* call-interactively:                    Interactive Call.    (line  37)
84483* call-process:                          Synchronous Processes.
84484                                                              (line  29)
84485* call-process, command-line arguments from minibuffer: Shell Arguments.
84486                                                              (line  40)
84487* call-process-region:                   Synchronous Processes.
84488                                                              (line 192)
84489* call-process-shell-command:            Synchronous Processes.
84490                                                              (line 241)
84491* call-shell-region:                     Synchronous Processes.
84492                                                              (line 258)
84493* called-interactively-p:                Distinguish Interactive.
84494                                                              (line  26)
84495* calling a function:                    Calling Functions.   (line   6)
84496* cancel-change-group:                   Atomic Changes.      (line  52)
84497* cancel-debug-on-entry:                 Function Debugging.  (line  51)
84498* cancel-debug-on-variable-change:       Variable Debugging.  (line  20)
84499* cancel-timer:                          Timers.              (line 135)
84500* canonical character height:            Frame Font.          (line  12)
84501* canonical character width:             Frame Font.          (line  12)
84502* capitalization:                        Case Conversion.     (line  54)
84503* capitalize:                            Case Conversion.     (line  53)
84504* capitalize-region:                     Case Changes.        (line  12)
84505* capitalize-word:                       Case Changes.        (line  49)
84506* caption bar:                           Frame Layout.        (line 100)
84507* car:                                   List Elements.       (line   6)
84508* car-safe:                              List Elements.       (line  34)
84509* case conversion in buffers:            Case Changes.        (line   6)
84510* case conversion in Lisp:               Case Conversion.     (line   6)
84511* case in replacements:                  Replacing Match.     (line   9)
84512* case-fold-search:                      Searching and Case.  (line  25)
84513* case-replace:                          Searching and Case.  (line  30)
84514* case-table-p:                          Case Tables.         (line  59)
84515* catch:                                 Catch and Throw.     (line  60)
84516* categories of characters:              Categories.          (line   6)
84517* category (overlay property):           Overlay Properties.  (line  83)
84518* category (text property):              Special Properties.  (line  15)
84519* category in rx:                        Rx Constructs.       (line 252)
84520* category set:                          Categories.          (line  23)
84521* category table:                        Categories.          (line  12)
84522* category, regexp search for:           Regexp Backslash.    (line 140)
84523* category-docstring:                    Categories.          (line  63)
84524* category-set-mnemonics:                Categories.          (line 122)
84525* category-table:                        Categories.          (line  77)
84526* category-table-p:                      Categories.          (line  80)
84527* cdaaar:                                List Elements.       (line 146)
84528* cdaadr:                                List Elements.       (line 146)
84529* cdaar:                                 List Elements.       (line 146)
84530* cdadar:                                List Elements.       (line 146)
84531* cdaddr:                                List Elements.       (line 146)
84532* cdadr:                                 List Elements.       (line 146)
84533* cdar:                                  List Elements.       (line 139)
84534* cddaar:                                List Elements.       (line 146)
84535* cddadr:                                List Elements.       (line 146)
84536* cddar:                                 List Elements.       (line 146)
84537* cdddar:                                List Elements.       (line 146)
84538* cddddr:                                List Elements.       (line 146)
84539* cdddr:                                 List Elements.       (line 146)
84540* cddr:                                  List Elements.       (line 142)
84541* cdr:                                   List Elements.       (line  20)
84542* cdr-safe:                              List Elements.       (line  47)
84543* ceiling:                               Numeric Conversions. (line  53)
84544* centering point:                       Textual Scrolling.   (line 195)
84545* change hooks:                          Change Hooks.        (line   6)
84546* change hooks for a character:          Special Properties.  (line 290)
84547* change load-path at configure time:    Building Emacs.      (line 117)
84548* change-major-mode-after-body-hook:     Mode Hooks.          (line  51)
84549* change-major-mode-hook:                Creating Buffer-Local.
84550                                                              (line 189)
84551* changing key bindings:                 Changing Key Bindings.
84552                                                              (line   6)
84553* changing text properties:              Changing Properties. (line   6)
84554* changing to another buffer:            Current Buffer.      (line   6)
84555* changing window size:                  Resizing Windows.    (line   6)
84556* char in rx:                            Rx Constructs.       (line 124)
84557* char-after:                            Near Point.          (line  13)
84558* char-before:                           Near Point.          (line  26)
84559* char-category-set:                     Categories.          (line 112)
84560* char-charset:                          Character Sets.      (line  38)
84561* char-code-property-description:        Character Properties.
84562                                                              (line 212)
84563* char-displayable-p:                    Fontsets.            (line 136)
84564* char-equal:                            Text Comparison.     (line   6)
84565* char-from-name:                        Character Codes.     (line  41)
84566* char-or-string-p:                      Predicates for Strings.
84567                                                              (line  16)
84568* char-property-alias-alist:             Examining Properties.
84569                                                              (line  56)
84570* char-script-table:                     Character Properties.
84571                                                              (line 232)
84572* char-syntax:                           Syntax Table Functions.
84573                                                              (line  66)
84574* char-table length:                     Sequence Functions.  (line  14)
84575* char-table-extra-slot:                 Char-Tables.         (line  72)
84576* char-table-p:                          Char-Tables.         (line  55)
84577* char-table-parent:                     Char-Tables.         (line  65)
84578* char-table-range:                      Char-Tables.         (line  84)
84579* char-table-subtype:                    Char-Tables.         (line  59)
84580* char-tables:                           Char-Tables.         (line   6)
84581* char-to-string:                        String Conversion.   (line  65)
84582* char-width:                            Size of Displayed Text.
84583                                                              (line  10)
84584* char-width-table:                      Character Properties.
84585                                                              (line 240)
84586* character alternative (in regexp):     Regexp Special.      (line  69)
84587* character arrays:                      Strings and Characters.
84588                                                              (line   6)
84589* character case:                        Case Conversion.     (line   6)
84590* character categories:                  Categories.          (line   6)
84591* character class in rx:                 Rx Constructs.       (line 125)
84592* character class in rx <1>:             Rx Constructs.       (line 159)
84593* character classes in regexp:           Char Classes.        (line   6)
84594* character code conversion:             Coding System Basics.
84595                                                              (line   6)
84596* character codepoint:                   Text Representations.
84597                                                              (line  10)
84598* character codes:                       Character Codes.     (line   6)
84599* character event:                       Keyboard Events.     (line   6)
84600* character insertion:                   Commands for Insertion.
84601                                                              (line  17)
84602* character printing:                    Describing Characters.
84603                                                              (line  29)
84604* character properties:                  Character Properties.
84605                                                              (line   6)
84606* character set, searching:              Scanning Charsets.   (line   6)
84607* character sets:                        Character Sets.      (line   6)
84608* character to string:                   String Conversion.   (line  66)
84609* character translation tables:          Translation of Characters.
84610                                                              (line   6)
84611* character width on display:            Size of Displayed Text.
84612                                                              (line   6)
84613* characterp:                            Character Codes.     (line  21)
84614* characters:                            Strings and Characters.
84615                                                              (line   6)
84616* characters for interactive codes:      Interactive Codes.   (line   6)
84617* characters, multi-byte:                Non-ASCII Characters.
84618                                                              (line   6)
84619* characters, representation in buffers and strings: Text Representations.
84620                                                              (line  20)
84621* charset:                               Character Sets.      (line   6)
84622* charset, coding systems to encode:     Lisp and Coding Systems.
84623                                                              (line  80)
84624* charset, text property:                Explicit Encoding.   (line 110)
84625* charset-after:                         Scanning Charsets.   (line  12)
84626* charset-list:                          Character Sets.      (line  27)
84627* charset-plist:                         Character Sets.      (line  48)
84628* charset-priority-list:                 Character Sets.      (line  30)
84629* charsetp:                              Character Sets.      (line  23)
84630* charsets supported by a coding system: Lisp and Coding Systems.
84631                                                              (line 137)
84632* check-coding-system:                   Lisp and Coding Systems.
84633                                                              (line  18)
84634* check-coding-systems-region:           Lisp and Coding Systems.
84635                                                              (line  84)
84636* check-declare-directory:               Declaring Functions. (line  50)
84637* check-declare-file:                    Declaring Functions. (line  50)
84638* checkdoc:                              Tips.                (line  11)
84639* checkdoc-current-buffer:               Tips.                (line  11)
84640* checkdoc-file:                         Tips.                (line  11)
84641* checkdoc-minor-mode:                   Documentation Tips.  (line   6)
84642* checkdoc-package-keywords:             Library Headers.     (line  84)
84643* checkdoc-package-keywords-flag:        Library Headers.     (line  84)
84644* child frames:                          Child Frames.        (line   6)
84645* child process:                         Processes.           (line   6)
84646* child window:                          Windows and Frames.  (line  51)
84647* child-frame-parameters, a buffer display action alist entry: Buffer Display Action Alists.
84648                                                              (line 180)
84649* choice, customization types:           Splicing into Lists. (line  27)
84650* cipher, AEAD:                          GnuTLS Cryptography. (line   6)
84651* cipher, symmetric:                     GnuTLS Cryptography. (line   6)
84652* circular list:                         Cons Cells.          (line  34)
84653* circular structure, read syntax:       Circular Objects.    (line   6)
84654* cl:                                    Lisp History.        (line  28)
84655* CL note—allocate more storage:         Garbage Collection.  (line  51)
84656* CL note—case of letters:               Symbol Type.         (line  38)
84657* CL note—default optional arg:          Argument List.       (line  46)
84658* CL note—interning existing symbol:     Creating Symbols.    (line 116)
84659* CL note—lack union, intersection:      Sets And Lists.      (line  13)
84660* CL note—no continuable errors:         Signaling Errors.    (line  98)
84661* CL note—no setf functions:             Adding Generalized Variables.
84662                                                              (line  80)
84663* CL note—only throw in Emacs:           Catch and Throw.     (line  54)
84664* CL note—rplaca vs setcar:              Modifying Lists.     (line  14)
84665* CL note—special forms compared:        Special Forms.       (line  96)
84666* CL note—symbol in obarrays:            Creating Symbols.    (line  65)
84667* cl-call-next-method:                   Generic Functions.   (line 208)
84668* cl-defgeneric:                         Generic Functions.   (line  49)
84669* cl-defmethod:                          Generic Functions.   (line  71)
84670* cl-next-method-p:                      Generic Functions.   (line 216)
84671* cl-old-struct-compat-mode:             Backward Compatibility.
84672                                                              (line  12)
84673* classification of file types:          Kinds of Files.      (line   6)
84674* classifying events:                    Classifying Events.  (line   6)
84675* cleanup forms:                         Cleanups.            (line  13)
84676* clear-abbrev-table:                    Abbrev Tables.       (line  18)
84677* clear-image-cache:                     Image Cache.         (line  39)
84678* clear-message-function:                Displaying Messages. (line  72)
84679* clear-string:                          Modifying Strings.   (line  29)
84680* clear-this-command-keys:               Command Loop Info.   (line  94)
84681* clear-visited-file-modtime:            Modification Time.   (line  33)
84682* click event:                           Click Events.        (line   6)
84683* clickable buttons in buffers:          Buttons.             (line   6)
84684* clickable text:                        Clickable Text.      (line   6)
84685* clipboard:                             Window System Selections.
84686                                                              (line   6)
84687* clipboard support (for MS-Windows):    Window System Selections.
84688                                                              (line  57)
84689* clone-indirect-buffer:                 Indirect Buffers.    (line  48)
84690* clone-of, a window parameter:          Window Parameters.   (line 104)
84691* CLOS:                                  Generic Functions.   (line  20)
84692* closepath:                             SVG Images.          (line 190)
84693* closure:                               Closures.            (line  13)
84694* closures, example of using:            Lexical Binding.     (line  50)
84695* clrhash:                               Hash Access.         (line  28)
84696* coded character set:                   Character Sets.      (line   6)
84697* codepoint, largest value:              Character Codes.     (line  32)
84698* codes, interactive, description of:    Interactive Codes.   (line   6)
84699* codespace:                             Text Representations.
84700                                                              (line  10)
84701* coding conventions in Emacs Lisp:      Coding Conventions.  (line   6)
84702* coding standards:                      Tips.                (line   6)
84703* coding system:                         Coding Systems.      (line   6)
84704* coding system for operation:           Specifying Coding Systems.
84705                                                              (line   6)
84706* coding system, automatically determined: Default Coding Systems.
84707                                                              (line   6)
84708* coding system, validity check:         Lisp and Coding Systems.
84709                                                              (line  18)
84710* coding systems for encoding a string:  Lisp and Coding Systems.
84711                                                              (line  73)
84712* coding systems for encoding region:    Lisp and Coding Systems.
84713                                                              (line  64)
84714* coding systems, priority:              Specifying Coding Systems.
84715                                                              (line  67)
84716* coding-system-aliases:                 Coding System Basics.
84717                                                              (line  91)
84718* coding-system-change-eol-conversion:   Lisp and Coding Systems.
84719                                                              (line  47)
84720* coding-system-change-text-conversion:  Lisp and Coding Systems.
84721                                                              (line  57)
84722* coding-system-charset-list:            Lisp and Coding Systems.
84723                                                              (line 137)
84724* coding-system-eol-type:                Lisp and Coding Systems.
84725                                                              (line  25)
84726* coding-system-for-read:                Specifying Coding Systems.
84727                                                              (line   9)
84728* coding-system-for-write:               Specifying Coding Systems.
84729                                                              (line  34)
84730* coding-system-get:                     Coding System Basics.
84731                                                              (line  74)
84732* coding-system-list:                    Lisp and Coding Systems.
84733                                                              (line   8)
84734* coding-system-p:                       Lisp and Coding Systems.
84735                                                              (line  14)
84736* coding-system-priority-list:           Specifying Coding Systems.
84737                                                              (line  73)
84738* coding-system-require-warning:         Specifying Coding Systems.
84739                                                              (line  45)
84740* collapse-delayed-warnings:             Delayed Warnings.    (line  39)
84741* color names:                           Color Names.         (line   6)
84742* color-defined-p:                       Color Names.         (line  25)
84743* color-gray-p:                          Color Names.         (line  61)
84744* color-supported-p:                     Color Names.         (line  49)
84745* color-values:                          Color Names.         (line  67)
84746* colors on text terminals:              Text Terminal Colors.
84747                                                              (line   6)
84748* column width:                          Frame Font.          (line  12)
84749* columns:                               Columns.             (line   6)
84750* COM1:                                  Serial Ports.        (line   6)
84751* combine-after-change-calls:            Change Hooks.        (line  56)
84752* combine-and-quote-strings:             Shell Arguments.     (line  67)
84753* combine-change-calls:                  Change Hooks.        (line  78)
84754* combining conditions:                  Combining Conditions.
84755                                                              (line   6)
84756* command:                               What Is a Function.  (line  64)
84757* command descriptions:                  A Sample Function Description.
84758                                                              (line   6)
84759* command history:                       Command History.     (line   6)
84760* command in keymap:                     Key Lookup.          (line  42)
84761* command loop:                          Command Loop.        (line   6)
84762* command loop variables:                Command Loop Info.   (line   6)
84763* command loop, recursive:               Recursive Editing.   (line   6)
84764* command-debug-status:                  Internals of Debugger.
84765                                                              (line 101)
84766* command-error-function:                Processing of Errors.
84767                                                              (line  22)
84768* command-execute:                       Interactive Call.    (line  79)
84769* command-history:                       Command History.     (line  14)
84770* command-line:                          Command-Line Arguments.
84771                                                              (line  14)
84772* command-line arguments:                Command-Line Arguments.
84773                                                              (line   6)
84774* command-line options:                  Command-Line Arguments.
84775                                                              (line  29)
84776* command-line-args:                     Command-Line Arguments.
84777                                                              (line  64)
84778* command-line-args-left:                Command-Line Arguments.
84779                                                              (line  68)
84780* command-line-functions:                Command-Line Arguments.
84781                                                              (line  72)
84782* command-line-processed:                Command-Line Arguments.
84783                                                              (line  19)
84784* command-remapping:                     Remapping Commands.  (line  42)
84785* command-switch-alist:                  Command-Line Arguments.
84786                                                              (line  28)
84787* commandp:                              Interactive Call.    (line  17)
84788* commandp example:                      High-Level Completion.
84789                                                              (line  97)
84790* commands, defining:                    Defining Commands.   (line   6)
84791* comment style:                         Syntax Flags.        (line  46)
84792* comment syntax:                        Syntax Class Table.  (line 110)
84793* comment-auto-fill-only-comments:       Auto Filling.        (line  36)
84794* comment-end-can-be-escaped:            Control Parsing.     (line  20)
84795* commentary, in a Lisp library:         Library Headers.     (line 140)
84796* comments:                              Comments.            (line   6)
84797* comments, Lisp convention for:         Comment Tips.        (line   6)
84798* Common Lisp:                           Lisp History.        (line  11)
84799* compare-buffer-substrings:             Comparing Text.      (line   9)
84800* compare-strings:                       Text Comparison.     (line 199)
84801* compare-window-configurations:         Window Configurations.
84802                                                              (line  70)
84803* comparing buffer text:                 Comparing Text.      (line   6)
84804* comparing file modification time:      Modification Time.   (line   6)
84805* comparing numbers:                     Comparison of Numbers.
84806                                                              (line   6)
84807* comparing time values:                 Time Calculations.   (line   6)
84808* compatibility, between modules and Emacs: Module Initialization.
84809                                                              (line  41)
84810* compilation (Emacs Lisp):              Byte Compilation.    (line   6)
84811* compilation functions:                 Compilation Functions.
84812                                                              (line   6)
84813* compile-defun:                         Compilation Functions.
84814                                                              (line  65)
84815* compile-time constant:                 Eval During Compile. (line  42)
84816* compiled function:                     Byte-Code Objects.   (line   6)
84817* compiler errors:                       Compiler Errors.     (line   6)
84818* complete key:                          Keymap Basics.       (line   6)
84819* completing-read:                       Minibuffer Completion.
84820                                                              (line   9)
84821* completing-read-function:              Minibuffer Completion.
84822                                                              (line  99)
84823* completion:                            Completion.          (line   6)
84824* completion styles:                     Completion Variables.
84825                                                              (line   9)
84826* completion table:                      Basic Completion.    (line  14)
84827* completion table, modifying:           Basic Completion.    (line 187)
84828* completion tables, combining:          Basic Completion.    (line 187)
84829* completion, file name:                 File Name Completion.
84830                                                              (line   6)
84831* completion-at-point:                   Completion in Buffers.
84832                                                              (line   6)
84833* completion-at-point-functions:         Completion in Buffers.
84834                                                              (line  13)
84835* completion-auto-help:                  Completion Commands. (line  86)
84836* completion-boundaries:                 Basic Completion.    (line 139)
84837* completion-category-overrides:         Completion Variables.
84838                                                              (line  49)
84839* completion-extra-properties:           Completion Variables.
84840                                                              (line  69)
84841* completion-ignore-case:                Basic Completion.    (line 160)
84842* completion-ignored-extensions:         File Name Completion.
84843                                                              (line  61)
84844* completion-in-region:                  Completion in Buffers.
84845                                                              (line  92)
84846* completion-regexp-list:                Basic Completion.    (line 168)
84847* completion-styles:                     Completion Variables.
84848                                                              (line   9)
84849* completion-styles-alist:               Completion Variables.
84850                                                              (line  15)
84851* completion-table-case-fold:            Basic Completion.    (line 187)
84852* completion-table-dynamic:              Programmed Completion.
84853                                                              (line  92)
84854* completion-table-in-turn:              Basic Completion.    (line 187)
84855* completion-table-merge:                Basic Completion.    (line 187)
84856* completion-table-subvert:              Basic Completion.    (line 187)
84857* completion-table-with-cache:           Programmed Completion.
84858                                                              (line 116)
84859* completion-table-with-predicate:       Basic Completion.    (line 187)
84860* completion-table-with-quoting:         Basic Completion.    (line 187)
84861* completion-table-with-terminator:      Basic Completion.    (line 187)
84862* complex arguments:                     Minibuffers.         (line   6)
84863* complex command:                       Command History.     (line   6)
84864* composite types (customization):       Composite Types.     (line   6)
84865* composition (text property):           Special Properties.  (line 376)
84866* composition property, and point display: Adjusting Point.   (line   6)
84867* compute-motion:                        Screen Lines.        (line 110)
84868* concat:                                Creating Strings.    (line 108)
84869* concatenating bidirectional strings:   Bidirectional Display.
84870                                                              (line 158)
84871* concatenating lists:                   Rearrangement.       (line  16)
84872* concatenating strings:                 Creating Strings.    (line 109)
84873* concurrency:                           Threads.             (line   6)
84874* cond:                                  Conditionals.        (line  52)
84875* condition name:                        Error Symbols.       (line   6)
84876* condition-case:                        Handling Errors.     (line  92)
84877* condition-case-unless-debug:           Handling Errors.     (line  67)
84878* condition-mutex:                       Condition Variables. (line  65)
84879* condition-name:                        Condition Variables. (line  62)
84880* condition-notify:                      Condition Variables. (line  52)
84881* condition-variable-p:                  Condition Variables. (line  36)
84882* condition-wait:                        Condition Variables. (line  40)
84883* conditional evaluation:                Conditionals.        (line   6)
84884* conditional selection of windows:      Cyclic Window Ordering.
84885                                                              (line 146)
84886* confirm-kill-processes:                Query Before Exit.   (line  27)
84887* connection local variables:            Connection Local Variables.
84888                                                              (line   6)
84889* connection-local-criteria-alist:       Connection Local Variables.
84890                                                              (line  78)
84891* connection-local-profile-alist:        Connection Local Variables.
84892                                                              (line  37)
84893* connection-local-set-profile-variables: Connection Local Variables.
84894                                                              (line  10)
84895* connection-local-set-profiles:         Connection Local Variables.
84896                                                              (line  42)
84897* cons:                                  Building Lists.      (line  11)
84898* cons cells:                            Building Lists.      (line   6)
84899* cons-cells-consed:                     Memory Usage.        (line  13)
84900* consing:                               Building Lists.      (line  25)
84901* consp:                                 List-related Predicates.
84902                                                              (line  11)
84903* constant variables:                    Constant Variables.  (line   6)
84904* constant variables <1>:                Defining Variables.  (line  85)
84905* constrain-to-field:                    Fields.              (line  68)
84906* content directory, package:            Packaging Basics.    (line  47)
84907* continuation lines:                    Truncation.          (line   6)
84908* continue-process:                      Signals to Processes.
84909                                                              (line  85)
84910* control character key constants:       Changing Key Bindings.
84911                                                              (line  20)
84912* control character printing:            Describing Characters.
84913                                                              (line  29)
84914* control characters:                    Ctl-Char Syntax.     (line   6)
84915* control characters in display:         Usual Display.       (line  66)
84916* control characters, reading:           Quoted Character Input.
84917                                                              (line  12)
84918* control structures:                    Control Structures.  (line   6)
84919* Control-X-prefix:                      Prefix Keys.         (line  27)
84920* controller part, model/view/controller: Abstract Display Example.
84921                                                              (line  63)
84922* controlling terminal:                  Suspending Emacs.    (line  13)
84923* controlling-tty-p:                     Suspending Emacs.    (line 107)
84924* conventions for writing major modes:   Major Mode Conventions.
84925                                                              (line   6)
84926* conventions for writing minor modes:   Minor Mode Conventions.
84927                                                              (line   6)
84928* conversion of strings:                 String Conversion.   (line   6)
84929* convert buffer position to file byte:  Text Representations.
84930                                                              (line  79)
84931* convert file byte to buffer position:  Text Representations.
84932                                                              (line  79)
84933* convert sequence to another type:      Sequence Functions.  (line 597)
84934* convert-standard-filename:             Standard File Names. (line  42)
84935* converting file names from/to MS-Windows syntax: File Names.
84936                                                              (line  19)
84937* converting numbers:                    Numeric Conversions. (line   6)
84938* coordinate, relative to frame:         Coordinates and Windows.
84939                                                              (line   6)
84940* coordinates-in-window-p:               Coordinates and Windows.
84941                                                              (line  70)
84942* copy-abbrev-table:                     Abbrev Tables.       (line  22)
84943* copy-alist:                            Association Lists.   (line 187)
84944* copy-category-table:                   Categories.          (line  87)
84945* copy-directory:                        Create/Delete Dirs.  (line  23)
84946* copy-file:                             Changing Files.      (line 116)
84947* copy-hash-table:                       Other Hash.          (line  11)
84948* copy-keymap:                           Creating Keymaps.    (line  39)
84949* copy-marker:                           Creating Markers.    (line  52)
84950* copy-overlay:                          Managing Overlays.   (line  85)
84951* copy-region-as-kill:                   Kill Functions.      (line  43)
84952* copy-sequence:                         Sequence Functions.  (line  65)
84953* copy-syntax-table:                     Syntax Table Functions.
84954                                                              (line  18)
84955* copy-tree:                             Building Lists.      (line 149)
84956* copying alists:                        Association Lists.   (line 188)
84957* copying bidirectional text, preserve visual order: Bidirectional Display.
84958                                                              (line 260)
84959* copying files:                         Changing Files.      (line   6)
84960* copying lists:                         Building Lists.      (line  62)
84961* copying sequences:                     Sequence Functions.  (line  66)
84962* copying strings:                       Creating Strings.    (line 109)
84963* copying vectors:                       Vector Functions.    (line  33)
84964* copysign:                              Float Basics.        (line  78)
84965* copy_string_contents:                  Module Values.       (line 122)
84966* cos:                                   Math Functions.      (line  10)
84967* count-lines:                           Text Lines.          (line  75)
84968* count-loop:                            A Sample Function Description.
84969                                                              (line  66)
84970* count-screen-lines:                    Screen Lines.        (line  58)
84971* count-words:                           Text Lines.          (line  83)
84972* counting columns:                      Columns.             (line   6)
84973* counting set bits:                     Bitwise Operations.  (line 173)
84974* coverage testing:                      Test Coverage.       (line   6)
84975* coverage testing (Edebug):             Coverage Testing.    (line   6)
84976* create subprocess:                     Subprocess Creation. (line   6)
84977* create-file-buffer:                    Subroutines of Visiting.
84978                                                              (line  10)
84979* create-fontset-from-fontset-spec:      Fontsets.            (line  13)
84980* create-image:                          Defining Images.     (line   9)
84981* create-lockfiles:                      File Locks.          (line  54)
84982* creating buffers:                      Creating Buffers.    (line   6)
84983* creating hash tables:                  Creating Hash.       (line   6)
84984* creating keymaps:                      Creating Keymaps.    (line   6)
84985* creating markers:                      Creating Markers.    (line   6)
84986* creating strings:                      Creating Strings.    (line   6)
84987* creating, copying and deleting directories: Create/Delete Dirs.
84988                                                              (line   6)
84989* cryptographic hash:                    Checksum/Hash.       (line   6)
84990* cryptographic hash <1>:                GnuTLS Cryptography. (line   6)
84991* ctl-arrow:                             Usual Display.       (line  65)
84992* ctl-x-4-map:                           Prefix Keys.         (line  34)
84993* ctl-x-5-map:                           Prefix Keys.         (line  36)
84994* ctl-x-map:                             Prefix Keys.         (line  27)
84995* ctl-x-r-map:                           Standard Keymaps.    (line  40)
84996* curly quotes:                          Keys in Documentation.
84997                                                              (line  47)
84998* curly quotes <1>:                      Text Quoting Style.  (line  30)
84999* curly quotes <2>:                      Documentation Tips.  (line  95)
85000* curly quotes, in formatted messages:   Formatting Strings.  (line  32)
85001* current binding:                       Local Variables.     (line  29)
85002* current buffer:                        Current Buffer.      (line   6)
85003* current buffer mark:                   The Mark.            (line  53)
85004* current buffer point and mark (Edebug): Edebug Display Update.
85005                                                              (line  22)
85006* current buffer position:               Point.               (line  32)
85007* current command:                       Command Loop Info.   (line  34)
85008* current stack frame:                   Backtraces.          (line  17)
85009* current-active-maps:                   Active Keymaps.      (line  58)
85010* current-bidi-paragraph-direction:      Bidirectional Display.
85011                                                              (line 129)
85012* current-buffer:                        Current Buffer.      (line  17)
85013* current-case-table:                    Case Tables.         (line  69)
85014* current-column:                        Columns.             (line  22)
85015* current-fill-column:                   Margins.             (line  50)
85016* current-frame-configuration:           Frame Configurations.
85017                                                              (line  10)
85018* current-global-map:                    Controlling Active Maps.
85019                                                              (line  16)
85020* current-idle-time:                     Idle Timers.         (line  61)
85021* current-indentation:                   Primitive Indent.    (line  10)
85022* current-input-method:                  Input Methods.       (line  17)
85023* current-input-mode:                    Input Modes.         (line  34)
85024* current-justification:                 Filling.             (line 123)
85025* current-kill:                          Low-Level Kill Ring. (line  11)
85026* current-left-margin:                   Margins.             (line  43)
85027* current-local-map:                     Controlling Active Maps.
85028                                                              (line  27)
85029* current-message:                       Displaying Messages. (line 135)
85030* current-minor-mode-maps:               Controlling Active Maps.
85031                                                              (line  47)
85032* current-prefix-arg:                    Prefix Command Arguments.
85033                                                              (line  85)
85034* current-thread:                        Basic Thread Functions.
85035                                                              (line  69)
85036* current-time:                          Time of Day.         (line  74)
85037* current-time-string:                   Time of Day.         (line  54)
85038* current-time-zone:                     Time Zone Rules.     (line  34)
85039* current-window-configuration:          Window Configurations.
85040                                                              (line  19)
85041* current-word:                          Buffer Contents.     (line 117)
85042* currying:                              Calling Functions.   (line  82)
85043* cursor:                                Window Point.        (line  25)
85044* cursor (text property):                Special Properties.  (line 211)
85045* cursor position for display properties and overlays: Special Properties.
85046                                                              (line 236)
85047* cursor, and frame parameters:          Cursor Parameters.   (line   6)
85048* cursor, fringe:                        Fringe Cursors.      (line   6)
85049* cursor-color, a frame parameter:       Font and Color Parameters.
85050                                                              (line 108)
85051* cursor-in-echo-area:                   Echo Area Customization.
85052                                                              (line   8)
85053* cursor-in-non-selected-windows:        Cursor Parameters.   (line  36)
85054* cursor-intangible (text property):     Special Properties.  (line 196)
85055* cursor-intangible-mode:                Special Properties.  (line 196)
85056* cursor-sensor-functions (text property): Special Properties.
85057                                                              (line 364)
85058* cursor-sensor-inhibit:                 Special Properties.  (line 200)
85059* cursor-sensor-mode:                    Special Properties.  (line 364)
85060* cursor-type:                           Cursor Parameters.   (line  26)
85061* cursor-type <1>:                       Cursor Parameters.   (line  29)
85062* cursor-type, a frame parameter:        Cursor Parameters.   (line   8)
85063* curved quotes:                         Keys in Documentation.
85064                                                              (line  47)
85065* curved quotes <1>:                     Text Quoting Style.  (line  30)
85066* curved quotes <2>:                     Documentation Tips.  (line  95)
85067* curved quotes, in formatted messages:  Formatting Strings.  (line  32)
85068* curveto:                               SVG Images.          (line 224)
85069* cust-print:                            Printing in Edebug.  (line   6)
85070* custom %-sequence in format:           Custom Format Strings.
85071                                                              (line   6)
85072* custom format string:                  Custom Format Strings.
85073                                                              (line   6)
85074* custom themes:                         Custom Themes.       (line   6)
85075* custom-add-frequent-value:             Variable Definitions.
85076                                                              (line 182)
85077* custom-group property:                 Group Definitions.   (line  51)
85078* custom-initialize-delay:               Building Emacs.      (line 137)
85079* custom-known-themes:                   Custom Themes.       (line  74)
85080* custom-reevaluate-setting:             Variable Definitions.
85081                                                              (line 198)
85082* custom-set-faces:                      Applying Customizations.
85083                                                              (line  36)
85084* custom-set-variables:                  Applying Customizations.
85085                                                              (line  13)
85086* custom-theme-p:                        Custom Themes.       (line  68)
85087* custom-theme-set-faces:                Custom Themes.       (line  47)
85088* custom-theme-set-variables:            Custom Themes.       (line  37)
85089* custom-unlispify-remove-prefixes:      Group Definitions.   (line  57)
85090* custom-variable-history:               Minibuffer History.  (line 120)
85091* custom-variable-p:                     Variable Definitions.
85092                                                              (line 211)
85093* customizable variables, how to define: Variable Definitions.
85094                                                              (line   6)
85095* customization groups, defining:        Group Definitions.   (line   6)
85096* customization item:                    Customization.       (line   6)
85097* customization keywords:                Common Keywords.     (line   6)
85098* customization types:                   Customization Types. (line   6)
85099* customization types, define new:       Defining New Types.  (line   6)
85100* customize-package-emacs-version-alist: Common Keywords.     (line 128)
85101* cyclic ordering of windows:            Cyclic Window Ordering.
85102                                                              (line   6)
85103* cygwin-convert-file-name-from-windows: File Names.          (line  19)
85104* cygwin-convert-file-name-to-windows:   File Names.          (line  19)
85105* data type:                             Lisp Data Types.     (line   6)
85106* data-directory:                        Help Functions.      (line 121)
85107* datagrams:                             Datagrams.           (line   6)
85108* date-days-in-month:                    Time Calculations.   (line  49)
85109* date-leap-year-p:                      Time Calculations.   (line  46)
85110* date-ordinal-to-time:                  Time Calculations.   (line  53)
85111* date-to-time:                          Time Parsing.        (line  10)
85112* deactivate-mark:                       The Mark.            (line 147)
85113* deactivate-mark <1>:                   The Mark.            (line 162)
85114* deactivate-mark-hook:                  The Mark.            (line 175)
85115* debug:                                 Invoking the Debugger.
85116                                                              (line   9)
85117* debug-ignored-errors:                  Error Debugging.     (line  39)
85118* debug-on-entry:                        Function Debugging.  (line  13)
85119* debug-on-error:                        Error Debugging.     (line  17)
85120* debug-on-error use:                    Processing of Errors.
85121                                                              (line  31)
85122* debug-on-event:                        Error Debugging.     (line  85)
85123* debug-on-message:                      Error Debugging.     (line  93)
85124* debug-on-next-call:                    Internals of Debugger.
85125                                                              (line  85)
85126* debug-on-quit:                         Infinite Loops.      (line  21)
85127* debug-on-signal:                       Error Debugging.     (line  63)
85128* debug-on-variable-change:              Variable Debugging.  (line  10)
85129* debugger:                              Internals of Debugger.
85130                                                              (line   9)
85131* debugger command list:                 Debugger Commands.   (line   6)
85132* debugger for Emacs Lisp:               Debugger.            (line   6)
85133* debugger, explicit entry:              Explicit Debug.      (line   6)
85134* debugger-bury-or-kill:                 Using Debugger.      (line  13)
85135* debugger-stack-frame-as-list:          Internals of Debugger.
85136                                                              (line  61)
85137* debugging changes to variables:        Variable Debugging.  (line   6)
85138* debugging errors:                      Error Debugging.     (line   6)
85139* debugging invalid Lisp syntax:         Syntax Errors.       (line   6)
85140* debugging lisp programs:               Debugging.           (line   6)
85141* debugging specific functions:          Function Debugging.  (line   6)
85142* declare:                               Declare Form.        (line   6)
85143* declare <1>:                           Declare Form.        (line  10)
85144* declare-function:                      Declaring Functions. (line   6)
85145* declare-function <1>:                  Declaring Functions. (line  38)
85146* declaring functions:                   Declaring Functions. (line   6)
85147* decode process output:                 Decoding Output.     (line   6)
85148* decode-char:                           Character Sets.      (line  70)
85149* decode-coding-inserted-region:         Explicit Encoding.   (line 117)
85150* decode-coding-region:                  Explicit Encoding.   (line  69)
85151* decode-coding-string:                  Explicit Encoding.   (line  93)
85152* decode-time:                           Time Conversion.     (line  62)
85153* decoded-time-add:                      Time Conversion.     (line 132)
85154* decoding file formats:                 Format Conversion.   (line   6)
85155* decoding in coding systems:            Explicit Encoding.   (line   6)
85156* decrement field of register:           Cons Cell Type.      (line   6)
85157* dedicated window:                      Dedicated Windows.   (line   6)
85158* dedicated, a buffer display action alist entry: Buffer Display Action Alists.
85159                                                              (line 154)
85160* def-edebug-spec:                       Instrumenting Macro Calls.
85161                                                              (line  44)
85162* defadvice:                             Porting Old Advice.  (line   6)
85163* defalias:                              Defining Functions.  (line  55)
85164* defalias-fset-function property:       Defining Functions.  (line  63)
85165* default argument string:               Interactive Codes.   (line  20)
85166* default character height:              Frame Font.          (line   6)
85167* default character size:                Frame Font.          (line   6)
85168* default character width:               Frame Font.          (line   6)
85169* default coding system:                 Default Coding Systems.
85170                                                              (line   6)
85171* default coding system, functions to determine: Default Coding Systems.
85172                                                              (line  97)
85173* default filter function of a process:  Filter Functions.    (line   6)
85174* default font:                          Frame Font.          (line   6)
85175* default height of character:           Frame Font.          (line   6)
85176* default init file:                     Init File.           (line  31)
85177* default key binding:                   Format of Keymaps.   (line  32)
85178* default sentinel function of a process: Sentinels.          (line  14)
85179* default value:                         Default Value.       (line   6)
85180* default value of char-table:           Char-Tables.         (line  34)
85181* default width of character:            Frame Font.          (line   6)
85182* default-boundp:                        Default Value.       (line  27)
85183* default-directory:                     File Name Expansion. (line  81)
85184* default-file-modes:                    Changing Files.      (line 240)
85185* default-font-height:                   Low-Level Font.      (line 309)
85186* default-font-width:                    Low-Level Font.      (line 304)
85187* default-frame-alist:                   Initial Parameters.  (line  47)
85188* default-input-method:                  Input Methods.       (line  23)
85189* default-justification:                 Filling.             (line 117)
85190* default-minibuffer-frame:              Minibuffers and Frames.
85191                                                              (line  27)
85192* default-process-coding-system:         Default Coding Systems.
85193                                                              (line  88)
85194* default-text-properties:               Examining Properties.
85195                                                              (line  69)
85196* default-toplevel-value:                Default Value.       (line  92)
85197* default-value:                         Default Value.       (line  21)
85198* default.el:                            Startup Summary.     (line  86)
85199* defconst:                              Defining Variables.  (line  85)
85200* defcustom:                             Variable Definitions.
85201                                                              (line  14)
85202* deferred evaluation:                   Deferred Eval.       (line   6)
85203* defface:                               Defining Faces.      (line  21)
85204* defgroup:                              Group Definitions.   (line  22)
85205* defimage:                              Defining Images.     (line  29)
85206* define customization group:            Group Definitions.   (line   6)
85207* define customization options:          Variable Definitions.
85208                                                              (line   6)
85209* define hash comparisons:               Defining Hash.       (line   6)
85210* define image:                          Defining Images.     (line   6)
85211* define new customization types:        Defining New Types.  (line   6)
85212* define-abbrev:                         Defining Abbrevs.    (line  15)
85213* define-abbrev-table:                   Abbrev Tables.       (line  27)
85214* define-advice:                         Advising Named Functions.
85215                                                              (line  56)
85216* define-alternatives:                   Generic Commands.    (line  10)
85217* define-button-type:                    Button Types.        (line  11)
85218* define-category:                       Categories.          (line  33)
85219* define-derived-mode:                   Derived Modes.       (line  13)
85220* define-error:                          Error Symbols.       (line   6)
85221* define-error <1>:                      Error Symbols.       (line  20)
85222* define-fringe-bitmap:                  Customizing Bitmaps. (line   6)
85223* define-generic-mode:                   Generic Modes.       (line  11)
85224* define-globalized-minor-mode:          Defining Minor Modes.
85225                                                              (line 153)
85226* define-hash-table-test:                Defining Hash.       (line  26)
85227* define-inline:                         Inline Functions.    (line  53)
85228* define-key:                            Changing Key Bindings.
85229                                                              (line  45)
85230* define-key-after:                      Modifying Menus.     (line  11)
85231* define-minor-mode:                     Defining Minor Modes.
85232                                                              (line   9)
85233* define-obsolete-face-alias:            Face Functions.      (line  40)
85234* define-obsolete-function-alias:        Obsolete Functions.  (line  39)
85235* define-obsolete-variable-alias:        Variable Aliases.    (line  52)
85236* define-package:                        Multi-file Packages. (line  27)
85237* define-prefix-command:                 Prefix Keys.         (line  90)
85238* defined-colors:                        Color Names.         (line  41)
85239* defining a function:                   Defining Functions.  (line   6)
85240* defining abbrevs:                      Defining Abbrevs.    (line   6)
85241* defining commands:                     Defining Commands.   (line   6)
85242* defining customization variables in C: Writing Emacs Primitives.
85243                                                              (line 259)
85244* defining faces:                        Defining Faces.      (line   6)
85245* defining Lisp variables in C:          Writing Emacs Primitives.
85246                                                              (line 202)
85247* defining macros:                       Defining Macros.     (line   6)
85248* defining menus:                        Defining Menus.      (line   6)
85249* defining tokens, SMIE:                 SMIE Lexer.          (line   6)
85250* defining-kbd-macro:                    Keyboard Macros.     (line  44)
85251* definition-prefixes:                   Autoload by Prefix.  (line   6)
85252* definitions of symbols:                Definitions.         (line   6)
85253* defmacro:                              Defining Macros.     (line  16)
85254* defsubr, Lisp symbol for a primitive:  Writing Emacs Primitives.
85255                                                              (line 185)
85256* defsubst:                              Inline Functions.    (line  15)
85257* deftheme:                              Custom Themes.       (line  17)
85258* defun:                                 Defining Functions.  (line  10)
85259* DEFUN, C macro to define Lisp primitives: Writing Emacs Primitives.
85260                                                              (line  37)
85261* defun-prompt-regexp:                   List Motion.         (line  74)
85262* defvar:                                Defining Variables.  (line  27)
85263* defvar-local:                          Creating Buffer-Local.
85264                                                              (line  94)
85265* defvaralias:                           Variable Aliases.    (line  14)
85266* DEFVAR_INT, DEFVAR_LISP, DEFVAR_BOOL, DEFSYM: Writing Emacs Primitives.
85267                                                              (line 202)
85268* delay-mode-hooks:                      Mode Hooks.          (line  42)
85269* delay-warning:                         Delayed Warnings.    (line  10)
85270* delayed warnings:                      Delayed Warnings.    (line   6)
85271* delayed-warnings-hook:                 Delayed Warnings.    (line  30)
85272* delayed-warnings-hook <1>:             Standard Hooks.      (line  98)
85273* delayed-warnings-list:                 Delayed Warnings.    (line  15)
85274* delete:                                Sets And Lists.      (line 125)
85275* delete-and-extract-region:             Deletion.            (line  33)
85276* delete-auto-save-file-if-necessary:    Auto-Saving.         (line 152)
85277* delete-auto-save-files:                Auto-Saving.         (line 161)
85278* delete-backward-char:                  Deletion.            (line  55)
85279* delete-before, a frame parameter:      Frame Interaction Parameters.
85280                                                              (line  13)
85281* delete-blank-lines:                    User-Level Deletion. (line 106)
85282* delete-by-moving-to-trash:             Changing Files.      (line 170)
85283* delete-by-moving-to-trash <1>:         Create/Delete Dirs.  (line  45)
85284* delete-char:                           Deletion.            (line  42)
85285* delete-directory:                      Create/Delete Dirs.  (line  45)
85286* delete-dups:                           Sets And Lists.      (line 179)
85287* delete-exited-processes:               Deleting Processes.  (line  21)
85288* delete-field:                          Fields.              (line  65)
85289* delete-file:                           Changing Files.      (line 170)
85290* delete-frame:                          Deleting Frames.     (line  11)
85291* delete-frame event:                    Misc Events.         (line   8)
85292* delete-frame-functions:                Deleting Frames.     (line  12)
85293* delete-horizontal-space:               User-Level Deletion. (line   9)
85294* delete-indentation:                    User-Level Deletion. (line  37)
85295* delete-minibuffer-contents:            Minibuffer Contents. (line  32)
85296* delete-old-versions:                   Numbered Backups.    (line  44)
85297* delete-other-frames:                   Deleting Frames.     (line  44)
85298* delete-other-windows:                  Deleting Windows.    (line  41)
85299* delete-other-windows, a window parameter: Window Parameters.
85300                                                              (line  84)
85301* delete-overlay:                        Managing Overlays.   (line  50)
85302* delete-process:                        Deleting Processes.  (line  27)
85303* delete-region:                         Deletion.            (line  27)
85304* delete-selection, symbol property:     The Mark.            (line 211)
85305* delete-selection-helper:               The Mark.            (line 211)
85306* delete-selection-pre-hook:             The Mark.            (line 211)
85307* delete-terminal:                       Multiple Terminals.  (line  47)
85308* delete-terminal-functions:             Multiple Terminals.  (line  62)
85309* delete-to-left-margin:                 Margins.             (line  65)
85310* delete-trailing-whitespace:            User-Level Deletion. (line 117)
85311* delete-window:                         Deleting Windows.    (line  15)
85312* delete-window, a window parameter:     Window Parameters.   (line  80)
85313* delete-windows-on:                     Deleting Windows.    (line  62)
85314* deleting files:                        Changing Files.      (line   6)
85315* deleting frames:                       Deleting Frames.     (line   6)
85316* deleting list elements:                Sets And Lists.      (line  31)
85317* deleting previous char:                Deletion.            (line  56)
85318* deleting processes:                    Deleting Processes.  (line   6)
85319* deleting text vs killing:              Deletion.            (line   6)
85320* deleting whitespace:                   User-Level Deletion. (line  10)
85321* deleting windows:                      Deleting Windows.    (line   6)
85322* delq:                                  Sets And Lists.      (line  30)
85323* dependencies:                          Packaging Basics.    (line   6)
85324* derived mode:                          Derived Modes.       (line   6)
85325* derived-mode-p:                        Derived Modes.       (line 117)
85326* describe characters and events:        Describing Characters.
85327                                                              (line   6)
85328* describe-bindings:                     Scanning Keymaps.    (line 123)
85329* describe-buffer-case-table:            Case Tables.         (line 111)
85330* describe-categories:                   Categories.          (line 140)
85331* describe-current-display-table:        Display Tables.      (line  94)
85332* describe-display-table:                Display Tables.      (line  90)
85333* describe-mode:                         Mode Help.           (line  11)
85334* describe-prefix-bindings:              Help Functions.      (line  97)
85335* describe-syntax:                       Syntax Table Functions.
85336                                                              (line  99)
85337* description for interactive codes:     Interactive Codes.   (line   6)
85338* description format:                    Format of Descriptions.
85339                                                              (line   6)
85340* deserializing:                         Byte Packing.        (line  13)
85341* desktop notifications:                 Desktop Notifications.
85342                                                              (line   6)
85343* desktop save mode:                     Desktop Save Mode.   (line   6)
85344* desktop-buffer-mode-handlers:          Desktop Save Mode.   (line  31)
85345* desktop-save-buffer:                   Desktop Save Mode.   (line  16)
85346* destroy-fringe-bitmap:                 Customizing Bitmaps. (line  33)
85347* destructive list operations:           Modifying Lists.     (line   6)
85348* destructuring with pcase patterns:     Destructuring with pcase Patterns.
85349                                                              (line   6)
85350* detect-coding-region:                  Lisp and Coding Systems.
85351                                                              (line  98)
85352* detect-coding-string:                  Lisp and Coding Systems.
85353                                                              (line 118)
85354* deterministic build:                   Building Emacs.      (line  74)
85355* diagrams, boxed, for lists:            Box Diagrams.        (line   6)
85356* dialog boxes:                          Dialog Boxes.        (line   6)
85357* digit-argument:                        Prefix Command Arguments.
85358                                                              (line 107)
85359* ding:                                  Beeping.             (line  12)
85360* dir-locals-class-alist:                Directory Local Variables.
85361                                                              (line  87)
85362* dir-locals-directory-cache:            Directory Local Variables.
85363                                                              (line  91)
85364* dir-locals-file:                       Directory Local Variables.
85365                                                              (line  16)
85366* dir-locals-set-class-variables:        Directory Local Variables.
85367                                                              (line  52)
85368* dir-locals-set-directory-class:        Directory Local Variables.
85369                                                              (line  72)
85370* direction, a buffer display action alist entry: Buffer Display Action Alists.
85371                                                              (line 200)
85372* directional overrides:                 Bidirectional Display.
85373                                                              (line 215)
85374* directory file name:                   Directory Names.     (line   6)
85375* directory local variables:             Directory Local Variables.
85376                                                              (line   6)
85377* directory name:                        Directory Names.     (line   6)
85378* directory part (of file name):         File Name Components.
85379                                                              (line   6)
85380* directory-abbrev-alist:                Directory Names.     (line  83)
85381* directory-file-name:                   Directory Names.     (line  41)
85382* directory-files:                       Contents of Directories.
85383                                                              (line  14)
85384* directory-files-and-attributes:        Contents of Directories.
85385                                                              (line  86)
85386* directory-files-recursively:           Contents of Directories.
85387                                                              (line  44)
85388* directory-name-p:                      Directory Names.     (line  35)
85389* directory-oriented functions:          Contents of Directories.
85390                                                              (line   6)
85391* dired-kept-versions:                   Numbered Backups.    (line  50)
85392* disable-command:                       Disabling Commands.  (line  36)
85393* disable-point-adjustment:              Adjusting Point.     (line  16)
85394* disable-theme:                         Custom Themes.       (line  98)
85395* disabled:                              Disabling Commands.  (line  11)
85396* disabled command:                      Disabling Commands.  (line   6)
85397* disabled-command-function:             Disabling Commands.  (line  41)
85398* disabling multibyte:                   Disabling Multibyte. (line   6)
85399* disabling undo:                        Maintaining Undo.    (line  27)
85400* disassemble:                           Disassembly.         (line  20)
85401* disassembled byte-code:                Disassembly.         (line   6)
85402* discard-input:                         Event Input Misc.    (line 100)
85403* discarding input:                      Event Input Misc.    (line 101)
85404* dispatch of methods for generic function: Generic Functions.
85405                                                              (line 186)
85406* display (overlay property):            Overlay Properties.  (line 117)
85407* display (text property):               Display Property.    (line   6)
85408* display action:                        Choosing Window.     (line  12)
85409* display area:                          Frame Layout.        (line 202)
85410* display feature testing:               Display Feature Testing.
85411                                                              (line   6)
85412* display margins:                       Display Margins.     (line   6)
85413* display message in echo area:          Displaying Messages. (line   6)
85414* display name on X:                     Multiple Terminals.  (line  87)
85415* display origin:                        Frame Layout.        (line 229)
85416* display properties, and bidi reordering of text: Bidirectional Display.
85417                                                              (line  65)
85418* display property, and point display:   Adjusting Point.     (line   6)
85419* display property, unsafe evaluation:   Display Property.    (line  18)
85420* display specification:                 Display Property.    (line   6)
85421* display table:                         Display Tables.      (line   6)
85422* display, a frame parameter:            Basic Parameters.    (line   9)
85423* display, abstract:                     Abstract Display.    (line   6)
85424* display, arbitrary objects:            Abstract Display.    (line   6)
85425* display-backing-store:                 Display Feature Testing.
85426                                                              (line 116)
85427* display-buffer:                        Choosing Window.     (line  30)
85428* display-buffer-alist:                  Choosing Window.     (line 105)
85429* display-buffer-at-bottom:              Buffer Display Action Functions.
85430                                                              (line 185)
85431* display-buffer-base-action:            Choosing Window.     (line 115)
85432* display-buffer-below-selected:         Buffer Display Action Functions.
85433                                                              (line 164)
85434* display-buffer-fallback-action:        Choosing Window.     (line 120)
85435* display-buffer-in-atom-window:         Atomic Windows.      (line  62)
85436* display-buffer-in-child-frame:         Buffer Display Action Functions.
85437                                                              (line 201)
85438* display-buffer-in-direction:           Buffer Display Action Functions.
85439                                                              (line 107)
85440* display-buffer-in-previous-window:     Buffer Display Action Functions.
85441                                                              (line  70)
85442* display-buffer-in-side-window:         Displaying Buffers in Side Windows.
85443                                                              (line  10)
85444* display-buffer-no-window:              Buffer Display Action Functions.
85445                                                              (line 236)
85446* display-buffer-overriding-action:      Choosing Window.     (line  99)
85447* display-buffer-pop-up-frame:           Buffer Display Action Functions.
85448                                                              (line 193)
85449* display-buffer-pop-up-window:          Buffer Display Action Functions.
85450                                                              (line  50)
85451* display-buffer-reuse-mode-window:      Buffer Display Action Functions.
85452                                                              (line  36)
85453* display-buffer-reuse-window:           Buffer Display Action Functions.
85454                                                              (line  20)
85455* display-buffer-same-window:            Buffer Display Action Functions.
85456                                                              (line  14)
85457* display-buffer-use-some-frame:         Buffer Display Action Functions.
85458                                                              (line 220)
85459* display-buffer-use-some-window:        Buffer Display Action Functions.
85460                                                              (line 101)
85461* display-color-cells:                   Display Feature Testing.
85462                                                              (line 144)
85463* display-color-p:                       Display Feature Testing.
85464                                                              (line  35)
85465* display-completion-list:               Completion Commands. (line  67)
85466* display-delayed-warnings:              Delayed Warnings.    (line  39)
85467* display-graphic-p:                     Display Feature Testing.
85468                                                              (line  25)
85469* display-grayscale-p:                   Display Feature Testing.
85470                                                              (line  40)
85471* display-images-p:                      Display Feature Testing.
85472                                                              (line  69)
85473* display-message-or-buffer:             Displaying Messages. (line 115)
85474* display-mm-dimensions-alist:           Display Feature Testing.
85475                                                              (line 111)
85476* display-mm-height:                     Display Feature Testing.
85477                                                              (line  95)
85478* display-mm-width:                      Display Feature Testing.
85479                                                              (line 103)
85480* display-monitor-attributes-list:       Multiple Terminals.  (line 152)
85481* display-mouse-p:                       Display Feature Testing.
85482                                                              (line  31)
85483* display-pixel-height:                  Display Feature Testing.
85484                                                              (line  79)
85485* display-pixel-width:                   Display Feature Testing.
85486                                                              (line  87)
85487* display-planes:                        Display Feature Testing.
85488                                                              (line 131)
85489* display-popup-menus-p:                 Display Feature Testing.
85490                                                              (line  19)
85491* display-save-under:                    Display Feature Testing.
85492                                                              (line 126)
85493* display-screens:                       Display Feature Testing.
85494                                                              (line  75)
85495* display-selections-p:                  Display Feature Testing.
85496                                                              (line  64)
85497* display-start position:                Window Start and End.
85498                                                              (line   6)
85499* display-supports-face-attributes-p:    Display Feature Testing.
85500                                                              (line  44)
85501* display-table-slot:                    Display Tables.      (line  77)
85502* display-type, a frame parameter:       Basic Parameters.    (line  15)
85503* display-visual-class:                  Display Feature Testing.
85504                                                              (line 136)
85505* display-warning:                       Warning Basics.      (line  39)
85506* displaying a buffer:                   Displaying Buffers.  (line   6)
85507* displaying faces:                      Displaying Faces.    (line   6)
85508* displays, multiple:                    Multiple Terminals.  (line   6)
85509* distance between strings:              Text Comparison.     (line 223)
85510* distinguish interactive calls:         Distinguish Interactive.
85511                                                              (line   6)
85512* dnd-protocol-alist:                    Drag and Drop.       (line  20)
85513* do-auto-save:                          Auto-Saving.         (line 139)
85514* DOC (documentation) file:              Documentation Basics.
85515                                                              (line  23)
85516* doc, customization keyword:            Type Keywords.       (line  88)
85517* doc-directory:                         Accessing Documentation.
85518                                                              (line 156)
85519* Document Object Model:                 Document Object Model.
85520                                                              (line   6)
85521* documentation:                         Accessing Documentation.
85522                                                              (line  35)
85523* documentation conventions:             Documentation Basics.
85524                                                              (line   6)
85525* documentation for major mode:          Mode Help.           (line   6)
85526* documentation notation:                Evaluation Notation. (line   6)
85527* documentation string of function:      Function Documentation.
85528                                                              (line   6)
85529* documentation strings:                 Documentation.       (line   6)
85530* documentation strings, conventions and tips: Documentation Tips.
85531                                                              (line   6)
85532* documentation, keys in:                Keys in Documentation.
85533                                                              (line   6)
85534* documentation-property:                Accessing Documentation.
85535                                                              (line   6)
85536* dolist:                                Iteration.           (line  51)
85537* dolist-with-progress-reporter:         Progress.            (line 131)
85538* DOM:                                   Document Object Model.
85539                                                              (line   6)
85540* dom-node:                              Document Object Model.
85541                                                              (line  18)
85542* dotimes:                               Iteration.           (line  63)
85543* dotimes-with-progress-reporter:        Progress.            (line 105)
85544* dotted list:                           Cons Cells.          (line  34)
85545* dotted lists (Edebug):                 Specification List.  (line 150)
85546* dotted pair notation:                  Dotted Pair Notation.
85547                                                              (line   6)
85548* double-click events:                   Repeat Events.       (line   6)
85549* double-click-fuzz:                     Repeat Events.       (line  70)
85550* double-click-time:                     Repeat Events.       (line  80)
85551* double-quote in strings:               Syntax for Strings.  (line   6)
85552* down-list:                             List Motion.         (line  38)
85553* downcase:                              Case Conversion.     (line  19)
85554* downcase-region:                       Case Changes.        (line  35)
85555* downcase-word:                         Case Changes.        (line  63)
85556* downcasing in lookup-key:              Key Sequence Input.  (line  73)
85557* drag and drop:                         Drag and Drop.       (line   6)
85558* drag event:                            Drag Events.         (line   6)
85559* drag-internal-border, a frame parameter: Mouse Dragging Parameters.
85560                                                              (line  15)
85561* drag-n-drop event:                     Misc Events.         (line  41)
85562* drag-with-header-line, a frame parameter: Mouse Dragging Parameters.
85563                                                              (line  19)
85564* drag-with-mode-line, a frame parameter: Mouse Dragging Parameters.
85565                                                              (line  23)
85566* dribble file:                          Recording Input.     (line  25)
85567* dump file:                             Building Emacs.      (line  34)
85568* dump-emacs:                            Building Emacs.      (line 164)
85569* dump-emacs-portable:                   Building Emacs.      (line 148)
85570* dumping Emacs:                         Building Emacs.      (line  23)
85571* dynamic binding:                       Variable Scoping.    (line  15)
85572* dynamic extent:                        Variable Scoping.    (line  15)
85573* dynamic libraries:                     Dynamic Libraries.   (line   6)
85574* dynamic loading of documentation:      Docs and Compilation.
85575                                                              (line   6)
85576* dynamic loading of functions:          Dynamic Loading.     (line   6)
85577* dynamic modules:                       Dynamic Modules.     (line   6)
85578* dynamic modules, writing:              Writing Dynamic Modules.
85579                                                              (line   6)
85580* dynamic scope:                         Variable Scoping.    (line  15)
85581* dynamic-library-alist:                 Dynamic Libraries.   (line  10)
85582* eager macro expansion:                 How Programs Do Loading.
85583                                                              (line  79)
85584* early init file:                       Init File.           (line  21)
85585* early-init.el:                         Init File.           (line   6)
85586* easy-menu-define:                      Easy Menu.           (line   9)
85587* easy-mmode-define-minor-mode:          Defining Minor Modes.
85588                                                              (line 108)
85589* echo area:                             The Echo Area.       (line   6)
85590* echo area customization:               Echo Area Customization.
85591                                                              (line   6)
85592* echo-area-clear-hook:                  Echo Area Customization.
85593                                                              (line  17)
85594* echo-keystrokes:                       Echo Area Customization.
85595                                                              (line  21)
85596* edebug:                                Source Breakpoints.  (line   6)
85597* Edebug debugging facility:             Edebug.              (line   6)
85598* Edebug execution modes:                Edebug Execution Modes.
85599                                                              (line   6)
85600* Edebug specification list:             Specification List.  (line   6)
85601* edebug, failure to instrument:         Instrumenting.       (line  52)
85602* edebug-after-instrumentation-function: Edebug Options.      (line 171)
85603* edebug-all-defs:                       Edebug Options.      (line  15)
85604* edebug-all-forms:                      Edebug Options.      (line  24)
85605* edebug-backtrace-hide-instrumentation: Edebug Misc.         (line  37)
85606* edebug-backtrace-show-instrumentation: Edebug Misc.         (line  37)
85607* edebug-behavior-alist:                 Edebug Options.      (line 149)
85608* edebug-continue-kbd-macro:             Edebug Options.      (line  87)
85609* edebug-defun:                          Instrumenting.       (line  26)
85610* edebug-display-freq-count:             Coverage Testing.    (line  28)
85611* edebug-eval-macro-args:                Instrumenting Macro Calls.
85612                                                              (line  76)
85613* edebug-eval-macro-args <1>:            Edebug Options.      (line  33)
85614* edebug-eval-top-level-form:            Instrumenting.       (line  26)
85615* edebug-global-break-condition:         Edebug Options.      (line 134)
85616* edebug-initial-mode:                   Edebug Options.      (line  66)
85617* edebug-max-depth:                      Checking Whether to Stop.
85618                                                              (line  10)
85619* edebug-new-definition-function:        Edebug Options.      (line 163)
85620* edebug-on-error:                       Edebug Options.      (line 122)
85621* edebug-on-quit:                        Edebug Options.      (line 126)
85622* edebug-print-circle:                   Printing in Edebug.  (line  37)
85623* edebug-print-circle <1>:               Edebug Options.      (line 100)
85624* edebug-print-length:                   Printing in Edebug.  (line  15)
85625* edebug-print-length <1>:               Edebug Options.      (line  92)
85626* edebug-print-level:                    Printing in Edebug.  (line  19)
85627* edebug-print-level <1>:                Edebug Options.      (line  96)
85628* edebug-print-trace-after:              Trace Buffer.        (line  24)
85629* edebug-print-trace-before:             Trace Buffer.        (line  24)
85630* edebug-remove-instrumentation:         Instrumenting.       (line  67)
85631* edebug-save-displayed-buffer-points:   Edebug Options.      (line  52)
85632* edebug-save-windows:                   Edebug Options.      (line  40)
85633* edebug-set-global-break-condition:     Global Break Condition.
85634                                                              (line  13)
85635* edebug-set-initial-mode:               Edebug Execution Modes.
85636                                                              (line  66)
85637* edebug-setup-hook:                     Edebug Options.      (line   8)
85638* edebug-sit-for-seconds:                Edebug Execution Modes.
85639                                                              (line  94)
85640* edebug-sit-for-seconds <1>:            Edebug Options.      (line 139)
85641* edebug-sit-on-break:                   Edebug Options.      (line 144)
85642* edebug-temp-display-freq-count:        Coverage Testing.    (line  23)
85643* edebug-test-coverage:                  Edebug Options.      (line  83)
85644* edebug-trace:                          Edebug Options.      (line  76)
85645* edebug-trace <1>:                      Trace Buffer.        (line  35)
85646* edebug-tracing:                        Trace Buffer.        (line  28)
85647* edebug-unwrap-results:                 Edebug Options.      (line 104)
85648* edge detection, images:                Image Descriptors.   (line 129)
85649* edit distance between strings:         Text Comparison.     (line 223)
85650* edit-and-eval-command:                 Object from Minibuffer.
85651                                                              (line  49)
85652* editing types:                         Editing Types.       (line   6)
85653* editor command loop:                   Command Loop.        (line   6)
85654* eight-bit, a charset:                  Character Sets.      (line  16)
85655* electric-future-map:                   A Sample Variable Description.
85656                                                              (line  17)
85657* element (of list):                     Lists.               (line   6)
85658* elements of sequences:                 Sequence Functions.  (line  43)
85659* elliptical-arc:                        SVG Images.          (line 284)
85660* elp.el:                                Profiling.           (line  39)
85661* elt:                                   Sequence Functions.  (line  42)
85662* Emacs event standard notation:         Describing Characters.
85663                                                              (line  14)
85664* Emacs process run time:                Processor Run Time.  (line   6)
85665* emacs, a charset:                      Character Sets.      (line  16)
85666* emacs-build-number:                    Version Info.        (line  46)
85667* emacs-build-time:                      Version Info.        (line  22)
85668* emacs-init-time:                       Processor Run Time.  (line  32)
85669* emacs-internal coding system:          Coding System Basics.
85670                                                              (line  66)
85671* emacs-lisp-docstring-fill-column:      Documentation Tips.  (line  22)
85672* emacs-major-version:                   Version Info.        (line  38)
85673* emacs-minor-version:                   Version Info.        (line  42)
85674* emacs-pid:                             System Environment.  (line 199)
85675* emacs-repository-branch:               Version Info.        (line  56)
85676* emacs-repository-version:              Version Info.        (line  51)
85677* emacs-save-session-functions:          Session Management.  (line  19)
85678* emacs-session-restore:                 Session Management.  (line  28)
85679* emacs-startup-hook:                    Init File.           (line  70)
85680* emacs-uptime:                          Processor Run Time.  (line   9)
85681* emacs-version:                         Version Info.        (line  30)
85682* emacs-version <1>:                     Version Info.        (line   9)
85683* emacsclient, getting a backtrace:      Error Debugging.     (line  74)
85684* EMACSLOADPATH environment variable:    Library Search.      (line  51)
85685* emacs_funcall_exit:                    Module Nonlocal.     (line  44)
85686* emacs_funcall_exit <1>:                Module Nonlocal.     (line  56)
85687* emacs_funcall_exit, enumeration:       Module Nonlocal.     (line  49)
85688* emacs_funcall_exit_return:             Module Nonlocal.     (line  49)
85689* emacs_funcall_exit_signal:             Module Nonlocal.     (line  51)
85690* emacs_funcall_exit_throw:              Module Nonlocal.     (line  53)
85691* EMACS_LIMB_MAX:                        Module Values.       (line  82)
85692* emacs_module_init:                     Dynamic Modules.     (line  19)
85693* emacs_module_init <1>:                 Module Initialization.
85694                                                              (line  19)
85695* emacs_process_input_result:            Module Misc.         (line  82)
85696* emacs_value data type:                 Module Values.       (line   6)
85697* emacs_variadic_function:               Module Functions.    (line  48)
85698* embedded widgets:                      Xwidgets.            (line   6)
85699* empty lines, indicating:               Fringe Indicators.   (line  10)
85700* empty list:                            Box Diagrams.        (line  41)
85701* empty overlay:                         Managing Overlays.   (line  21)
85702* empty region:                          The Region.          (line  37)
85703* emulation-mode-map-alists:             Controlling Active Maps.
85704                                                              (line 138)
85705* enable-command:                        Disabling Commands.  (line  31)
85706* enable-connection-local-variables:     Connection Local Variables.
85707                                                              (line 122)
85708* enable-dir-local-variables:            Directory Local Variables.
85709                                                              (line  97)
85710* enable-local-eval:                     File Local Variables.
85711                                                              (line 162)
85712* enable-local-variables:                File Local Variables.
85713                                                              (line  24)
85714* enable-multibyte-characters:           Text Representations.
85715                                                              (line  53)
85716* enable-multibyte-characters <1>:       Disabling Multibyte. (line  30)
85717* enable-recursive-minibuffers:          Recursive Mini.      (line  14)
85718* enable-theme:                          Custom Themes.       (line  94)
85719* encapsulation, ewoc:                   Abstract Display.    (line  41)
85720* encode-char:                           Character Sets.      (line  82)
85721* encode-coding-region:                  Explicit Encoding.   (line  37)
85722* encode-coding-string:                  Explicit Encoding.   (line  61)
85723* encode-time:                           Time Conversion.     (line 163)
85724* encoding file formats:                 Format Conversion.   (line   6)
85725* encoding in coding systems:            Explicit Encoding.   (line   6)
85726* encrypted network connections:         Network.             (line  55)
85727* end of line in regexp:                 Regexp Special.      (line 185)
85728* end-of-buffer:                         Buffer End Motion.   (line  31)
85729* end-of-defun:                          List Motion.         (line  69)
85730* end-of-defun-function:                 List Motion.         (line  96)
85731* end-of-file:                           Input Functions.     (line  13)
85732* end-of-line:                           Text Lines.          (line  35)
85733* end-of-line conversion:                Coding System Basics.
85734                                                              (line  37)
85735* endianness:                            Bindat Spec.         (line  13)
85736* environment:                           Intro Eval.          (line  40)
85737* environment variable access:           System Environment.  (line  80)
85738* environment variables, subprocesses:   Subprocess Creation. (line  67)
85739* eobp:                                  Near Point.          (line  67)
85740* EOL conversion:                        Coding System Basics.
85741                                                              (line  37)
85742* eol conversion of coding system:       Lisp and Coding Systems.
85743                                                              (line  47)
85744* eol in rx:                             Rx Constructs.       (line 316)
85745* eol type of coding system:             Lisp and Coding Systems.
85746                                                              (line  25)
85747* eolp:                                  Near Point.          (line  77)
85748* eos in rx:                             Rx Constructs.       (line 324)
85749* eot in rx:                             Rx Constructs.       (line 324)
85750* eow in rx:                             Rx Constructs.       (line 336)
85751* epoch:                                 Time of Day.         (line  18)
85752* eq:                                    Equality Predicates. (line  11)
85753* eq <1>:                                Module Misc.         (line  12)
85754* eql:                                   Comparison of Numbers.
85755                                                              (line  46)
85756* equal:                                 Equality Predicates. (line  85)
85757* equal-including-properties:            Equality Predicates. (line 145)
85758* equality:                              Equality Predicates. (line   6)
85759* erase-buffer:                          Deletion.            (line  13)
85760* error:                                 Signaling Errors.    (line  25)
85761* error cleanup:                         Cleanups.            (line  13)
85762* error debugging:                       Error Debugging.     (line   6)
85763* error description:                     Handling Errors.     (line 127)
85764* error display:                         The Echo Area.       (line   6)
85765* error handler:                         Handling Errors.     (line   6)
85766* error in debug:                        Invoking the Debugger.
85767                                                              (line  61)
85768* error message notation:                Error Messages.      (line   6)
85769* error name:                            Error Symbols.       (line   6)
85770* error symbol:                          Error Symbols.       (line   6)
85771* error-conditions:                      Error Symbols.       (line   6)
85772* error-message-string:                  Handling Errors.     (line 149)
85773* errors:                                Errors.              (line   6)
85774* <ESC>:                                 Functions for Key Lookup.
85775                                                              (line  86)
85776* esc-map:                               Prefix Keys.         (line  15)
85777* ESC-prefix:                            Prefix Keys.         (line  15)
85778* escape (ASCII character):              Basic Char Syntax.   (line  27)
85779* escape characters:                     Output Variables.    (line  17)
85780* escape characters in printing:         Output Functions.    (line   9)
85781* escape sequence:                       Basic Char Syntax.   (line  45)
85782* eval:                                  Eval.                (line  26)
85783* eval during compilation:               Eval During Compile. (line   6)
85784* eval in rx:                            Rx Constructs.       (line 392)
85785* eval, and debugging:                   Internals of Debugger.
85786                                                              (line  86)
85787* eval-and-compile:                      Eval During Compile. (line   9)
85788* eval-buffer:                           Eval.                (line  82)
85789* eval-buffer (Edebug):                  Instrumenting.       (line  19)
85790* eval-current-buffer:                   Eval.                (line  98)
85791* eval-current-buffer (Edebug):          Instrumenting.       (line  19)
85792* eval-defun (Edebug):                   Instrumenting.       (line  10)
85793* eval-defun, and defcustom forms:       Variable Definitions.
85794                                                              (line  43)
85795* eval-defun, and defface forms:         Defining Faces.      (line  40)
85796* eval-defun, and defvar forms:          Defining Variables.  (line  57)
85797* eval-defun, and explicit entry to debugger: Explicit Debug. (line   6)
85798* eval-expression (Edebug):              Instrumenting.       (line  62)
85799* eval-expression, and lexical-binding:  Using Lexical Binding.
85800                                                              (line  24)
85801* eval-expression-debug-on-error:        Error Debugging.     (line  54)
85802* eval-expression-print-length:          Output Variables.    (line  99)
85803* eval-expression-print-level:           Output Variables.    (line 100)
85804* eval-minibuffer:                       Object from Minibuffer.
85805                                                              (line  37)
85806* eval-region:                           Eval.                (line  60)
85807* eval-region (Edebug):                  Instrumenting.       (line  19)
85808* eval-when-compile:                     Eval During Compile. (line  35)
85809* evaluated expression argument:         Interactive Codes.   (line 206)
85810* evaluation:                            Evaluation.          (line   6)
85811* evaluation error:                      Local Variables.     (line 130)
85812* evaluation list group:                 Eval List.           (line  49)
85813* evaluation notation:                   Evaluation Notation. (line   6)
85814* evaluation of buffer contents:         Eval.                (line  82)
85815* evaluation of special forms:           Special Forms.       (line   6)
85816* evaporate (overlay property):          Overlay Properties.  (line 216)
85817* even-window-sizes:                     Choosing Window Options.
85818                                                              (line  63)
85819* event printing:                        Describing Characters.
85820                                                              (line  29)
85821* event translation:                     Event Mod.           (line   6)
85822* event type:                            Classifying Events.  (line   6)
85823* event, reading only one:               Reading One Event.   (line   6)
85824* event-basic-type:                      Classifying Events.  (line  70)
85825* event-click-count:                     Repeat Events.       (line  63)
85826* event-convert-list:                    Classifying Events.  (line  96)
85827* event-end:                             Accessing Mouse.     (line  21)
85828* event-modifiers:                       Classifying Events.  (line  26)
85829* event-start:                           Accessing Mouse.     (line  14)
85830* eventp:                                Input Events.        (line  12)
85831* events:                                Input Events.        (line   6)
85832* ewoc:                                  Abstract Display.    (line   6)
85833* ewoc-buffer:                           Abstract Display Functions.
85834                                                              (line  29)
85835* ewoc-collect:                          Abstract Display Functions.
85836                                                              (line 107)
85837* ewoc-create:                           Abstract Display Functions.
85838                                                              (line  10)
85839* ewoc-data:                             Abstract Display Functions.
85840                                                              (line  60)
85841* ewoc-delete:                           Abstract Display Functions.
85842                                                              (line  99)
85843* ewoc-enter-after:                      Abstract Display Functions.
85844                                                              (line  46)
85845* ewoc-enter-before:                     Abstract Display Functions.
85846                                                              (line  45)
85847* ewoc-enter-first:                      Abstract Display Functions.
85848                                                              (line  40)
85849* ewoc-enter-last:                       Abstract Display Functions.
85850                                                              (line  41)
85851* ewoc-filter:                           Abstract Display Functions.
85852                                                              (line 102)
85853* ewoc-get-hf:                           Abstract Display Functions.
85854                                                              (line  32)
85855* ewoc-goto-next:                        Abstract Display Functions.
85856                                                              (line  79)
85857* ewoc-goto-node:                        Abstract Display Functions.
85858                                                              (line  86)
85859* ewoc-goto-prev:                        Abstract Display Functions.
85860                                                              (line  78)
85861* ewoc-invalidate:                       Abstract Display Functions.
85862                                                              (line  95)
85863* ewoc-locate:                           Abstract Display Functions.
85864                                                              (line  66)
85865* ewoc-location:                         Abstract Display Functions.
85866                                                              (line  75)
85867* ewoc-map:                              Abstract Display Functions.
85868                                                              (line 113)
85869* ewoc-next:                             Abstract Display Functions.
85870                                                              (line  51)
85871* ewoc-nth:                              Abstract Display Functions.
85872                                                              (line  55)
85873* ewoc-prev:                             Abstract Display Functions.
85874                                                              (line  50)
85875* ewoc-refresh:                          Abstract Display Functions.
85876                                                              (line  89)
85877* ewoc-set-data:                         Abstract Display Functions.
85878                                                              (line  63)
85879* ewoc-set-hf:                           Abstract Display Functions.
85880                                                              (line  36)
85881* examining text properties:             Examining Properties.
85882                                                              (line   6)
85883* examining the interactive form:        Using Interactive.   (line 129)
85884* examining windows:                     Buffers and Windows. (line   6)
85885* examples of using interactive:         Interactive Examples.
85886                                                              (line   6)
85887* excess close parentheses:              Excess Close.        (line   6)
85888* excess open parentheses:               Excess Open.         (line   6)
85889* excursion:                             Excursions.          (line   6)
85890* exec-directory:                        Subprocess Creation. (line  72)
85891* exec-path:                             Subprocess Creation. (line  78)
85892* exec-path <1>:                         Subprocess Creation. (line  95)
85893* exec-suffixes:                         Subprocess Creation. (line  32)
85894* executable-find:                       Locating Files.      (line  53)
85895* execute program:                       Subprocess Creation. (line  18)
85896* execute with prefix argument:          Interactive Call.    (line 104)
85897* execute-extended-command:              Interactive Call.    (line  98)
85898* execute-kbd-macro:                     Keyboard Macros.     (line  12)
85899* executing-kbd-macro:                   Keyboard Macros.     (line  37)
85900* execution order of buffer display action functions: Precedence of Action Functions.
85901                                                              (line   6)
85902* execution speed:                       Compilation Tips.    (line   6)
85903* exit:                                  Recursive Editing.   (line  32)
85904* exit recursive editing:                Recursive Editing.   (line  32)
85905* exit-minibuffer:                       Minibuffer Commands. (line   8)
85906* exit-recursive-edit:                   Recursive Editing.   (line  87)
85907* exiting Emacs:                         Getting Out.         (line   6)
85908* exp:                                   Math Functions.      (line  31)
85909* expand-abbrev:                         Abbrev Expansion.    (line  25)
85910* expand-file-name:                      File Name Expansion. (line  13)
85911* expanding abbrevs:                     Abbrev Expansion.    (line   6)
85912* expansion of file names:               File Name Expansion. (line   6)
85913* expansion of macros:                   Expansion.           (line   6)
85914* explicit selective display:            Selective Display.   (line   9)
85915* explicit-name, a frame parameter:      Basic Parameters.    (line  37)
85916* expression:                            Intro Eval.          (line  12)
85917* expt:                                  Math Functions.      (line  39)
85918* extended file attributes:              Extended Attributes. (line   6)
85919* extended menu item:                    Extended Menu Items. (line   6)
85920* extended-command-history:              Minibuffer History.  (line 108)
85921* extent:                                Variable Scoping.    (line  10)
85922* external border:                       Frame Layout.        (line  70)
85923* external menu bar:                     Frame Layout.        (line 112)
85924* external tool bar:                     Frame Layout.        (line 131)
85925* external-debugging-output:             Output Streams.      (line 128)
85926* extra slots of char-table:             Char-Tables.         (line   6)
85927* extra-keyboard-modifiers:              Event Mod.           (line  11)
85928* extract_big_integer:                   Module Values.       (line  53)
85929* extract_float:                         Module Values.       (line  87)
85930* extract_integer:                       Module Values.       (line  43)
85931* face (button property):                Button Properties.   (line  23)
85932* face (non-removability of):            Defining Faces.      (line  18)
85933* face (overlay property):               Overlay Properties.  (line  88)
85934* face (text property):                  Special Properties.  (line  22)
85935* face alias:                            Face Functions.      (line  33)
85936* face attributes:                       Face Attributes.     (line   6)
85937* face attributes, access and modification: Attribute Functions.
85938                                                              (line   6)
85939* face codes of text:                    Special Properties.  (line  22)
85940* face merging:                          Displaying Faces.    (line   6)
85941* face name:                             Faces.               (line  17)
85942* face number:                           Face Functions.      (line  11)
85943* face property of face symbols:         Face Functions.      (line  11)
85944* face remapping:                        Face Remapping.      (line   6)
85945* face spec:                             Defining Faces.      (line   6)
85946* face-all-attributes:                   Attribute Functions. (line  53)
85947* face-attribute:                        Attribute Functions. (line   9)
85948* face-attribute-relative-p:             Attribute Functions. (line  38)
85949* face-background:                       Attribute Functions. (line 160)
85950* face-bold-p:                           Attribute Functions. (line 169)
85951* face-differs-from-default-p:           Face Functions.      (line  29)
85952* face-documentation:                    Accessing Documentation.
85953                                                              (line  59)
85954* face-documentation <1>:                Face Functions.      (line  21)
85955* face-equal:                            Face Functions.      (line  25)
85956* face-extend-p:                         Attribute Functions. (line 186)
85957* face-filters-always-match:             Special Properties.  (line 410)
85958* face-font:                             Attribute Functions. (line 150)
85959* face-font-family-alternatives:         Font Selection.      (line  16)
85960* face-font-registry-alternatives:       Font Selection.      (line  54)
85961* face-font-rescale-alist:               Font Selection.      (line  81)
85962* face-font-selection-order:             Font Selection.      (line  27)
85963* face-foreground:                       Attribute Functions. (line 159)
85964* face-id:                               Face Functions.      (line  11)
85965* face-inverse-video-p:                  Attribute Functions. (line 182)
85966* face-italic-p:                         Attribute Functions. (line 174)
85967* face-list:                             Face Functions.      (line   8)
85968* face-name-history:                     Minibuffer History.  (line 117)
85969* face-remap-add-relative:               Face Remapping.      (line  66)
85970* face-remap-remove-relative:            Face Remapping.      (line  83)
85971* face-remap-reset-base:                 Face Remapping.      (line 100)
85972* face-remap-set-base:                   Face Remapping.      (line  88)
85973* face-remapping-alist:                  Face Remapping.      (line  10)
85974* face-spec-set:                         Defining Faces.      (line 147)
85975* face-stipple:                          Attribute Functions. (line 165)
85976* face-underline-p:                      Attribute Functions. (line 178)
85977* facemenu-keymap:                       Prefix Keys.         (line  50)
85978* facep:                                 Faces.               (line  26)
85979* faces:                                 Faces.               (line   6)
85980* faces for font lock:                   Faces for Font Lock. (line   6)
85981* faces, automatic choice:               Auto Faces.          (line   6)
85982* false:                                 nil and t.           (line   6)
85983* fboundp:                               Function Cells.      (line  44)
85984* fceiling:                              Rounding Operations. (line  16)
85985* FEATURE-unload-function:               Unloading.           (line  31)
85986* featurep:                              Named Features.      (line 126)
85987* features:                              Named Features.      (line 133)
85988* features <1>:                          Named Features.      (line   6)
85989* fetch-bytecode:                        Dynamic Loading.     (line  52)
85990* ffloor:                                Rounding Operations. (line  12)
85991* field (overlay property):              Overlay Properties.  (line 129)
85992* field (text property):                 Special Properties.  (line 205)
85993* field numbers in format spec:          Formatting Strings.  (line 153)
85994* field width:                           Formatting Strings.  (line 202)
85995* field-beginning:                       Fields.              (line  35)
85996* field-end:                             Fields.              (line  46)
85997* field-string:                          Fields.              (line  57)
85998* field-string-no-properties:            Fields.              (line  61)
85999* fields:                                Fields.              (line   6)
86000* fifo data structure:                   Rings.               (line  73)
86001* file accessibility:                    Testing Accessibility.
86002                                                              (line   6)
86003* file age:                              File Attributes.     (line  12)
86004* file attributes:                       File Attributes.     (line   6)
86005* file classification:                   Kinds of Files.      (line   6)
86006* file contents, and default coding system: Default Coding Systems.
86007                                                              (line  17)
86008* file format conversion:                Format Conversion.   (line   6)
86009* file hard link:                        Changing Files.      (line  40)
86010* file local variables:                  File Local Variables.
86011                                                              (line   6)
86012* file local variables <1>:              Security Considerations.
86013                                                              (line  18)
86014* file locks:                            File Locks.          (line   6)
86015* file mode specification error:         Auto Major Mode.     (line  33)
86016* file modes:                            Testing Accessibility.
86017                                                              (line  84)
86018* file modes and MS-DOS:                 Testing Accessibility.
86019                                                              (line 111)
86020* file modes, setting:                   Changing Files.      (line 189)
86021* file modification time:                File Attributes.     (line  12)
86022* file name abbreviations:               Directory Names.     (line  83)
86023* file name completion subroutines:      File Name Completion.
86024                                                              (line   6)
86025* file name handler:                     Magic File Names.    (line  16)
86026* file name of buffer:                   Buffer File Name.    (line   6)
86027* file name of directory:                Directory Names.     (line   6)
86028* file name, and default coding system:  Default Coding Systems.
86029                                                              (line  27)
86030* file names:                            File Names.          (line   6)
86031* file names in directory:               Contents of Directories.
86032                                                              (line   6)
86033* file names, trailing whitespace:       Information about Files.
86034                                                              (line  12)
86035* file notifications:                    File Notifications.  (line   6)
86036* file open error:                       Subroutines of Visiting.
86037                                                              (line  39)
86038* file permissions:                      Testing Accessibility.
86039                                                              (line  84)
86040* file permissions, setting:             Changing Files.      (line 189)
86041* file with multiple names:              Changing Files.      (line  40)
86042* file, information about:               Information about Files.
86043                                                              (line   6)
86044* file-accessible-directory-p:           Testing Accessibility.
86045                                                              (line  55)
86046* file-acl:                              Extended Attributes. (line  20)
86047* file-already-exists:                   Changing Files.      (line 152)
86048* file-attributes:                       File Attributes.     (line  29)
86049* file-chase-links:                      Truenames.           (line  35)
86050* file-coding-system-alist:              Default Coding Systems.
86051                                                              (line  27)
86052* file-directory-p:                      Kinds of Files.      (line  68)
86053* file-equal-p:                          Truenames.           (line  57)
86054* file-error:                            How Programs Do Loading.
86055                                                              (line 102)
86056* file-executable-p:                     Testing Accessibility.
86057                                                              (line  34)
86058* file-exists-p:                         Testing Accessibility.
86059                                                              (line  14)
86060* file-expand-wildcards:                 Contents of Directories.
86061                                                              (line  96)
86062* file-extended-attributes:              Extended Attributes. (line  46)
86063* file-in-directory-p:                   Truenames.           (line  80)
86064* file-local-copy:                       Magic File Names.    (line 161)
86065* file-local-name:                       Magic File Names.    (line 214)
86066* file-local-variables-alist:            File Local Variables.
86067                                                              (line  74)
86068* file-locked:                           File Locks.          (line  69)
86069* file-locked-p:                         File Locks.          (line  31)
86070* file-modes:                            Testing Accessibility.
86071                                                              (line  83)
86072* file-modes-symbolic-to-number:         Changing Files.      (line 263)
86073* file-name encoding, MS-Windows:        Encoding and I/O.    (line  79)
86074* file-name-absolute-p:                  Relative File Names. (line  17)
86075* file-name-all-completions:             File Name Completion.
86076                                                              (line   9)
86077* file-name-as-directory:                Directory Names.     (line  26)
86078* file-name-base:                        File Name Components.
86079                                                              (line  99)
86080* file-name-case-insensitive-p:          Truenames.           (line  63)
86081* file-name-coding-system:               Encoding and I/O.    (line  60)
86082* file-name-completion:                  File Name Completion.
86083                                                              (line  32)
86084* file-name-directory:                   File Name Components.
86085                                                              (line  21)
86086* file-name-extension:                   File Name Components.
86087                                                              (line  61)
86088* file-name-handler-alist:               Magic File Names.    (line  16)
86089* file-name-history:                     Minibuffer History.  (line  99)
86090* file-name-nondirectory:                File Name Components.
86091                                                              (line  35)
86092* file-name-quote:                       File Name Expansion. (line 136)
86093* file-name-quoted-p:                    File Name Expansion. (line 157)
86094* file-name-sans-extension:              File Name Components.
86095                                                              (line  78)
86096* file-name-sans-versions:               File Name Components.
86097                                                              (line  45)
86098* file-name-unquote:                     File Name Expansion. (line 152)
86099* file-newer-than-file-p:                File Attributes.     (line  11)
86100* file-newest-backup:                    Backup Names.        (line  84)
86101* file-nlinks:                           File Attributes.     (line 154)
86102* file-notify-add-watch:                 File Notifications.  (line  21)
86103* file-notify-rm-watch:                  File Notifications.  (line 122)
86104* file-notify-valid-p:                   File Notifications.  (line 126)
86105* file-ownership-preserved-p:            Testing Accessibility.
86106                                                              (line  73)
86107* file-precious-flag:                    Saving Buffers.      (line 152)
86108* file-readable-p:                       Testing Accessibility.
86109                                                              (line  30)
86110* file-regular-p:                        Kinds of Files.      (line  86)
86111* file-relative-name:                    Relative File Names. (line  38)
86112* file-remote-p:                         Magic File Names.    (line 173)
86113* file-selinux-context:                  Extended Attributes. (line  34)
86114* file-supersession:                     Modification Time.   (line  81)
86115* file-symlink-p:                        Kinds of Files.      (line  17)
86116* file-truename:                         Truenames.           (line  14)
86117* file-writable-p:                       Testing Accessibility.
86118                                                              (line  41)
86119* filepos-to-bufferpos:                  Text Representations.
86120                                                              (line 106)
86121* fill-column:                           Margins.             (line  19)
86122* fill-context-prefix:                   Adaptive Fill.       (line  16)
86123* fill-forward-paragraph-function:       Filling.             (line 166)
86124* fill-individual-paragraphs:            Filling.             (line  57)
86125* fill-individual-varying-indent:        Filling.             (line  80)
86126* fill-nobreak-predicate:                Margins.             (line  84)
86127* fill-paragraph:                        Filling.             (line  33)
86128* fill-paragraph-function:               Filling.             (line 152)
86129* fill-prefix:                           Margins.             (line   6)
86130* fill-region:                           Filling.             (line  45)
86131* fill-region-as-paragraph:              Filling.             (line  84)
86132* fill-separate-heterogeneous-words-with-space: Filling.      (line 146)
86133* fillarray:                             Array Functions.     (line  58)
86134* filling text:                          Filling.             (line   6)
86135* filling, automatic:                    Auto Filling.        (line   6)
86136* filter function:                       Filter Functions.    (line   6)
86137* filter multibyte flag, of process:     Decoding Output.     (line  30)
86138* filter-buffer-substring:               Buffer Contents.     (line  55)
86139* filter-buffer-substring-function:      Buffer Contents.     (line  78)
86140* filter-buffer-substring-functions:     Buffer Contents.     (line  90)
86141* filtering killed text:                 Kill Functions.      (line  14)
86142* filtering sequences:                   Sequence Functions.  (line 379)
86143* find file in path:                     Locating Files.      (line   6)
86144* find library:                          Library Search.      (line   6)
86145* find-auto-coding:                      Default Coding Systems.
86146                                                              (line 117)
86147* find-backup-file-name:                 Backup Names.        (line  64)
86148* find-buffer-visiting:                  Buffer File Name.    (line  73)
86149* find-charset-region:                   Scanning Charsets.   (line  18)
86150* find-charset-string:                   Scanning Charsets.   (line  29)
86151* find-coding-systems-for-charsets:      Lisp and Coding Systems.
86152                                                              (line  80)
86153* find-coding-systems-region:            Lisp and Coding Systems.
86154                                                              (line  64)
86155* find-coding-systems-string:            Lisp and Coding Systems.
86156                                                              (line  73)
86157* find-file:                             Visiting Functions.  (line  17)
86158* find-file-hook:                        Visiting Functions.  (line 125)
86159* find-file-literally:                   Visiting Functions.  (line 145)
86160* find-file-literally <1>:               Visiting Functions.  (line  36)
86161* find-file-name-handler:                Magic File Names.    (line 153)
86162* find-file-noselect:                    Visiting Functions.  (line  55)
86163* find-file-not-found-functions:         Visiting Functions.  (line 134)
86164* find-file-other-window:                Visiting Functions.  (line 103)
86165* find-file-read-only:                   Visiting Functions.  (line 110)
86166* find-file-wildcards:                   Visiting Functions.  (line 117)
86167* find-font:                             Low-Level Font.      (line 125)
86168* find-image:                            Defining Images.     (line  58)
86169* find-operation-coding-system:          Default Coding Systems.
86170                                                              (line 146)
86171* find-word-boundary-function-table:     Word Motion.         (line  54)
86172* finding files:                         Visiting Files.      (line   6)
86173* finding windows:                       Cyclic Window Ordering.
86174                                                              (line 108)
86175* first-change-hook:                     Change Hooks.        (line 100)
86176* fit-frame-to-buffer:                   Resizing Windows.    (line 147)
86177* fit-frame-to-buffer <1>:               Resizing Windows.    (line 158)
86178* fit-frame-to-buffer-margins:           Resizing Windows.    (line 175)
86179* fit-frame-to-buffer-margins, a frame parameter: Size Parameters.
86180                                                              (line 130)
86181* fit-frame-to-buffer-sizes:             Resizing Windows.    (line 187)
86182* fit-frame-to-buffer-sizes, a frame parameter: Size Parameters.
86183                                                              (line 136)
86184* fit-window-to-buffer:                  Resizing Windows.    (line 103)
86185* fit-window-to-buffer-horizontally:     Resizing Windows.    (line 139)
86186* fixed-size window:                     Window Sizes.        (line 235)
86187* fixnump:                               Predicates on Numbers.
86188                                                              (line  18)
86189* fixup-whitespace:                      User-Level Deletion. (line  72)
86190* flags in format specifications:        Formatting Strings.  (line 164)
86191* flatten-tree:                          Building Lists.      (line 158)
86192* float:                                 Numeric Conversions. (line   8)
86193* float-e:                               Math Functions.      (line  53)
86194* float-output-format:                   Output Variables.    (line 131)
86195* float-pi:                              Math Functions.      (line  56)
86196* float-time:                            Time of Day.         (line  81)
86197* floating-point functions:              Math Functions.      (line   6)
86198* floatp:                                Predicates on Numbers.
86199                                                              (line  23)
86200* floats-consed:                         Memory Usage.        (line  17)
86201* floor:                                 Numeric Conversions. (line  35)
86202* flowcontrol, in serial connections:    Serial Ports.        (line 116)
86203* flushing input:                        Event Input Misc.    (line 101)
86204* fmakunbound:                           Function Cells.      (line  49)
86205* fn in function’s documentation string: Autoload.            (line 165)
86206* focus event:                           Focus Events.        (line   6)
86207* focus-follows-mouse:                   Input Focus.         (line 193)
86208* focus-in-hook:                         Standard Hooks.      (line 101)
86209* focus-out-hook:                        Standard Hooks.      (line 102)
86210* follow links:                          Clickable Text.      (line   6)
86211* follow-link (button property):         Button Properties.   (line  53)
86212* follow-link (text or overlay property): Clickable Text.     (line  84)
86213* following-char:                        Near Point.          (line  33)
86214* font and color, frame parameters:      Font and Color Parameters.
86215                                                              (line   6)
86216* font entity:                           Low-Level Font.      (line 117)
86217* font information for layout:           Low-Level Font.      (line 298)
86218* font lock faces:                       Faces for Font Lock. (line   6)
86219* Font Lock mode:                        Font Lock Mode.      (line   6)
86220* font lookup:                           Font Lookup.         (line   6)
86221* font object:                           Low-Level Font.      (line  20)
86222* font property:                         Low-Level Font.      (line   6)
86223* font registry:                         Low-Level Font.      (line  65)
86224* font selection:                        Font Selection.      (line   6)
86225* font spec:                             Low-Level Font.      (line  32)
86226* font, a frame parameter:               Font and Color Parameters.
86227                                                              (line  90)
86228* font-at:                               Low-Level Font.      (line  24)
86229* font-backend, a frame parameter:       Font and Color Parameters.
86230                                                              (line   8)
86231* font-face-attributes:                  Low-Level Font.      (line 161)
86232* font-family-list:                      Face Attributes.     (line 216)
86233* font-get:                              Low-Level Font.      (line 152)
86234* font-info:                             Low-Level Font.      (line 186)
86235* font-lock-add-keywords:                Customizing Keywords.
86236                                                              (line  10)
86237* font-lock-builtin-face:                Faces for Font Lock. (line  51)
86238* font-lock-comment-delimiter-face:      Faces for Font Lock. (line  41)
86239* font-lock-comment-face:                Faces for Font Lock. (line  38)
86240* font-lock-constant-face:               Faces for Font Lock. (line  48)
86241* font-lock-debug-fontify:               Font Lock Basics.    (line  48)
86242* font-lock-defaults:                    Font Lock Basics.    (line  60)
86243* font-lock-doc-face:                    Faces for Font Lock. (line  61)
86244* font-lock-ensure &optional beg end:    Font Lock Basics.    (line  42)
86245* font-lock-ensure-function:             Other Font Lock Variables.
86246                                                              (line  57)
86247* font-lock-extend-after-change-region-function: Region to Refontify.
86248                                                              (line  15)
86249* font-lock-extra-managed-props:         Other Font Lock Variables.
86250                                                              (line  21)
86251* font-lock-face (text property):        Special Properties.  (line  61)
86252* font-lock-flush &optional beg end:     Font Lock Basics.    (line  35)
86253* font-lock-flush-function:              Other Font Lock Variables.
86254                                                              (line  51)
86255* font-lock-fontify-buffer:              Font Lock Basics.    (line  16)
86256* font-lock-fontify-buffer-function:     Other Font Lock Variables.
86257                                                              (line  30)
86258* font-lock-fontify-region beg end &optional loudly: Font Lock Basics.
86259                                                              (line  25)
86260* font-lock-fontify-region-function:     Other Font Lock Variables.
86261                                                              (line  39)
86262* font-lock-function-name-face:          Faces for Font Lock. (line  28)
86263* font-lock-keyword-face:                Faces for Font Lock. (line  34)
86264* font-lock-keywords:                    Search-based Fontification.
86265                                                              (line  10)
86266* font-lock-keywords-case-fold-search:   Search-based Fontification.
86267                                                              (line 204)
86268* font-lock-keywords-only:               Syntactic Font Lock. (line  20)
86269* font-lock-mark-block-function:         Other Font Lock Variables.
86270                                                              (line   9)
86271* font-lock-multiline:                   Font Lock Multiline. (line  22)
86272* font-lock-negation-char-face:          Faces for Font Lock. (line  65)
86273* font-lock-preprocessor-face:           Faces for Font Lock. (line  54)
86274* font-lock-remove-keywords:             Customizing Keywords.
86275                                                              (line  42)
86276* font-lock-string-face:                 Faces for Font Lock. (line  58)
86277* font-lock-syntactic-face-function:     Syntactic Font Lock. (line  38)
86278* font-lock-syntax-table:                Syntactic Font Lock. (line  30)
86279* font-lock-type-face:                   Faces for Font Lock. (line  45)
86280* font-lock-unfontify-buffer:            Font Lock Basics.    (line  21)
86281* font-lock-unfontify-buffer-function:   Other Font Lock Variables.
86282                                                              (line  34)
86283* font-lock-unfontify-region beg end:    Font Lock Basics.    (line  30)
86284* font-lock-unfontify-region-function:   Other Font Lock Variables.
86285                                                              (line  46)
86286* font-lock-variable-name-face:          Faces for Font Lock. (line  31)
86287* font-lock-warning-face:                Faces for Font Lock. (line  22)
86288* font-put:                              Low-Level Font.      (line 114)
86289* font-spec:                             Low-Level Font.      (line  36)
86290* font-xlfd-name:                        Low-Level Font.      (line 174)
86291* fontification-functions:               Auto Faces.          (line  10)
86292* fontified (text property):             Special Properties.  (line  80)
86293* fontp:                                 Low-Level Font.      (line  12)
86294* fontset:                               Fontsets.            (line   6)
86295* foo:                                   A Sample Function Description.
86296                                                              (line  24)
86297* for:                                   Argument Evaluation. (line  11)
86298* force coding system for operation:     Specifying Coding Systems.
86299                                                              (line   6)
86300* force entry to debugger:               Explicit Debug.      (line   6)
86301* force-mode-line-update:                Mode Line Basics.    (line  24)
86302* force-window-update:                   Forcing Redisplay.   (line  27)
86303* forcing redisplay:                     Forcing Redisplay.   (line   6)
86304* foreground-color, a frame parameter:   Font and Color Parameters.
86305                                                              (line  96)
86306* form:                                  Intro Eval.          (line  12)
86307* form, self-evaluating:                 Self-Evaluating Forms.
86308                                                              (line   6)
86309* format:                                Formatting Strings.  (line  16)
86310* format definition:                     Format Conversion Round-Trip.
86311                                                              (line  19)
86312* format of gnutls cryptography inputs:  Format of GnuTLS Cryptography Inputs.
86313                                                              (line   6)
86314* format of keymaps:                     Format of Keymaps.   (line   6)
86315* format specification:                  Formatting Strings.  (line  41)
86316* format, customization keyword:         Type Keywords.       (line  25)
86317* format-alist:                          Format Conversion Round-Trip.
86318                                                              (line  13)
86319* format-find-file:                      Format Conversion Round-Trip.
86320                                                              (line 130)
86321* format-insert-file:                    Format Conversion Round-Trip.
86322                                                              (line 139)
86323* format-message:                        Formatting Strings.  (line  31)
86324* format-mode-line:                      Emulating Mode Line. (line  10)
86325* format-network-address:                Misc Network.        (line  85)
86326* format-seconds:                        Time Parsing.        (line 195)
86327* format-spec:                           Custom Format Strings.
86328                                                              (line  27)
86329* format-time-string:                    Time Parsing.        (line  43)
86330* format-write-file:                     Format Conversion Round-Trip.
86331                                                              (line 117)
86332* formatting numbers for rereading later: Formatting Strings. (line 240)
86333* formatting strings:                    Formatting Strings.  (line   6)
86334* formatting time values:                Time Parsing.        (line   6)
86335* formfeed:                              Basic Char Syntax.   (line  27)
86336* forms for cleanup:                     Cleanups.            (line   6)
86337* forms for control structures:          Control Structures.  (line   6)
86338* forms for handling errors:             Handling Errors.     (line   6)
86339* forms for nonlocal exits:              Catch and Throw.     (line   6)
86340* forms for sequential execution:        Sequencing.          (line   6)
86341* forms, backquote:                      Backquote.           (line   6)
86342* forms, conditional:                    Conditionals.        (line   6)
86343* forms, function call:                  Function Forms.      (line   6)
86344* forms, iteration:                      Iteration.           (line   6)
86345* forms, list:                           Classifying Lists.   (line   6)
86346* forms, macro call:                     Macro Forms.         (line   6)
86347* forms, quote:                          Quoting.             (line   6)
86348* forms, special:                        Special Forms.       (line   6)
86349* forms, symbol:                         Symbol Forms.        (line   6)
86350* forward-button:                        Button Buffer Commands.
86351                                                              (line  32)
86352* forward-char:                          Character Motion.    (line  24)
86353* forward-comment:                       Motion via Parsing.  (line  42)
86354* forward-line:                          Text Lines.          (line  53)
86355* forward-list:                          List Motion.         (line  14)
86356* forward-sexp:                          List Motion.         (line  43)
86357* forward-to-indentation:                Motion by Indent.    (line  19)
86358* forward-word:                          Word Motion.         (line  10)
86359* forward-word-strictly:                 Word Motion.         (line  68)
86360* frame:                                 Frames.              (line   6)
86361* frame configuration:                   Frame Configurations.
86362                                                              (line   6)
86363* frame creation:                        Creating Frames.     (line   6)
86364* frame geometry:                        Frame Geometry.      (line   6)
86365* frame height ratio:                    Size Parameters.     (line  23)
86366* frame interaction parameters:          Frame Interaction Parameters.
86367                                                              (line   6)
86368* frame layout:                          Frame Layout.        (line   6)
86369* frame layout parameters:               Layout Parameters.   (line   6)
86370* frame parameters:                      Frame Parameters.    (line   6)
86371* frame parameters for windowed displays: Window Frame Parameters.
86372                                                              (line   6)
86373* frame position:                        Frame Geometry.      (line   6)
86374* frame position <1>:                    Frame Position.      (line   6)
86375* frame position <2>:                    Position Parameters. (line   6)
86376* frame position changes, a hook:        Frame Position.      (line  61)
86377* frame size:                            Frame Geometry.      (line   6)
86378* frame size <1>:                        Frame Size.          (line   6)
86379* frame stacking order:                  Raising and Lowering.
86380                                                              (line   6)
86381* frame title:                           Frame Titles.        (line   6)
86382* frame visibility:                      Visibility of Frames.
86383                                                              (line   6)
86384* frame width ratio:                     Size Parameters.     (line  23)
86385* frame without a minibuffer:            Minibuffers and Frames.
86386                                                              (line  10)
86387* frame Z-order:                         Raising and Lowering.
86388                                                              (line   6)
86389* frame, which buffers to display:       Buffer Parameters.   (line   6)
86390* frame-alpha-lower-limit:               Font and Color Parameters.
86391                                                              (line  66)
86392* frame-ancestor-p:                      Child Frames.        (line 192)
86393* frame-auto-hide-function:              Quitting Windows.    (line 134)
86394* frame-char-height:                     Frame Font.          (line  17)
86395* frame-char-width:                      Frame Font.          (line  18)
86396* frame-current-scroll-bars:             Scroll Bars.         (line  23)
86397* frame-edges:                           Frame Layout.        (line 307)
86398* frame-first-window:                    Windows and Frames.  (line 152)
86399* frame-focus-state:                     Input Focus.         (line 157)
86400* frame-geometry:                        Frame Layout.        (line 249)
86401* frame-height:                          Frame Size.          (line  32)
86402* frame-inherited-parameters:            Creating Frames.     (line  57)
86403* frame-inhibit-implied-resize:          Implied Frame Resizing.
86404                                                              (line  17)
86405* frame-inner-height:                    Frame Size.          (line  61)
86406* frame-inner-width:                     Frame Size.          (line  60)
86407* frame-list:                            Finding All Frames.  (line   6)
86408* frame-list-z-order:                    Finding All Frames.  (line  19)
86409* frame-live-p:                          Deleting Frames.     (line  33)
86410* frame-monitor-attributes:              Multiple Terminals.  (line 219)
86411* frame-native-height:                   Frame Size.          (line  55)
86412* frame-native-width:                    Frame Size.          (line  56)
86413* frame-old-selected-window:             Window Hooks.        (line 242)
86414* frame-outer-height:                    Frame Size.          (line  51)
86415* frame-outer-width:                     Frame Size.          (line  50)
86416* frame-parameter:                       Parameter Access.    (line   8)
86417* frame-parameters:                      Parameter Access.    (line  14)
86418* frame-parent:                          Child Frames.        (line 184)
86419* frame-pointer-visible-p:               Mouse Position.      (line  64)
86420* frame-position:                        Frame Position.      (line  18)
86421* frame-predicate, a buffer display action alist entry: Buffer Display Action Alists.
86422                                                              (line  46)
86423* frame-relative coordinate:             Coordinates and Windows.
86424                                                              (line   6)
86425* frame-resize-pixelwise:                Frame Size.          (line  79)
86426* frame-restack:                         Raising and Lowering.
86427                                                              (line  38)
86428* frame-root-window:                     Windows and Frames.  (line  44)
86429* frame-scroll-bar-height:               Scroll Bars.         (line  34)
86430* frame-scroll-bar-width:                Scroll Bars.         (line  30)
86431* frame-selected-window:                 Selecting Windows.   (line  96)
86432* frame-size-changed-p:                  Frame Size.          (line 170)
86433* frame-terminal:                        Frames.              (line  54)
86434* frame-text-height:                     Frame Size.          (line  66)
86435* frame-text-width:                      Frame Size.          (line  65)
86436* frame-title-format:                    Frame Titles.        (line  16)
86437* frame-visible-p:                       Visibility of Frames.
86438                                                              (line  24)
86439* frame-width:                           Frame Size.          (line  33)
86440* frame-window-state-change:             Window Hooks.        (line 200)
86441* framep:                                Frames.              (line  37)
86442* frames, scanning all:                  Finding All Frames.  (line   6)
86443* free list:                             Garbage Collection.  (line  41)
86444* free variable:                         Using Lexical Binding.
86445                                                              (line  78)
86446* free variable, byte-compiler warning:  Compiler Errors.     (line  21)
86447* free_global_ref:                       Module Values.       (line 338)
86448* frequency counts:                      Coverage Testing.    (line   6)
86449* frexp:                                 Float Basics.        (line  64)
86450* fringe bitmaps:                        Fringe Bitmaps.      (line   6)
86451* fringe bitmaps, customizing:           Customizing Bitmaps. (line   6)
86452* fringe cursors:                        Fringe Cursors.      (line   6)
86453* fringe indicators:                     Fringe Indicators.   (line   6)
86454* fringe-bitmaps-at-pos:                 Fringe Bitmaps.      (line  72)
86455* fringe-cursor-alist:                   Fringe Cursors.      (line  17)
86456* fringe-indicator-alist:                Fringe Indicators.   (line  50)
86457* fringes:                               Fringes.             (line   6)
86458* fringes, and empty line indication:    Fringe Indicators.   (line  10)
86459* fringes-outside-margins:               Fringe Size/Pos.     (line   9)
86460* fround:                                Rounding Operations. (line  24)
86461* fset:                                  Function Cells.      (line  63)
86462* ftp-login:                             Cleanups.            (line  57)
86463* ftruncate:                             Rounding Operations. (line  20)
86464* full keymap:                           Format of Keymaps.   (line   6)
86465* full-height window:                    Window Sizes.        (line 127)
86466* full-width window:                     Window Sizes.        (line 127)
86467* fullboth frames:                       Size Parameters.     (line  84)
86468* fullheight frames:                     Size Parameters.     (line  84)
86469* fullscreen, a frame parameter:         Size Parameters.     (line  84)
86470* fullscreen-restore, a frame parameter: Size Parameters.     (line 114)
86471* fullwidth frames:                      Size Parameters.     (line  84)
86472* func-arity:                            What Is a Function.  (line 104)
86473* funcall:                               Calling Functions.   (line  22)
86474* funcall <1>:                           Module Misc.         (line  56)
86475* funcall, and debugging:                Internals of Debugger.
86476                                                              (line  86)
86477* funcall-interactively:                 Interactive Call.    (line  73)
86478* function:                              Anonymous Functions. (line  39)
86479* function aliases:                      Defining Functions.  (line  55)
86480* function call:                         Function Forms.      (line   6)
86481* function call debugging:               Function Debugging.  (line   6)
86482* function cell:                         Symbol Components.   (line  16)
86483* function cell in autoload:             Autoload.            (line  70)
86484* function declaration:                  Declaring Functions. (line   6)
86485* function definition:                   Function Names.      (line   6)
86486* function descriptions:                 A Sample Function Description.
86487                                                              (line   6)
86488* function form evaluation:              Function Forms.      (line   6)
86489* function input stream:                 Input Streams.       (line  26)
86490* function invocation:                   Calling Functions.   (line   6)
86491* function keys:                         Function Keys.       (line   6)
86492* function name:                         Function Names.      (line   6)
86493* function not known to be defined, compilation warning: Compiler Errors.
86494                                                              (line  21)
86495* function output stream:                Output Streams.      (line  24)
86496* function quoting:                      Anonymous Functions. (line  40)
86497* function safety:                       Function Safety.     (line   6)
86498* function’s documentation string:       Function Documentation.
86499                                                              (line   6)
86500* function-documentation property:       Documentation Basics.
86501                                                              (line  12)
86502* function-get:                          Symbol Plists.       (line  58)
86503* function-put:                          Symbol Plists.       (line  68)
86504* functionals:                           Calling Functions.   (line 107)
86505* functionp:                             What Is a Function.  (line  95)
86506* functions in modes:                    Major Mode Conventions.
86507                                                              (line  55)
86508* functions, making them interactive:    Defining Commands.   (line   6)
86509* fundamental-mode:                      Major Modes.         (line  20)
86510* fundamental-mode-abbrev-table:         Standard Abbrev Tables.
86511                                                              (line  27)
86512* future history in minibuffer input:    Text from Minibuffer.
86513                                                              (line  36)
86514* gamma correction:                      Font and Color Parameters.
86515                                                              (line  48)
86516* gap-position:                          Buffer Gap.          (line  18)
86517* gap-size:                              Buffer Gap.          (line  22)
86518* garbage collection:                    Garbage Collection.  (line  25)
86519* garbage collection protection:         Writing Emacs Primitives.
86520                                                              (line 160)
86521* garbage-collect:                       Garbage Collection.  (line  63)
86522* garbage-collection-messages:           Garbage Collection.  (line 210)
86523* gc-cons-percentage:                    Garbage Collection.  (line 242)
86524* gc-cons-threshold:                     Garbage Collection.  (line 220)
86525* gc-elapsed:                            Garbage Collection.  (line 291)
86526* gcs-done:                              Garbage Collection.  (line 287)
86527* generalized variable:                  Generalized Variables.
86528                                                              (line   6)
86529* generate-autoload-cookie:              Autoload.            (line 188)
86530* generate-new-buffer:                   Creating Buffers.    (line  36)
86531* generate-new-buffer-name:              Buffer Names.        (line  66)
86532* generated-autoload-file:               Autoload.            (line 194)
86533* generators:                            Generators.          (line   6)
86534* generic commands:                      Generic Commands.    (line   6)
86535* generic functions:                     Generic Functions.   (line   6)
86536* generic mode:                          Generic Modes.       (line   6)
86537* gensym:                                Creating Symbols.    (line  95)
86538* geometry specification:                Geometry.            (line  10)
86539* get:                                   Symbol Plists.       (line   8)
86540* get, defcustom keyword:                Variable Definitions.
86541                                                              (line  89)
86542* get-buffer:                            Buffer Names.        (line  49)
86543* get-buffer-create:                     Creating Buffers.    (line  16)
86544* get-buffer-process:                    Process Buffers.     (line  59)
86545* get-buffer-window:                     Buffers and Windows. (line  54)
86546* get-buffer-window-list:                Buffers and Windows. (line  75)
86547* get-buffer-xwidgets:                   Xwidgets.            (line  42)
86548* get-byte:                              Character Codes.     (line  50)
86549* get-char-code-property:                Character Properties.
86550                                                              (line 188)
86551* get-char-property:                     Examining Properties.
86552                                                              (line  25)
86553* get-char-property-and-overlay:         Examining Properties.
86554                                                              (line  43)
86555* get-charset-property:                  Character Sets.      (line  59)
86556* get-device-terminal:                   Multiple Terminals.  (line  37)
86557* get-file-buffer:                       Buffer File Name.    (line  57)
86558* get-internal-run-time:                 Processor Run Time.  (line  19)
86559* get-largest-window:                    Cyclic Window Ordering.
86560                                                              (line 129)
86561* get-load-suffixes:                     Load Suffixes.       (line  31)
86562* get-lru-window:                        Cyclic Window Ordering.
86563                                                              (line 111)
86564* get-mru-window:                        Cyclic Window Ordering.
86565                                                              (line 124)
86566* get-pos-property:                      Examining Properties.
86567                                                              (line  37)
86568* get-process:                           Process Information. (line  27)
86569* get-register:                          Registers.           (line  57)
86570* get-text-property:                     Examining Properties.
86571                                                              (line  16)
86572* get-unused-category:                   Categories.          (line  72)
86573* get-variable-watchers:                 Watching Variables.  (line  34)
86574* get-window-with-predicate:             Cyclic Window Ordering.
86575                                                              (line 146)
86576* getenv:                                System Environment.  (line  79)
86577* gethash:                               Hash Access.         (line  11)
86578* get_user_finalizer:                    Module Values.       (line 377)
86579* GID:                                   User Identification. (line  61)
86580* global binding:                        Local Variables.     (line   6)
86581* global break condition:                Global Break Condition.
86582                                                              (line   6)
86583* global keymap:                         Active Keymaps.      (line  38)
86584* global variable:                       Global Variables.    (line   6)
86585* global-abbrev-table:                   Standard Abbrev Tables.
86586                                                              (line   9)
86587* global-buffers-menu-map:               Standard Keymaps.    (line  92)
86588* global-disable-point-adjustment:       Adjusting Point.     (line  25)
86589* global-key-binding:                    Functions for Key Lookup.
86590                                                              (line  62)
86591* global-map:                            Controlling Active Maps.
86592                                                              (line   6)
86593* global-mode-string:                    Mode Line Variables. (line 122)
86594* global-set-key:                        Key Binding Commands.
86595                                                              (line  46)
86596* global-unset-key:                      Key Binding Commands.
86597                                                              (line  54)
86598* glyph:                                 Glyphs.              (line   6)
86599* glyph code:                            Glyphs.              (line   6)
86600* glyph-char:                            Glyphs.              (line  19)
86601* glyph-face:                            Glyphs.              (line  22)
86602* glyph-table:                           Glyphs.              (line  30)
86603* glyphless characters:                  Glyphless Chars.     (line   6)
86604* glyphless-char-display:                Glyphless Chars.     (line  13)
86605* glyphless-char-display-control:        Glyphless Chars.     (line  58)
86606* gnutls cryptographic functions:        GnuTLS Cryptographic Functions.
86607                                                              (line   6)
86608* gnutls cryptography inputs format:     Format of GnuTLS Cryptography Inputs.
86609                                                              (line   6)
86610* gnutls-ciphers:                        GnuTLS Cryptographic Functions.
86611                                                              (line  61)
86612* gnutls-digests:                        GnuTLS Cryptographic Functions.
86613                                                              (line   6)
86614* gnutls-hash-digest:                    GnuTLS Cryptographic Functions.
86615                                                              (line  18)
86616* gnutls-hash-mac:                       GnuTLS Cryptographic Functions.
86617                                                              (line  44)
86618* gnutls-macs:                           GnuTLS Cryptographic Functions.
86619                                                              (line  29)
86620* gnutls-symmetric-decrypt:              GnuTLS Cryptographic Functions.
86621                                                              (line  96)
86622* gnutls-symmetric-encrypt:              GnuTLS Cryptographic Functions.
86623                                                              (line  73)
86624* goto-char:                             Character Motion.    (line   9)
86625* goto-history-element:                  Minibuffer Commands. (line  47)
86626* goto-map:                              Prefix Keys.         (line  46)
86627* grammar, SMIE:                         SMIE Grammar.        (line   6)
86628* graphical display:                     Frames.              (line  21)
86629* graphical terminal:                    Frames.              (line  21)
86630* group in rx:                           Rx Constructs.       (line 359)
86631* group, customization keyword:          Common Keywords.     (line  23)
86632* group-gid:                             User Identification. (line  61)
86633* group-n in rx:                         Rx Constructs.       (line 367)
86634* group-name:                            User Identification. (line  78)
86635* group-real-gid:                        User Identification. (line  64)
86636* gui-get-selection:                     Window System Selections.
86637                                                              (line  35)
86638* gui-set-selection:                     Window System Selections.
86639                                                              (line  15)
86640* guidelines for buffer display:         The Zen of Buffer Display.
86641                                                              (line   6)
86642* gv-define-expander:                    Adding Generalized Variables.
86643                                                              (line  48)
86644* gv-define-setter:                      Adding Generalized Variables.
86645                                                              (line  34)
86646* gv-define-simple-setter:               Adding Generalized Variables.
86647                                                              (line   9)
86648* gv-letplace:                           Adding Generalized Variables.
86649                                                              (line  62)
86650* hack-connection-local-variables:       Connection Local Variables.
86651                                                              (line  83)
86652* hack-connection-local-variables-apply: Connection Local Variables.
86653                                                              (line  98)
86654* hack-dir-local-variables:              Directory Local Variables.
86655                                                              (line  34)
86656* hack-dir-local-variables-non-file-buffer: Directory Local Variables.
86657                                                              (line  44)
86658* hack-local-variables:                  File Local Variables.
86659                                                              (line  46)
86660* hack-local-variables-hook:             File Local Variables.
86661                                                              (line  87)
86662* Hamming weight:                        Bitwise Operations.  (line 173)
86663* handle Lisp errors:                    Handling Errors.     (line   6)
86664* handle-focus-in:                       Input Focus.         (line 107)
86665* handle-shift-selection:                The Mark.            (line 182)
86666* handle-switch-frame:                   Input Focus.         (line 120)
86667* handling errors:                       Handling Errors.     (line   6)
86668* hardening:                             Security Considerations.
86669                                                              (line   6)
86670* hash code:                             Defining Hash.       (line   6)
86671* hash notation:                         Printed Representation.
86672                                                              (line  13)
86673* hash table access:                     Hash Access.         (line   6)
86674* hash tables:                           Hash Tables.         (line   6)
86675* hash, cryptographic:                   Checksum/Hash.       (line   6)
86676* hash, cryptographic <1>:               GnuTLS Cryptography. (line   6)
86677* hash-table-count:                      Other Hash.          (line  15)
86678* hash-table-p:                          Other Hash.          (line   8)
86679* hash-table-rehash-size:                Other Hash.          (line  27)
86680* hash-table-rehash-threshold:           Other Hash.          (line  30)
86681* hash-table-size:                       Other Hash.          (line  33)
86682* hash-table-test:                       Other Hash.          (line  18)
86683* hash-table-weakness:                   Other Hash.          (line  23)
86684* hashing:                               Creating Symbols.    (line  11)
86685* header comments:                       Library Headers.     (line   6)
86686* header line (of a window):             Header Lines.        (line   6)
86687* header-line, prefix key:               Key Sequence Input.  (line  92)
86688* header-line-format:                    Header Lines.        (line  10)
86689* header-line-format, a window parameter: Window Parameters.  (line 142)
86690* height of a line:                      Line Height.         (line   6)
86691* height of a window:                    Window Sizes.        (line  47)
86692* height spec:                           Line Height.         (line  41)
86693* height, a frame parameter:             Size Parameters.     (line  55)
86694* help for major mode:                   Mode Help.           (line   6)
86695* help functions:                        Help Functions.      (line   6)
86696* help-buffer:                           Help Functions.      (line 125)
86697* help-char:                             Help Functions.      (line  51)
86698* help-command:                          Help Functions.      (line  43)
86699* help-echo (button property):           Button Properties.   (line  41)
86700* help-echo (overlay property):          Overlay Properties.  (line 123)
86701* help-echo (text property):             Special Properties.  (line  93)
86702* help-echo event:                       Misc Events.         (line  55)
86703* help-echo text, avoid command-key substitution: Special Properties.
86704                                                              (line 121)
86705* help-echo, customization keyword:      Type Keywords.       (line  98)
86706* help-echo-inhibit-substitution (text property): Special Properties.
86707                                                              (line 121)
86708* help-event-list:                       Help Functions.      (line  69)
86709* help-form:                             Help Functions.      (line  74)
86710* help-map:                              Help Functions.      (line  39)
86711* help-setup-xref:                       Help Functions.      (line 141)
86712* help-window-select:                    Help Functions.      (line 130)
86713* Helper-describe-bindings:              Help Functions.      (line 108)
86714* Helper-help:                           Help Functions.      (line 113)
86715* Helper-help-map:                       Help Functions.      (line 119)
86716* hex numbers:                           Integer Basics.      (line  16)
86717* hidden buffers:                        Buffer Names.        (line  12)
86718* history list:                          Minibuffer History.  (line   6)
86719* history of commands:                   Command History.     (line   6)
86720* history-add-new-input:                 Minibuffer History.  (line  72)
86721* history-delete-duplicates:             Minibuffer History.  (line  86)
86722* history-length:                        Minibuffer History.  (line  78)
86723* HOME environment variable:             Subprocess Creation. (line  18)
86724* hook variables, list of:               Standard Hooks.      (line   6)
86725* hooks:                                 Hooks.               (line   6)
86726* hooks for changing a character:        Special Properties.  (line 290)
86727* hooks for loading:                     Hooks for Loading.   (line   6)
86728* hooks for motion of point:             Special Properties.  (line 333)
86729* hooks for text changes:                Change Hooks.        (line   6)
86730* hooks for window operations:           Window Hooks.        (line   6)
86731* horizontal combination:                Windows and Frames.  (line  78)
86732* horizontal position:                   Columns.             (line   6)
86733* horizontal scrolling:                  Horizontal Scrolling.
86734                                                              (line   6)
86735* horizontal-lineto:                     SVG Images.          (line 208)
86736* horizontal-scroll-bar:                 Scroll Bars.         (line 143)
86737* horizontal-scroll-bar, prefix key:     Key Sequence Input.  (line  92)
86738* horizontal-scroll-bar-mode:            Scroll Bars.         (line 168)
86739* horizontal-scroll-bars, a frame parameter: Layout Parameters.
86740                                                              (line  23)
86741* horizontal-scroll-bars-available-p:    Scroll Bars.         (line  16)
86742* how to visit files:                    Visiting Functions.  (line   6)
86743* HTML DOM:                              Document Object Model.
86744                                                              (line   6)
86745* hyper characters:                      Other Char Bits.     (line  16)
86746* hyperlinks in documentation strings:   Documentation Tips.  (line 113)
86747* icon-left, a frame parameter:          Position Parameters. (line  93)
86748* icon-name, a frame parameter:          Management Parameters.
86749                                                              (line  29)
86750* icon-title-format:                     Frame Titles.        (line  23)
86751* icon-top, a frame parameter:           Position Parameters. (line 100)
86752* icon-type, a frame parameter:          Management Parameters.
86753                                                              (line  23)
86754* iconified frame:                       Visibility of Frames.
86755                                                              (line   6)
86756* iconify-child-frame:                   Child Frames.        (line 207)
86757* iconify-frame:                         Visibility of Frames.
86758                                                              (line  33)
86759* iconify-frame event:                   Misc Events.         (line  16)
86760* identical-contents objects, and byte-compiler: Equality Predicates.
86761                                                              (line  73)
86762* identity:                              Calling Functions.   (line 116)
86763* idle timers:                           Idle Timers.         (line   6)
86764* idleness:                              Idle Timers.         (line  23)
86765* IEEE floating point:                   Float Basics.        (line   6)
86766* if:                                    Conditionals.        (line  12)
86767* ignore:                                Calling Functions.   (line 119)
86768* ignore-error:                          Handling Errors.     (line 210)
86769* ignore-errors:                         Handling Errors.     (line 198)
86770* ignore-window-parameters:              Window Parameters.   (line  65)
86771* ignored-local-variables:               File Local Variables.
86772                                                              (line 154)
86773* image animation:                       Multi-Frame Images.  (line   6)
86774* image cache:                           Image Cache.         (line   6)
86775* image descriptor:                      Image Descriptors.   (line   6)
86776* image formats:                         Image Formats.       (line   6)
86777* image frames:                          Multi-Frame Images.  (line   6)
86778* image maps:                            Image Descriptors.   (line 179)
86779* image slice:                           Showing Images.      (line  34)
86780* image types:                           Image Formats.       (line   6)
86781* image-animate:                         Multi-Frame Images.  (line  37)
86782* image-animate-timer:                   Multi-Frame Images.  (line  49)
86783* image-cache-eviction-delay:            Image Cache.         (line  51)
86784* image-current-frame:                   Multi-Frame Images.  (line  26)
86785* image-default-frame-delay:             Multi-Frame Images.  (line  44)
86786* image-flush:                           Image Cache.         (line  12)
86787* image-format-suffixes:                 ImageMagick Images.  (line  36)
86788* image-load-path:                       Defining Images.     (line  74)
86789* image-load-path-for-library:           Defining Images.     (line  93)
86790* image-mask-p:                          Image Descriptors.   (line 207)
86791* image-minimum-frame-delay:             Multi-Frame Images.  (line  44)
86792* image-multi-frame-p:                   Multi-Frame Images.  (line  17)
86793* image-property:                        Defining Images.     (line  53)
86794* image-scaling-factor:                  Defining Images.     (line 122)
86795* image-show-frame:                      Multi-Frame Images.  (line  30)
86796* image-size:                            Showing Images.      (line  71)
86797* image-transforms-p:                    Image Descriptors.   (line 212)
86798* image-type-available-p:                Image Formats.       (line  36)
86799* image-types:                           Image Formats.       (line  27)
86800* ImageMagick images:                    ImageMagick Images.  (line   6)
86801* imagemagick-enabled-types:             ImageMagick Images.  (line  21)
86802* imagemagick-types:                     ImageMagick Images.  (line  15)
86803* imagemagick-types-inhibit:             ImageMagick Images.  (line  30)
86804* images in buffers:                     Images.              (line   6)
86805* images, support for more formats:      ImageMagick Images.  (line   6)
86806* Imenu:                                 Imenu.               (line   6)
86807* imenu-add-to-menubar:                  Imenu.               (line  14)
86808* imenu-case-fold-search:                Imenu.               (line  68)
86809* imenu-create-index-function:           Imenu.               (line 128)
86810* imenu-extract-index-name-function:     Imenu.               (line 117)
86811* imenu-generic-expression:              Imenu.               (line  26)
86812* imenu-prev-index-position-function:    Imenu.               (line 107)
86813* imenu-syntax-alist:                    Imenu.               (line  76)
86814* implicit progn:                        Sequencing.          (line  21)
86815* implied frame resizing:                Implied Frame Resizing.
86816                                                              (line   6)
86817* implied resizing of frame:             Implied Frame Resizing.
86818                                                              (line   6)
86819* in in rx:                              Rx Constructs.       (line 125)
86820* inactive minibuffer:                   Intro to Minibuffers.
86821                                                              (line  60)
86822* inc:                                   Simple Macro.        (line  11)
86823* indefinite extent:                     Variable Scoping.    (line  21)
86824* indent-according-to-mode:              Mode-Specific Indent.
86825                                                              (line  48)
86826* indent-code-rigidly:                   Region Indent.       (line  58)
86827* indent-for-tab-command:                Mode-Specific Indent.
86828                                                              (line  11)
86829* indent-line-function:                  Mode-Specific Indent.
86830                                                              (line  40)
86831* indent-region:                         Region Indent.       (line   9)
86832* indent-region-function:                Region Indent.       (line  23)
86833* indent-relative:                       Relative Indent.     (line   9)
86834* indent-relative-first-indent-point:    Relative Indent.     (line  50)
86835* indent-rigidly:                        Region Indent.       (line  44)
86836* indent-tabs-mode:                      Primitive Indent.    (line  28)
86837* indent-to:                             Primitive Indent.    (line  16)
86838* indent-to-left-margin:                 Margins.             (line  72)
86839* indentation:                           Indentation.         (line   6)
86840* indentation rules, SMIE:               SMIE Indentation.    (line   6)
86841* indicate-buffer-boundaries:            Fringe Indicators.   (line  15)
86842* indicate-empty-lines:                  Fringe Indicators.   (line   9)
86843* indicators, fringe:                    Fringe Indicators.   (line   6)
86844* indirect buffers:                      Indirect Buffers.    (line   6)
86845* indirect specifications:               Specification List.  (line 117)
86846* indirect-function:                     Function Indirection.
86847                                                              (line  65)
86848* indirect-variable:                     Variable Aliases.    (line  61)
86849* indirection for functions:             Function Indirection.
86850                                                              (line   6)
86851* infinite loops:                        Infinite Loops.      (line   6)
86852* infinite recursion:                    Local Variables.     (line 130)
86853* infinity:                              Float Basics.        (line  32)
86854* inheritance, for faces:                Face Attributes.     (line 191)
86855* inheritance, keymap:                   Inheritance and Keymaps.
86856                                                              (line   6)
86857* inheritance, syntax table:             Syntax Basics.       (line  36)
86858* inheritance, text property:            Sticky Properties.   (line   6)
86859* inhibit-default-init:                  Init File.           (line  55)
86860* inhibit-double-buffering, a frame parameter: Management Parameters.
86861                                                              (line  53)
86862* inhibit-eol-conversion:                Specifying Coding Systems.
86863                                                              (line  61)
86864* inhibit-field-text-motion:             Word Motion.         (line  49)
86865* inhibit-file-name-handlers:            Magic File Names.    (line 146)
86866* inhibit-file-name-operation:           Magic File Names.    (line 150)
86867* inhibit-iso-escape-detection:          Lisp and Coding Systems.
86868                                                              (line 128)
86869* inhibit-local-variables-regexps:       File Local Variables.
86870                                                              (line  40)
86871* inhibit-local-variables-regexps <1>:   Auto Major Mode.     (line  51)
86872* inhibit-message:                       Displaying Messages. (line  85)
86873* inhibit-modification-hooks:            Change Hooks.        (line 104)
86874* inhibit-nul-byte-detection:            Lisp and Coding Systems.
86875                                                              (line 122)
86876* inhibit-point-motion-hooks:            Special Properties.  (line 390)
86877* inhibit-quit:                          Quitting.            (line  78)
86878* inhibit-read-only:                     Read Only Buffers.   (line  34)
86879* inhibit-read-only (text property):     Special Properties.  (line 166)
86880* inhibit-same-window, a buffer display action alist entry: Buffer Display Action Alists.
86881                                                              (line  29)
86882* inhibit-splash-screen:                 Startup Summary.     (line 167)
86883* inhibit-startup-echo-area-message:     Startup Summary.     (line 177)
86884* inhibit-startup-message:               Startup Summary.     (line 167)
86885* inhibit-startup-screen:                Startup Summary.     (line 157)
86886* inhibit-switch-frame, a buffer display action alist entry: Buffer Display Action Alists.
86887                                                              (line  75)
86888* inhibit-x-resources:                   Resources.           (line  51)
86889* init file:                             Init File.           (line   6)
86890* init-file-user:                        User Identification. (line   6)
86891* init.el:                               Init File.           (line   6)
86892* initial-buffer-choice:                 Startup Summary.     (line 170)
86893* initial-environment:                   System Environment.  (line 137)
86894* initial-frame-alist:                   Initial Parameters.  (line   9)
86895* initial-major-mode:                    Auto Major Mode.     (line  78)
86896* initial-scratch-message:               Startup Summary.     (line 194)
86897* initial-window-system:                 Window Systems.      (line  28)
86898* initial-window-system, and startup:    Startup Summary.     (line  45)
86899* initialization of Emacs:               Startup Summary.     (line   6)
86900* initialize, defcustom keyword:         Variable Definitions.
86901                                                              (line 102)
86902* inline completion:                     Completion in Buffers.
86903                                                              (line   6)
86904* inline functions:                      Inline Functions.    (line   6)
86905* inline-const-p:                        Inline Functions.    (line  99)
86906* inline-const-val:                      Inline Functions.    (line 102)
86907* inline-error:                          Inline Functions.    (line 105)
86908* inline-letevals:                       Inline Functions.    (line  88)
86909* inline-quote:                          Inline Functions.    (line  83)
86910* inner edges:                           Frame Layout.        (line 202)
86911* inner frame:                           Frame Layout.        (line 202)
86912* inner height:                          Frame Layout.        (line 202)
86913* inner size:                            Frame Layout.        (line 202)
86914* inner width:                           Frame Layout.        (line 202)
86915* innermost containing parentheses:      Parser State.        (line  20)
86916* input events:                          Input Events.        (line   6)
86917* input events, prevent recording:       Event Input Misc.    (line  40)
86918* input focus:                           Input Focus.         (line   6)
86919* input methods:                         Input Methods.       (line   6)
86920* input modes:                           Input Modes.         (line   6)
86921* input stream:                          Input Streams.       (line   6)
86922* input-decode-map:                      Translation Keymaps. (line  32)
86923* input-method-alist:                    Input Methods.       (line  43)
86924* input-method-function:                 Invoking the Input Method.
86925                                                              (line  12)
86926* input-pending-p:                       Event Input Misc.    (line  50)
86927* insert:                                Insertion.           (line  37)
86928* insert-abbrev-table-description:       Abbrev Tables.       (line  49)
86929* insert-and-inherit:                    Sticky Properties.   (line  73)
86930* insert-before-markers:                 Insertion.           (line  43)
86931* insert-before-markers-and-inherit:     Sticky Properties.   (line  77)
86932* insert-behind-hooks (overlay property): Overlay Properties. (line 172)
86933* insert-behind-hooks (text property):   Special Properties.  (line 314)
86934* insert-buffer:                         Commands for Insertion.
86935                                                              (line  10)
86936* insert-buffer-substring:               Insertion.           (line  72)
86937* insert-buffer-substring-as-yank:       Yanking.             (line  18)
86938* insert-buffer-substring-no-properties: Insertion.           (line  94)
86939* insert-button:                         Making Buttons.      (line  35)
86940* insert-char:                           Insertion.           (line  56)
86941* insert-default-directory:              Reading File Names.  (line 132)
86942* insert-directory:                      Contents of Directories.
86943                                                              (line 108)
86944* insert-directory-program:              Contents of Directories.
86945                                                              (line 139)
86946* insert-file-contents:                  Reading from Files.  (line  10)
86947* insert-file-contents-literally:        Reading from Files.  (line  52)
86948* insert-for-yank:                       Yanking.             (line  11)
86949* insert-image:                          Showing Images.      (line   9)
86950* insert-in-front-hooks (overlay property): Overlay Properties.
86951                                                              (line 166)
86952* insert-in-front-hooks (text property): Special Properties.  (line 314)
86953* insert-register:                       Registers.           (line  69)
86954* insert-sliced-image:                   Showing Images.      (line  34)
86955* insert-text-button:                    Making Buttons.      (line  50)
86956* inserting killed text:                 Yank Commands.       (line  12)
86957* insertion before point:                Insertion.           (line   6)
86958* insertion of text:                     Insertion.           (line   6)
86959* insertion type of a marker:            Marker Insertion Types.
86960                                                              (line   6)
86961* inside comment:                        Parser State.        (line  30)
86962* inside string:                         Parser State.        (line  26)
86963* installation-directory:                System Environment.  (line 166)
86964* instrumenting for Edebug:              Instrumenting.       (line   6)
86965* int-to-string:                         String Conversion.   (line  31)
86966* intangible (overlay property):         Overlay Properties.  (line 183)
86967* intangible (text property):            Special Properties.  (line 174)
86968* integer range:                         Integer Basics.      (line  96)
86969* integer to decimal:                    String Conversion.   (line  20)
86970* integer to hexadecimal:                Formatting Strings.  (line  94)
86971* integer to octal:                      Formatting Strings.  (line  82)
86972* integer to string:                     String Conversion.   (line  20)
86973* integer types (C programming language): C Integer Types.    (line   6)
86974* integer-or-marker-p:                   Predicates on Markers.
86975                                                              (line  15)
86976* integer-width:                         Integer Basics.      (line  96)
86977* integerp:                              Predicates on Numbers.
86978                                                              (line  27)
86979* integers:                              Numbers.             (line   6)
86980* integers in specific radix:            Integer Basics.      (line  16)
86981* interaction parameters between frames: Frame Interaction Parameters.
86982                                                              (line   6)
86983* interactive:                           Using Interactive.   (line  10)
86984* interactive call:                      Interactive Call.    (line   6)
86985* interactive code description:          Interactive Codes.   (line   6)
86986* interactive completion:                Interactive Codes.   (line  10)
86987* interactive function:                  Defining Commands.   (line   6)
86988* interactive spec, using:               Using Interactive.   (line   6)
86989* interactive specification in primitives: Writing Emacs Primitives.
86990                                                              (line  73)
86991* interactive, examples of using:        Interactive Examples.
86992                                                              (line   6)
86993* interactive-form:                      Using Interactive.   (line 129)
86994* interactive-form property:             Defining Commands.   (line  16)
86995* interactive-form, symbol property:     Using Interactive.   (line  21)
86996* interactive-only property:             Defining Commands.   (line  21)
86997* intern:                                Creating Symbols.    (line 100)
86998* intern <1>:                            Module Misc.         (line  39)
86999* intern-soft:                           Creating Symbols.    (line 120)
87000* internal menu bar:                     Frame Layout.        (line 112)
87001* internal representation of characters: Text Representations.
87002                                                              (line  20)
87003* internal tool bar:                     Frame Layout.        (line 131)
87004* internal windows:                      Basic Windows.       (line  39)
87005* internal-border-width, a frame parameter: Layout Parameters.
87006                                                              (line  13)
87007* internals, of buffer:                  Buffer Internals.    (line   6)
87008* internals, of process:                 Process Internals.   (line   6)
87009* internals, of window:                  Window Internals.    (line   6)
87010* interning:                             Creating Symbols.    (line  23)
87011* interpreter:                           Evaluation.          (line   6)
87012* interpreter <1>:                       Evaluation.          (line   6)
87013* interpreter-mode-alist:                Auto Major Mode.     (line  83)
87014* interprogram-cut-function:             Low-Level Kill Ring. (line  77)
87015* interprogram-paste-function:           Low-Level Kill Ring. (line  55)
87016* interrupt Lisp functions:              Quitting.            (line   6)
87017* interrupt-process:                     Signals to Processes.
87018                                                              (line  52)
87019* interrupt-process-functions:           Signals to Processes.
87020                                                              (line 108)
87021* intersection in rx:                    Rx Constructs.       (line 145)
87022* intersection of sequences:             Sequence Functions.  (line 569)
87023* intervals:                             Not Intervals.       (line   6)
87024* intervals-consed:                      Memory Usage.        (line  34)
87025* invalid prefix key error:              Changing Key Bindings.
87026                                                              (line  57)
87027* invalid-function:                      Function Indirection.
87028                                                              (line  18)
87029* invalid-read-syntax:                   Printed Representation.
87030                                                              (line  25)
87031* invalid-regexp:                        Regexp Backslash.    (line 204)
87032* invert-face:                           Attribute Functions. (line 132)
87033* invisible (overlay property):          Overlay Properties.  (line 178)
87034* invisible (text property):             Special Properties.  (line 170)
87035* invisible frame:                       Visibility of Frames.
87036                                                              (line   6)
87037* invisible text:                        Invisible Text.      (line   6)
87038* invisible-p:                           Invisible Text.      (line  92)
87039* invisible/intangible text, and point:  Adjusting Point.     (line   6)
87040* invocation-directory:                  System Environment.  (line 161)
87041* invocation-name:                       System Environment.  (line 157)
87042* invoking input method:                 Invoking the Input Method.
87043                                                              (line   6)
87044* invoking lisp debugger:                Invoking the Debugger.
87045                                                              (line   6)
87046* is this call interactive:              Distinguish Interactive.
87047                                                              (line   6)
87048* isnan:                                 Float Basics.        (line  60)
87049* ISO 8601 date/time strings:            Time Parsing.        (line  32)
87050* iso8601-parse:                         Time Parsing.        (line  32)
87051* is_not_nil:                            Module Misc.         (line  23)
87052* italic text:                           Face Attributes.     (line  59)
87053* iter-close:                            Generators.          (line  65)
87054* iter-defun:                            Generators.          (line  10)
87055* iter-do:                               Generators.          (line  75)
87056* iter-lambda:                           Generators.          (line  23)
87057* iter-next:                             Generators.          (line  52)
87058* iter-yield:                            Generators.          (line  27)
87059* iter-yield-from:                       Generators.          (line  33)
87060* iteration:                             Iteration.           (line   6)
87061* iteration over vector or string:       Sequence Functions.  (line 627)
87062* JavaScript Object Notation:            Parsing JSON.        (line   6)
87063* jit-lock-register:                     Other Font Lock Variables.
87064                                                              (line  65)
87065* jit-lock-unregister:                   Other Font Lock Variables.
87066                                                              (line  81)
87067* joining lists:                         Rearrangement.       (line  16)
87068* JSON:                                  Parsing JSON.        (line   6)
87069* JSON remote procedure call protocol:   JSONRPC.             (line   6)
87070* json-insert:                           Parsing JSON.        (line  66)
87071* json-parse-buffer:                     Parsing JSON.        (line  99)
87072* json-parse-string:                     Parsing JSON.        (line  71)
87073* json-serialize:                        Parsing JSON.        (line  53)
87074* JSONRPC:                               JSONRPC.             (line   6)
87075* JSONRPC application interfaces:        JSONRPC Overview.    (line  18)
87076* JSONRPC connection initargs:           Process-based JSONRPC connections.
87077                                                              (line  20)
87078* JSONRPC deferred requests:             JSONRPC deferred requests.
87079                                                              (line   6)
87080* JSONRPC object format:                 JSONRPC JSON object format.
87081                                                              (line   6)
87082* JSONRPC process-based connections:     Process-based JSONRPC connections.
87083                                                              (line   6)
87084* jsonrpc-async-request:                 JSONRPC Overview.    (line  20)
87085* jsonrpc-connection:                    JSONRPC Overview.    (line  10)
87086* jsonrpc-connection-ready-p:            JSONRPC deferred requests.
87087                                                              (line  25)
87088* jsonrpc-connection-receive:            JSONRPC Overview.    (line  64)
87089* jsonrpc-connection-send:               JSONRPC Overview.    (line  60)
87090* jsonrpc-error:                         JSONRPC Overview.    (line  32)
87091* jsonrpc-lambda:                        JSONRPC JSON object format.
87092                                                              (line  11)
87093* jsonrpc-notify:                        JSONRPC Overview.    (line  20)
87094* jsonrpc-process-connection:            Process-based JSONRPC connections.
87095                                                              (line   6)
87096* jsonrpc-request:                       JSONRPC Overview.    (line  20)
87097* jsonrpc-running-p:                     JSONRPC Overview.    (line  70)
87098* jsonrpc-shutdown:                      JSONRPC Overview.    (line  70)
87099* jumbled display of bidirectional text: Bidirectional Display.
87100                                                              (line 158)
87101* just-one-space:                        User-Level Deletion. (line 102)
87102* justify-current-line:                  Filling.             (line  99)
87103* kbd:                                   Key Sequences.       (line  35)
87104* kbd-macro-termination-hook:            Keyboard Macros.     (line  62)
87105* keep-ratio, a frame parameter:         Frame Interaction Parameters.
87106                                                              (line  43)
87107* kept-new-versions:                     Numbered Backups.    (line  28)
87108* kept-old-versions:                     Numbered Backups.    (line  33)
87109* key:                                   Key Sequences.       (line   6)
87110* key binding:                           Keymap Basics.       (line   6)
87111* key binding, conventions for:          Key Binding Conventions.
87112                                                              (line   6)
87113* key lookup:                            Key Lookup.          (line   6)
87114* key sequence:                          Key Sequences.       (line   6)
87115* key sequence error:                    Changing Key Bindings.
87116                                                              (line  57)
87117* key sequence input:                    Key Sequence Input.  (line   6)
87118* key substitution sequence:             Keys in Documentation.
87119                                                              (line   6)
87120* key translation function:              Translation Keymaps. (line  79)
87121* key-binding:                           Active Keymaps.      (line  67)
87122* key-description:                       Describing Characters.
87123                                                              (line  13)
87124* key-translation-map:                   Translation Keymaps. (line  59)
87125* keyboard events:                       Keyboard Events.     (line   6)
87126* keyboard events in strings:            Strings of Events.   (line   6)
87127* keyboard events, data in:              Accessing Mouse.     (line   6)
87128* keyboard input:                        Reading Input.       (line   6)
87129* keyboard input decoding on X:          Locales.             (line  11)
87130* keyboard macro execution:              Interactive Call.    (line  80)
87131* keyboard macro termination:            Beeping.             (line  13)
87132* keyboard macro, terminating:           Event Input Misc.    (line 101)
87133* keyboard macros:                       Keyboard Macros.     (line   6)
87134* keyboard macros (Edebug):              Edebug Execution Modes.
87135                                                              (line  87)
87136* keyboard-coding-system:                Terminal I/O Encoding.
87137                                                              (line  11)
87138* keyboard-quit:                         Quitting.            (line 104)
87139* keyboard-translate:                    Event Mod.           (line  54)
87140* keyboard-translate-table:              Event Mod.           (line  32)
87141* keymap:                                Keymaps.             (line   6)
87142* keymap (button property):              Button Properties.   (line  32)
87143* keymap (overlay property):             Overlay Properties.  (line 225)
87144* keymap (text property):                Special Properties.  (line 127)
87145* keymap entry:                          Key Lookup.          (line   6)
87146* keymap format:                         Format of Keymaps.   (line   6)
87147* keymap in keymap:                      Key Lookup.          (line  51)
87148* keymap inheritance:                    Inheritance and Keymaps.
87149                                                              (line   6)
87150* keymap inheritance from multiple maps: Inheritance and Keymaps.
87151                                                              (line  53)
87152* keymap of character:                   Special Properties.  (line 127)
87153* keymap of character (and overlays):    Overlay Properties.  (line 225)
87154* keymap prompt string:                  Format of Keymaps.   (line  57)
87155* keymap-parent:                         Inheritance and Keymaps.
87156                                                              (line  27)
87157* keymap-prompt:                         Defining Menus.      (line  20)
87158* keymapp:                               Format of Keymaps.   (line 106)
87159* keymaps for translating events:        Translation Keymaps. (line   6)
87160* keymaps in modes:                      Major Mode Conventions.
87161                                                              (line  67)
87162* keymaps, scanning:                     Scanning Keymaps.    (line   6)
87163* keymaps, standard:                     Standard Keymaps.    (line   6)
87164* keys in documentation strings:         Keys in Documentation.
87165                                                              (line   6)
87166* keys, reserved:                        Key Binding Conventions.
87167                                                              (line  14)
87168* keystroke:                             Key Sequences.       (line   6)
87169* keyword symbol:                        Constant Variables.  (line   6)
87170* keywordp:                              Constant Variables.  (line  19)
87171* kill command repetition:               Command Loop Info.   (line  43)
87172* kill ring:                             The Kill Ring.       (line   6)
87173* kill-all-local-variables:              Creating Buffer-Local.
87174                                                              (line 165)
87175* kill-append:                           Low-Level Kill Ring. (line  45)
87176* kill-buffer:                           Killing Buffers.     (line  31)
87177* kill-buffer-hook:                      Killing Buffers.     (line  73)
87178* kill-buffer-query-functions:           Killing Buffers.     (line  65)
87179* kill-emacs:                            Killing Emacs.       (line  10)
87180* kill-emacs-hook:                       Killing Emacs.       (line  33)
87181* kill-emacs-query-functions:            Killing Emacs.       (line  50)
87182* kill-local-variable:                   Creating Buffer-Local.
87183                                                              (line 145)
87184* kill-new:                              Low-Level Kill Ring. (line  33)
87185* kill-process:                          Signals to Processes.
87186                                                              (line  60)
87187* kill-read-only-ok:                     Kill Functions.      (line  38)
87188* kill-region:                           Kill Functions.      (line  21)
87189* kill-ring:                             Internals of Kill Ring.
87190                                                              (line  50)
87191* kill-ring-max:                         Internals of Kill Ring.
87192                                                              (line  60)
87193* kill-ring-yank-pointer:                Internals of Kill Ring.
87194                                                              (line  54)
87195* killing buffers:                       Killing Buffers.     (line   6)
87196* killing Emacs:                         Killing Emacs.       (line   6)
87197* kmacro-keymap:                         Standard Keymaps.    (line  78)
87198* lambda:                                Anonymous Functions. (line  20)
87199* lambda expression:                     Lambda Expressions.  (line   6)
87200* lambda in debug:                       Invoking the Debugger.
87201                                                              (line  32)
87202* lambda in keymap:                      Key Lookup.          (line  60)
87203* lambda list:                           Lambda Components.   (line  13)
87204* lambda-list (Edebug):                  Specification List.  (line 185)
87205* language-change event:                 Misc Events.         (line  90)
87206* largest fixnum:                        Integer Basics.      (line  86)
87207* largest window:                        Cyclic Window Ordering.
87208                                                              (line 129)
87209* last:                                  List Elements.       (line 115)
87210* last visible position in a window:     Window Start and End.
87211                                                              (line  46)
87212* last-abbrev:                           Abbrev Expansion.    (line  79)
87213* last-abbrev-location:                  Abbrev Expansion.    (line  85)
87214* last-abbrev-text:                      Abbrev Expansion.    (line  90)
87215* last-buffer:                           Buffer List.         (line  92)
87216* last-coding-system-used:               Encoding and I/O.    (line  47)
87217* last-command:                          Command Loop Info.   (line  11)
87218* last-command-event:                    Command Loop Info.   (line 110)
87219* last-event-frame:                      Command Loop Info.   (line 122)
87220* last-input-event:                      Event Input Misc.    (line  60)
87221* last-kbd-macro:                        Keyboard Macros.     (line  55)
87222* last-nonmenu-event:                    Command Loop Info.   (line 102)
87223* last-prefix-arg:                       Prefix Command Arguments.
87224                                                              (line  96)
87225* last-repeatable-command:               Command Loop Info.   (line  28)
87226* lax-plist-get:                         Plist Access.        (line  37)
87227* lax-plist-put:                         Plist Access.        (line  41)
87228* layout of frame:                       Frame Layout.        (line   6)
87229* layout on display, and bidirectional text: Bidirectional Display.
87230                                                              (line 158)
87231* layout parameters of frames:           Layout Parameters.   (line   6)
87232* lazy evaluation:                       Deferred Eval.       (line   6)
87233* lazy loading:                          Dynamic Loading.     (line   6)
87234* lazy-completion-table:                 Basic Completion.    (line 174)
87235* ldexp:                                 Float Basics.        (line  74)
87236* least recently used window:            Cyclic Window Ordering.
87237                                                              (line 111)
87238* left position ratio:                   Position Parameters. (line  39)
87239* left, a frame parameter:               Position Parameters. (line  14)
87240* left-fringe, a frame parameter:        Layout Parameters.   (line  35)
87241* left-fringe, prefix key:               Key Sequence Input.  (line  92)
87242* left-fringe-width:                     Fringe Size/Pos.     (line  14)
87243* left-margin:                           Margins.             (line  79)
87244* left-margin, prefix key:               Key Sequence Input.  (line  92)
87245* left-margin-width:                     Display Margins.     (line  37)
87246* length:                                Sequence Functions.  (line  13)
87247* let:                                   Local Variables.     (line  47)
87248* let*:                                  Local Variables.     (line  83)
87249* let-alist:                             Association Lists.   (line 255)
87250* letrec:                                Local Variables.     (line  98)
87251* Levenshtein distance:                  Text Comparison.     (line 223)
87252* lexical binding:                       Variable Scoping.    (line  21)
87253* lexical binding (Edebug):              Edebug Eval.         (line  28)
87254* lexical comparison of strings:         Text Comparison.     (line  90)
87255* lexical environment:                   Lexical Binding.     (line  35)
87256* lexical scope:                         Variable Scoping.    (line  21)
87257* lexical-binding:                       Using Lexical Binding.
87258                                                              (line  10)
87259* library:                               Loading.             (line   6)
87260* library compilation:                   Compilation Functions.
87261                                                              (line 106)
87262* library header comments:               Library Headers.     (line   6)
87263* library search:                        Library Search.      (line   6)
87264* libxml-available-p:                    Parsing HTML/XML.    (line   8)
87265* libxml-parse-html-region:              Parsing HTML/XML.    (line  15)
87266* libxml-parse-xml-region:               Parsing HTML/XML.    (line  57)
87267* line end conversion:                   Coding System Basics.
87268                                                              (line  37)
87269* line height:                           Frame Font.          (line  12)
87270* line height <1>:                       Line Height.         (line   6)
87271* line number:                           Text Lines.          (line  92)
87272* line truncation:                       Truncation.          (line   6)
87273* line wrapping:                         Truncation.          (line   6)
87274* line-beginning-position:               Text Lines.          (line  32)
87275* line-end in rx:                        Rx Constructs.       (line 316)
87276* line-end-position:                     Text Lines.          (line  50)
87277* line-height (text property):           Special Properties.  (line 258)
87278* line-height (text property) <1>:       Line Height.         (line  22)
87279* line-move-ignore-invisible:            Invisible Text.      (line 107)
87280* line-number-at-pos:                    Text Lines.          (line  91)
87281* line-number-display-width:             Size of Displayed Text.
87282                                                              (line 184)
87283* line-pixel-height:                     Size of Displayed Text.
87284                                                              (line 174)
87285* line-prefix:                           Truncation.          (line  58)
87286* line-spacing:                          Line Height.         (line  78)
87287* line-spacing (text property):          Special Properties.  (line 252)
87288* line-spacing (text property) <1>:      Line Height.         (line  84)
87289* line-spacing, a frame parameter:       Layout Parameters.   (line  77)
87290* line-start in rx:                      Rx Constructs.       (line 312)
87291* lines:                                 Text Lines.          (line   6)
87292* lines in region:                       Text Lines.          (line  76)
87293* lineto:                                SVG Images.          (line 200)
87294* link, customization keyword:           Common Keywords.     (line  37)
87295* linked list:                           Cons Cell Type.      (line  17)
87296* linking files:                         Changing Files.      (line   6)
87297* Lisp debugger:                         Debugger.            (line   6)
87298* Lisp expression motion:                List Motion.         (line   6)
87299* Lisp history:                          Lisp History.        (line   6)
87300* Lisp library:                          Loading.             (line   6)
87301* Lisp nesting error:                    Eval.                (line 114)
87302* Lisp object:                           Lisp Data Types.     (line   6)
87303* Lisp objects, stack-allocated:         Stack-allocated Objects.
87304                                                              (line   6)
87305* Lisp package:                          Packaging.           (line   6)
87306* Lisp printer:                          Output Functions.    (line  42)
87307* Lisp reader:                           Streams Intro.       (line   6)
87308* Lisp timestamp:                        Time of Day.         (line   8)
87309* lisp variables defined in C, restrictions: Variables with Restricted Values.
87310                                                              (line   6)
87311* lisp-indent-function property:         Indenting Macros.    (line  12)
87312* lisp-mode-abbrev-table:                Standard Abbrev Tables.
87313                                                              (line  35)
87314* lisp-mode.el:                          Example Major Modes. (line  43)
87315* list:                                  Building Lists.      (line  35)
87316* list all coding systems:               Lisp and Coding Systems.
87317                                                              (line   8)
87318* list elements:                         List Elements.       (line   6)
87319* list form evaluation:                  Classifying Lists.   (line   6)
87320* list in keymap:                        Key Lookup.          (line  55)
87321* list length:                           Sequence Functions.  (line  14)
87322* list modification:                     List Variables.      (line   6)
87323* list motion:                           List Motion.         (line   6)
87324* list of threads:                       The Thread List.     (line   6)
87325* list predicates:                       List-related Predicates.
87326                                                              (line   6)
87327* list reverse:                          Sequence Functions.  (line 116)
87328* list structure:                        Cons Cell Type.      (line  11)
87329* list structure <1>:                    Cons Cells.          (line  48)
87330* list to vector:                        Sequence Functions.  (line 597)
87331* list, replace element:                 Setcar.              (line   6)
87332* list-buffers-directory:                Buffer File Name.    (line 121)
87333* list-charset-chars:                    Character Sets.      (line  62)
87334* list-fonts:                            Low-Level Font.      (line 130)
87335* list-load-path-shadows:                Library Search.      (line 111)
87336* list-processes:                        Process Information. (line   8)
87337* list-system-processes:                 System Processes.    (line  15)
87338* list-threads:                          The Thread List.     (line   6)
87339* list-timers:                           Timers.              (line 142)
87340* listify-key-sequence:                  Event Input Misc.    (line  46)
87341* listing all buffers:                   Buffer List.         (line   6)
87342* listp:                                 List-related Predicates.
87343                                                              (line  22)
87344* lists:                                 Lists.               (line   6)
87345* lists and cons cells:                  Cons Cells.          (line   6)
87346* lists as sets:                         Sets And Lists.      (line   6)
87347* literal evaluation:                    Self-Evaluating Forms.
87348                                                              (line   6)
87349* literal in rx:                         Rx Constructs.       (line 381)
87350* literate programming:                  Mode-Specific Indent.
87351                                                              (line  74)
87352* little endian:                         Bindat Spec.         (line  13)
87353* live buffer:                           Killing Buffers.     (line  26)
87354* live windows:                          Basic Windows.       (line  32)
87355* ln:                                    Changing Files.      (line 152)
87356* load:                                  How Programs Do Loading.
87357                                                              (line  13)
87358* load error with require:               Named Features.      (line  17)
87359* load errors:                           How Programs Do Loading.
87360                                                              (line  98)
87361* load, customization keyword:           Common Keywords.     (line  95)
87362* load-average:                          System Environment.  (line 174)
87363* load-file:                             How Programs Do Loading.
87364                                                              (line 112)
87365* load-file-name:                        How Programs Do Loading.
87366                                                              (line 129)
87367* load-file-rep-suffixes:                Load Suffixes.       (line  16)
87368* load-history:                          Where Defined.       (line  20)
87369* load-in-progress:                      How Programs Do Loading.
87370                                                              (line 125)
87371* load-library:                          How Programs Do Loading.
87372                                                              (line 120)
87373* load-path:                             Library Search.      (line   9)
87374* load-prefer-newer:                     Load Suffixes.       (line  46)
87375* load-read-function:                    How Programs Do Loading.
87376                                                              (line 134)
87377* load-suffixes:                         Load Suffixes.       (line   9)
87378* load-theme:                            Custom Themes.       (line  84)
87379* loading:                               Loading.             (line   6)
87380* loading hooks:                         Hooks for Loading.   (line   6)
87381* loading, and non-ASCII characters:     Loading Non-ASCII.   (line   6)
87382* loadup.el:                             Building Emacs.      (line  18)
87383* local binding:                         Local Variables.     (line   6)
87384* local keymap:                          Active Keymaps.      (line  26)
87385* local part of remote file name:        Magic File Names.    (line 214)
87386* local variables:                       Local Variables.     (line   6)
87387* local variables, killed by major mode: Creating Buffer-Local.
87388                                                              (line 165)
87389* local, defcustom keyword:              Variable Definitions.
87390                                                              (line 140)
87391* local-abbrev-table:                    Standard Abbrev Tables.
87392                                                              (line  15)
87393* local-function-key-map:                Translation Keymaps. (line  44)
87394* local-key-binding:                     Functions for Key Lookup.
87395                                                              (line  55)
87396* local-map (overlay property):          Overlay Properties.  (line 231)
87397* local-map (text property):             Special Properties.  (line 140)
87398* local-set-key:                         Key Binding Commands.
87399                                                              (line  73)
87400* local-unset-key:                       Key Binding Commands.
87401                                                              (line  81)
87402* local-variable-if-set-p:               Creating Buffer-Local.
87403                                                              (line 105)
87404* local-variable-p:                      Creating Buffer-Local.
87405                                                              (line 101)
87406* locale:                                Locales.             (line   6)
87407* locale-coding-system:                  Locales.             (line  10)
87408* locale-dependent string comparison:    Text Comparison.     (line 143)
87409* locale-dependent string equivalence:   Text Comparison.     (line  55)
87410* locale-info:                           Locales.             (line  31)
87411* locate file in path:                   Locating Files.      (line   6)
87412* locate-dominating-file:                Contents of Directories.
87413                                                              (line  69)
87414* locate-file:                           Locating Files.      (line  13)
87415* locate-library:                        Library Search.      (line  96)
87416* locate-user-emacs-file:                Standard File Names. (line  16)
87417* lock file:                             File Locks.          (line   6)
87418* lock-buffer:                           File Locks.          (line  40)
87419* log:                                   Math Functions.      (line  34)
87420* logand:                                Bitwise Operations.  (line  90)
87421* logb:                                  Float Basics.        (line  82)
87422* logcount:                              Bitwise Operations.  (line 173)
87423* logging echo-area messages:            Logging Messages.    (line   6)
87424* logical arithmetic:                    Bitwise Operations.  (line   6)
87425* logical order:                         Bidirectional Display.
87426                                                              (line  17)
87427* logical shift:                         Bitwise Operations.  (line  66)
87428* logior:                                Bitwise Operations.  (line 126)
87429* lognot:                                Bitwise Operations.  (line 162)
87430* logxor:                                Bitwise Operations.  (line 144)
87431* looking up abbrevs:                    Abbrev Expansion.    (line   6)
87432* looking up fonts:                      Font Lookup.         (line   6)
87433* looking-at:                            Regexp Search.       (line 119)
87434* looking-at-p:                          Regexp Search.       (line 172)
87435* looking-back:                          Regexp Search.       (line 141)
87436* lookup tables:                         Hash Tables.         (line   6)
87437* lookup-key:                            Functions for Key Lookup.
87438                                                              (line   8)
87439* loops, infinite:                       Infinite Loops.      (line   6)
87440* lower case:                            Case Conversion.     (line   6)
87441* lower-frame:                           Raising and Lowering.
87442                                                              (line  32)
87443* lowering a frame:                      Raising and Lowering.
87444                                                              (line   6)
87445* LRO:                                   Bidirectional Display.
87446                                                              (line 215)
87447* lsh:                                   Bitwise Operations.  (line  65)
87448* lwarn:                                 Warning Basics.      (line  47)
87449* M-g:                                   Prefix Keys.         (line  46)
87450* M-o:                                   Prefix Keys.         (line  50)
87451* M-s:                                   Prefix Keys.         (line  48)
87452* M-x:                                   Interactive Call.    (line 109)
87453* Maclisp:                               Lisp History.        (line  11)
87454* macro:                                 What Is a Function.  (line  57)
87455* macro argument evaluation:             Argument Evaluation. (line  55)
87456* macro call:                            Expansion.           (line   6)
87457* macro call evaluation:                 Macro Forms.         (line   6)
87458* macro caveats:                         Problems with Macros.
87459                                                              (line   6)
87460* macro compilation:                     Compilation Functions.
87461                                                              (line  18)
87462* macro descriptions:                    A Sample Function Description.
87463                                                              (line   6)
87464* macro expansion:                       Expansion.           (line  41)
87465* macro, how to define:                  Defining Macros.     (line   6)
87466* macroexpand:                           Expansion.           (line  40)
87467* macroexpand-1:                         Expansion.           (line  84)
87468* macroexpand-all:                       Expansion.           (line  72)
87469* macrop:                                Simple Macro.        (line  20)
87470* macros:                                Macros.              (line   6)
87471* macros, at compile time:               Eval During Compile. (line  48)
87472* magic autoload comment:                Autoload.            (line 109)
87473* magic file names:                      Magic File Names.    (line   6)
87474* magic-fallback-mode-alist:             Auto Major Mode.     (line  99)
87475* magic-mode-alist:                      Auto Major Mode.     (line  91)
87476* mail-host-address:                     System Environment.  (line  73)
87477* main window:                           Side Windows.        (line   6)
87478* main window of a frame:                Side Windows.        (line   6)
87479* main-thread:                           Basic Thread Functions.
87480                                                              (line  76)
87481* major mode:                            Major Modes.         (line   6)
87482* major mode command:                    Major Modes.         (line   6)
87483* major mode conventions:                Major Mode Conventions.
87484                                                              (line   6)
87485* major mode hook:                       Major Mode Conventions.
87486                                                              (line 169)
87487* major mode keymap:                     Active Keymaps.      (line  32)
87488* major mode, automatic selection:       Auto Major Mode.     (line   6)
87489* major-mode:                            Major Modes.         (line  54)
87490* major-mode-restore:                    Major Modes.         (line  35)
87491* major-mode-suspend:                    Major Modes.         (line  25)
87492* make-abbrev-table:                     Abbrev Tables.       (line   8)
87493* make-auto-save-file-name:              Auto-Saving.         (line  57)
87494* make-backup-file-name:                 Backup Names.        (line  35)
87495* make-backup-file-name-function:        Making Backups.      (line  90)
87496* make-backup-files:                     Making Backups.      (line  29)
87497* make-bool-vector:                      Bool-Vectors.        (line  17)
87498* make-button:                           Making Buttons.      (line  31)
87499* make-byte-code:                        Byte-Code Objects.   (line  63)
87500* make-category-set:                     Categories.          (line 102)
87501* make-category-table:                   Categories.          (line  97)
87502* make-char-table:                       Char-Tables.         (line  38)
87503* make-composed-keymap:                  Inheritance and Keymaps.
87504                                                              (line  56)
87505* make-condition-variable:               Condition Variables. (line  30)
87506* make-decoded-time:                     Time Conversion.     (line 155)
87507* make-directory:                        Create/Delete Dirs.  (line  11)
87508* make-display-table:                    Display Tables.      (line  11)
87509* make-empty-file:                       Create/Delete Dirs.  (line  17)
87510* make-finalizer:                        Finalizer Type.      (line  19)
87511* make-frame:                            Creating Frames.     (line   8)
87512* make-frame-invisible:                  Visibility of Frames.
87513                                                              (line  47)
87514* make-frame-on-display:                 Multiple Terminals.  (line 106)
87515* make-frame-on-monitor:                 Multiple Terminals.  (line 226)
87516* make-frame-visible:                    Visibility of Frames.
87517                                                              (line  38)
87518* make-frame-visible event:              Misc Events.         (line  23)
87519* make-glyph-code:                       Glyphs.              (line  13)
87520* make-hash-table:                       Creating Hash.       (line   8)
87521* make-help-screen:                      Help Functions.      (line 156)
87522* make-indirect-buffer:                  Indirect Buffers.    (line  31)
87523* make-keymap:                           Creating Keymaps.    (line  25)
87524* make-list:                             Building Lists.      (line  47)
87525* make-local-variable:                   Creating Buffer-Local.
87526                                                              (line   6)
87527* make-marker:                           Creating Markers.    (line  14)
87528* make-mutex:                            Mutexes.             (line  22)
87529* make-nearby-temp-file:                 Unique File Names.   (line 101)
87530* make-network-process:                  Network Processes.   (line  10)
87531* make-obsolete:                         Obsolete Functions.  (line  23)
87532* make-obsolete-variable:                Variable Aliases.    (line  35)
87533* make-overlay:                          Managing Overlays.   (line  14)
87534* make-pipe-process:                     Asynchronous Processes.
87535                                                              (line 153)
87536* make-process:                          Asynchronous Processes.
87537                                                              (line  29)
87538* make-progress-reporter:                Progress.            (line  21)
87539* make-record:                           Record Functions.    (line  19)
87540* make-ring:                             Rings.               (line  15)
87541* make-serial-process:                   Serial Ports.        (line  44)
87542* make-sparse-keymap:                    Creating Keymaps.    (line   8)
87543* make-string:                           Creating Strings.    (line  12)
87544* make-symbol:                           Creating Symbols.    (line  83)
87545* make-symbolic-link:                    Changing Files.      (line 150)
87546* make-syntax-table:                     Syntax Table Functions.
87547                                                              (line   9)
87548* make-temp-file:                        Unique File Names.   (line  14)
87549* make-temp-name:                        Unique File Names.   (line  84)
87550* make-text-button:                      Making Buttons.      (line  46)
87551* make-thread:                           Basic Thread Functions.
87552                                                              (line  10)
87553* make-translation-table:                Translation of Characters.
87554                                                              (line  18)
87555* make-translation-table-from-alist:     Translation of Characters.
87556                                                              (line  78)
87557* make-translation-table-from-vector:    Translation of Characters.
87558                                                              (line  64)
87559* make-variable-buffer-local:            Creating Buffer-Local.
87560                                                              (line  58)
87561* make-vector:                           Vector Functions.    (line  25)
87562* make-xwidget:                          Xwidgets.            (line  16)
87563* make_big_integer:                      Module Values.       (line 176)
87564* make_float:                            Module Values.       (line 294)
87565* make_function:                         Module Functions.    (line  45)
87566* make_global_ref:                       Module Values.       (line 334)
87567* make_integer:                          Module Values.       (line 169)
87568* make_string:                           Module Values.       (line 310)
87569* make_time:                             Module Values.       (line 298)
87570* make_user_ptr:                         Module Values.       (line 354)
87571* making backup files:                   Making Backups.      (line   6)
87572* making buttons:                        Making Buttons.      (line   6)
87573* makunbound:                            Void Variables.      (line  23)
87574* malicious use of directional overrides: Bidirectional Display.
87575                                                              (line 225)
87576* managing overlays:                     Managing Overlays.   (line   6)
87577* manipulating buttons:                  Manipulating Buttons.
87578                                                              (line   6)
87579* map-char-table:                        Char-Tables.         (line 117)
87580* map-charset-chars:                     Character Sets.      (line  90)
87581* map-keymap:                            Scanning Keymaps.    (line  64)
87582* map-y-or-n-p:                          Multiple Queries.    (line  15)
87583* mapatoms:                              Creating Symbols.    (line 148)
87584* mapbacktrace:                          Internals of Debugger.
87585                                                              (line 135)
87586* mapc:                                  Mapping Functions.   (line  67)
87587* mapcan:                                Mapping Functions.   (line  52)
87588* mapcar:                                Mapping Functions.   (line  19)
87589* mapconcat:                             Mapping Functions.   (line  72)
87590* maphash:                               Hash Access.         (line  36)
87591* mapped frame:                          Visibility of Frames.
87592                                                              (line  14)
87593* mapping functions:                     Mapping Functions.   (line   6)
87594* margins, display:                      Display Margins.     (line   6)
87595* margins, filling:                      Margins.             (line   6)
87596* mark:                                  The Mark.            (line  52)
87597* mark excursion:                        Excursions.          (line  59)
87598* mark ring:                             The Mark.            (line  41)
87599* mark, the:                             The Mark.            (line   6)
87600* mark-active:                           The Mark.            (line 167)
87601* mark-even-if-inactive:                 The Mark.            (line 140)
87602* mark-marker:                           The Mark.            (line  61)
87603* mark-ring:                             The Mark.            (line 197)
87604* mark-ring-max:                         The Mark.            (line 206)
87605* marker argument:                       Interactive Codes.   (line 141)
87606* marker creation:                       Creating Markers.    (line   6)
87607* marker garbage collection:             Overview of Markers. (line  31)
87608* marker information:                    Information from Markers.
87609                                                              (line   6)
87610* marker input stream:                   Input Streams.       (line  16)
87611* marker output stream:                  Output Streams.      (line  15)
87612* marker relocation:                     Overview of Markers. (line  24)
87613* marker, how to move position:          Moving Markers.      (line   6)
87614* marker-buffer:                         Information from Markers.
87615                                                              (line  13)
87616* marker-insertion-type:                 Marker Insertion Types.
87617                                                              (line  19)
87618* marker-position:                       Information from Markers.
87619                                                              (line   9)
87620* markerp:                               Predicates on Markers.
87621                                                              (line  10)
87622* markers:                               Markers.             (line   6)
87623* markers as numbers:                    Overview of Markers. (line  38)
87624* markers, predicates for:               Predicates on Markers.
87625                                                              (line   6)
87626* match data:                            Match Data.          (line   6)
87627* match, customization keyword:          Type Keywords.       (line 106)
87628* match-alternatives, customization keyword: Composite Types. (line 285)
87629* match-beginning:                       Simple Match Data.   (line  57)
87630* match-data:                            Entire Match Data.   (line   9)
87631* match-end:                             Simple Match Data.   (line  70)
87632* match-inline, customization keyword:   Type Keywords.       (line 112)
87633* match-string:                          Simple Match Data.   (line  35)
87634* match-string-no-properties:            Simple Match Data.   (line  53)
87635* match-substitute-replacement:          Replacing Match.     (line  69)
87636* matching, structural:                  Backquote Patterns.  (line   6)
87637* mathematical functions:                Math Functions.      (line   6)
87638* max:                                   Comparison of Numbers.
87639                                                              (line  73)
87640* max-char:                              Character Codes.     (line  32)
87641* max-image-size:                        Showing Images.      (line  80)
87642* max-lisp-eval-depth:                   Eval.                (line 100)
87643* max-mini-window-height:                Minibuffer Windows.  (line  62)
87644* max-specpdl-size:                      Local Variables.     (line 129)
87645* maximal-match in rx:                   Rx Constructs.       (line 115)
87646* maximize-window:                       Resizing Windows.    (line 221)
87647* maximized frames:                      Size Parameters.     (line  84)
87648* maximizing windows:                    Resizing Windows.    (line 221)
87649* maximum fixnum:                        Integer Basics.      (line  86)
87650* maximum value of character codepoint:  Character Codes.     (line  32)
87651* maximum value of sequence:             Sequence Functions.  (line 618)
87652* maximum-scroll-margin:                 Textual Scrolling.   (line 114)
87653* maybe_quit, use in Lisp primitives:    Writing Emacs Primitives.
87654                                                              (line 173)
87655* md5:                                   Checksum/Hash.       (line  50)
87656* MD5 checksum:                          Checksum/Hash.       (line   6)
87657* MD5 checksum <1>:                      GnuTLS Cryptography. (line   6)
87658* measuring resource usage:              Profiling.           (line   6)
87659* member:                                Sets And Lists.      (line 109)
87660* member-ignore-case:                    Sets And Lists.      (line 172)
87661* membership in a list:                  Sets And Lists.      (line  19)
87662* memory allocation:                     Garbage Collection.  (line   6)
87663* memory usage:                          Profiling.           (line   6)
87664* memory usage <1>:                      Memory Usage.        (line   6)
87665* memory-full:                           Garbage Collection.  (line 272)
87666* memory-info:                           Garbage Collection.  (line 282)
87667* memory-limit:                          Garbage Collection.  (line 266)
87668* memory-use-counts:                     Garbage Collection.  (line 276)
87669* memq:                                  Sets And Lists.      (line  18)
87670* memql:                                 Sets And Lists.      (line  91)
87671* menu bar:                              Menu Bar.            (line   6)
87672* menu bar keymaps:                      Standard Keymaps.    (line  92)
87673* menu definition example:               Menu Example.        (line   6)
87674* menu item:                             Defining Menus.      (line   6)
87675* menu keymaps:                          Menu Keymaps.        (line   6)
87676* menu modification:                     Modifying Menus.     (line   6)
87677* menu prompt string:                    Defining Menus.      (line   6)
87678* menu separators:                       Menu Separators.     (line   6)
87679* menu-bar, prefix key:                  Key Sequence Input.  (line  92)
87680* menu-bar-file-menu:                    Standard Keymaps.    (line  92)
87681* menu-bar-final-items:                  Menu Bar.            (line  52)
87682* menu-bar-help-menu:                    Standard Keymaps.    (line  92)
87683* menu-bar-lines, a frame parameter:     Layout Parameters.   (line  56)
87684* menu-bar-options-menu:                 Standard Keymaps.    (line  92)
87685* menu-bar-tools-menu:                   Standard Keymaps.    (line  92)
87686* menu-bar-update-hook:                  Menu Bar.            (line  62)
87687* menu-item:                             Extended Menu Items. (line   6)
87688* menu-prompt-more-char:                 Keyboard Menus.      (line  23)
87689* menus, popup:                          Pop-Up Menus.        (line   6)
87690* merge-face-attribute:                  Attribute Functions. (line  62)
87691* message:                               Displaying Messages. (line   9)
87692* message digest:                        Checksum/Hash.       (line  11)
87693* message, finding what causes a particular message: Error Debugging.
87694                                                              (line  93)
87695* message-box:                           Displaying Messages. (line 108)
87696* message-log-max:                       Logging Messages.    (line  19)
87697* message-or-box:                        Displaying Messages. (line  95)
87698* message-truncate-lines:                Echo Area Customization.
87699                                                              (line  32)
87700* messages-buffer:                       Logging Messages.    (line  15)
87701* meta character key constants:          Changing Key Bindings.
87702                                                              (line  20)
87703* meta character printing:               Describing Characters.
87704                                                              (line  29)
87705* meta characters:                       Meta-Char Syntax.    (line   6)
87706* meta characters lookup:                Format of Keymaps.   (line  73)
87707* meta-prefix-char:                      Functions for Key Lookup.
87708                                                              (line  85)
87709* min:                                   Comparison of Numbers.
87710                                                              (line  83)
87711* min-height, a frame parameter:         Size Parameters.     (line  74)
87712* min-margins, a window parameter:       Window Parameters.   (line 158)
87713* min-width, a frame parameter:          Size Parameters.     (line  64)
87714* minibuffer:                            Minibuffers.         (line   6)
87715* minibuffer completion:                 Minibuffer Completion.
87716                                                              (line   6)
87717* minibuffer contents, accessing:        Minibuffer Contents. (line   6)
87718* minibuffer history:                    Minibuffer History.  (line   6)
87719* minibuffer input:                      Recursive Editing.   (line  25)
87720* minibuffer input, and command-line arguments: Shell Arguments.
87721                                                              (line  40)
87722* minibuffer input, reading lisp objects: Object from Minibuffer.
87723                                                              (line   6)
87724* minibuffer input, reading text strings: Text from Minibuffer.
87725                                                              (line   6)
87726* minibuffer window, and next-window:    Cyclic Window Ordering.
87727                                                              (line  18)
87728* minibuffer windows:                    Minibuffer Windows.  (line   6)
87729* minibuffer, a frame parameter:         Buffer Parameters.   (line   9)
87730* minibuffer-allow-text-properties:      Text from Minibuffer.
87731                                                              (line 176)
87732* minibuffer-auto-raise:                 Raising and Lowering.
87733                                                              (line  66)
87734* minibuffer-beginning-of-buffer-movement: Completion Commands.
87735                                                              (line 130)
87736* minibuffer-complete:                   Completion Commands. (line  47)
87737* minibuffer-complete-and-exit:          Completion Commands. (line  50)
87738* minibuffer-complete-word:              Completion Commands. (line  40)
87739* minibuffer-completion-confirm:         Completion Commands. (line  21)
87740* minibuffer-completion-help:            Completion Commands. (line  58)
87741* minibuffer-completion-predicate:       Completion Commands. (line  16)
87742* minibuffer-completion-table:           Completion Commands. (line   9)
87743* minibuffer-confirm-exit-commands:      Completion Commands. (line  33)
87744* minibuffer-contents:                   Minibuffer Contents. (line  21)
87745* minibuffer-contents-no-properties:     Minibuffer Contents. (line  27)
87746* minibuffer-depth:                      Recursive Mini.      (line   9)
87747* minibuffer-exit, a frame parameter:    Frame Interaction Parameters.
87748                                                              (line  35)
87749* minibuffer-exit-hook:                  Minibuffer Misc.     (line  25)
87750* minibuffer-frame-alist:                Initial Parameters.  (line  41)
87751* minibuffer-help-form:                  Minibuffer Misc.     (line  29)
87752* minibuffer-history:                    Minibuffer History.  (line  92)
87753* minibuffer-inactive-mode:              Minibuffer Misc.     (line  52)
87754* minibuffer-less frame:                 Frame Layout.        (line 209)
87755* minibuffer-local-completion-map:       Completion Commands. (line  92)
87756* minibuffer-local-filename-completion-map: Completion Commands.
87757                                                              (line 124)
87758* minibuffer-local-map:                  Text from Minibuffer.
87759                                                              (line 186)
87760* minibuffer-local-must-match-map:       Completion Commands. (line 109)
87761* minibuffer-local-ns-map:               Text from Minibuffer.
87762                                                              (line 237)
87763* minibuffer-local-shell-command-map:    Reading File Names.  (line 187)
87764* minibuffer-message:                    Minibuffer Misc.     (line  43)
87765* minibuffer-message (text property):    Special Properties.  (line 382)
87766* minibuffer-message-timeout:            Minibuffer Misc.     (line  43)
87767* minibuffer-only frame:                 Frame Layout.        (line 209)
87768* minibuffer-only frame <1>:             Initial Parameters.  (line  37)
87769* minibuffer-prompt:                     Minibuffer Contents. (line   8)
87770* minibuffer-prompt-end:                 Minibuffer Contents. (line  12)
87771* minibuffer-prompt-properties:          Text from Minibuffer.
87772                                                              (line  67)
87773* minibuffer-prompt-width:               Minibuffer Contents. (line  17)
87774* minibuffer-scroll-window:              Minibuffer Misc.     (line  33)
87775* minibuffer-selected-window:            Minibuffer Misc.     (line  38)
87776* minibuffer-setup-hook:                 Minibuffer Misc.     (line  10)
87777* minibuffer-window:                     Minibuffer Windows.  (line   9)
87778* minibuffer-window-active-p:            Minibuffer Windows.  (line  43)
87779* minibuffer-with-setup-hook:            Minibuffer Misc.     (line  14)
87780* minibufferp:                           Minibuffer Misc.     (line   6)
87781* minimal-match in rx:                   Rx Constructs.       (line 111)
87782* minimize-window:                       Resizing Windows.    (line 226)
87783* minimized frame:                       Visibility of Frames.
87784                                                              (line   6)
87785* minimizing windows:                    Resizing Windows.    (line 226)
87786* minimum fixnum:                        Integer Basics.      (line  91)
87787* minimum value of sequence:             Sequence Functions.  (line 609)
87788* minor mode:                            Minor Modes.         (line   6)
87789* minor mode conventions:                Minor Mode Conventions.
87790                                                              (line   6)
87791* minor-mode-alist:                      Mode Line Variables. (line 104)
87792* minor-mode-key-binding:                Functions for Key Lookup.
87793                                                              (line  69)
87794* minor-mode-list:                       Minor Modes.         (line  21)
87795* minor-mode-map-alist:                  Controlling Active Maps.
87796                                                              (line  63)
87797* minor-mode-overriding-map-alist:       Controlling Active Maps.
87798                                                              (line  89)
87799* mirroring of characters:               Character Properties.
87800                                                              (line 101)
87801* mkdir:                                 Create/Delete Dirs.  (line  11)
87802* mod:                                   Arithmetic Operations.
87803                                                              (line 126)
87804* mode:                                  Modes.               (line   6)
87805* mode bits:                             Testing Accessibility.
87806                                                              (line  84)
87807* mode help:                             Mode Help.           (line   6)
87808* mode hook:                             Major Mode Conventions.
87809                                                              (line 169)
87810* mode line:                             Mode Line Format.    (line   6)
87811* mode line construct:                   Mode Line Data.      (line   6)
87812* mode loading:                          Major Mode Conventions.
87813                                                              (line 226)
87814* mode variable:                         Minor Mode Conventions.
87815                                                              (line  11)
87816* mode, a buffer display action alist entry: Buffer Display Action Alists.
87817                                                              (line  40)
87818* mode-class (property):                 Major Mode Conventions.
87819                                                              (line 197)
87820* mode-line, prefix key:                 Key Sequence Input.  (line  92)
87821* mode-line-buffer-identification:       Mode Line Variables. (line  35)
87822* mode-line-client:                      Mode Line Variables. (line  68)
87823* mode-line-coding-system-map:           Standard Keymaps.    (line 103)
87824* mode-line-column-line-number-mode-map: Standard Keymaps.    (line 103)
87825* mode-line-end-spaces:                  Mode Line Variables. (line  97)
87826* mode-line-format:                      Mode Line Top.       (line   8)
87827* mode-line-format, a window parameter:  Window Parameters.   (line 134)
87828* mode-line-frame-identification:        Mode Line Variables. (line  29)
87829* mode-line-front-space:                 Mode Line Variables. (line  91)
87830* mode-line-input-method-map:            Standard Keymaps.    (line 103)
87831* mode-line-misc-info:                   Mode Line Variables. (line 100)
87832* mode-line-modes:                       Mode Line Variables. (line  58)
87833* mode-line-modified:                    Mode Line Variables. (line  20)
87834* mode-line-mule-info:                   Mode Line Variables. (line  15)
87835* mode-line-percent-position:            Mode Line Variables. (line  45)
87836* mode-line-position:                    Mode Line Variables. (line  40)
87837* mode-line-process:                     Mode Line Variables. (line  82)
87838* mode-line-remote:                      Mode Line Variables. (line  64)
87839* mode-name:                             Mode Line Variables. (line  73)
87840* mode-specific-map:                     Prefix Keys.         (line  21)
87841* model/view/controller:                 Abstract Display.    (line   6)
87842* modification flag (of buffer):         Buffer Modification. (line   6)
87843* modification of lists:                 Rearrangement.       (line   6)
87844* modification time of buffer:           Modification Time.   (line   6)
87845* modification time of file:             File Attributes.     (line  73)
87846* modification-hooks (overlay property): Overlay Properties.  (line 135)
87847* modification-hooks (text property):    Special Properties.  (line 290)
87848* modifier bits (of input character):    Keyboard Events.     (line  13)
87849* modifiers of events:                   Event Mod.           (line   6)
87850* modify a list:                         List Variables.      (line   6)
87851* modify-all-frames-parameters:          Parameter Access.    (line  53)
87852* modify-category-entry:                 Categories.          (line 130)
87853* modify-frame-parameters:               Parameter Access.    (line  19)
87854* modify-syntax-entry:                   Syntax Table Functions.
87855                                                              (line  24)
87856* modifying strings:                     Modifying Strings.   (line   6)
87857* module API:                            Writing Dynamic Modules.
87858                                                              (line   6)
87859* module functions:                      Module Functions.    (line   6)
87860* module initialization:                 Module Initialization.
87861                                                              (line   6)
87862* module runtime environment:            Module Initialization.
87863                                                              (line  69)
87864* module values, conversion:             Module Values.       (line   6)
87865* module-file-suffix:                    Dynamic Modules.     (line  14)
87866* module-load:                           Dynamic Modules.     (line  44)
87867* module_func:                           Module Functions.    (line  12)
87868* modulus:                               Arithmetic Operations.
87869                                                              (line 127)
87870* momentary-string-display:              Temporary Displays.  (line 153)
87871* most recently selected windows:        Selecting Windows.   (line  63)
87872* most recently used window:             Cyclic Window Ordering.
87873                                                              (line 124)
87874* most-negative-fixnum:                  Integer Basics.      (line  91)
87875* most-positive-fixnum:                  Integer Basics.      (line  86)
87876* motion based on parsing:               Motion via Parsing.  (line   6)
87877* motion by chars, words, lines, lists:  Motion.              (line   6)
87878* motion event:                          Motion Events.       (line   6)
87879* mouse click event:                     Click Events.        (line   6)
87880* mouse drag event:                      Drag Events.         (line   6)
87881* mouse dragging parameters:             Mouse Dragging Parameters.
87882                                                              (line   6)
87883* mouse events, data in:                 Accessing Mouse.     (line   6)
87884* mouse events, in special parts of window or frame: Key Sequence Input.
87885                                                              (line  92)
87886* mouse events, repeated:                Repeat Events.       (line   6)
87887* mouse motion events:                   Motion Events.       (line   6)
87888* mouse pointer shape:                   Pointer Shape.       (line   6)
87889* mouse position:                        Mouse Position.      (line   6)
87890* mouse position list:                   Click Events.        (line  27)
87891* mouse position list, accessing:        Accessing Mouse.     (line  34)
87892* mouse tracking:                        Mouse Tracking.      (line   6)
87893* mouse, a face:                         Font and Color Parameters.
87894                                                              (line 104)
87895* mouse, availability:                   Display Feature Testing.
87896                                                              (line  32)
87897* mouse-1:                               Clickable Text.      (line   6)
87898* mouse-1-click-follows-link:            Clickable Text.      (line  77)
87899* mouse-2:                               Key Binding Conventions.
87900                                                              (line   6)
87901* mouse-absolute-pixel-position:         Mouse Position.      (line  51)
87902* mouse-action (button property):        Button Properties.   (line  17)
87903* mouse-appearance-menu-map:             Standard Keymaps.    (line 113)
87904* mouse-autoselect-window:               Mouse Window Auto-selection.
87905                                                              (line  12)
87906* mouse-color, a frame parameter:        Font and Color Parameters.
87907                                                              (line 104)
87908* mouse-face (button property):          Button Properties.   (line  27)
87909* mouse-face (overlay property):         Overlay Properties.  (line 110)
87910* mouse-face (text property):            Special Properties.  (line  69)
87911* mouse-fine-grained-tracking:           Motion Events.       (line  23)
87912* mouse-leave-buffer-hook:               Standard Hooks.      (line 160)
87913* mouse-movement-p:                      Classifying Events.  (line  92)
87914* mouse-on-link-p:                       Clickable Text.      (line 160)
87915* mouse-pixel-position:                  Mouse Position.      (line  36)
87916* mouse-position:                        Mouse Position.      (line   9)
87917* mouse-position-function:               Mouse Position.      (line  16)
87918* mouse-wheel-down-event:                Misc Events.         (line  35)
87919* mouse-wheel-frame, a frame parameter:  Frame Interaction Parameters.
87920                                                              (line  18)
87921* mouse-wheel-up-event:                  Misc Events.         (line  35)
87922* move to beginning or end of buffer:    Buffer End Motion.   (line   6)
87923* move-frame-functions:                  Frame Position.      (line  60)
87924* move-marker:                           Moving Markers.      (line  29)
87925* move-overlay:                          Managing Overlays.   (line  59)
87926* move-point-visually:                   Bidirectional Display.
87927                                                              (line 144)
87928* move-to-column:                        Columns.             (line  28)
87929* move-to-left-margin:                   Margins.             (line  56)
87930* move-to-window-group-line:             Screen Lines.        (line 100)
87931* move-to-window-group-line-function:    Screen Lines.        (line 100)
87932* move-to-window-line:                   Screen Lines.        (line  78)
87933* movemail:                              Subprocess Creation. (line  73)
87934* moveto:                                SVG Images.          (line 181)
87935* moving across syntax classes:          Motion and Syntax.   (line   6)
87936* moving markers:                        Moving Markers.      (line   6)
87937* MS-DOS and file modes:                 Testing Accessibility.
87938                                                              (line 111)
87939* MS-Windows file-name syntax:           File Names.          (line  19)
87940* mule-keymap:                           Prefix Keys.         (line  31)
87941* multi-file package:                    Multi-file Packages. (line   6)
87942* multi-frame images:                    Multi-Frame Images.  (line   6)
87943* multi-mode indentation:                Mode-Specific Indent.
87944                                                              (line  74)
87945* multi-monitor:                         Multiple Terminals.  (line 147)
87946* multi-query-replace-map:               Search and Replace.  (line 175)
87947* multi-tty:                             Multiple Terminals.  (line   6)
87948* multibyte characters:                  Non-ASCII Characters.
87949                                                              (line   6)
87950* multibyte text:                        Text Representations.
87951                                                              (line  20)
87952* multibyte-char-to-unibyte:             Converting Representations.
87953                                                              (line  63)
87954* multibyte-string-p:                    Text Representations.
87955                                                              (line 114)
87956* multibyte-syntax-as-symbol:            Control Parsing.     (line   6)
87957* multiline font lock:                   Multiline Font Lock. (line   6)
87958* multiple terminals:                    Multiple Terminals.  (line   6)
87959* multiple windows:                      Basic Windows.       (line  10)
87960* multiple X displays:                   Multiple Terminals.  (line   6)
87961* multiple yes-or-no questions:          Multiple Queries.    (line   9)
87962* multiple-dispatch methods:             Generic Functions.   (line 186)
87963* multiple-frames:                       Frame Titles.        (line  28)
87964* mutable lists:                         Modifying Lists.     (line   6)
87965* mutable objects:                       Mutability.          (line   6)
87966* mutex-lock:                            Mutexes.             (line  30)
87967* mutex-name:                            Mutexes.             (line  27)
87968* mutex-unlock:                          Mutexes.             (line  35)
87969* mutexp:                                Mutexes.             (line  18)
87970* name, a frame parameter:               Basic Parameters.    (line  27)
87971* named function:                        Function Names.      (line   6)
87972* naming backup files:                   Backup Names.        (line   6)
87973* NaN:                                   Float Basics.        (line  32)
87974* narrow-map:                            Standard Keymaps.    (line 119)
87975* narrow-to-page:                        Narrowing.           (line  35)
87976* narrow-to-region:                      Narrowing.           (line  27)
87977* narrowing:                             Narrowing.           (line   6)
87978* native edges:                          Frame Layout.        (line 151)
87979* native frame:                          Frame Layout.        (line 151)
87980* native height:                         Frame Layout.        (line 151)
87981* native position:                       Frame Layout.        (line 166)
87982* native size:                           Frame Layout.        (line 151)
87983* native width:                          Frame Layout.        (line 151)
87984* natnump:                               Predicates on Numbers.
87985                                                              (line  35)
87986* natural numbers:                       Predicates on Numbers.
87987                                                              (line  36)
87988* nbutlast:                              List Elements.       (line 159)
87989* nconc:                                 Rearrangement.       (line  15)
87990* negative infinity:                     Float Basics.        (line  32)
87991* negative-argument:                     Prefix Command Arguments.
87992                                                              (line 113)
87993* nest frame:                            Child Frames.        (line  25)
87994* network byte ordering:                 Bindat Spec.         (line  13)
87995* network connection:                    Network.             (line   6)
87996* network connection, encrypted:         Network.             (line  55)
87997* network servers:                       Network Servers.     (line   6)
87998* network service name, and default coding system: Default Coding Systems.
87999                                                              (line  80)
88000* network-coding-system-alist:           Default Coding Systems.
88001                                                              (line  80)
88002* network-interface-info:                Misc Network.        (line  67)
88003* network-interface-list:                Misc Network.        (line   9)
88004* network-lookup-address-info:           Misc Network.        (line 100)
88005* network-stream-use-client-certificates: Network.            (line 142)
88006* new file message:                      Subroutines of Visiting.
88007                                                              (line  39)
88008* newline:                               Basic Char Syntax.   (line  27)
88009* newline <1>:                           Commands for Insertion.
88010                                                              (line  53)
88011* newline and Auto Fill mode:            Commands for Insertion.
88012                                                              (line  59)
88013* newline in print:                      Output Functions.    (line  86)
88014* newline in strings:                    Syntax for Strings.  (line  13)
88015* newline-and-indent:                    Mode-Specific Indent.
88016                                                              (line  52)
88017* next input:                            Event Input Misc.    (line  11)
88018* next-button:                           Button Buffer Commands.
88019                                                              (line  52)
88020* next-char-property-change:             Property Search.     (line  82)
88021* next-complete-history-element:         Minibuffer Commands. (line  42)
88022* next-frame:                            Finding All Frames.  (line  33)
88023* next-history-element:                  Minibuffer Commands. (line  21)
88024* next-matching-history-element:         Minibuffer Commands. (line  32)
88025* next-overlay-change:                   Finding Overlays.    (line  34)
88026* next-property-change:                  Property Search.     (line  25)
88027* next-screen-context-lines:             Textual Scrolling.   (line 178)
88028* next-single-char-property-change:      Property Search.     (line  97)
88029* next-single-property-change:           Property Search.     (line  58)
88030* next-window:                           Cyclic Window Ordering.
88031                                                              (line  17)
88032* nil:                                   nil and t.           (line   6)
88033* nil as a list:                         Box Diagrams.        (line  41)
88034* nil in keymap:                         Key Lookup.          (line  36)
88035* nil input stream:                      Input Streams.       (line  51)
88036* nil output stream:                     Output Streams.      (line  36)
88037* nlistp:                                List-related Predicates.
88038                                                              (line  31)
88039* no-accept-focus, a frame parameter:    Management Parameters.
88040                                                              (line  72)
88041* no-byte-compile:                       Byte Compilation.    (line  21)
88042* no-catch:                              Catch and Throw.     (line  86)
88043* no-conversion coding system:           Coding System Basics.
88044                                                              (line  62)
88045* no-delete-other-windows, a window parameter: Window Parameters.
88046                                                              (line  88)
88047* no-focus-on-map, a frame parameter:    Management Parameters.
88048                                                              (line  67)
88049* no-other-frame, a frame parameter:     Frame Interaction Parameters.
88050                                                              (line  24)
88051* no-other-window, a window parameter:   Window Parameters.   (line 100)
88052* no-redraw-on-reenter:                  Refresh Screen.      (line  30)
88053* no-self-insert property:               Defining Abbrevs.    (line  34)
88054* no-special-glyphs, a frame parameter:  Layout Parameters.   (line  81)
88055* node, ewoc:                            Abstract Display.    (line  24)
88056* non-ASCII characters:                  Non-ASCII Characters.
88057                                                              (line   6)
88058* non-ASCII characters in loaded files:  Loading Non-ASCII.   (line   6)
88059* non-ASCII text in keybindings:         Key Binding Commands.
88060                                                              (line  29)
88061* non-capturing group:                   Regexp Backslash.    (line  67)
88062* non-greedy repetition characters in regexp: Regexp Special. (line  56)
88063* nondirectory part (of file name):      File Name Components.
88064                                                              (line   6)
88065* noninteractive:                        Batch Mode.          (line  32)
88066* nonl in rx:                            Rx Constructs.       (line 151)
88067* nonlocal exits:                        Nonlocal Exits.      (line   6)
88068* nonlocal exits, cleaning up:           Cleanups.            (line   6)
88069* nonlocal exits, in modules:            Module Nonlocal.     (line   6)
88070* nonprinting characters, reading:       Quoted Character Input.
88071                                                              (line  12)
88072* non_local_exit_clear:                  Module Nonlocal.     (line  79)
88073* non_local_exit_signal:                 Module Nonlocal.     (line  96)
88074* non_local_exit_throw:                  Module Nonlocal.     (line  88)
88075* noreturn:                              Test Coverage.       (line  29)
88076* normal hook:                           Hooks.               (line  12)
88077* normal-auto-fill-function:             Auto Filling.        (line  25)
88078* normal-backup-enable-predicate:        Making Backups.      (line  51)
88079* normal-mode:                           Auto Major Mode.     (line  10)
88080* not:                                   Combining Conditions.
88081                                                              (line  11)
88082* not in rx:                             Rx Constructs.       (line 137)
88083* not recording input events:            Event Input Misc.    (line  40)
88084* not-modified:                          Buffer Modification. (line  41)
88085* not-newline in rx:                     Rx Constructs.       (line 151)
88086* not-word-boundary in rx:               Rx Constructs.       (line 344)
88087* notation:                              Evaluation Notation. (line   6)
88088* notifications, on desktop:             Desktop Notifications.
88089                                                              (line   6)
88090* notifications-close-notification:      Desktop Notifications.
88091                                                              (line 167)
88092* notifications-get-capabilities:        Desktop Notifications.
88093                                                              (line 171)
88094* notifications-get-server-information:  Desktop Notifications.
88095                                                              (line 208)
88096* notifications-notify:                  Desktop Notifications.
88097                                                              (line  13)
88098* nreverse:                              Sequence Functions.  (line 140)
88099* ns-appearance, a frame parameter:      Management Parameters.
88100                                                              (line 104)
88101* ns-transparent-titlebar, a frame parameter: Management Parameters.
88102                                                              (line 111)
88103* nth:                                   List Elements.       (line  85)
88104* nthcdr:                                List Elements.       (line 101)
88105* null:                                  List-related Predicates.
88106                                                              (line  37)
88107* null bytes, and decoding text:         Lisp and Coding Systems.
88108                                                              (line 122)
88109* num-input-keys:                        Key Sequence Input.  (line 114)
88110* num-nonmacro-input-events:             Reading One Event.   (line 112)
88111* number comparison:                     Comparison of Numbers.
88112                                                              (line   6)
88113* number conversions:                    Numeric Conversions. (line   6)
88114* number of bignum bits, limit on:       Integer Basics.      (line  96)
88115* number-or-marker-p:                    Predicates on Markers.
88116                                                              (line  19)
88117* number-sequence:                       Building Lists.      (line 167)
88118* number-to-string:                      String Conversion.   (line  19)
88119* numbered backups:                      Numbered Backups.    (line   6)
88120* numberp:                               Predicates on Numbers.
88121                                                              (line  31)
88122* numbers:                               Numbers.             (line   6)
88123* numeric prefix argument:               Prefix Command Arguments.
88124                                                              (line   6)
88125* numeric prefix argument usage:         Interactive Codes.   (line 159)
88126* numerical RGB color specification:     Color Names.         (line   6)
88127* obarray:                               Creating Symbols.    (line 144)
88128* obarray <1>:                           Creating Symbols.    (line  11)
88129* obarray in completion:                 Basic Completion.    (line  31)
88130* object:                                Lisp Data Types.     (line   6)
88131* object internals:                      Object Internals.    (line   6)
88132* object to string:                      Output Functions.    (line  96)
88133* objects with identical contents, and byte-compiler: Equality Predicates.
88134                                                              (line  73)
88135* obsolete functions:                    Obsolete Functions.  (line   6)
88136* octal character code:                  General Escape Syntax.
88137                                                              (line  34)
88138* octal character input:                 Quoted Character Input.
88139                                                              (line  12)
88140* octal escapes:                         Usual Display.       (line  38)
88141* octal numbers:                         Integer Basics.      (line  16)
88142* old advices, porting:                  Porting Old Advice.  (line   6)
88143* old-selected-frame:                    Window Hooks.        (line 251)
88144* old-selected-window:                   Window Hooks.        (line 247)
88145* one-or-more in rx:                     Rx Constructs.       (line  58)
88146* one-window-p:                          Cyclic Window Ordering.
88147                                                              (line  98)
88148* only-global-abbrevs:                   Defining Abbrevs.    (line  47)
88149* opacity, frame:                        Font and Color Parameters.
88150                                                              (line  66)
88151* open-dribble-file:                     Recording Input.     (line  24)
88152* open-network-stream:                   Network.             (line  67)
88153* open-paren-in-column-0-is-defun-start: List Motion.         (line  81)
88154* open-termscript:                       Terminal Output.     (line  49)
88155* OpenType font:                         Low-Level Font.      (line  97)
88156* operating system environment:          System Environment.  (line   6)
88157* operating system signal:               Killing Emacs.       (line  26)
88158* operations (property):                 Magic File Names.    (line 132)
88159* opt in rx:                             Rx Constructs.       (line  65)
88160* optimize regexp:                       Regexp Functions.    (line  32)
88161* option descriptions:                   A Sample Variable Description.
88162                                                              (line   6)
88163* optional arguments:                    Argument List.       (line  18)
88164* optional in rx:                        Rx Constructs.       (line  64)
88165* options on command line:               Command-Line Arguments.
88166                                                              (line  29)
88167* options, defcustom keyword:            Variable Definitions.
88168                                                              (line  67)
88169* or:                                    Combining Conditions.
88170                                                              (line  59)
88171* or in rx:                              Rx Constructs.       (line  33)
88172* ordering of windows, cyclic:           Cyclic Window Ordering.
88173                                                              (line   6)
88174* origin of display:                     Frame Layout.        (line 229)
88175* other-buffer:                          Buffer List.         (line  67)
88176* other-window:                          Cyclic Window Ordering.
88177                                                              (line  63)
88178* other-window, a window parameter:      Window Parameters.   (line  96)
88179* other-window-scroll-buffer:            Textual Scrolling.   (line 102)
88180* outer border:                          Frame Layout.        (line  82)
88181* outer edges:                           Frame Layout.        (line  36)
88182* outer frame:                           Frame Layout.        (line  36)
88183* outer height:                          Frame Layout.        (line  36)
88184* outer position:                        Frame Layout.        (line  53)
88185* outer size:                            Frame Layout.        (line  36)
88186* outer width:                           Frame Layout.        (line  36)
88187* outer-window-id, a frame parameter:    Management Parameters.
88188                                                              (line  38)
88189* output from processes:                 Output from Processes.
88190                                                              (line   6)
88191* output stream:                         Output Streams.      (line   6)
88192* output-controlling variables:          Output Variables.    (line   6)
88193* overall prompt string:                 Format of Keymaps.   (line  57)
88194* overflow-newline-into-fringe:          Fringe Cursors.      (line  11)
88195* overlay properties:                    Overlay Properties.  (line   6)
88196* overlay, empty:                        Managing Overlays.   (line  21)
88197* overlay-arrow-position:                Overlay Arrow.       (line  19)
88198* overlay-arrow-string:                  Overlay Arrow.       (line  12)
88199* overlay-arrow-variable-list:           Overlay Arrow.       (line  40)
88200* overlay-buffer:                        Managing Overlays.   (line  46)
88201* overlay-end:                           Managing Overlays.   (line  42)
88202* overlay-get:                           Overlay Properties.  (line  26)
88203* overlay-properties:                    Overlay Properties.  (line  37)
88204* overlay-put:                           Overlay Properties.  (line  33)
88205* overlay-recenter:                      Managing Overlays.   (line 148)
88206* overlay-start:                         Managing Overlays.   (line  38)
88207* overlayp:                              Managing Overlays.   (line  11)
88208* overlays:                              Overlays.            (line   6)
88209* overlays, managing:                    Managing Overlays.   (line   6)
88210* overlays, scalability:                 Overlays.            (line  12)
88211* overlays, searching for:               Finding Overlays.    (line   6)
88212* overlays-at:                           Finding Overlays.    (line   6)
88213* overlays-in:                           Finding Overlays.    (line  26)
88214* overlined text:                        Face Attributes.     (line 107)
88215* override existing functions:           Defining Functions.  (line  48)
88216* override redirect frames:              Management Parameters.
88217                                                              (line  97)
88218* override spec (for a face):            Defining Faces.      (line 155)
88219* override-redirect, a frame parameter:  Management Parameters.
88220                                                              (line  96)
88221* overriding bidirectional properties:   Bidirectional Display.
88222                                                              (line 215)
88223* overriding-local-map:                  Controlling Active Maps.
88224                                                              (line 102)
88225* overriding-local-map-menu-flag:        Controlling Active Maps.
88226                                                              (line 118)
88227* overriding-terminal-local-map:         Controlling Active Maps.
88228                                                              (line 109)
88229* overwrite-mode:                        Commands for Insertion.
88230                                                              (line  75)
88231* package:                               Packaging.           (line   6)
88232* package archive:                       Package Archives.    (line   6)
88233* package archive security:              Package Archives.    (line  42)
88234* package attributes:                    Packaging Basics.    (line   6)
88235* package autoloads:                     Packaging Basics.    (line  55)
88236* package dependencies:                  Packaging Basics.    (line   6)
88237* package name:                          Packaging Basics.    (line   6)
88238* package signing:                       Package Archives.    (line  42)
88239* package version:                       Packaging Basics.    (line   6)
88240* package-activate-all:                  Packaging Basics.    (line  77)
88241* package-archives:                      Package Archives.    (line  12)
88242* package-initialize:                    Packaging Basics.    (line  89)
88243* package-version, customization keyword: Common Keywords.    (line 114)
88244* packing:                               Byte Packing.        (line  13)
88245* padding:                               Formatting Strings.  (line 202)
88246* page-delimiter:                        Standard Regexps.    (line   9)
88247* paragraph-separate:                    Standard Regexps.    (line  24)
88248* paragraph-separate, and bidirectional display: Bidirectional Display.
88249                                                              (line  85)
88250* paragraph-start:                       Standard Regexps.    (line  31)
88251* paragraph-start, and bidirectional display: Bidirectional Display.
88252                                                              (line  85)
88253* parameters for moving frames with the mouse: Mouse Dragging Parameters.
88254                                                              (line   6)
88255* parameters for resizing frames with the mouse: Mouse Dragging Parameters.
88256                                                              (line   6)
88257* parameters of initial frame:           Initial Parameters.  (line   6)
88258* parent frames:                         Child Frames.        (line   6)
88259* parent of char-table:                  Char-Tables.         (line  28)
88260* parent process:                        Processes.           (line   6)
88261* parent window:                         Windows and Frames.  (line  51)
88262* parent window <1>:                     Windows and Frames.  (line  61)
88263* parent-frame, a buffer display action alist entry: Buffer Display Action Alists.
88264                                                              (line 175)
88265* parent-frame, a frame parameter:       Frame Interaction Parameters.
88266                                                              (line   8)
88267* parenthesis:                           Cons Cell Type.      (line  25)
88268* parenthesis depth:                     Low-Level Parsing.   (line  19)
88269* parenthesis matching:                  Blinking.            (line   6)
88270* parenthesis mismatch, debugging:       Syntax Errors.       (line  21)
88271* parity, in serial connections:         Serial Ports.        (line 116)
88272* parse state for a position:            Position Parse.      (line   6)
88273* parse-colon-path:                      System Environment.  (line 147)
88274* parse-partial-sexp:                    Low-Level Parsing.   (line  10)
88275* parse-sexp-ignore-comments:            Control Parsing.     (line  12)
88276* parse-sexp-lookup-properties:          Syntax Properties.   (line  27)
88277* parse-time-string:                     Time Parsing.        (line  18)
88278* parser state:                          Parser State.        (line   6)
88279* parsing buffer text:                   Syntax Tables.       (line   6)
88280* parsing expressions:                   Parsing Expressions. (line   6)
88281* parsing html:                          Parsing HTML/XML.    (line   6)
88282* parsing xml:                           Parsing HTML/XML.    (line  57)
88283* parsing, control parameters:           Control Parsing.     (line   6)
88284* partial application of functions:      Calling Functions.   (line  82)
88285* partial-width windows:                 Truncation.          (line  30)
88286* passwords, reading:                    Reading a Password.  (line   6)
88287* PATH environment variable:             Subprocess Creation. (line  18)
88288* path-separator:                        System Environment.  (line 141)
88289* pattern matching, programming style:   Pattern-Matching Conditional.
88290                                                              (line   6)
88291* PBM:                                   Other Image Types.   (line   6)
88292* pcase:                                 pcase Macro.         (line   8)
88293* pcase <1>:                             Pattern-Matching Conditional.
88294                                                              (line   6)
88295* pcase pattern:                         pcase Macro.         (line  19)
88296* pcase, defining new kinds of patterns: Extending pcase.     (line   6)
88297* pcase-defmacro:                        Extending pcase.     (line  10)
88298* pcase-dolist:                          Destructuring with pcase Patterns.
88299                                                              (line  77)
88300* pcase-let:                             Destructuring with pcase Patterns.
88301                                                              (line  48)
88302* pcase-let*:                            Destructuring with pcase Patterns.
88303                                                              (line  61)
88304* pdumper-stats:                         Building Emacs.      (line 173)
88305* peculiar error:                        Error Symbols.       (line  29)
88306* peeking at input:                      Event Input Misc.    (line  11)
88307* percent symbol in mode line:           Mode Line Data.      (line  20)
88308* perform-replace:                       Search and Replace.  (line  43)
88309* performance analysis:                  Profiling.           (line   6)
88310* performance analysis (Edebug):         Coverage Testing.    (line   6)
88311* permanent local variable:              Creating Buffer-Local.
88312                                                              (line 200)
88313* permissions, file:                     Testing Accessibility.
88314                                                              (line  84)
88315* permissions, file <1>:                 Changing Files.      (line 189)
88316* persistent window parameters:          Window Parameters.   (line  34)
88317* phishing using directional overrides:  Bidirectional Display.
88318                                                              (line 225)
88319* piece of advice:                       Advising Functions.  (line   6)
88320* pipe, when to use for subprocess communications: Asynchronous Processes.
88321                                                              (line  14)
88322* pixel height of a window:              Window Sizes.        (line 109)
88323* pixel width of a window:               Window Sizes.        (line 118)
88324* pixelwise, resizing windows:           Resizing Windows.    (line  89)
88325* place form:                            Generalized Variables.
88326                                                              (line   6)
88327* play-sound:                            Sound Output.        (line  13)
88328* play-sound-file:                       Sound Output.        (line  45)
88329* play-sound-functions:                  Sound Output.        (line  49)
88330* plist:                                 Property Lists.      (line   6)
88331* plist access:                          Plist Access.        (line   6)
88332* plist vs. alist:                       Plists and Alists.   (line   6)
88333* plist-get:                             Plist Access.        (line   9)
88334* plist-member:                          Plist Access.        (line  45)
88335* plist-put:                             Plist Access.        (line  23)
88336* plugin_is_GPL_compatible:              Dynamic Modules.     (line  19)
88337* point:                                 Point.               (line  31)
88338* point <1>:                             Point.               (line   6)
88339* point excursion:                       Excursions.          (line  21)
88340* point excursion <1>:                   Excursions.          (line  59)
88341* point in rx:                           Rx Constructs.       (line 328)
88342* point in window:                       Window Point.        (line   6)
88343* point with narrowing:                  Point.               (line  17)
88344* point-entered (text property):         Special Properties.  (line 333)
88345* point-left (text property):            Special Properties.  (line 333)
88346* point-marker:                          Creating Markers.    (line  21)
88347* point-max:                             Point.               (line  44)
88348* point-max-marker:                      Creating Markers.    (line  31)
88349* point-min:                             Point.               (line  38)
88350* point-min-marker:                      Creating Markers.    (line  26)
88351* pointer (text property):               Special Properties.  (line 247)
88352* pointer shape:                         Pointer Shape.       (line   6)
88353* pointers:                              Cons Cell Type.      (line   6)
88354* polymorphism:                          Generic Functions.   (line   6)
88355* pop:                                   List Elements.       (line  60)
88356* pop-mark:                              The Mark.            (line 111)
88357* pop-to-buffer:                         Switching Buffers.   (line 135)
88358* pop-up-frame-alist:                    Choosing Window Options.
88359                                                              (line 105)
88360* pop-up-frame-function:                 Choosing Window Options.
88361                                                              (line  95)
88362* pop-up-frame-parameters, a buffer display action alist entry: Buffer Display Action Alists.
88363                                                              (line 170)
88364* pop-up-frames:                         Choosing Window Options.
88365                                                              (line  77)
88366* pop-up-frames, replacement for:        Choosing Window Options.
88367                                                              (line 145)
88368* pop-up-windows:                        Choosing Window Options.
88369                                                              (line   9)
88370* pop-up-windows, replacement for:       Choosing Window Options.
88371                                                              (line 133)
88372* popcount:                              Bitwise Operations.  (line 173)
88373* port number, and default coding system: Default Coding Systems.
88374                                                              (line  80)
88375* pos-visible-in-window-group-p:         Window Start and End.
88376                                                              (line 188)
88377* pos-visible-in-window-group-p-function: Window Start and End.
88378                                                              (line 188)
88379* pos-visible-in-window-p:               Window Start and End.
88380                                                              (line 153)
88381* position (in buffer):                  Positions.           (line   6)
88382* position argument:                     Interactive Codes.   (line  79)
88383* position in window:                    Window Point.        (line   6)
88384* position of frame:                     Frame Geometry.      (line   6)
88385* position of frame <1>:                 Frame Position.      (line   6)
88386* position of mouse:                     Mouse Position.      (line   6)
88387* position-bytes:                        Text Representations.
88388                                                              (line  61)
88389* positive infinity:                     Float Basics.        (line  32)
88390* posix-looking-at:                      POSIX Regexps.       (line  33)
88391* posix-search-backward:                 POSIX Regexps.       (line  28)
88392* posix-search-forward:                  POSIX Regexps.       (line  23)
88393* posix-string-match:                    POSIX Regexps.       (line  38)
88394* posn-actual-col-row:                   Accessing Mouse.     (line  84)
88395* posn-area:                             Accessing Mouse.     (line  42)
88396* posn-at-point:                         Accessing Mouse.     (line 132)
88397* posn-at-x-y:                           Accessing Mouse.     (line 139)
88398* posn-col-row:                          Accessing Mouse.     (line  71)
88399* posn-image:                            Accessing Mouse.     (line 102)
88400* posn-object:                           Accessing Mouse.     (line 106)
88401* posn-object-width-height:              Accessing Mouse.     (line 118)
88402* posn-object-x-y:                       Accessing Mouse.     (line 111)
88403* posn-point:                            Accessing Mouse.     (line  47)
88404* posn-string:                           Accessing Mouse.     (line  97)
88405* posn-timestamp:                        Accessing Mouse.     (line 124)
88406* posn-window:                           Accessing Mouse.     (line  37)
88407* posn-x-y:                              Accessing Mouse.     (line  53)
88408* posnp:                                 Accessing Mouse.     (line  29)
88409* post-command-hook:                     Command Overview.    (line  44)
88410* post-gc-hook:                          Garbage Collection.  (line 215)
88411* post-self-insert-hook:                 Commands for Insertion.
88412                                                              (line  38)
88413* pp:                                    Output Functions.    (line 128)
88414* pre-command-hook:                      Command Overview.    (line  38)
88415* pre-redisplay-function:                Forcing Redisplay.   (line  37)
88416* pre-redisplay-functions:               Forcing Redisplay.   (line  43)
88417* precedence of buffer display action functions: Precedence of Action Functions.
88418                                                              (line   6)
88419* preceding-char:                        Near Point.          (line  55)
88420* precision in format specifications:    Formatting Strings.  (line 226)
88421* predicates for lists:                  List-related Predicates.
88422                                                              (line   6)
88423* predicates for markers:                Predicates on Markers.
88424                                                              (line   6)
88425* predicates for numbers:                Predicates on Numbers.
88426                                                              (line   6)
88427* predicates for strings:                Predicates for Strings.
88428                                                              (line   6)
88429* prefer-utf-8 coding system:            Coding System Basics.
88430                                                              (line  15)
88431* prefix argument:                       Prefix Command Arguments.
88432                                                              (line   6)
88433* prefix argument unreading:             Event Input Misc.    (line  20)
88434* prefix command:                        Prefix Keys.         (line  91)
88435* prefix key:                            Prefix Keys.         (line   6)
88436* prefix, defgroup keyword:              Group Definitions.   (line  46)
88437* prefix-arg:                            Prefix Command Arguments.
88438                                                              (line  90)
88439* prefix-command-echo-keystrokes-functions: Standard Hooks.   (line 166)
88440* prefix-command-preserve-state-hook:    Standard Hooks.      (line 174)
88441* prefix-help-command:                   Help Functions.      (line  90)
88442* prefix-numeric-value:                  Prefix Command Arguments.
88443                                                              (line  77)
88444* preloaded Lisp files:                  Building Emacs.      (line  65)
88445* preloaded-file-list:                   Building Emacs.      (line  65)
88446* preloading additional functions and variables: Building Emacs.
88447                                                              (line  97)
88448* prepare-change-group:                  Atomic Changes.      (line  30)
88449* preserve-size, a buffer display action alist entry: Buffer Display Action Alists.
88450                                                              (line 161)
88451* preserving window sizes:               Preserving Window Sizes.
88452                                                              (line   6)
88453* pretty-printer:                        Output Functions.    (line 128)
88454* preventing backtracking:               Specification List.  (line 110)
88455* preventing prefix key:                 Key Lookup.          (line  85)
88456* preventing quitting:                   Quitting.            (line  45)
88457* previous complete subexpression:       Parser State.        (line  23)
88458* previous-button:                       Button Buffer Commands.
88459                                                              (line  53)
88460* previous-char-property-change:         Property Search.     (line  92)
88461* previous-complete-history-element:     Minibuffer Commands. (line  37)
88462* previous-frame:                        Finding All Frames.  (line  56)
88463* previous-history-element:              Minibuffer Commands. (line  17)
88464* previous-matching-history-element:     Minibuffer Commands. (line  27)
88465* previous-overlay-change:               Finding Overlays.    (line  39)
88466* previous-property-change:              Property Search.     (line  53)
88467* previous-single-char-property-change:  Property Search.     (line 107)
88468* previous-single-property-change:       Property Search.     (line  76)
88469* previous-window:                       Cyclic Window Ordering.
88470                                                              (line  58)
88471* previous-window, a buffer display action alist entry: Buffer Display Action Alists.
88472                                                              (line  34)
88473* primary selection:                     Window System Selections.
88474                                                              (line   6)
88475* primitive:                             What Is a Function.  (line  37)
88476* primitive function:                    Primitive Function Type.
88477                                                              (line   6)
88478* primitive function internals:          Writing Emacs Primitives.
88479                                                              (line   6)
88480* primitive type:                        Lisp Data Types.     (line  16)
88481* primitive-undo:                        Undo.                (line 137)
88482* prin1:                                 Output Functions.    (line  58)
88483* prin1-to-string:                       Output Functions.    (line  95)
88484* princ:                                 Output Functions.    (line  70)
88485* print:                                 Output Functions.    (line  41)
88486* print example:                         Output Streams.      (line  52)
88487* print name cell:                       Symbol Components.   (line  10)
88488* print-charset-text-property:           Output Variables.    (line  67)
88489* print-circle:                          Output Variables.    (line 109)
88490* print-continuous-numbering:            Output Variables.    (line 119)
88491* print-escape-control-characters:       Output Variables.    (line  41)
88492* print-escape-multibyte:                Output Variables.    (line  57)
88493* print-escape-newlines:                 Output Variables.    (line  16)
88494* print-escape-nonascii:                 Output Variables.    (line  48)
88495* print-gensym:                          Output Variables.    (line 113)
88496* print-length:                          Output Variables.    (line  79)
88497* print-level:                           Output Variables.    (line  93)
88498* print-number-table:                    Output Variables.    (line 126)
88499* print-quoted:                          Output Variables.    (line  11)
88500* printable ASCII characters:            Usual Display.       (line  10)
88501* printable-chars:                       Character Properties.
88502                                                              (line 244)
88503* printed representation:                Printed Representation.
88504                                                              (line   6)
88505* printed representation for characters: Basic Char Syntax.   (line   6)
88506* printing:                              Streams Intro.       (line   6)
88507* printing (Edebug):                     Printing in Edebug.  (line   6)
88508* printing circular structures:          Printing in Edebug.  (line   6)
88509* printing limits:                       Output Variables.    (line  80)
88510* printing notation:                     Printing Notation.   (line   6)
88511* priority (overlay property):           Overlay Properties.  (line  48)
88512* priority order of coding systems:      Specifying Coding Systems.
88513                                                              (line  67)
88514* process:                               Processes.           (line   6)
88515* process creation:                      Subprocess Creation. (line   6)
88516* process filter:                        Filter Functions.    (line   6)
88517* process filter multibyte flag:         Decoding Output.     (line  30)
88518* process information:                   Process Information. (line   6)
88519* process input:                         Input to Processes.  (line   6)
88520* process internals:                     Process Internals.   (line   6)
88521* process output:                        Output from Processes.
88522                                                              (line   6)
88523* process sentinel:                      Sentinels.           (line   6)
88524* process signals:                       Signals to Processes.
88525                                                              (line   6)
88526* process-adaptive-read-buffering:       Output from Processes.
88527                                                              (line  44)
88528* process-attributes:                    System Processes.    (line  22)
88529* process-buffer:                        Process Buffers.     (line  28)
88530* process-coding-system:                 Process Information. (line 176)
88531* process-coding-system-alist:           Default Coding Systems.
88532                                                              (line  57)
88533* process-command:                       Process Information. (line  35)
88534* process-connection-type:               Asynchronous Processes.
88535                                                              (line 299)
88536* process-contact:                       Process Information. (line  46)
88537* process-datagram-address:              Datagrams.           (line  20)
88538* process-environment:                   System Environment.  (line 120)
88539* process-exit-status:                   Process Information. (line 158)
88540* process-file:                          Synchronous Processes.
88541                                                              (line 137)
88542* process-file-shell-command:            Synchronous Processes.
88543                                                              (line 249)
88544* process-file-side-effects:             Synchronous Processes.
88545                                                              (line 180)
88546* process-filter:                        Filter Functions.    (line  86)
88547* process-get:                           Process Information. (line 191)
88548* process-id:                            Process Information. (line  96)
88549* process-kill-buffer-query-function:    Process Buffers.     (line  21)
88550* process-lines:                         Synchronous Processes.
88551                                                              (line 271)
88552* process-list:                          Process Information. (line  20)
88553* process-live-p:                        Process Information. (line 147)
88554* process-mark:                          Process Buffers.     (line  35)
88555* process-name:                          Process Information. (line 105)
88556* process-plist:                         Process Information. (line 199)
88557* process-put:                           Process Information. (line 195)
88558* process-query-on-exit-flag:            Query Before Exit.   (line  14)
88559* process-running-child-p:               Input to Processes.  (line  61)
88560* process-send-eof:                      Input to Processes.  (line  53)
88561* process-send-region:                   Input to Processes.  (line  45)
88562* process-send-string:                   Input to Processes.  (line  37)
88563* process-sentinel:                      Sentinels.           (line 110)
88564* process-status:                        Process Information. (line 108)
88565* process-thread:                        Processes and Threads.
88566                                                              (line  21)
88567* process-tty-name:                      Process Information. (line 167)
88568* process-type:                          Process Information. (line 152)
88569* processes, threads:                    Processes and Threads.
88570                                                              (line   6)
88571* processing of errors:                  Processing of Errors.
88572                                                              (line   6)
88573* processor run time:                    Processor Run Time.  (line   6)
88574* processp:                              Processes.           (line  30)
88575* profile:                               Profiling.           (line   6)
88576* profiler-report:                       Profiling.           (line  13)
88577* profiler-start:                        Profiling.           (line  13)
88578* profiler-stop:                         Profiling.           (line  13)
88579* profiling:                             Profiling.           (line   6)
88580* prog-first-column:                     Mode-Specific Indent.
88581                                                              (line 102)
88582* prog-indentation-context:              Mode-Specific Indent.
88583                                                              (line  85)
88584* prog-mode:                             Basic Major Modes.   (line  27)
88585* prog-mode, and bidi-paragraph-direction: Bidirectional Display.
88586                                                              (line 125)
88587* prog-mode-hook:                        Basic Major Modes.   (line  12)
88588* prog1:                                 Sequencing.          (line  47)
88589* prog2:                                 Sequencing.          (line  64)
88590* progn:                                 Sequencing.          (line  32)
88591* program arguments:                     Subprocess Creation. (line  57)
88592* program directories:                   Subprocess Creation. (line  84)
88593* program name, and default coding system: Default Coding Systems.
88594                                                              (line  57)
88595* programmed completion:                 Programmed Completion.
88596                                                              (line   6)
88597* programming conventions:               Programming Tips.    (line   6)
88598* programming types:                     Programming Types.   (line   6)
88599* progress reporting:                    Progress.            (line   6)
88600* progress-reporter-done:                Progress.            (line  95)
88601* progress-reporter-force-update:        Progress.            (line  84)
88602* progress-reporter-update:              Progress.            (line  60)
88603* prompt for file name:                  Reading File Names.  (line   6)
88604* prompt string (of menu):               Defining Menus.      (line   6)
88605* prompt string of keymap:               Format of Keymaps.   (line  57)
88606* proper list:                           Cons Cells.          (line  24)
88607* proper-list-p:                         List-related Predicates.
88608                                                              (line  49)
88609* properties of text:                    Text Properties.     (line   6)
88610* propertize:                            Changing Properties. (line 118)
88611* property category of text character:   Special Properties.  (line  15)
88612* property list:                         Property Lists.      (line   6)
88613* property list cell:                    Symbol Components.   (line  20)
88614* property lists vs association lists:   Plists and Alists.   (line   6)
88615* protect C variables from garbage collection: Writing Emacs Primitives.
88616                                                              (line 160)
88617* protected forms:                       Cleanups.            (line  13)
88618* provide:                               Named Features.      (line  73)
88619* provide-theme:                         Custom Themes.       (line  29)
88620* providing features:                    Named Features.      (line   6)
88621* pseudo window:                         Window Internals.    (line  17)
88622* pty, when to use for subprocess communications: Asynchronous Processes.
88623                                                              (line  14)
88624* pure function:                         What Is a Function.  (line   6)
88625* pure property:                         Standard Properties. (line  75)
88626* pure storage:                          Pure Storage.        (line   6)
88627* pure-bytes-used:                       Pure Storage.        (line  44)
88628* purecopy:                              Pure Storage.        (line  33)
88629* purify-flag:                           Pure Storage.        (line  50)
88630* push:                                  List Variables.      (line   9)
88631* push-button:                           Button Buffer Commands.
88632                                                              (line  21)
88633* push-mark:                             The Mark.            (line 101)
88634* put:                                   Symbol Plists.       (line  19)
88635* put-char-code-property:                Character Properties.
88636                                                              (line 223)
88637* put-charset-property:                  Character Sets.      (line  55)
88638* put-image:                             Showing Images.      (line  43)
88639* put-text-property:                     Changing Properties. (line  18)
88640* puthash:                               Hash Access.         (line  15)
88641* quadratic-bezier-curveto:              SVG Images.          (line 253)
88642* query-font:                            Low-Level Font.      (line 249)
88643* query-replace-history:                 Minibuffer History.  (line  95)
88644* query-replace-map:                     Search and Replace.  (line  94)
88645* querying the user:                     Yes-or-No Queries.   (line   6)
88646* question mark in character constant:   Basic Char Syntax.   (line   6)
88647* quietly-read-abbrev-file:              Abbrev Files.        (line  22)
88648* quit-flag:                             Quitting.            (line  73)
88649* quit-process:                          Signals to Processes.
88650                                                              (line  65)
88651* quit-restore, a window parameter:      Window Parameters.   (line 118)
88652* quit-restore-window:                   Quitting Windows.    (line  31)
88653* quit-window:                           Quitting Windows.    (line  21)
88654* quit-window-hook:                      Quitting Windows.    (line  28)
88655* quitting:                              Quitting.            (line   6)
88656* quitting from infinite loop:           Infinite Loops.      (line   6)
88657* quote:                                 Quoting.             (line  12)
88658* quote character:                       Parser State.        (line  34)
88659* quote special characters in regexp:    Regexp Functions.    (line   8)
88660* quoted character input:                Quoted Character Input.
88661                                                              (line   6)
88662* quoted-insert suppression:             Changing Key Bindings.
88663                                                              (line 159)
88664* quoting and unquoting command-line arguments: Shell Arguments.
88665                                                              (line  40)
88666* quoting characters in printing:        Output Functions.    (line   9)
88667* quoting using apostrophe:              Quoting.             (line  17)
88668* radio, customization types:            Composite Types.     (line 172)
88669* radix for reading an integer:          Integer Basics.      (line  16)
88670* raise-frame:                           Raising and Lowering.
88671                                                              (line  25)
88672* raising a frame:                       Raising and Lowering.
88673                                                              (line   6)
88674* random:                                Random Numbers.      (line  27)
88675* random numbers:                        Random Numbers.      (line   6)
88676* rassoc:                                Association Lists.   (line  90)
88677* rassq:                                 Association Lists.   (line 138)
88678* rassq-delete-all:                      Association Lists.   (line 248)
88679* raw prefix argument:                   Prefix Command Arguments.
88680                                                              (line   6)
88681* raw prefix argument usage:             Interactive Codes.   (line 163)
88682* raw syntax descriptor:                 Syntax Table Internals.
88683                                                              (line  13)
88684* raw-text coding system:                Coding System Basics.
88685                                                              (line  52)
88686* re-builder:                            Regular Expressions. (line  11)
88687* re-search-backward:                    Regexp Search.       (line  67)
88688* re-search-forward:                     Regexp Search.       (line  16)
88689* read:                                  Input Functions.     (line  16)
88690* read command name:                     Interactive Call.    (line  99)
88691* read file names:                       Reading File Names.  (line   6)
88692* read input:                            Reading Input.       (line   6)
88693* read syntax:                           Printed Representation.
88694                                                              (line   6)
88695* read syntax for characters:            Basic Char Syntax.   (line   6)
88696* read-answer:                           Multiple Queries.    (line  96)
88697* read-answer-short:                     Multiple Queries.    (line  97)
88698* read-buffer:                           High-Level Completion.
88699                                                              (line  14)
88700* read-buffer-completion-ignore-case:    High-Level Completion.
88701                                                              (line  60)
88702* read-buffer-function:                  High-Level Completion.
88703                                                              (line  55)
88704* read-char:                             Reading One Event.   (line  65)
88705* read-char-choice:                      Reading One Event.   (line 134)
88706* read-char-exclusive:                   Reading One Event.   (line 102)
88707* read-char-from-minibuffer:             Multiple Queries.    (line 132)
88708* read-circle:                           Input Functions.     (line  55)
88709* read-coding-system:                    User-Chosen Coding Systems.
88710                                                              (line  82)
88711* read-color:                            High-Level Completion.
88712                                                              (line 108)
88713* read-command:                          High-Level Completion.
88714                                                              (line  64)
88715* read-directory-name:                   Reading File Names.  (line 120)
88716* read-event:                            Reading One Event.   (line  12)
88717* read-expression-history:               Minibuffer History.  (line 114)
88718* read-file-modes:                       Changing Files.      (line 243)
88719* read-file-name:                        Reading File Names.  (line  12)
88720* read-file-name-completion-ignore-case: Reading File Names.  (line 116)
88721* read-file-name-function:               Reading File Names.  (line 110)
88722* read-from-minibuffer:                  Text from Minibuffer.
88723                                                              (line  18)
88724* read-from-string:                      Input Functions.     (line  21)
88725* read-hide-char:                        Reading a Password.  (line   9)
88726* read-input-method-name:                Input Methods.       (line  34)
88727* read-kbd-macro:                        Describing Characters.
88728                                                              (line  71)
88729* read-key:                              Reading One Event.   (line 123)
88730* read-key-sequence:                     Key Sequence Input.  (line  10)
88731* read-key-sequence-vector:              Key Sequence Input.  (line  67)
88732* read-minibuffer:                       Object from Minibuffer.
88733                                                              (line   9)
88734* read-multiple-choice:                  Reading One Event.   (line 144)
88735* read-no-blanks-input:                  Text from Minibuffer.
88736                                                              (line 216)
88737* read-non-nil-coding-system:            User-Chosen Coding Systems.
88738                                                              (line  88)
88739* read-only (text property):             Special Properties.  (line 149)
88740* read-only buffer:                      Read Only Buffers.   (line   6)
88741* read-only buffers in interactive:      Using Interactive.   (line  67)
88742* read-only character:                   Special Properties.  (line 149)
88743* read-only variables:                   Constant Variables.  (line  29)
88744* read-only-mode:                        Read Only Buffers.   (line  46)
88745* read-passwd:                           Reading a Password.  (line   9)
88746* read-quoted-char:                      Quoted Character Input.
88747                                                              (line  11)
88748* read-quoted-char quitting:             Quitting.            (line  54)
88749* read-regexp:                           Text from Minibuffer.
88750                                                              (line 118)
88751* read-regexp-defaults-function:         Text from Minibuffer.
88752                                                              (line 164)
88753* read-shell-command:                    Reading File Names.  (line 171)
88754* read-string:                           Text from Minibuffer.
88755                                                              (line  91)
88756* read-variable:                         High-Level Completion.
88757                                                              (line 102)
88758* read-variable, history list:           Minibuffer History.  (line 120)
88759* reading:                               Streams Intro.       (line   6)
88760* reading a single event:                Reading One Event.   (line   6)
88761* reading from files:                    Reading from Files.  (line   6)
88762* reading from minibuffer with completion: Minibuffer Completion.
88763                                                              (line   6)
88764* reading interactive arguments:         Interactive Codes.   (line  41)
88765* reading numbers in hex, octal, and binary: Integer Basics.  (line  16)
88766* reading order:                         Bidirectional Display.
88767                                                              (line  17)
88768* reading symbols:                       Creating Symbols.    (line   6)
88769* real-last-command:                     Command Loop Info.   (line  24)
88770* rearrangement of lists:                Rearrangement.       (line   6)
88771* rebinding:                             Changing Key Bindings.
88772                                                              (line   6)
88773* recent-auto-save-p:                    Auto-Saving.         (line 104)
88774* recent-keys:                           Recording Input.     (line   6)
88775* recenter:                              Textual Scrolling.   (line 194)
88776* recenter-positions:                    Textual Scrolling.   (line 244)
88777* recenter-redisplay:                    Textual Scrolling.   (line 232)
88778* recenter-top-bottom:                   Textual Scrolling.   (line 238)
88779* recenter-window-group:                 Textual Scrolling.   (line 221)
88780* recenter-window-group-function:        Textual Scrolling.   (line 221)
88781* recombining windows:                   Recombining Windows. (line   6)
88782* record:                                Record Functions.    (line  12)
88783* record command history:                Interactive Call.    (line  62)
88784* recording input:                       Recording Input.     (line   6)
88785* recordp:                               Record Functions.    (line   6)
88786* records:                               Records.             (line   6)
88787* rectangle, as contents of a register:  Registers.           (line  34)
88788* recursion:                             Iteration.           (line   6)
88789* recursion-depth:                       Recursive Editing.   (line 103)
88790* recursive command loop:                Recursive Editing.   (line   6)
88791* recursive editing level:               Recursive Editing.   (line   6)
88792* recursive evaluation:                  Intro Eval.          (line  30)
88793* recursive minibuffers:                 Recursive Mini.      (line   6)
88794* recursive traverse of directory tree:  Contents of Directories.
88795                                                              (line  44)
88796* recursive-edit:                        Recursive Editing.   (line  61)
88797* redefine existing functions:           Defining Functions.  (line  48)
88798* redirect-frame-focus:                  Input Focus.         (line 126)
88799* redisplay:                             Forcing Redisplay.   (line  11)
88800* redo:                                  Undo.                (line   6)
88801* redraw-display:                        Refresh Screen.      (line  16)
88802* redraw-frame:                          Refresh Screen.      (line  10)
88803* reducing sequences:                    Sequence Functions.  (line 397)
88804* reference to free variable, compilation warning: Compiler Errors.
88805                                                              (line  21)
88806* references, following:                 Key Binding Conventions.
88807                                                              (line   6)
88808* refresh the screen:                    Refresh Screen.      (line   6)
88809* regex in rx:                           Rx Constructs.       (line 387)
88810* regexp:                                Regular Expressions. (line   6)
88811* regexp alternative:                    Regexp Backslash.    (line  12)
88812* regexp grouping:                       Regexp Backslash.    (line  45)
88813* regexp in rx:                          Rx Constructs.       (line 386)
88814* regexp searching:                      Regexp Search.       (line   6)
88815* regexp syntax:                         Syntax of Regexps.   (line   6)
88816* regexp syntax <1>:                     Rx Notation.         (line   6)
88817* regexp, special characters in:         Regexp Special.      (line   6)
88818* regexp-history:                        Minibuffer History.  (line 105)
88819* regexp-opt:                            Regexp Functions.    (line  32)
88820* regexp-opt-charset:                    Regexp Functions.    (line  88)
88821* regexp-opt-depth:                      Regexp Functions.    (line  83)
88822* regexp-quote:                          Regexp Functions.    (line   8)
88823* regexp-unmatchable:                    Regexp Functions.    (line  95)
88824* regexps used standardly in editing:    Standard Regexps.    (line   6)
88825* region:                                The Region.          (line   6)
88826* region argument:                       Interactive Codes.   (line 167)
88827* region-beginning:                      The Region.          (line  15)
88828* region-end:                            The Region.          (line  20)
88829* register preview:                      Registers.           (line  90)
88830* register-alist:                        Registers.           (line  13)
88831* register-definition-prefixes:          Autoload by Prefix.  (line   6)
88832* register-read-with-preview:            Registers.           (line  89)
88833* registers:                             Registers.           (line   6)
88834* regular expression:                    Regular Expressions. (line   6)
88835* regular expression searching:          Regexp Search.       (line   6)
88836* regular expressions, developing:       Regular Expressions. (line  11)
88837* reindent-then-newline-and-indent:      Mode-Specific Indent.
88838                                                              (line  57)
88839* relative file name:                    Relative File Names. (line   6)
88840* relative remapping, faces:             Face Remapping.      (line  46)
88841* remainder:                             Arithmetic Operations.
88842                                                              (line 107)
88843* remapping commands:                    Remapping Commands.  (line   6)
88844* remhash:                               Hash Access.         (line  20)
88845* remote-file-name-inhibit-cache:        Magic File Names.    (line 230)
88846* remove:                                Sets And Lists.      (line 158)
88847* remove-from-invisibility-spec:         Invisible Text.      (line  69)
88848* remove-function:                       Core Advising Primitives.
88849                                                              (line  75)
88850* remove-hook:                           Setting Hooks.       (line  68)
88851* remove-images:                         Showing Images.      (line  62)
88852* remove-list-of-text-properties:        Changing Properties. (line  64)
88853* remove-overlays:                       Managing Overlays.   (line  75)
88854* remove-text-properties:                Changing Properties. (line  43)
88855* remove-variable-watcher:               Watching Variables.  (line  30)
88856* removing from sequences:               Sequence Functions.  (line 388)
88857* remq:                                  Sets And Lists.      (line  79)
88858* rename-auto-save-file:                 Auto-Saving.         (line 167)
88859* rename-buffer:                         Buffer Names.        (line  37)
88860* rename-file:                           Changing Files.      (line  92)
88861* rendering html:                        Parsing HTML/XML.    (line  51)
88862* reordering, of bidirectional text:     Bidirectional Display.
88863                                                              (line  17)
88864* reordering, of elements in lists:      Rearrangement.       (line   6)
88865* reparent frame:                        Child Frames.        (line  25)
88866* repeat events:                         Repeat Events.       (line   6)
88867* repeat in rx:                          Rx Constructs.       (line 103)
88868* repeated loading:                      Repeated Loading.    (line   6)
88869* replace bindings:                      Changing Key Bindings.
88870                                                              (line 112)
88871* replace characters:                    Substitution.        (line  11)
88872* replace characters in region:          Substitution.        (line   6)
88873* replace list element:                  Setcar.              (line   6)
88874* replace matched text:                  Replacing Match.     (line   6)
88875* replace part of list:                  Setcdr.              (line   6)
88876* replace-buffer-contents:               Replacing.           (line   9)
88877* replace-buffer-in-windows:             Buffers and Windows. (line  89)
88878* replace-match:                         Replacing Match.     (line   9)
88879* replace-re-search-function:            Search and Replace.  (line 197)
88880* replace-regexp-in-string:              Search and Replace.  (line  19)
88881* replace-region-contents:               Replacing.           (line  44)
88882* replace-search-function:               Search and Replace.  (line 190)
88883* replacement after search:              Search and Replace.  (line   6)
88884* replacing display specs:               Replacing Specs.     (line   6)
88885* require:                               Named Features.      (line 106)
88886* require, customization keyword:        Common Keywords.     (line 100)
88887* require-final-newline:                 Saving Buffers.      (line 168)
88888* requiring features:                    Named Features.      (line   6)
88889* reserved keys:                         Key Binding Conventions.
88890                                                              (line  14)
88891* resize window:                         Resizing Windows.    (line   6)
88892* resize-mini-frames:                    Minibuffer Windows.  (line  79)
88893* resize-mini-windows:                   Minibuffer Windows.  (line  50)
88894* rest arguments:                        Argument List.       (line  18)
88895* restacking a frame:                    Raising and Lowering.
88896                                                              (line   6)
88897* restore-buffer-modified-p:             Buffer Modification. (line  37)
88898* restricted-sexp, customization types:  Composite Types.     (line 253)
88899* restriction (in a buffer):             Narrowing.           (line   6)
88900* resume (cf. no-redraw-on-reenter):     Refresh Screen.      (line  31)
88901* resume-tty:                            Suspending Emacs.    (line  93)
88902* resume-tty-functions:                  Suspending Emacs.    (line  98)
88903* rethrow a signal:                      Handling Errors.     (line 139)
88904* return (ASCII character):              Basic Char Syntax.   (line  27)
88905* return value:                          What Is a Function.  (line   6)
88906* reusable-frames, a buffer display action alist entry: Buffer Display Action Alists.
88907                                                              (line  52)
88908* reverse:                               Sequence Functions.  (line 115)
88909* reversing a list:                      Sequence Functions.  (line 141)
88910* reversing a string:                    Sequence Functions.  (line 141)
88911* reversing a vector:                    Sequence Functions.  (line 141)
88912* revert-buffer:                         Reverting.           (line  11)
88913* revert-buffer-function:                Reverting.           (line  59)
88914* revert-buffer-in-progress-p:           Reverting.           (line  41)
88915* revert-buffer-insert-file-contents-function: Reverting.     (line  70)
88916* revert-without-query:                  Reverting.           (line  48)
88917* reverting buffers:                     Reverting.           (line   6)
88918* rgb value:                             Color Names.         (line  68)
88919* right dividers:                        Window Dividers.     (line   6)
88920* right-divider, prefix key:             Key Sequence Input.  (line  92)
88921* right-divider-width, a frame parameter: Layout Parameters.  (line  46)
88922* right-fringe, a frame parameter:       Layout Parameters.   (line  35)
88923* right-fringe, prefix key:              Key Sequence Input.  (line  92)
88924* right-fringe-width:                    Fringe Size/Pos.     (line  19)
88925* right-margin, prefix key:              Key Sequence Input.  (line  92)
88926* right-margin-width:                    Display Margins.     (line  42)
88927* right-to-left text:                    Bidirectional Display.
88928                                                              (line   6)
88929* ring data structure:                   Rings.               (line   6)
88930* ring-bell-function:                    Beeping.             (line  27)
88931* ring-copy:                             Rings.               (line  32)
88932* ring-elements:                         Rings.               (line  29)
88933* ring-empty-p:                          Rings.               (line  36)
88934* ring-insert:                           Rings.               (line  49)
88935* ring-insert-at-beginning:              Rings.               (line  62)
88936* ring-length:                           Rings.               (line  25)
88937* ring-p:                                Rings.               (line  19)
88938* ring-ref:                              Rings.               (line  44)
88939* ring-remove:                           Rings.               (line  56)
88940* ring-resize:                           Rings.               (line  69)
88941* ring-size:                             Rings.               (line  22)
88942* risky, defcustom keyword:              Variable Definitions.
88943                                                              (line 145)
88944* risky-local-variable-p:                File Local Variables.
88945                                                              (line 150)
88946* RLO:                                   Bidirectional Display.
88947                                                              (line 215)
88948* rm:                                    Changing Files.      (line 171)
88949* root window:                           Windows and Frames.  (line  29)
88950* root window of atomic window:          Atomic Windows.      (line  33)
88951* round:                                 Numeric Conversions. (line  66)
88952* rounding in conversions:               Numeric Conversions. (line   6)
88953* rounding without conversion:           Rounding Operations. (line   6)
88954* rplaca:                                Modifying Lists.     (line  14)
88955* rplacd:                                Modifying Lists.     (line  14)
88956* run time stack:                        Internals of Debugger.
88957                                                              (line  21)
88958* run-at-time:                           Timers.              (line  47)
88959* run-hook-with-args:                    Running Hooks.       (line  29)
88960* run-hook-with-args-until-failure:      Running Hooks.       (line  33)
88961* run-hook-with-args-until-success:      Running Hooks.       (line  40)
88962* run-hooks:                             Running Hooks.       (line  10)
88963* run-mode-hooks:                        Mode Hooks.          (line  28)
88964* run-with-idle-timer:                   Idle Timers.         (line  10)
88965* run-with-timer:                        Timers.              (line  91)
88966* running a hook when a window gets selected: Selecting Windows.
88967                                                              (line  31)
88968* rx:                                    Rx Functions.        (line   6)
88969* rx <1>:                                Rx Notation.         (line   6)
88970* rx-define:                             Extending Rx.        (line  41)
88971* rx-let:                                Extending Rx.        (line  68)
88972* rx-let-eval:                           Extending Rx.        (line  99)
88973* rx-to-string:                          Rx Functions.        (line  12)
88974* S-expression:                          Intro Eval.          (line  12)
88975* safe local variable:                   File Local Variables.
88976                                                              (line  91)
88977* safe, defcustom keyword:               Variable Definitions.
88978                                                              (line 149)
88979* safe-length:                           List Elements.       (line 121)
88980* safe-local-eval-forms:                 File Local Variables.
88981                                                              (line 169)
88982* safe-local-variable-p:                 File Local Variables.
88983                                                              (line 129)
88984* safe-local-variable-values:            File Local Variables.
88985                                                              (line 118)
88986* safe-magic (property):                 Magic File Names.    (line 124)
88987* safely encode a string:                Lisp and Coding Systems.
88988                                                              (line  73)
88989* safely encode characters in a charset: Lisp and Coding Systems.
88990                                                              (line  80)
88991* safely encode region:                  Lisp and Coding Systems.
88992                                                              (line  64)
88993* safety of functions:                   Function Safety.     (line   6)
88994* same-window-buffer-names, replacement for: Choosing Window Options.
88995                                                              (line 155)
88996* same-window-regexps, replacement for:  Choosing Window Options.
88997                                                              (line 155)
88998* save abbrevs in files:                 Abbrev Files.        (line   6)
88999* save-abbrevs:                          Abbrev Files.        (line  29)
89000* save-buffer:                           Saving Buffers.      (line  14)
89001* save-buffer-coding-system:             Encoding and I/O.    (line  34)
89002* save-current-buffer:                   Current Buffer.      (line 100)
89003* save-excursion:                        Excursions.          (line  20)
89004* save-mark-and-excursion:               Excursions.          (line  58)
89005* save-match-data:                       Saving Match Data.   (line  19)
89006* save-restriction:                      Narrowing.           (line  57)
89007* save-selected-window:                  Selecting Windows.   (line  68)
89008* save-some-buffers:                     Saving Buffers.      (line  36)
89009* save-some-buffers-default-predicate:   Saving Buffers.      (line  42)
89010* save-window-excursion:                 Window Configurations.
89011                                                              (line  54)
89012* SaveUnder feature:                     Display Feature Testing.
89013                                                              (line 126)
89014* saving buffers:                        Saving Buffers.      (line   6)
89015* saving text properties:                Format Conversion.   (line   6)
89016* saving window information:             Window Configurations.
89017                                                              (line   6)
89018* scalability of overlays:               Overlays.            (line  12)
89019* scalable fonts:                        Font Selection.      (line  65)
89020* scalable-fonts-allowed:                Font Selection.      (line  68)
89021* scan-lists:                            Motion via Parsing.  (line   9)
89022* scan-sexps:                            Motion via Parsing.  (line  29)
89023* scanning expressions:                  Parsing Expressions. (line   6)
89024* scanning for character sets:           Scanning Charsets.   (line   6)
89025* scanning keymaps:                      Scanning Keymaps.    (line   6)
89026* scope:                                 Variable Scoping.    (line  10)
89027* scoping rule:                          Variable Scoping.    (line   6)
89028* screen layout:                         Frame Configuration Type.
89029                                                              (line   6)
89030* screen lines, moving by:               Screen Lines.        (line   6)
89031* screen of terminal:                    Basic Windows.       (line  17)
89032* screen refresh:                        Refresh Screen.      (line   6)
89033* screen-gamma, a frame parameter:       Font and Color Parameters.
89034                                                              (line  47)
89035* script symbols:                        Character Properties.
89036                                                              (line 233)
89037* scroll bar events, data in:            Accessing Scroll.    (line   6)
89038* scroll bars:                           Scroll Bars.         (line   6)
89039* scroll-bar-background, a frame parameter: Font and Color Parameters.
89040                                                              (line 120)
89041* scroll-bar-event-ratio:                Accessing Scroll.    (line   8)
89042* scroll-bar-foreground, a frame parameter: Font and Color Parameters.
89043                                                              (line 116)
89044* scroll-bar-height:                     Scroll Bars.         (line 153)
89045* scroll-bar-height, a frame parameter:  Layout Parameters.   (line  31)
89046* scroll-bar-mode:                       Scroll Bars.         (line 162)
89047* scroll-bar-scale:                      Accessing Scroll.    (line  14)
89048* scroll-bar-width:                      Scroll Bars.         (line 148)
89049* scroll-bar-width, a frame parameter:   Layout Parameters.   (line  27)
89050* scroll-command property:               Textual Scrolling.   (line 166)
89051* scroll-conservatively:                 Textual Scrolling.   (line 128)
89052* scroll-down:                           Textual Scrolling.   (line  49)
89053* scroll-down-aggressively:              Textual Scrolling.   (line 141)
89054* scroll-down-command:                   Textual Scrolling.   (line  63)
89055* scroll-error-top-bottom:               Textual Scrolling.   (line 185)
89056* scroll-left:                           Horizontal Scrolling.
89057                                                              (line  54)
89058* scroll-margin:                         Textual Scrolling.   (line 106)
89059* scroll-other-window:                   Textual Scrolling.   (line  70)
89060* scroll-other-window-down:              Textual Scrolling.   (line  96)
89061* scroll-preserve-screen-position:       Textual Scrolling.   (line 166)
89062* scroll-right:                          Horizontal Scrolling.
89063                                                              (line  78)
89064* scroll-step:                           Textual Scrolling.   (line 160)
89065* scroll-up:                             Textual Scrolling.   (line  37)
89066* scroll-up-aggressively:                Textual Scrolling.   (line 154)
89067* scroll-up-command:                     Textual Scrolling.   (line  56)
89068* scrolling textually:                   Textual Scrolling.   (line   6)
89069* search-backward:                       String Search.       (line  60)
89070* search-failed:                         String Search.       (line  43)
89071* search-forward:                        String Search.       (line  17)
89072* search-map:                            Prefix Keys.         (line  48)
89073* search-spaces-regexp:                  Regexp Search.       (line 176)
89074* searching:                             Searching and Matching.
89075                                                              (line   6)
89076* searching active keymaps for keys:     Searching Keymaps.   (line   6)
89077* searching and case:                    Searching and Case.  (line   6)
89078* searching and replacing:               Search and Replace.  (line   6)
89079* searching for overlays:                Finding Overlays.    (line   6)
89080* searching for regexp:                  Regexp Search.       (line   6)
89081* searching text properties:             Property Search.     (line   6)
89082* secondary selection:                   Window System Selections.
89083                                                              (line   6)
89084* secondary storage:                     Files and Storage.   (line   6)
89085* secure-hash:                           Checksum/Hash.       (line  25)
89086* secure-hash-algorithms:                Checksum/Hash.       (line  21)
89087* security:                              Security Considerations.
89088                                                              (line   6)
89089* security, and display specifications:  Display Property.    (line  18)
89090* seed, for random number generation:    Random Numbers.      (line  13)
89091* select safe coding system:             User-Chosen Coding Systems.
89092                                                              (line   6)
89093* select window hooks:                   Selecting Windows.   (line  31)
89094* select-frame:                          Input Focus.         (line  75)
89095* select-frame-set-input-focus:          Input Focus.         (line  49)
89096* select-safe-coding-system:             User-Chosen Coding Systems.
89097                                                              (line   6)
89098* select-safe-coding-system-accept-default-p: User-Chosen Coding Systems.
89099                                                              (line  51)
89100* select-safe-coding-system-function:    User-Chosen Coding Systems.
89101                                                              (line  68)
89102* select-window:                         Selecting Windows.   (line   6)
89103* selected frame:                        Input Focus.         (line   6)
89104* selected window:                       Basic Windows.       (line  59)
89105* selected-frame:                        Input Focus.         (line  19)
89106* selected-window:                       Basic Windows.       (line  70)
89107* selected-window-group:                 Basic Windows.       (line  83)
89108* selected-window-group-function:        Basic Windows.       (line  84)
89109* selecting a buffer:                    Current Buffer.      (line   6)
89110* selecting a font:                      Font Selection.      (line   6)
89111* selecting a window:                    Selecting Windows.   (line   6)
89112* selection (for window systems):        Window System Selections.
89113                                                              (line   6)
89114* selection-coding-system:               Window System Selections.
89115                                                              (line  51)
89116* selective-display:                     Selective Display.   (line  39)
89117* selective-display-ellipses:            Selective Display.   (line  85)
89118* self-evaluating form:                  Self-Evaluating Forms.
89119                                                              (line   6)
89120* self-insert-and-exit:                  Minibuffer Commands. (line  12)
89121* self-insert-command:                   Commands for Insertion.
89122                                                              (line  16)
89123* self-insert-command override:          Changing Key Bindings.
89124                                                              (line 149)
89125* self-insert-command, minor modes:      Keymaps and Minor Modes.
89126                                                              (line  11)
89127* self-insert-uses-region-functions:     Commands for Insertion.
89128                                                              (line  38)
89129* self-insertion:                        Commands for Insertion.
89130                                                              (line  17)
89131* SELinux context:                       Extended Attributes. (line  14)
89132* send-string-to-terminal:               Terminal Output.     (line  30)
89133* sending signals:                       Signals to Processes.
89134                                                              (line   6)
89135* sentence-end:                          Standard Regexps.    (line  37)
89136* sentence-end <1>:                      Standard Regexps.    (line  48)
89137* sentence-end-double-space:             Filling.             (line 132)
89138* sentence-end-without-period:           Filling.             (line 137)
89139* sentence-end-without-space:            Filling.             (line 142)
89140* sentinel (of process):                 Sentinels.           (line   6)
89141* seq in rx:                             Rx Constructs.       (line  25)
89142* seq library:                           Sequence Functions.  (line 259)
89143* seq-concatenate:                       Sequence Functions.  (line 541)
89144* seq-contains-p:                        Sequence Functions.  (line 481)
89145* seq-count:                             Sequence Functions.  (line 461)
89146* seq-difference:                        Sequence Functions.  (line 577)
89147* seq-do:                                Sequence Functions.  (line 343)
89148* seq-doseq:                             Sequence Functions.  (line 626)
89149* seq-drop:                              Sequence Functions.  (line 307)
89150* seq-drop-while:                        Sequence Functions.  (line 334)
89151* seq-elt:                               Sequence Functions.  (line 274)
89152* seq-empty-p:                           Sequence Functions.  (line 453)
89153* seq-every-p:                           Sequence Functions.  (line 444)
89154* seq-filter:                            Sequence Functions.  (line 378)
89155* seq-find:                              Sequence Functions.  (line 430)
89156* seq-group-by:                          Sequence Functions.  (line 586)
89157* seq-intersection:                      Sequence Functions.  (line 568)
89158* seq-into:                              Sequence Functions.  (line 596)
89159* seq-length:                            Sequence Functions.  (line 292)
89160* seq-let:                               Sequence Functions.  (line 631)
89161* seq-map:                               Sequence Functions.  (line 347)
89162* seq-map-indexed:                       Sequence Functions.  (line 356)
89163* seq-mapcat:                            Sequence Functions.  (line 551)
89164* seq-mapn:                              Sequence Functions.  (line 366)
89165* seq-max:                               Sequence Functions.  (line 617)
89166* seq-min:                               Sequence Functions.  (line 608)
89167* seq-partition:                         Sequence Functions.  (line 559)
89168* seq-position:                          Sequence Functions.  (line 507)
89169* seq-random-elt:                        Sequence Functions.  (line 659)
89170* seq-reduce:                            Sequence Functions.  (line 396)
89171* seq-remove:                            Sequence Functions.  (line 387)
89172* seq-set-equal-p:                       Sequence Functions.  (line 492)
89173* seq-some:                              Sequence Functions.  (line 417)
89174* seq-sort:                              Sequence Functions.  (line 468)
89175* seq-sort-by:                           Sequence Functions.  (line 473)
89176* seq-subseq:                            Sequence Functions.  (line 529)
89177* seq-take:                              Sequence Functions.  (line 316)
89178* seq-take-while:                        Sequence Functions.  (line 325)
89179* seq-uniq:                              Sequence Functions.  (line 518)
89180* seqp:                                  Sequence Functions.  (line 297)
89181* sequence:                              Sequences Arrays Vectors.
89182                                                              (line   6)
89183* sequence destructuring:                Sequence Functions.  (line 632)
89184* sequence functions in seq:             Sequence Functions.  (line 259)
89185* sequence in rx:                        Rx Constructs.       (line  26)
89186* sequence iteration:                    Sequence Functions.  (line 627)
89187* sequence length:                       Sequence Functions.  (line  14)
89188* sequence maximum:                      Sequence Functions.  (line 618)
89189* sequence minimum:                      Sequence Functions.  (line 609)
89190* sequence reverse:                      Sequence Functions.  (line 116)
89191* sequencep:                             Sequence Functions.  (line   8)
89192* sequences, generalized:                Sequence Functions.  (line 259)
89193* sequences, intersection of:            Sequence Functions.  (line 569)
89194* sequencing:                            Sequencing.          (line   6)
89195* sequencing pattern:                    pcase Macro.         (line  97)
89196* sequential execution:                  Sequencing.          (line   6)
89197* serial connections:                    Serial Ports.        (line   6)
89198* serial-process-configure:              Serial Ports.        (line 115)
89199* serial-term:                           Serial Ports.        (line  31)
89200* serializing:                           Byte Packing.        (line  13)
89201* server-after-make-frame-hook:          Creating Frames.     (line  65)
89202* session file:                          Session Management.  (line  20)
89203* session manager:                       Session Management.  (line   6)
89204* set:                                   Setting Variables.   (line  41)
89205* set, defcustom keyword:                Variable Definitions.
89206                                                              (line  76)
89207* set-advertised-calling-convention:     Obsolete Functions.  (line  51)
89208* set-after, defcustom keyword:          Variable Definitions.
89209                                                              (line 153)
89210* set-auto-coding:                       Default Coding Systems.
89211                                                              (line 140)
89212* set-auto-mode:                         Auto Major Mode.     (line  37)
89213* set-binary-mode:                       Input Functions.     (line  68)
89214* set-buffer:                            Current Buffer.      (line  23)
89215* set-buffer-auto-saved:                 Auto-Saving.         (line 108)
89216* set-buffer-major-mode:                 Auto Major Mode.     (line  68)
89217* set-buffer-modified-p:                 Buffer Modification. (line  27)
89218* set-buffer-multibyte:                  Selecting a Representation.
89219                                                              (line   9)
89220* set-case-syntax:                       Case Tables.         (line 108)
89221* set-case-syntax-delims:                Case Tables.         (line 104)
89222* set-case-syntax-pair:                  Case Tables.         (line 100)
89223* set-case-table:                        Case Tables.         (line  72)
89224* set-category-table:                    Categories.          (line  93)
89225* set-char-table-extra-slot:             Char-Tables.         (line  77)
89226* set-char-table-parent:                 Char-Tables.         (line  69)
89227* set-char-table-range:                  Char-Tables.         (line  99)
89228* set-charset-priority:                  Character Sets.      (line  35)
89229* set-coding-system-priority:            Specifying Coding Systems.
89230                                                              (line  78)
89231* set-default:                           Default Value.       (line  76)
89232* set-default-file-modes:                Changing Files.      (line 212)
89233* set-default-toplevel-value:            Default Value.       (line 105)
89234* set-display-table-slot:                Display Tables.      (line  84)
89235* set-face-attribute:                    Attribute Functions. (line  74)
89236* set-face-background:                   Attribute Functions. (line 101)
89237* set-face-bold:                         Attribute Functions. (line 117)
89238* set-face-extend:                       Attribute Functions. (line 135)
89239* set-face-font:                         Attribute Functions. (line 108)
89240* set-face-foreground:                   Attribute Functions. (line 100)
89241* set-face-inverse-video:                Attribute Functions. (line 128)
89242* set-face-italic:                       Attribute Functions. (line 121)
89243* set-face-stipple:                      Attribute Functions. (line 105)
89244* set-face-underline:                    Attribute Functions. (line 125)
89245* set-file-acl:                          Changing Files.      (line 294)
89246* set-file-extended-attributes:          Changing Files.      (line 276)
89247* set-file-modes:                        Changing Files.      (line 189)
89248* set-file-selinux-context:              Changing Files.      (line 283)
89249* set-file-times:                        Changing Files.      (line 270)
89250* set-fontset-font:                      Fontsets.            (line  83)
89251* set-frame-configuration:               Frame Configurations.
89252                                                              (line  14)
89253* set-frame-font:                        Frame Font.          (line  27)
89254* set-frame-height:                      Frame Size.          (line 113)
89255* set-frame-parameter:                   Parameter Access.    (line  49)
89256* set-frame-position:                    Frame Position.      (line  37)
89257* set-frame-selected-window:             Selecting Windows.   (line 101)
89258* set-frame-size:                        Frame Size.          (line 102)
89259* set-frame-width:                       Frame Size.          (line 138)
89260* set-frame-window-state-change:         Window Hooks.        (line 195)
89261* set-fringe-bitmap-face:                Customizing Bitmaps. (line  39)
89262* set-input-method:                      Input Methods.       (line  28)
89263* set-input-mode:                        Input Modes.         (line   6)
89264* set-keyboard-coding-system:            Terminal I/O Encoding.
89265                                                              (line  17)
89266* set-keymap-parent:                     Inheritance and Keymaps.
89267                                                              (line  31)
89268* set-left-margin:                       Margins.             (line  33)
89269* set-mark:                              The Mark.            (line  79)
89270* set-marker:                            Moving Markers.      (line  11)
89271* set-marker-insertion-type:             Marker Insertion Types.
89272                                                              (line  13)
89273* set-match-data:                        Entire Match Data.   (line  49)
89274* set-message-function:                  Displaying Messages. (line  53)
89275* set-minibuffer-window:                 Minibuffer Windows.  (line  19)
89276* set-mouse-absolute-pixel-position:     Mouse Position.      (line  56)
89277* set-mouse-pixel-position:              Mouse Position.      (line  40)
89278* set-mouse-position:                    Mouse Position.      (line  25)
89279* set-network-process-option:            Network Options.     (line  66)
89280* set-process-buffer:                    Process Buffers.     (line  55)
89281* set-process-coding-system:             Process Information. (line 181)
89282* set-process-datagram-address:          Datagrams.           (line  24)
89283* set-process-filter:                    Filter Functions.    (line  81)
89284* set-process-plist:                     Process Information. (line 202)
89285* set-process-query-on-exit-flag:        Query Before Exit.   (line  17)
89286* set-process-sentinel:                  Sentinels.           (line  90)
89287* set-process-thread:                    Processes and Threads.
89288                                                              (line  25)
89289* set-process-window-size:               Process Buffers.     (line  84)
89290* set-register:                          Registers.           (line  61)
89291* set-right-margin:                      Margins.             (line  38)
89292* set-standard-case-table:               Case Tables.         (line  62)
89293* set-syntax-table:                      Syntax Table Functions.
89294                                                              (line  91)
89295* set-terminal-coding-system:            Terminal I/O Encoding.
89296                                                              (line  32)
89297* set-terminal-parameter:                Terminal Parameters. (line  24)
89298* set-text-properties:                   Changing Properties. (line  70)
89299* set-transient-map:                     Controlling Active Maps.
89300                                                              (line 147)
89301* set-visited-file-modtime:              Modification Time.   (line  59)
89302* set-visited-file-name:                 Buffer File Name.    (line  84)
89303* set-window-buffer:                     Buffers and Windows. (line  15)
89304* set-window-combination-limit:          Recombining Windows. (line 197)
89305* set-window-configuration:              Window Configurations.
89306                                                              (line  26)
89307* set-window-dedicated-p:                Dedicated Windows.   (line  43)
89308* set-window-display-table:              Active Display Table.
89309                                                              (line  20)
89310* set-window-fringes:                    Fringe Size/Pos.     (line  36)
89311* set-window-group-start:                Window Start and End.
89312                                                              (line 142)
89313* set-window-group-start-function:       Window Start and End.
89314                                                              (line 142)
89315* set-window-hscroll:                    Horizontal Scrolling.
89316                                                              (line 101)
89317* set-window-margins:                    Display Margins.     (line  56)
89318* set-window-next-buffers:               Window History.      (line  45)
89319* set-window-parameter:                  Window Parameters.   (line  20)
89320* set-window-point:                      Window Point.        (line  43)
89321* set-window-prev-buffers:               Window History.      (line  29)
89322* set-window-scroll-bars:                Scroll Bars.         (line  41)
89323* set-window-start:                      Window Start and End.
89324                                                              (line  81)
89325* set-window-vscroll:                    Vertical Scrolling.  (line  35)
89326* set-xwidget-plist:                     Xwidgets.            (line  35)
89327* set-xwidget-query-on-exit-flag:        Xwidgets.            (line  80)
89328* setcar:                                Setcar.              (line   9)
89329* setcdr:                                Setcdr.              (line   8)
89330* setenv:                                System Environment.  (line  99)
89331* setf:                                  Setting Generalized Variables.
89332                                                              (line  13)
89333* setplist:                              Symbol Plists.       (line  36)
89334* setq:                                  Setting Variables.   (line  10)
89335* setq-default:                          Default Value.       (line  35)
89336* setq-local:                            Creating Buffer-Local.
89337                                                              (line  48)
89338* sets:                                  Sets And Lists.      (line   6)
89339* setting modes of files:                Changing Files.      (line   6)
89340* setting-constant error:                Constant Variables.  (line   6)
89341* set_user_finalizer:                    Module Values.       (line 382)
89342* set_user_ptr:                          Module Values.       (line 372)
89343* severity level:                        Warning Basics.      (line   6)
89344* sexp:                                  Intro Eval.          (line  12)
89345* sexp motion:                           List Motion.         (line   6)
89346* SHA hash:                              Checksum/Hash.       (line   6)
89347* SHA hash <1>:                          GnuTLS Cryptography. (line   6)
89348* shadowed Lisp files:                   Library Search.      (line 111)
89349* shadowing of variables:                Local Variables.     (line  22)
89350* shared structure, read syntax:         Circular Objects.    (line   6)
89351* shell command arguments:               Shell Arguments.     (line   6)
89352* shell-command-history:                 Minibuffer History.  (line 111)
89353* shell-command-to-string:               Synchronous Processes.
89354                                                              (line 267)
89355* shell-quote-argument:                  Shell Arguments.     (line  13)
89356* shift-selection, and interactive spec: Using Interactive.   (line  75)
89357* shift-translation:                     Key Sequence Input.  (line  73)
89358* should_quit:                           Module Misc.         (line  72)
89359* show image:                            Showing Images.      (line   6)
89360* show-help-function:                    Special Properties.  (line 397)
89361* shr-insert-document:                   Parsing HTML/XML.    (line  51)
89362* shrink-window-if-larger-than-buffer:   Resizing Windows.    (line 194)
89363* shy groups:                            Regexp Backslash.    (line  67)
89364* sibling window:                        Windows and Frames.  (line  51)
89365* side effect:                           Intro Eval.          (line  47)
89366* side windows:                          Side Windows.        (line   6)
89367* side, a buffer display action alist entry: Buffer Display Action Alists.
89368                                                              (line 185)
89369* side-effect-free property:             Standard Properties. (line  98)
89370* SIGHUP:                                Killing Emacs.       (line  26)
89371* SIGINT:                                Killing Emacs.       (line  26)
89372* signal:                                Signaling Errors.    (line  52)
89373* signal-process:                        Signals to Processes.
89374                                                              (line  94)
89375* signaling errors:                      Signaling Errors.    (line   6)
89376* signals:                               Signals to Processes.
89377                                                              (line   6)
89378* SIGTERM:                               Killing Emacs.       (line  26)
89379* SIGTSTP:                               Suspending Emacs.    (line  20)
89380* sigusr1 event:                         Misc Events.         (line  66)
89381* sigusr2 event:                         Misc Events.         (line  66)
89382* simple package:                        Simple Packages.     (line   6)
89383* sin:                                   Math Functions.      (line   9)
89384* single file package:                   Simple Packages.     (line   6)
89385* single-function hook:                  Hooks.               (line  41)
89386* single-key-description:                Describing Characters.
89387                                                              (line  28)
89388* sit-for:                               Waiting.             (line  12)
89389* site-init.el:                          Building Emacs.      (line  97)
89390* site-lisp directories:                 Library Search.      (line  34)
89391* site-load.el:                          Building Emacs.      (line  80)
89392* site-run-file:                         Init File.           (line  46)
89393* site-start.el:                         Startup Summary.     (line  77)
89394* size of frame:                         Frame Geometry.      (line   6)
89395* size of image:                         Showing Images.      (line  72)
89396* size of text on display:               Size of Displayed Text.
89397                                                              (line   6)
89398* size of window:                        Window Sizes.        (line   6)
89399* skip-chars-backward:                   Skipping Characters. (line  52)
89400* skip-chars-forward:                    Skipping Characters. (line  14)
89401* skip-syntax-backward:                  Motion and Syntax.   (line  22)
89402* skip-syntax-forward:                   Motion and Syntax.   (line   9)
89403* skip-taskbar, a frame parameter:       Management Parameters.
89404                                                              (line  59)
89405* skipping characters:                   Skipping Characters. (line   6)
89406* skipping characters of certain syntax: Motion and Syntax.   (line   6)
89407* skipping comments:                     Control Parsing.     (line  13)
89408* sleep-for:                             Waiting.             (line  41)
89409* slice, image:                          Showing Images.      (line  34)
89410* slot, a buffer display action alist entry: Buffer Display Action Alists.
89411                                                              (line 195)
89412* small-temporary-file-directory:        Unique File Names.   (line  72)
89413* smallest fixnum:                       Integer Basics.      (line  91)
89414* SMIE:                                  SMIE.                (line   6)
89415* SMIE grammar:                          SMIE Grammar.        (line   6)
89416* SMIE lexer:                            SMIE Lexer.          (line   6)
89417* smie-bnf->prec2:                       Operator Precedence Grammars.
89418                                                              (line  37)
89419* smie-close-block:                      SMIE setup.          (line  32)
89420* smie-config:                           SMIE Customization.  (line  12)
89421* smie-config-guess:                     SMIE Customization.  (line  18)
89422* smie-config-local:                     SMIE Customization.  (line  35)
89423* smie-config-save:                      SMIE Customization.  (line  23)
89424* smie-config-set-indent:                SMIE Customization.  (line  31)
89425* smie-config-show-indent:               SMIE Customization.  (line  27)
89426* smie-down-list:                        SMIE setup.          (line  36)
89427* smie-merge-prec2s:                     Operator Precedence Grammars.
89428                                                              (line  24)
89429* smie-prec2->grammar:                   Operator Precedence Grammars.
89430                                                              (line  19)
89431* smie-precs->prec2:                     Operator Precedence Grammars.
89432                                                              (line  28)
89433* smie-rule-bolp:                        SMIE Indentation Helpers.
89434                                                              (line  11)
89435* smie-rule-hanging-p:                   SMIE Indentation Helpers.
89436                                                              (line  14)
89437* smie-rule-next-p:                      SMIE Indentation Helpers.
89438                                                              (line  19)
89439* smie-rule-parent:                      SMIE Indentation Helpers.
89440                                                              (line  33)
89441* smie-rule-parent-p:                    SMIE Indentation Helpers.
89442                                                              (line  25)
89443* smie-rule-prev-p:                      SMIE Indentation Helpers.
89444                                                              (line  22)
89445* smie-rule-separator:                   SMIE Indentation Helpers.
89446                                                              (line  38)
89447* smie-rule-sibling-p:                   SMIE Indentation Helpers.
89448                                                              (line  28)
89449* smie-setup:                            SMIE setup.          (line  11)
89450* smooth-curveto:                        SVG Images.          (line 237)
89451* smooth-quadratic-bezier-curveto:       SVG Images.          (line 267)
89452* snap-width, a frame parameter:         Mouse Dragging Parameters.
89453                                                              (line  28)
89454* Snarf-documentation:                   Accessing Documentation.
89455                                                              (line 145)
89456* sort:                                  Sequence Functions.  (line 187)
89457* sort-columns:                          Sorting.             (line 212)
89458* sort-fields:                           Sorting.             (line 190)
89459* sort-fold-case:                        Sorting.             (line 111)
89460* sort-lines:                            Sorting.             (line 177)
89461* sort-numeric-base:                     Sorting.             (line 208)
89462* sort-numeric-fields:                   Sorting.             (line 197)
89463* sort-pages:                            Sorting.             (line 186)
89464* sort-paragraphs:                       Sorting.             (line 181)
89465* sort-regexp-fields:                    Sorting.             (line 115)
89466* sort-subr:                             Sorting.             (line  11)
89467* sorting lists:                         Sequence Functions.  (line 188)
89468* sorting sequences:                     Sequence Functions.  (line 468)
89469* sorting text:                          Sorting.             (line   6)
89470* sorting vectors:                       Sequence Functions.  (line 188)
89471* sound:                                 Sound Output.        (line   6)
89472* source breakpoints:                    Source Breakpoints.  (line   6)
89473* space (ASCII character):               Basic Char Syntax.   (line  27)
89474* space display spec, and bidirectional text: Bidirectional Display.
89475                                                              (line 183)
89476* spaces, pixel specification:           Pixel Specification. (line   6)
89477* spaces, specified height or width:     Specified Space.     (line   6)
89478* sparse keymap:                         Format of Keymaps.   (line   6)
89479* <SPC> in minibuffer:                   Text from Minibuffer.
89480                                                              (line 244)
89481* special events:                        Special Events.      (line   6)
89482* special form descriptions:             A Sample Function Description.
89483                                                              (line   6)
89484* special forms:                         Special Forms.       (line   6)
89485* special forms for control structures:  Control Structures.  (line   6)
89486* special modes:                         Major Mode Conventions.
89487                                                              (line 197)
89488* special read syntax:                   Special Read Syntax. (line   6)
89489* special variables:                     Using Lexical Binding.
89490                                                              (line  30)
89491* special-event-map:                     Controlling Active Maps.
89492                                                              (line 132)
89493* special-form-p:                        Special Forms.       (line  23)
89494* special-mode:                          Basic Major Modes.   (line  36)
89495* special-variable-p:                    Using Lexical Binding.
89496                                                              (line  57)
89497* Specified time is not representable:   Time of Day.         (line  44)
89498* specify coding system:                 Specifying Coding Systems.
89499                                                              (line   6)
89500* specify color:                         Color Names.         (line   6)
89501* speedups:                              Compilation Tips.    (line   6)
89502* splicing (with backquote):             Backquote.           (line  29)
89503* split-height-threshold:                Choosing Window Options.
89504                                                              (line  49)
89505* split-string:                          Creating Strings.    (line 143)
89506* split-string-and-unquote:              Shell Arguments.     (line  52)
89507* split-string-default-separators:       Creating Strings.    (line 220)
89508* split-width-threshold:                 Choosing Window Options.
89509                                                              (line  56)
89510* split-window:                          Splitting Windows.   (line  12)
89511* split-window, a window parameter:      Window Parameters.   (line  92)
89512* split-window-below:                    Splitting Windows.   (line 128)
89513* split-window-keep-point:               Splitting Windows.   (line 134)
89514* split-window-preferred-function:       Choosing Window Options.
89515                                                              (line  22)
89516* split-window-right:                    Splitting Windows.   (line 122)
89517* split-window-sensibly:                 Choosing Window Options.
89518                                                              (line  33)
89519* splitting windows:                     Splitting Windows.   (line   6)
89520* sqrt:                                  Math Functions.      (line  46)
89521* stable sort:                           Sequence Functions.  (line 188)
89522* stack allocated Lisp objects:          Stack-allocated Objects.
89523                                                              (line   6)
89524* stack frame:                           Backtraces.          (line  10)
89525* standard abbrev tables:                Standard Abbrev Tables.
89526                                                              (line   6)
89527* standard colors for character terminals: Font and Color Parameters.
89528                                                              (line  34)
89529* standard error process:                Asynchronous Processes.
89530                                                              (line 112)
89531* standard errors:                       Standard Errors.     (line   6)
89532* standard hooks:                        Standard Hooks.      (line   6)
89533* standard regexps used in editing:      Standard Regexps.    (line   6)
89534* standard syntax table:                 Syntax Basics.       (line  36)
89535* standard-case-table:                   Case Tables.         (line  66)
89536* standard-category-table:               Categories.          (line  84)
89537* standard-display-table:                Active Display Table.
89538                                                              (line  29)
89539* standard-input:                        Input Functions.     (line  50)
89540* standard-output:                       Output Variables.    (line   6)
89541* standard-syntax-table:                 Syntax Basics.       (line  44)
89542* standard-translation-table-for-decode: Translation of Characters.
89543                                                              (line  46)
89544* standard-translation-table-for-encode: Translation of Characters.
89545                                                              (line  51)
89546* standards of coding style:             Tips.                (line   6)
89547* start-file-process:                    Asynchronous Processes.
89548                                                              (line 250)
89549* start-file-process-shell-command:      Asynchronous Processes.
89550                                                              (line 293)
89551* start-process:                         Asynchronous Processes.
89552                                                              (line 204)
89553* start-process, command-line arguments from minibuffer: Shell Arguments.
89554                                                              (line  40)
89555* start-process-shell-command:           Asynchronous Processes.
89556                                                              (line 277)
89557* STARTTLS network connections:          Network.             (line  55)
89558* startup of Emacs:                      Startup Summary.     (line   6)
89559* startup screen:                        Startup Summary.     (line 141)
89560* startup.el:                            Startup Summary.     (line   6)
89561* staticpro, protection from GC:         Writing Emacs Primitives.
89562                                                              (line 264)
89563* stderr stream, use for debugging:      Output Streams.      (line 128)
89564* sticky text properties:                Sticky Properties.   (line   6)
89565* sticky, a frame parameter:             Management Parameters.
89566                                                              (line  49)
89567* stop points:                           Using Edebug.        (line  36)
89568* stop-process:                          Signals to Processes.
89569                                                              (line  70)
89570* stopbits, in serial connections:       Serial Ports.        (line 116)
89571* stopping an infinite loop:             Infinite Loops.      (line   6)
89572* stopping on events:                    Global Break Condition.
89573                                                              (line   6)
89574* storage of vector-like Lisp objects:   Garbage Collection.  (line  16)
89575* store-match-data:                      Entire Match Data.   (line  62)
89576* store-substring:                       Modifying Strings.   (line  17)
89577* stream (for printing):                 Output Streams.      (line   6)
89578* stream (for reading):                  Input Streams.       (line   6)
89579* strike-through text:                   Face Attributes.     (line 113)
89580* string:                                Creating Strings.    (line  31)
89581* string creation:                       Creating Strings.    (line   6)
89582* string equality:                       Text Comparison.     (line   6)
89583* string in keymap:                      Key Lookup.          (line  46)
89584* string input stream:                   Input Streams.       (line  22)
89585* string length:                         Sequence Functions.  (line  14)
89586* string modification:                   Modifying Strings.   (line   6)
89587* string predicates:                     Predicates for Strings.
89588                                                              (line   6)
89589* string reverse:                        Sequence Functions.  (line 116)
89590* string search:                         String Search.       (line   6)
89591* string to number:                      String Conversion.   (line  36)
89592* string to object:                      Input Functions.     (line  22)
89593* string to vector:                      Sequence Functions.  (line 597)
89594* string, number of bytes:               Text Representations.
89595                                                              (line 120)
89596* string, writing a doc string:          Documentation Basics.
89597                                                              (line   6)
89598* string-as-multibyte:                   Selecting a Representation.
89599                                                              (line  45)
89600* string-as-unibyte:                     Selecting a Representation.
89601                                                              (line  37)
89602* string-bytes:                          Text Representations.
89603                                                              (line 119)
89604* string-chars-consed:                   Memory Usage.        (line  30)
89605* string-collate-equalp:                 Text Comparison.     (line  55)
89606* string-collate-lessp:                  Text Comparison.     (line 143)
89607* string-distance:                       Text Comparison.     (line 223)
89608* string-end in rx:                      Rx Constructs.       (line 324)
89609* string-equal:                          Text Comparison.     (line  52)
89610* string-greaterp:                       Text Comparison.     (line 138)
89611* string-lessp:                          Text Comparison.     (line 135)
89612* string-match:                          Regexp Search.       (line  86)
89613* string-match-p:                        Regexp Search.       (line 115)
89614* string-or-null-p:                      Predicates for Strings.
89615                                                              (line  12)
89616* string-prefix-p:                       Text Comparison.     (line 189)
89617* string-start in rx:                    Rx Constructs.       (line 320)
89618* string-suffix-p:                       Text Comparison.     (line 194)
89619* string-to-char:                        String Conversion.   (line  70)
89620* string-to-int:                         String Conversion.   (line  63)
89621* string-to-multibyte:                   Converting Representations.
89622                                                              (line  42)
89623* string-to-number:                      String Conversion.   (line  35)
89624* string-to-syntax:                      Syntax Table Internals.
89625                                                              (line  49)
89626* string-to-unibyte:                     Converting Representations.
89627                                                              (line  51)
89628* string-version-lessp:                  Text Comparison.     (line 182)
89629* string-width:                          Size of Displayed Text.
89630                                                              (line  17)
89631* string<:                               Text Comparison.     (line  90)
89632* string=:                               Text Comparison.     (line  17)
89633* stringp:                               Predicates for Strings.
89634                                                              (line   9)
89635* strings:                               Strings and Characters.
89636                                                              (line   6)
89637* strings with keyboard events:          Strings of Events.   (line   6)
89638* strings, formatting them:              Formatting Strings.  (line   6)
89639* strings-consed:                        Memory Usage.        (line  38)
89640* structural matching:                   Backquote Patterns.  (line   6)
89641* sub-sequence:                          Sequence Functions.  (line 530)
89642* submatch in rx:                        Rx Constructs.       (line 360)
89643* submatch-n in rx:                      Rx Constructs.       (line 368)
89644* submenu:                               Mouse Menus.         (line  20)
89645* subprocess:                            Processes.           (line   6)
89646* subr:                                  What Is a Function.  (line  37)
89647* subr-arity:                            What Is a Function.  (line 143)
89648* subrp:                                 What Is a Function.  (line 127)
89649* subst-char-in-region:                  Substitution.        (line   9)
89650* substitute characters:                 Substitution.        (line   6)
89651* substitute-command-keys:               Keys in Documentation.
89652                                                              (line  61)
89653* substitute-in-file-name:               File Name Expansion. (line  95)
89654* substitute-key-definition:             Changing Key Bindings.
89655                                                              (line 110)
89656* substituting keys in documentation:    Keys in Documentation.
89657                                                              (line   6)
89658* substring:                             Creating Strings.    (line  37)
89659* substring-no-properties:               Creating Strings.    (line 101)
89660* subtype of char-table:                 Char-Tables.         (line  14)
89661* suggestions:                           Caveats.             (line  27)
89662* super characters:                      Other Char Bits.     (line  16)
89663* suppress-keymap:                       Changing Key Bindings.
89664                                                              (line 148)
89665* surrogate minibuffer frame:            Minibuffers and Frames.
89666                                                              (line  10)
89667* suspend (cf. no-redraw-on-reenter):    Refresh Screen.      (line  31)
89668* suspend evaluation:                    Recursive Editing.   (line  62)
89669* suspend major mode temporarily:        Major Modes.         (line   6)
89670* suspend-emacs:                         Suspending Emacs.    (line  25)
89671* suspend-frame:                         Suspending Emacs.    (line 113)
89672* suspend-hook:                          Suspending Emacs.    (line  73)
89673* suspend-resume-hook:                   Suspending Emacs.    (line  76)
89674* suspend-tty:                           Suspending Emacs.    (line  80)
89675* suspend-tty-functions:                 Suspending Emacs.    (line  90)
89676* suspending Emacs:                      Suspending Emacs.    (line   6)
89677* SVG images:                            SVG Images.          (line   6)
89678* SVG object:                            SVG Images.          (line  20)
89679* svg path commands:                     SVG Images.          (line 177)
89680* svg-circle:                            SVG Images.          (line  69)
89681* svg-clip-path:                         SVG Images.          (line 139)
89682* svg-create:                            SVG Images.          (line  10)
89683* svg-ellipse:                           SVG Images.          (line  73)
89684* svg-embed:                             SVG Images.          (line 129)
89685* svg-gradient:                          SVG Images.          (line  25)
89686* svg-image:                             SVG Images.          (line 160)
89687* svg-line:                              SVG Images.          (line  77)
89688* svg-node:                              SVG Images.          (line 150)
89689* svg-path:                              SVG Images.          (line  94)
89690* svg-polygon:                           SVG Images.          (line  87)
89691* svg-polyline:                          SVG Images.          (line  80)
89692* svg-rectangle:                         SVG Images.          (line  63)
89693* svg-remove:                            SVG Images.          (line 157)
89694* svg-text:                              SVG Images.          (line 114)
89695* swap text between buffers:             Swapping Text.       (line   6)
89696* switch-to-buffer:                      Switching Buffers.   (line  19)
89697* switch-to-buffer-in-dedicated-window:  Switching Buffers.   (line  53)
89698* switch-to-buffer-obey-display-actions: Switching Buffers.   (line  93)
89699* switch-to-buffer-other-frame:          Switching Buffers.   (line 114)
89700* switch-to-buffer-other-window:         Switching Buffers.   (line 101)
89701* switch-to-buffer-preserve-window-point: Switching Buffers.  (line  79)
89702* switch-to-next-buffer:                 Window History.      (line  84)
89703* switch-to-prev-buffer:                 Window History.      (line  60)
89704* switch-to-prev-buffer-skip:            Window History.      (line 102)
89705* switches on command line:              Command-Line Arguments.
89706                                                              (line  29)
89707* switching to a buffer:                 Switching Buffers.   (line   6)
89708* sxhash-eq:                             Defining Hash.       (line  63)
89709* sxhash-eql:                            Defining Hash.       (line  70)
89710* sxhash-equal:                          Defining Hash.       (line  46)
89711* symbol:                                Symbols.             (line   6)
89712* symbol components:                     Symbol Components.   (line   6)
89713* symbol equality:                       Creating Symbols.    (line  39)
89714* symbol evaluation:                     Symbol Forms.        (line   6)
89715* symbol forms:                          Symbol Forms.        (line   6)
89716* symbol function indirection:           Function Indirection.
89717                                                              (line   6)
89718* symbol in keymap:                      Key Lookup.          (line  67)
89719* symbol name hashing:                   Creating Symbols.    (line  11)
89720* symbol property:                       Symbol Properties.   (line   6)
89721* symbol that evaluates to itself:       Constant Variables.  (line   6)
89722* symbol with constant value:            Constant Variables.  (line   6)
89723* symbol, where defined:                 Where Defined.       (line   6)
89724* symbol-end in rx:                      Rx Constructs.       (line 352)
89725* symbol-file:                           Where Defined.       (line   6)
89726* symbol-function:                       Function Cells.      (line  13)
89727* symbol-name:                           Creating Symbols.    (line  72)
89728* symbol-plist:                          Symbol Plists.       (line  33)
89729* symbol-start in rx:                    Rx Constructs.       (line 348)
89730* symbol-value:                          Accessing Variables. (line  14)
89731* symbolic links:                        Kinds of Files.      (line   6)
89732* symbolic links <1>:                    Kinds of Files.      (line  18)
89733* symbolp:                               Symbols.             (line  16)
89734* symbols-consed:                        Memory Usage.        (line  26)
89735* symmetric cipher:                      GnuTLS Cryptography. (line   6)
89736* synchronous subprocess:                Synchronous Processes.
89737                                                              (line   6)
89738* syntactic font lock:                   Syntactic Font Lock. (line   6)
89739* syntax class:                          Syntax Descriptors.  (line   6)
89740* syntax class table:                    Syntax Class Table.  (line   6)
89741* syntax code:                           Syntax Table Internals.
89742                                                              (line  13)
89743* syntax descriptor:                     Syntax Descriptors.  (line  21)
89744* syntax entry, setting:                 Syntax Table Functions.
89745                                                              (line  25)
89746* syntax error (Edebug):                 Backtracking.        (line   6)
89747* syntax flags:                          Syntax Flags.        (line   6)
89748* syntax for characters:                 Basic Char Syntax.   (line   6)
89749* syntax in rx:                          Rx Constructs.       (line 225)
89750* syntax of regular expressions:         Syntax of Regexps.   (line   6)
89751* syntax table:                          Syntax Tables.       (line   6)
89752* syntax table example:                  Example Major Modes. (line  50)
89753* syntax table internals:                Syntax Table Internals.
89754                                                              (line   6)
89755* syntax tables (accessing elements of): Syntax Table Internals.
89756                                                              (line  19)
89757* syntax tables in modes:                Major Mode Conventions.
89758                                                              (line 117)
89759* syntax-after:                          Syntax Table Internals.
89760                                                              (line  53)
89761* syntax-class:                          Syntax Table Internals.
89762                                                              (line  60)
89763* syntax-ppss:                           Position Parse.      (line  10)
89764* syntax-ppss-context:                   Parser State.        (line  72)
89765* syntax-ppss-flush-cache:               Position Parse.      (line  34)
89766* syntax-ppss-toplevel-pos:              Parser State.        (line  63)
89767* syntax-propertize-extend-region-functions: Syntax Properties.
89768                                                              (line  58)
89769* syntax-propertize-function:            Syntax Properties.   (line  32)
89770* syntax-table:                          Syntax Table Functions.
89771                                                              (line  95)
89772* syntax-table (text property):          Syntax Properties.   (line   6)
89773* syntax-table-p:                        Syntax Basics.       (line  19)
89774* system abbrev:                         Abbrevs.             (line  25)
89775* system processes:                      System Processes.    (line   6)
89776* system type and name:                  System Environment.  (line  16)
89777* system-configuration:                  System Environment.  (line  10)
89778* system-groups:                         User Identification. (line  73)
89779* system-key-alist:                      X11 Keysyms.         (line   9)
89780* system-messages-locale:                Locales.             (line  17)
89781* system-name:                           System Environment.  (line  69)
89782* system-time-locale:                    Locales.             (line  24)
89783* system-type:                           System Environment.  (line  16)
89784* system-users:                          User Identification. (line  67)
89785* t:                                     nil and t.           (line  25)
89786* t input stream:                        Input Streams.       (line  40)
89787* t output stream:                       Output Streams.      (line  31)
89788* tab (ASCII character):                 Basic Char Syntax.   (line  27)
89789* tab deletion:                          Deletion.            (line  69)
89790* <TAB> in minibuffer:                   Text from Minibuffer.
89791                                                              (line 247)
89792* tab-always-indent:                     Mode-Specific Indent.
89793                                                              (line  63)
89794* tab-bar, prefix key:                   Key Sequence Input.  (line  92)
89795* tab-line, prefix key:                  Key Sequence Input.  (line  92)
89796* tab-line-format, a window parameter:   Window Parameters.   (line 150)
89797* tab-prefix-map:                        Prefix Keys.         (line  40)
89798* tab-stop-list:                         Indent Tabs.         (line  19)
89799* tab-to-tab-stop:                       Indent Tabs.         (line  15)
89800* tab-width:                             Usual Display.       (line  72)
89801* tabs stops for indentation:            Indent Tabs.         (line   6)
89802* Tabulated List mode:                   Tabulated List Mode. (line   6)
89803* tabulated-list-clear-all-tags:         Tabulated List Mode. (line 183)
89804* tabulated-list-delete-entry:           Tabulated List Mode. (line 145)
89805* tabulated-list-entries:                Tabulated List Mode. (line  71)
89806* tabulated-list-format:                 Tabulated List Mode. (line  52)
89807* tabulated-list-get-entry:              Tabulated List Mode. (line 162)
89808* tabulated-list-get-id:                 Tabulated List Mode. (line 156)
89809* tabulated-list-gui-sort-indicator-asc: Tabulated List Mode. (line  32)
89810* tabulated-list-gui-sort-indicator-desc: Tabulated List Mode.
89811                                                              (line  40)
89812* tabulated-list-header-overlay-p:       Tabulated List Mode. (line 169)
89813* tabulated-list-init-header:            Tabulated List Mode. (line 116)
89814* tabulated-list-mode:                   Tabulated List Mode. (line  18)
89815* tabulated-list-padding:                Tabulated List Mode. (line 175)
89816* tabulated-list-print:                  Tabulated List Mode. (line 126)
89817* tabulated-list-printer:                Tabulated List Mode. (line 100)
89818* tabulated-list-put-tag:                Tabulated List Mode. (line 175)
89819* tabulated-list-revert-hook:            Tabulated List Mode. (line  95)
89820* tabulated-list-set-col:                Tabulated List Mode. (line 187)
89821* tabulated-list-sort-key:               Tabulated List Mode. (line 109)
89822* tabulated-list-tty-sort-indicator-asc: Tabulated List Mode. (line  44)
89823* tabulated-list-tty-sort-indicator-desc: Tabulated List Mode.
89824                                                              (line  48)
89825* tabulated-list-use-header-line:        Tabulated List Mode. (line 169)
89826* tag on run time stack:                 Catch and Throw.     (line  61)
89827* tag, customization keyword:            Common Keywords.     (line  18)
89828* tan:                                   Math Functions.      (line  11)
89829* TCP:                                   Network.             (line   6)
89830* temacs:                                Building Emacs.      (line   6)
89831* TEMP environment variable:             Unique File Names.   (line  55)
89832* temp-buffer-max-height:                Temporary Displays.  (line 135)
89833* temp-buffer-max-width:                 Temporary Displays.  (line 143)
89834* temp-buffer-resize-mode:               Temporary Displays.  (line 124)
89835* temp-buffer-setup-hook:                Temporary Displays.  (line  69)
89836* temp-buffer-show-function:             Temporary Displays.  (line  59)
89837* temp-buffer-show-hook:                 Temporary Displays.  (line  75)
89838* temp-buffer-window-setup-hook:         Temporary Displays.  (line 103)
89839* temp-buffer-window-show-hook:          Temporary Displays.  (line 103)
89840* temporary buffer display:              Temporary Displays.  (line   6)
89841* temporary display:                     Temporary Displays.  (line   6)
89842* temporary file on a remote host:       Unique File Names.   (line 101)
89843* temporary files:                       Unique File Names.   (line   6)
89844* temporary-file-directory:              Unique File Names.   (line  54)
89845* temporary-file-directory <1>:          Unique File Names.   (line 115)
89846* TERM environment variable:             Terminal-Specific.   (line  43)
89847* term-file-aliases:                     Terminal-Specific.   (line  54)
89848* term-file-prefix:                      Terminal-Specific.   (line  42)
89849* Termcap:                               Terminal-Specific.   (line  17)
89850* terminal:                              Frames.              (line  17)
89851* terminal input:                        Terminal Input.      (line   6)
89852* terminal input modes:                  Input Modes.         (line   6)
89853* terminal output:                       Terminal Output.     (line   6)
89854* terminal parameters:                   Terminal Parameters. (line   6)
89855* terminal screen:                       Basic Windows.       (line  17)
89856* terminal type:                         Terminal Type.       (line   6)
89857* terminal-coding-system:                Terminal I/O Encoding.
89858                                                              (line  25)
89859* terminal-list:                         Multiple Terminals.  (line  34)
89860* terminal-live-p:                       Frames.              (line  58)
89861* terminal-local variables:              Multiple Terminals.  (line  68)
89862* terminal-name:                         Multiple Terminals.  (line  28)
89863* terminal-parameter:                    Terminal Parameters. (line  19)
89864* terminal-parameters:                   Terminal Parameters. (line  15)
89865* terminal-specific initialization:      Terminal-Specific.   (line   6)
89866* termscript file:                       Terminal Output.     (line  50)
89867* terpri:                                Output Functions.    (line  85)
89868* test-completion:                       Basic Completion.    (line 119)
89869* testcover-mark-all:                    Test Coverage.       (line   6)
89870* testcover-next-mark:                   Test Coverage.       (line   6)
89871* testcover-start:                       Test Coverage.       (line   6)
89872* testing types:                         Type Predicates.     (line  21)
89873* text:                                  Text.                (line   6)
89874* text area:                             Frame Layout.        (line 219)
89875* text area of a window:                 Window Sizes.        (line  23)
89876* text comparison:                       Text Comparison.     (line   6)
89877* text conversion of coding system:      Lisp and Coding Systems.
89878                                                              (line  57)
89879* text deletion:                         Deletion.            (line   6)
89880* text height of a frame:                Frame Size.          (line   6)
89881* text insertion:                        Insertion.           (line   6)
89882* text near point:                       Near Point.          (line   6)
89883* text parsing:                          Syntax Tables.       (line   6)
89884* text properties:                       Text Properties.     (line   6)
89885* text properties in files:              Format Conversion.   (line   6)
89886* text properties in the mode line:      Properties in Mode.  (line   6)
89887* text properties, changing:             Changing Properties. (line   6)
89888* text properties, examining:            Examining Properties.
89889                                                              (line   6)
89890* text properties, read syntax:          Text Props and Strings.
89891                                                              (line   6)
89892* text properties, searching:            Property Search.     (line   6)
89893* text representation:                   Text Representations.
89894                                                              (line   6)
89895* text size of a frame:                  Frame Size.          (line   6)
89896* text terminal:                         Frames.              (line  21)
89897* text width of a frame:                 Frame Size.          (line   6)
89898* text-char-description:                 Describing Characters.
89899                                                              (line  54)
89900* text-mode:                             Basic Major Modes.   (line  18)
89901* text-mode-abbrev-table:                Standard Abbrev Tables.
89902                                                              (line  32)
89903* text-properties-at:                    Examining Properties.
89904                                                              (line  64)
89905* text-property-any:                     Property Search.     (line 113)
89906* text-property-default-nonsticky:       Sticky Properties.   (line  55)
89907* text-property-not-all:                 Property Search.     (line 123)
89908* text-property-search-backward:         Property Search.     (line 204)
89909* text-property-search-forward:          Property Search.     (line 134)
89910* text-quoting-style:                    Keys in Documentation.
89911                                                              (line  46)
89912* text-quoting-style <1>:                Text Quoting Style.  (line  29)
89913* text-terminal focus notification:      Input Focus.         (line  98)
89914* textual order:                         Control Structures.  (line  12)
89915* textual scrolling:                     Textual Scrolling.   (line   6)
89916* thing-at-point:                        Buffer Contents.     (line 130)
89917* this-command:                          Command Loop Info.   (line  33)
89918* this-command-keys:                     Command Loop Info.   (line  73)
89919* this-command-keys-shift-translated:    Key Sequence Input.  (line  78)
89920* this-command-keys-vector:              Command Loop Info.   (line  89)
89921* this-original-command:                 Command Loop Info.   (line  66)
89922* thread backtrace:                      The Thread List.     (line  21)
89923* thread list:                           The Thread List.     (line   6)
89924* thread--blocker:                       Basic Thread Functions.
89925                                                              (line  54)
89926* thread-join:                           Basic Thread Functions.
89927                                                              (line  28)
89928* thread-last-error:                     Basic Thread Functions.
89929                                                              (line  84)
89930* thread-list-refresh-seconds:           The Thread List.     (line  14)
89931* thread-live-p:                         Basic Thread Functions.
89932                                                              (line  50)
89933* thread-name:                           Basic Thread Functions.
89934                                                              (line  47)
89935* thread-signal:                         Basic Thread Functions.
89936                                                              (line  33)
89937* thread-yield:                          Basic Thread Functions.
89938                                                              (line  44)
89939* threadp:                               Basic Thread Functions.
89940                                                              (line  24)
89941* threads:                               Threads.             (line   6)
89942* three-step-help:                       Help Functions.      (line 179)
89943* throw:                                 Catch and Throw.     (line  76)
89944* throw example:                         Recursive Editing.   (line  32)
89945* thunk:                                 Deferred Eval.       (line  12)
89946* thunk-delay:                           Deferred Eval.       (line  12)
89947* thunk-force:                           Deferred Eval.       (line  17)
89948* thunk-let:                             Deferred Eval.       (line  25)
89949* thunk-let*:                            Deferred Eval.       (line  55)
89950* tiled windows:                         Basic Windows.       (line  23)
89951* time calculations:                     Time Calculations.   (line   6)
89952* time conversion:                       Time Conversion.     (line   6)
89953* time formatting:                       Time Parsing.        (line   6)
89954* time of day:                           Time of Day.         (line   6)
89955* time parsing:                          Time Parsing.        (line   6)
89956* time value:                            Time of Day.         (line  38)
89957* time zone rule:                        Time Zone Rules.     (line  20)
89958* time zone rules:                       Time Zone Rules.     (line   6)
89959* time zone, current:                    Time Zone Rules.     (line  35)
89960* time-add:                              Time Calculations.   (line  27)
89961* time-convert:                          Time Conversion.     (line  22)
89962* time-equal-p:                          Time Calculations.   (line  15)
89963* time-less-p:                           Time Calculations.   (line  11)
89964* time-subtract:                         Time Calculations.   (line  19)
89965* time-to-day-in-year:                   Time Calculations.   (line  41)
89966* time-to-days:                          Time Calculations.   (line  36)
89967* timer-max-repeats:                     Timers.              (line 108)
89968* timerp:                                Timers.              (line  11)
89969* timers:                                Timers.              (line   6)
89970* timespec:                              Module Values.       (line  91)
89971* timestamp of a mouse event:            Accessing Mouse.     (line 124)
89972* timestamp, Lisp:                       Time of Day.         (line   8)
89973* timing programs:                       Profiling.           (line  39)
89974* tips for writing Lisp:                 Tips.                (line   6)
89975* title bar:                             Frame Layout.        (line 100)
89976* title, a frame parameter:              Basic Parameters.    (line  19)
89977* TLS network connections:               Network.             (line  55)
89978* TMP environment variable:              Unique File Names.   (line  55)
89979* TMPDIR environment variable:           Unique File Names.   (line  55)
89980* toggle-enable-multibyte-characters:    Disabling Multibyte. (line  41)
89981* tool bar:                              Tool Bar.            (line   6)
89982* tool-bar-add-item:                     Tool Bar.            (line 101)
89983* tool-bar-add-item-from-menu:           Tool Bar.            (line 121)
89984* tool-bar-border:                       Tool Bar.            (line 167)
89985* tool-bar-button-margin:                Tool Bar.            (line 158)
89986* tool-bar-button-relief:                Tool Bar.            (line 163)
89987* tool-bar-lines, a frame parameter:     Layout Parameters.   (line  66)
89988* tool-bar-local-item-from-menu:         Tool Bar.            (line 135)
89989* tool-bar-map:                          Tool Bar.            (line  84)
89990* tool-bar-position, a frame parameter:  Layout Parameters.   (line  72)
89991* tooltip face:                          Tooltips.            (line  42)
89992* tooltip for help strings:              Special Properties.  (line  93)
89993* tooltip frames:                        Tooltips.            (line  26)
89994* tooltip-event-buffer:                  Tooltips.            (line  59)
89995* tooltip-frame-parameters:              Tooltips.            (line  31)
89996* tooltip-functions:                     Tooltips.            (line  46)
89997* tooltip-help-tips:                     Tooltips.            (line  46)
89998* tooltip-mode:                          Tooltips.            (line  13)
89999* tooltips:                              Tooltips.            (line   6)
90000* top frame:                             Raising and Lowering.
90001                                                              (line  74)
90002* top position ratio:                    Position Parameters. (line  39)
90003* top, a frame parameter:                Position Parameters. (line  87)
90004* top-level:                             Recursive Editing.   (line  98)
90005* top-level default value:               Default Value.       (line  92)
90006* top-level form:                        Loading.             (line  16)
90007* top-level frame:                       Frames.              (line  65)
90008* top-visible, a frame parameter:        Mouse Dragging Parameters.
90009                                                              (line  34)
90010* total height of a window:              Window Sizes.        (line  47)
90011* total pixel height of a window:        Window Sizes.        (line 109)
90012* total pixel width of a window:         Window Sizes.        (line 118)
90013* total width of a window:               Window Sizes.        (line  75)
90014* tq-close:                              Transaction Queues.  (line  37)
90015* tq-create:                             Transaction Queues.  (line  11)
90016* tq-enqueue:                            Transaction Queues.  (line  18)
90017* trace buffer:                          Trace Buffer.        (line   6)
90018* tracing Lisp programs:                 Debugging.           (line  15)
90019* track-mouse:                           Mouse Tracking.      (line  18)
90020* tracking frame size changes:           Frame Size.          (line 163)
90021* trailing blanks in file names:         Information about Files.
90022                                                              (line  12)
90023* transaction queue:                     Transaction Queues.  (line   6)
90024* transcendental functions:              Math Functions.      (line   6)
90025* transient keymap:                      Controlling Active Maps.
90026                                                              (line 147)
90027* transient-mark-mode:                   The Mark.            (line 117)
90028* translate-region:                      Substitution.        (line  33)
90029* translating input events:              Event Mod.           (line   6)
90030* translation keymap:                    Translation Keymaps. (line   6)
90031* translation tables:                    Translation of Characters.
90032                                                              (line   6)
90033* translation-table-for-input:           Translation of Characters.
90034                                                              (line  56)
90035* transparency, frame:                   Font and Color Parameters.
90036                                                              (line  66)
90037* transpose-regions:                     Transposition.       (line   8)
90038* trash:                                 Changing Files.      (line 170)
90039* trash <1>:                             Create/Delete Dirs.  (line  45)
90040* tray notifications, MS-Windows:        Desktop Notifications.
90041                                                              (line 229)
90042* triple-click events:                   Repeat Events.       (line   6)
90043* true:                                  nil and t.           (line  25)
90044* true list:                             Cons Cells.          (line  24)
90045* truename (of file):                    Truenames.           (line   6)
90046* truncate:                              Numeric Conversions. (line  22)
90047* truncate-lines:                        Truncation.          (line  21)
90048* truncate-partial-width-windows:        Truncation.          (line  29)
90049* truncate-string-ellipsis:              Size of Displayed Text.
90050                                                              (line  44)
90051* truncate-string-to-width:              Size of Displayed Text.
90052                                                              (line  21)
90053* truth value:                           nil and t.           (line   6)
90054* try-completion:                        Basic Completion.    (line  10)
90055* tty-color-alist:                       Text Terminal Colors.
90056                                                              (line  40)
90057* tty-color-approximate:                 Text Terminal Colors.
90058                                                              (line  50)
90059* tty-color-clear:                       Text Terminal Colors.
90060                                                              (line  36)
90061* tty-color-define:                      Text Terminal Colors.
90062                                                              (line  26)
90063* tty-color-mode, a frame parameter:     Font and Color Parameters.
90064                                                              (line  33)
90065* tty-color-translate:                   Text Terminal Colors.
90066                                                              (line  56)
90067* tty-erase-char:                        System Environment.  (line 203)
90068* tty-setup-hook:                        Terminal-Specific.   (line  60)
90069* tty-top-frame:                         Raising and Lowering.
90070                                                              (line  78)
90071* turn multibyte support on or off:      Disabling Multibyte. (line  11)
90072* two’s complement:                      Integer Basics.      (line  46)
90073* type:                                  Lisp Data Types.     (line   6)
90074* type (button property):                Button Properties.   (line  38)
90075* type checking:                         Type Predicates.     (line   6)
90076* type checking internals:               Writing Emacs Primitives.
90077                                                              (line 158)
90078* type predicates:                       Type Predicates.     (line  21)
90079* type, defcustom keyword:               Customization Types. (line  11)
90080* type-of:                               Type Predicates.     (line 196)
90081* type_of:                               Module Misc.         (line  32)
90082* typographic conventions:               Some Terms.          (line  14)
90083* TZ, environment variable:              Time Zone Rules.     (line   6)
90084* UBA:                                   Bidirectional Display.
90085                                                              (line  17)
90086* UDP:                                   Network.             (line   6)
90087* UID:                                   User Identification. (line  55)
90088* umask:                                 Changing Files.      (line 213)
90089* unassigned character codepoints:       Character Properties.
90090                                                              (line  32)
90091* unbalanced parentheses:                Syntax Errors.       (line  21)
90092* unbinding keys:                        Key Binding Commands.
90093                                                              (line  55)
90094* unbury-buffer:                         Buffer List.         (line 132)
90095* undecided coding system:               Coding System Basics.
90096                                                              (line  15)
90097* undecided coding-system, when encoding: Explicit Encoding.  (line  55)
90098* undecorated, a frame parameter:        Management Parameters.
90099                                                              (line  81)
90100* undefined:                             Functions for Key Lookup.
90101                                                              (line  51)
90102* undefined in keymap:                   Key Lookup.          (line  79)
90103* undefined key:                         Keymap Basics.       (line   6)
90104* underline-minimum-offset:              Face Attributes.     (line 221)
90105* underlined text:                       Face Attributes.     (line  86)
90106* undo avoidance:                        Substitution.        (line  15)
90107* undo-amalgamate-change-group:          Atomic Changes.      (line  60)
90108* undo-ask-before-discard:               Maintaining Undo.    (line  62)
90109* undo-auto-amalgamate:                  Undo.                (line  97)
90110* undo-auto-current-boundary-timer:      Undo.                (line 126)
90111* undo-boundary:                         Undo.                (line  84)
90112* undo-in-progress:                      Undo.                (line 132)
90113* undo-limit:                            Maintaining Undo.    (line  45)
90114* undo-outer-limit:                      Maintaining Undo.    (line  57)
90115* undo-strong-limit:                     Maintaining Undo.    (line  50)
90116* unexec:                                Building Emacs.      (line  50)
90117* unexec <1>:                            Building Emacs.      (line 165)
90118* unhandled-file-name-directory:         Magic File Names.    (line 202)
90119* unibyte buffers, and bidi reordering:  Bidirectional Display.
90120                                                              (line  46)
90121* unibyte text:                          Text Representations.
90122                                                              (line  40)
90123* unibyte-char-to-multibyte:             Converting Representations.
90124                                                              (line  68)
90125* unibyte-string:                        Text Representations.
90126                                                              (line 123)
90127* Unicode:                               Text Representations.
90128                                                              (line  10)
90129* unicode bidirectional algorithm:       Bidirectional Display.
90130                                                              (line  17)
90131* unicode character escape:              General Escape Syntax.
90132                                                              (line  10)
90133* unicode general category:              Character Properties.
90134                                                              (line  46)
90135* unicode, a charset:                    Character Sets.      (line  16)
90136* unicode-category-table:                Character Properties.
90137                                                              (line 227)
90138* unintern:                              Creating Symbols.    (line 167)
90139* uninterned symbol:                     Creating Symbols.    (line  39)
90140* unique file names:                     Unique File Names.   (line   6)
90141* universal-argument:                    Prefix Command Arguments.
90142                                                              (line 102)
90143* universal-argument-map:                Standard Keymaps.    (line 156)
90144* unless:                                Conditionals.        (line  42)
90145* unload-feature:                        Unloading.           (line  10)
90146* unload-feature-special-hooks:          Unloading.           (line  49)
90147* unloading packages:                    Unloading.           (line   6)
90148* unloading packages, preparing for:     Coding Conventions.  (line 120)
90149* unlock-buffer:                         File Locks.          (line  47)
90150* unmapped frame:                        Visibility of Frames.
90151                                                              (line  14)
90152* unmatchable in rx:                     Rx Constructs.       (line  42)
90153* unnumbered group:                      Regexp Backslash.    (line  67)
90154* unpacking:                             Byte Packing.        (line  13)
90155* unread-command-events:                 Event Input Misc.    (line  10)
90156* unsafep:                               Function Safety.     (line  13)
90157* unsplittable, a frame parameter:       Buffer Parameters.   (line  42)
90158* unused lexical variable:               Using Lexical Binding.
90159                                                              (line  78)
90160* unwind-protect:                        Cleanups.            (line  12)
90161* unwinding:                             Cleanups.            (line  13)
90162* up-list:                               List Motion.         (line  24)
90163* upcase:                                Case Conversion.     (line  36)
90164* upcase-initials:                       Case Conversion.     (line  76)
90165* upcase-region:                         Case Changes.        (line  42)
90166* upcase-word:                           Case Changes.        (line  72)
90167* update-directory-autoloads:            Autoload.            (line 109)
90168* update-file-autoloads:                 Autoload.            (line 109)
90169* upper case:                            Case Conversion.     (line   6)
90170* upper case key sequence:               Key Sequence Input.  (line  73)
90171* uptime of Emacs:                       Processor Run Time.  (line  10)
90172* use time of window:                    Selecting Windows.   (line 114)
90173* use-empty-active-region:               The Region.          (line  37)
90174* use-global-map:                        Controlling Active Maps.
90175                                                              (line  51)
90176* use-hard-newlines:                     Filling.             (line 175)
90177* use-local-map:                         Controlling Active Maps.
90178                                                              (line  57)
90179* use-region-p:                          The Region.          (line  31)
90180* user errors, signaling:                Signaling Errors.    (line  88)
90181* user groups:                           User Identification. (line  73)
90182* user identification:                   User Identification. (line   6)
90183* user options, how to define:           Variable Definitions.
90184                                                              (line   6)
90185* user pointer object:                   Dynamic Modules.     (line  32)
90186* user pointer, using in module functions: Module Values.     (line 345)
90187* user signals:                          Misc Events.         (line  66)
90188* user-defined error:                    Error Symbols.       (line   6)
90189* user-emacs-directory:                  Init File.           (line  84)
90190* user-error:                            Signaling Errors.    (line  88)
90191* user-full-name:                        User Identification. (line  48)
90192* user-full-name <1>:                    User Identification. (line  36)
90193* user-init-file:                        Init File.           (line  79)
90194* user-login-name:                       User Identification. (line  48)
90195* user-login-name <1>:                   User Identification. (line  22)
90196* user-mail-address:                     User Identification. (line  19)
90197* user-position, a frame parameter:      Position Parameters. (line 106)
90198* user-ptr object:                       Dynamic Modules.     (line  32)
90199* user-ptrp:                             Dynamic Modules.     (line  41)
90200* user-real-login-name:                  User Identification. (line  48)
90201* user-real-login-name <1>:              User Identification. (line  31)
90202* user-real-uid:                         User Identification. (line  55)
90203* user-size, a frame parameter:          Size Parameters.     (line  59)
90204* user-uid:                              User Identification. (line  58)
90205* utf-8-emacs coding system:             Coding System Basics.
90206                                                              (line  66)
90207* valid windows:                         Basic Windows.       (line  44)
90208* validity of coding system:             Lisp and Coding Systems.
90209                                                              (line  18)
90210* value cell:                            Symbol Components.   (line  13)
90211* value of expression:                   Evaluation.          (line   6)
90212* value of function:                     What Is a Function.  (line   6)
90213* values:                                Eval.                (line 128)
90214* variable:                              Variables.           (line   6)
90215* variable aliases:                      Variable Aliases.    (line   6)
90216* variable definition:                   Defining Variables.  (line   6)
90217* variable descriptions:                 A Sample Variable Description.
90218                                                              (line   6)
90219* variable limit error:                  Local Variables.     (line 130)
90220* variable watchpoints:                  Watching Variables.  (line   6)
90221* variable with constant value:          Constant Variables.  (line   6)
90222* variable write debugging:              Variable Debugging.  (line   6)
90223* variable, buffer-local:                Buffer-Local Variables.
90224                                                              (line   6)
90225* variable-documentation property:       Documentation Basics.
90226                                                              (line  19)
90227* variable-width spaces:                 Specified Space.     (line   6)
90228* variant coding system:                 Coding System Basics.
90229                                                              (line  45)
90230* vc-mode:                               Mode Line Variables. (line  52)
90231* vc-prefix-map:                         Prefix Keys.         (line  43)
90232* vc-responsible-backend:                Truenames.           (line  87)
90233* vconcat:                               Vector Functions.    (line  32)
90234* vector:                                Vector Functions.    (line  16)
90235* vector (type):                         Vectors.             (line   6)
90236* vector evaluation:                     Self-Evaluating Forms.
90237                                                              (line   6)
90238* vector length:                         Sequence Functions.  (line  14)
90239* vector reverse:                        Sequence Functions.  (line 116)
90240* vector to list:                        Sequence Functions.  (line 597)
90241* vector-cells-consed:                   Memory Usage.        (line  21)
90242* vector-like objects, storage:          Garbage Collection.  (line  16)
90243* vectorp:                               Vector Functions.    (line   8)
90244* vec_get:                               Module Values.       (line 148)
90245* vec_set:                               Module Values.       (line 160)
90246* vec_size:                              Module Values.       (line 157)
90247* verify-visited-file-modtime:           Modification Time.   (line  14)
90248* version number (in file name):         File Name Components.
90249                                                              (line   6)
90250* version, customization keyword:        Common Keywords.     (line 109)
90251* version-control:                       Numbered Backups.    (line  10)
90252* vertical combination:                  Windows and Frames.  (line  78)
90253* vertical fractional scrolling:         Vertical Scrolling.  (line   6)
90254* vertical scroll position:              Vertical Scrolling.  (line   6)
90255* vertical tab:                          Basic Char Syntax.   (line  27)
90256* vertical-line, prefix key:             Key Sequence Input.  (line  92)
90257* vertical-lineto:                       SVG Images.          (line 217)
90258* vertical-motion:                       Screen Lines.        (line  28)
90259* vertical-scroll-bar:                   Scroll Bars.         (line 138)
90260* vertical-scroll-bar, prefix key:       Key Sequence Input.  (line  92)
90261* vertical-scroll-bars, a frame parameter: Layout Parameters. (line  17)
90262* view part, model/view/controller:      Abstract Display.    (line   6)
90263* view-register:                         Registers.           (line  66)
90264* virtual buffers:                       Swapping Text.       (line   6)
90265* visibility, a frame parameter:         Management Parameters.
90266                                                              (line  10)
90267* visible frame:                         Visibility of Frames.
90268                                                              (line   6)
90269* visible-bell:                          Beeping.             (line  20)
90270* visible-frame-list:                    Finding All Frames.  (line  13)
90271* visited file:                          Buffer File Name.    (line   6)
90272* visited file mode:                     Auto Major Mode.     (line  38)
90273* visited-file-modtime:                  Modification Time.   (line  43)
90274* visiting files:                        Visiting Files.      (line   6)
90275* visiting files, functions for:         Visiting Functions.  (line   6)
90276* visual order:                          Bidirectional Display.
90277                                                              (line  17)
90278* visual order, preserve when copying bidirectional text: Bidirectional Display.
90279                                                              (line 260)
90280* visual-order cursor motion:            Bidirectional Display.
90281                                                              (line 140)
90282* void function:                         Function Indirection.
90283                                                              (line   6)
90284* void function cell:                    Function Cells.      (line  29)
90285* void variable:                         Void Variables.      (line   6)
90286* void-function:                         Function Cells.      (line  14)
90287* void-text-area-pointer:                Pointer Shape.       (line  18)
90288* void-variable error:                   Void Variables.      (line   6)
90289* w32-collate-ignore-punctuation:        Text Comparison.     (line  79)
90290* w32-notification-close:                Desktop Notifications.
90291                                                              (line 295)
90292* w32-notification-notify:               Desktop Notifications.
90293                                                              (line 232)
90294* wait-for-wm, a frame parameter:        Management Parameters.
90295                                                              (line  43)
90296* waiting:                               Waiting.             (line   6)
90297* waiting for command key input:         Event Input Misc.    (line  51)
90298* waiting-for-user-input-p:              Sentinels.           (line 117)
90299* walk-windows:                          Cyclic Window Ordering.
90300                                                              (line  83)
90301* warn:                                  Warning Basics.      (line  52)
90302* warning options:                       Warning Options.     (line   6)
90303* warning type:                          Warning Basics.      (line  33)
90304* warning variables:                     Warning Variables.   (line   6)
90305* warning-fill-column:                   Warning Variables.   (line  65)
90306* warning-fill-prefix:                   Warning Variables.   (line  61)
90307* warning-levels:                        Warning Variables.   (line   9)
90308* warning-minimum-level:                 Warning Options.     (line   9)
90309* warning-minimum-log-level:             Warning Options.     (line  14)
90310* warning-prefix-function:               Warning Variables.   (line  25)
90311* warning-series:                        Warning Variables.   (line  41)
90312* warning-suppress-log-types:            Warning Options.     (line  25)
90313* warning-suppress-types:                Warning Options.     (line  19)
90314* warning-type-format:                   Warning Variables.   (line  68)
90315* warnings:                              Warnings.            (line   6)
90316* watch, for filesystem events:          File Notifications.  (line   6)
90317* watchpoints for Lisp variables:        Watching Variables.  (line   6)
90318* webkit browser widget:                 Xwidgets.            (line   6)
90319* wheel-down event:                      Misc Events.         (line  28)
90320* wheel-up event:                        Misc Events.         (line  28)
90321* when:                                  Conditionals.        (line  32)
90322* where was a symbol defined:            Where Defined.       (line   6)
90323* where-is-internal:                     Scanning Keymaps.    (line  75)
90324* while:                                 Iteration.           (line  11)
90325* while-no-input:                        Event Input Misc.    (line  76)
90326* while-no-input-ignore-events:          Event Input Misc.    (line  95)
90327* whitespace:                            Basic Char Syntax.   (line  27)
90328* wholenump:                             Predicates on Numbers.
90329                                                              (line  40)
90330* widen:                                 Narrowing.           (line  46)
90331* widening:                              Narrowing.           (line  47)
90332* width of a window:                     Window Sizes.        (line  75)
90333* width, a frame parameter:              Size Parameters.     (line  10)
90334* window:                                Basic Windows.       (line   6)
90335* window (overlay property):             Overlay Properties.  (line  79)
90336* window auto-selection:                 Mouse Window Auto-selection.
90337                                                              (line   6)
90338* window body:                           Window Sizes.        (line  23)
90339* window body height:                    Window Sizes.        (line 144)
90340* window body size:                      Window Sizes.        (line 185)
90341* window body width:                     Window Sizes.        (line 162)
90342* window buffer change:                  Window Hooks.        (line  40)
90343* window change functions:               Window Hooks.        (line  35)
90344* window combination:                    Windows and Frames.  (line  78)
90345* window combination limit:              Recombining Windows. (line 197)
90346* window configuration (Edebug):         Edebug Display Update.
90347                                                              (line  25)
90348* window configuration change:           Window Hooks.        (line 127)
90349* window configurations:                 Window Configurations.
90350                                                              (line   6)
90351* window dividers:                       Window Dividers.     (line   6)
90352* window end position:                   Window Start and End.
90353                                                              (line  46)
90354* window excursions:                     Excursions.          (line  49)
90355* window header line:                    Header Lines.        (line   6)
90356* window height:                         Window Sizes.        (line  47)
90357* window history:                        Window History.      (line   6)
90358* window in direction:                   Windows and Frames.  (line 173)
90359* window internals:                      Window Internals.    (line   6)
90360* window layout in a frame:              Window Configuration Type.
90361                                                              (line   6)
90362* window layout, all frames:             Frame Configuration Type.
90363                                                              (line   6)
90364* window manager interaction, and frame parameters: Management Parameters.
90365                                                              (line   6)
90366* window order by time of last use:      Selecting Windows.   (line 114)
90367* window ordering, cyclic:               Cyclic Window Ordering.
90368                                                              (line   6)
90369* window parameters:                     Window Parameters.   (line   6)
90370* window pixel height:                   Window Sizes.        (line 109)
90371* window pixel width:                    Window Sizes.        (line 118)
90372* window point:                          Window Point.        (line   6)
90373* window point internals:                Window Internals.    (line  90)
90374* window position:                       Window Point.        (line   6)
90375* window position <1>:                   Coordinates and Windows.
90376                                                              (line   6)
90377* window position on display:            Position Parameters. (line   6)
90378* window positions and window managers:  Position Parameters. (line 113)
90379* window resizing:                       Resizing Windows.    (line   6)
90380* window selected within a frame:        Basic Windows.       (line  59)
90381* window selection change:               Window Hooks.        (line  80)
90382* window size:                           Window Sizes.        (line   6)
90383* window size change:                    Window Hooks.        (line  59)
90384* window size on display:                Size Parameters.     (line   6)
90385* window size, changing:                 Resizing Windows.    (line   6)
90386* window splitting:                      Splitting Windows.   (line   6)
90387* window start position:                 Window Start and End.
90388                                                              (line   6)
90389* window state:                          Window Configurations.
90390                                                              (line  95)
90391* window state change:                   Window Hooks.        (line  99)
90392* window state change flag:              Window Hooks.        (line 187)
90393* window that satisfies a predicate:     Cyclic Window Ordering.
90394                                                              (line 146)
90395* window top line:                       Window Start and End.
90396                                                              (line  22)
90397* window tree:                           Windows and Frames.  (line  29)
90398* window use time:                       Selecting Windows.   (line 114)
90399* window width:                          Window Sizes.        (line  75)
90400* window, a buffer display action alist entry: Buffer Display Action Alists.
90401                                                              (line 205)
90402* window-absolute-body-pixel-edges:      Coordinates and Windows.
90403                                                              (line 150)
90404* window-absolute-pixel-edges:           Coordinates and Windows.
90405                                                              (line 144)
90406* window-absolute-pixel-position:        Coordinates and Windows.
90407                                                              (line 174)
90408* window-adjust-process-window-size-function: Process Buffers.
90409                                                              (line 102)
90410* window-at:                             Coordinates and Windows.
90411                                                              (line  62)
90412* window-at-side-p:                      Windows and Frames.  (line 161)
90413* window-atom, a window parameter:       Window Parameters.   (line 130)
90414* window-atom-root:                      Atomic Windows.      (line  43)
90415* window-body-edges:                     Coordinates and Windows.
90416                                                              (line  54)
90417* window-body-height:                    Window Sizes.        (line 148)
90418* window-body-pixel-edges:               Coordinates and Windows.
90419                                                              (line 136)
90420* window-body-size:                      Window Sizes.        (line 185)
90421* window-body-width:                     Window Sizes.        (line 171)
90422* window-bottom-divider-width:           Window Dividers.     (line  53)
90423* window-buffer:                         Buffers and Windows. (line  10)
90424* window-buffer-change-functions:        Window Hooks.        (line  44)
90425* window-child:                          Windows and Frames.  (line 119)
90426* window-combination-limit:              Recombining Windows. (line 121)
90427* window-combination-limit <1>:          Recombining Windows. (line 206)
90428* window-combination-resize:             Recombining Windows. (line 226)
90429* window-combined-p:                     Windows and Frames.  (line 125)
90430* window-configuration-change-hook:      Window Hooks.        (line 132)
90431* window-configuration-frame:            Window Configurations.
90432                                                              (line  79)
90433* window-configuration-p:                Window Configurations.
90434                                                              (line  67)
90435* window-current-scroll-bars:            Scroll Bars.         (line 109)
90436* window-dedicated-p:                    Dedicated Windows.   (line  36)
90437* window-display-table:                  Active Display Table.
90438                                                              (line  16)
90439* window-edges:                          Coordinates and Windows.
90440                                                              (line  19)
90441* window-end:                            Window Start and End.
90442                                                              (line  46)
90443* window-font-height:                    Low-Level Font.      (line 320)
90444* window-font-width:                     Low-Level Font.      (line 314)
90445* window-frame:                          Windows and Frames.  (line   8)
90446* window-fringes:                        Fringe Size/Pos.     (line  60)
90447* window-full-height-p:                  Window Sizes.        (line 130)
90448* window-full-width-p:                   Window Sizes.        (line 138)
90449* window-group-end:                      Window Start and End.
90450                                                              (line  71)
90451* window-group-end-function:             Window Start and End.
90452                                                              (line  71)
90453* window-group-start:                    Window Start and End.
90454                                                              (line  37)
90455* window-group-start-function:           Window Start and End.
90456                                                              (line  38)
90457* window-header-line-height:             Header Lines.        (line  17)
90458* window-header-line-height <1>:         Window Sizes.        (line 208)
90459* window-height, a buffer display action alist entry: Buffer Display Action Alists.
90460                                                              (line 103)
90461* window-hscroll:                        Horizontal Scrolling.
90462                                                              (line  84)
90463* window-id, a frame parameter:          Management Parameters.
90464                                                              (line  33)
90465* window-in-direction:                   Windows and Frames.  (line 173)
90466* window-largest-empty-rectangle:        Coordinates and Windows.
90467                                                              (line 195)
90468* window-left-child:                     Windows and Frames.  (line 113)
90469* window-line-height:                    Window Start and End.
90470                                                              (line 201)
90471* window-lines-pixel-dimensions:         Size of Displayed Text.
90472                                                              (line 114)
90473* window-list:                           Windows and Frames.  (line  12)
90474* window-live-p:                         Basic Windows.       (line  35)
90475* window-main-window:                    Side Window Options and Functions.
90476                                                              (line  52)
90477* window-make-atom:                      Atomic Windows.      (line  52)
90478* window-margins:                        Display Margins.     (line  68)
90479* window-max-chars-per-line:             Window Sizes.        (line 221)
90480* window-min-height:                     Window Sizes.        (line 235)
90481* window-min-height <1>:                 Window Sizes.        (line 242)
90482* window-min-height, a buffer display action alist entry: Buffer Display Action Alists.
90483                                                              (line  88)
90484* window-min-size:                       Window Sizes.        (line 258)
90485* window-min-width:                      Window Sizes.        (line 235)
90486* window-min-width <1>:                  Window Sizes.        (line 248)
90487* window-minibuffer-p:                   Minibuffer Windows.  (line  27)
90488* window-mode-line-height:               Window Sizes.        (line 203)
90489* window-next-buffers:                   Window History.      (line  40)
90490* window-next-sibling:                   Windows and Frames.  (line 134)
90491* window-old-body-pixel-height:          Window Hooks.        (line 234)
90492* window-old-body-pixel-width:           Window Hooks.        (line 229)
90493* window-old-buffer:                     Window Hooks.        (line 211)
90494* window-old-pixel-height:               Window Hooks.        (line 224)
90495* window-old-pixel-width:                Window Hooks.        (line 219)
90496* window-parameter:                      Window Parameters.   (line   9)
90497* window-parameters:                     Window Parameters.   (line  14)
90498* window-parameters, a buffer display action alist entry: Buffer Display Action Alists.
90499                                                              (line  83)
90500* window-parent:                         Windows and Frames.  (line  61)
90501* window-persistent-parameters:          Window Parameters.   (line  34)
90502* window-pixel-edges:                    Coordinates and Windows.
90503                                                              (line 131)
90504* window-pixel-height:                   Window Sizes.        (line 109)
90505* window-pixel-width:                    Window Sizes.        (line 118)
90506* window-point:                          Window Point.        (line  32)
90507* window-point-insertion-type:           Window Point.        (line  50)
90508* window-preserve-size:                  Preserving Window Sizes.
90509                                                              (line  39)
90510* window-preserved-size:                 Preserving Window Sizes.
90511                                                              (line  80)
90512* window-preserved-size, a window parameter: Window Parameters.
90513                                                              (line 109)
90514* window-prev-buffers:                   Window History.      (line  13)
90515* window-prev-sibling:                   Windows and Frames.  (line 139)
90516* window-resizable:                      Resizing Windows.    (line  17)
90517* window-resize:                         Resizing Windows.    (line  47)
90518* window-resize-pixelwise:               Resizing Windows.    (line  89)
90519* window-right-divider-width:            Window Dividers.     (line  48)
90520* window-scroll-bar-height:              Scroll Bars.         (line 120)
90521* window-scroll-bar-width:               Scroll Bars.         (line 116)
90522* window-scroll-bars:                    Scroll Bars.         (line  91)
90523* window-scroll-functions:               Window Hooks.        (line  10)
90524* window-selection-change-functions:     Window Hooks.        (line  83)
90525* window-setup-hook:                     Init File.           (line  74)
90526* window-side, a window parameter:       Window Parameters.   (line 126)
90527* window-sides-reversed:                 Side Window Options and Functions.
90528                                                              (line  30)
90529* window-sides-slots:                    Side Window Options and Functions.
90530                                                              (line  14)
90531* window-sides-vertical:                 Side Window Options and Functions.
90532                                                              (line   9)
90533* window-size-change-functions:          Window Hooks.        (line  63)
90534* window-size-fixed:                     Preserving Window Sizes.
90535                                                              (line  17)
90536* window-slot, a window parameter:       Window Parameters.   (line 126)
90537* window-start:                          Window Start and End.
90538                                                              (line  21)
90539* window-state-change-functions:         Window Hooks.        (line 103)
90540* window-state-change-hook:              Window Hooks.        (line 154)
90541* window-state-get:                      Window Configurations.
90542                                                              (line  95)
90543* window-state-put:                      Window Configurations.
90544                                                              (line 114)
90545* window-swap-states:                    Window Configurations.
90546                                                              (line 133)
90547* window-system:                         Window Systems.      (line  11)
90548* window-system <1>:                     Window Systems.      (line  35)
90549* window-system-initialization:          Startup Summary.     (line  45)
90550* window-text-pixel-size:                Size of Displayed Text.
90551                                                              (line  61)
90552* window-toggle-side-windows:            Side Window Options and Functions.
90553                                                              (line  66)
90554* window-top-child:                      Windows and Frames.  (line 108)
90555* window-total-height:                   Window Sizes.        (line  51)
90556* window-total-size:                     Window Sizes.        (line  98)
90557* window-total-width:                    Window Sizes.        (line  79)
90558* window-tree:                           Windows and Frames.  (line 215)
90559* window-use-time:                       Selecting Windows.   (line 114)
90560* window-valid-p:                        Basic Windows.       (line  54)
90561* window-vscroll:                        Vertical Scrolling.  (line  26)
90562* window-width, a buffer display action alist entry: Buffer Display Action Alists.
90563                                                              (line 129)
90564* windowp:                               Basic Windows.       (line  28)
90565* windows, controlling precisely:        Buffers and Windows. (line   6)
90566* windows, recombining:                  Recombining Windows. (line   6)
90567* with-case-table:                       Case Tables.         (line  75)
90568* with-coding-priority:                  Specifying Coding Systems.
90569                                                              (line  83)
90570* with-connection-local-variables:       Connection Local Variables.
90571                                                              (line 102)
90572* with-current-buffer:                   Current Buffer.      (line 112)
90573* with-current-buffer-window:            Temporary Displays.  (line 110)
90574* with-demoted-errors:                   Handling Errors.     (line 219)
90575* with-displayed-buffer-window:          Temporary Displays.  (line 115)
90576* with-eval-after-load:                  Hooks for Loading.   (line  17)
90577* with-file-modes:                       Changing Files.      (line 231)
90578* with-help-window:                      Help Functions.      (line 130)
90579* with-local-quit:                       Quitting.            (line  83)
90580* with-mutex:                            Mutexes.             (line  39)
90581* with-no-warnings:                      Compiler Errors.     (line  73)
90582* with-output-to-string:                 Output Functions.    (line 116)
90583* with-output-to-temp-buffer:            Temporary Displays.  (line  10)
90584* with-selected-window:                  Selecting Windows.   (line  86)
90585* with-silent-modifications:             Buffer Modification. (line  71)
90586* with-silent-modifications, and changes in text properties: Changing Properties.
90587                                                              (line 147)
90588* with-suppressed-warnings:              Compiler Errors.     (line  59)
90589* with-syntax-table:                     Syntax Table Functions.
90590                                                              (line 103)
90591* with-temp-buffer:                      Current Buffer.      (line 122)
90592* with-temp-buffer-window:               Temporary Displays.  (line  80)
90593* with-temp-file:                        Writing to Files.    (line  93)
90594* with-temp-message:                     Displaying Messages. (line  89)
90595* with-timeout:                          Timers.              (line 113)
90596* word-boundary in rx:                   Rx Constructs.       (line 340)
90597* word-end in rx:                        Rx Constructs.       (line 336)
90598* word-search-backward:                  String Search.       (line 121)
90599* word-search-backward-lax:              String Search.       (line 127)
90600* word-search-forward:                   String Search.       (line  66)
90601* word-search-forward-lax:               String Search.       (line 113)
90602* word-search-regexp:                    String Search.       (line 109)
90603* word-start in rx:                      Rx Constructs.       (line 332)
90604* words in region:                       Text Lines.          (line  84)
90605* words-include-escapes:                 Word Motion.         (line  43)
90606* wrap-prefix:                           Truncation.          (line  44)
90607* write-abbrev-file:                     Abbrev Files.        (line  41)
90608* write-char:                            Output Functions.    (line  92)
90609* write-contents-functions:              Saving Buffers.      (line 119)
90610* write-file:                            Saving Buffers.      (line  60)
90611* write-file-functions:                  Saving Buffers.      (line  83)
90612* write-region:                          Writing to Files.    (line  22)
90613* write-region <1>:                      Files and Storage.   (line  15)
90614* write-region-annotate-functions:       Format Conversion Piecemeal.
90615                                                              (line  48)
90616* write-region-inhibit-fsync:            Writing to Files.    (line  85)
90617* write-region-post-annotation-function: Format Conversion Piecemeal.
90618                                                              (line  62)
90619* writing a documentation string:        Documentation Basics.
90620                                                              (line   6)
90621* writing buffer display actions:        The Zen of Buffer Display.
90622                                                              (line   6)
90623* writing emacs modules:                 Writing Dynamic Modules.
90624                                                              (line   6)
90625* writing Emacs primitives:              Writing Emacs Primitives.
90626                                                              (line   6)
90627* writing module functions:              Module Functions.    (line   6)
90628* writing to files:                      Writing to Files.    (line   6)
90629* wrong-number-of-arguments:             Argument List.       (line   6)
90630* wrong-type-argument:                   Type Predicates.     (line   6)
90631* X display names:                       Multiple Terminals.  (line  87)
90632* X Window System:                       Window Systems.      (line  16)
90633* x-alt-keysym:                          X11 Keysyms.         (line  30)
90634* x-alternatives-map:                    Standard Keymaps.    (line 163)
90635* x-bitmap-file-path:                    Face Attributes.     (line 225)
90636* x-close-connection:                    Multiple Terminals.  (line 142)
90637* x-color-defined-p:                     Color Names.         (line  38)
90638* x-color-values:                        Color Names.         (line  93)
90639* x-ctrl-keysym:                         X11 Keysyms.         (line  29)
90640* x-defined-colors:                      Color Names.         (line  46)
90641* x-display-color-p:                     Display Feature Testing.
90642                                                              (line  36)
90643* x-display-list:                        Multiple Terminals.  (line 117)
90644* x-dnd-known-types:                     Drag and Drop.       (line   6)
90645* x-dnd-test-function:                   Drag and Drop.       (line   6)
90646* x-dnd-types-alist:                     Drag and Drop.       (line  15)
90647* x-double-buffered-p:                   Visibility of Frames.
90648                                                              (line  63)
90649* x-family-fonts:                        Font Lookup.         (line  29)
90650* x-focus-frame:                         Input Focus.         (line  61)
90651* x-get-resource:                        Resources.           (line  11)
90652* x-gtk-use-system-tooltips:             Tooltips.            (line  19)
90653* x-hyper-keysym:                        X11 Keysyms.         (line  32)
90654* x-list-fonts:                          Font Lookup.         (line   6)
90655* x-meta-keysym:                         X11 Keysyms.         (line  31)
90656* x-open-connection:                     Multiple Terminals.  (line 122)
90657* x-parse-geometry:                      Geometry.            (line   9)
90658* x-pointer-shape:                       Pointer Shape.       (line  27)
90659* x-popup-dialog:                        Dialog Boxes.        (line  15)
90660* x-popup-menu:                          Pop-Up Menus.        (line  11)
90661* x-resource-class:                      Resources.           (line  26)
90662* x-resource-name:                       Resources.           (line  32)
90663* x-sensitive-text-pointer-shape:        Pointer Shape.       (line  31)
90664* x-server-vendor:                       Display Feature Testing.
90665                                                              (line 162)
90666* x-server-version:                      Display Feature Testing.
90667                                                              (line 152)
90668* x-setup-function-keys:                 Standard Keymaps.    (line 163)
90669* x-stretch-cursor:                      Cursor Parameters.   (line  44)
90670* x-super-keysym:                        X11 Keysyms.         (line  33)
90671* X11 keysyms:                           X11 Keysyms.         (line   6)
90672* XBM:                                   XBM Images.          (line   6)
90673* xdigit character class, regexp:        Char Classes.        (line   6)
90674* XML DOM:                               Document Object Model.
90675                                                              (line   6)
90676* xor:                                   Combining Conditions.
90677                                                              (line  98)
90678* XPM:                                   XPM Images.          (line   6)
90679* xwidget:                               Xwidgets.            (line   6)
90680* xwidget-buffer:                        Xwidgets.            (line  39)
90681* xwidget-info:                          Xwidgets.            (line  75)
90682* xwidget-plist:                         Xwidgets.            (line  32)
90683* xwidget-query-on-exit-flag:            Xwidgets.            (line  86)
90684* xwidget-resize:                        Xwidgets.            (line  67)
90685* xwidget-size-request:                  Xwidgets.            (line  71)
90686* xwidget-webkit-execute-script:         Xwidgets.            (line  52)
90687* xwidget-webkit-execute-script-rv:      Xwidgets.            (line  56)
90688* xwidget-webkit-get-title:              Xwidgets.            (line  64)
90689* xwidget-webkit-goto-uri:               Xwidgets.            (line  48)
90690* xwidgetp:                              Xwidgets.            (line  29)
90691* y-or-n-p:                              Yes-or-No Queries.   (line  22)
90692* y-or-n-p-with-timeout:                 Yes-or-No Queries.   (line  51)
90693* yank:                                  Yank Commands.       (line  11)
90694* yank suppression:                      Changing Key Bindings.
90695                                                              (line 159)
90696* yank-excluded-properties:              Yanking.             (line  70)
90697* yank-handled-properties:               Yanking.             (line  58)
90698* yank-pop:                              Yank Commands.       (line  34)
90699* yank-undo-function:                    Yank Commands.       (line  57)
90700* yanking and text properties:           Yanking.             (line  58)
90701* yes-or-no questions:                   Yes-or-No Queries.   (line   6)
90702* yes-or-no-p:                           Yes-or-No Queries.   (line  57)
90703* z-group, a frame parameter:            Position Parameters. (line 124)
90704* Z-order:                               Raising and Lowering.
90705                                                              (line   6)
90706* zero-or-more in rx:                    Rx Constructs.       (line  53)
90707* zero-or-one in rx:                     Rx Constructs.       (line  63)
90708* zerop:                                 Predicates on Numbers.
90709                                                              (line  42)
90710* zlib-available-p:                      Decompression.       (line  16)
90711* zlib-decompress-region:                Decompression.       (line  20)
90712
90713
90714
90715Tag Table:
90716Node: Top1072
90717Node: Introduction74065
90718Node: Caveats75966
90719Node: Lisp History77282
90720Node: Conventions78970
90721Node: Some Terms79786
90722Node: nil and t80539
90723Node: Evaluation Notation82457
90724Node: Printing Notation83415
90725Node: Error Messages84302
90726Node: Buffer Text Notation84757
90727Node: Format of Descriptions85667
90728Node: A Sample Function Description86538
90729Node: A Sample Variable Description90711
90730Node: Version Info91802
90731Node: Acknowledgments94267
90732Node: Lisp Data Types96063
90733Node: Printed Representation98800
90734Node: Special Read Syntax100868
90735Node: Comments102860
90736Node: Programming Types103783
90737Node: Integer Type105785
90738Node: Floating-Point Type107140
90739Node: Character Type108077
90740Node: Basic Char Syntax109445
90741Node: General Escape Syntax113003
90742Node: Ctl-Char Syntax115310
90743Node: Meta-Char Syntax117150
90744Node: Other Char Bits118279
90745Ref: modifier bits119098
90746Node: Symbol Type119521
90747Node: Sequence Type122919
90748Node: Cons Cell Type124666
90749Node: Box Diagrams127588
90750Node: Dotted Pair Notation131260
90751Node: Association List Type133842
90752Node: Array Type134878
90753Node: String Type136684
90754Node: Syntax for Strings137481
90755Node: Non-ASCII in Strings138665
90756Node: Nonprinting Characters141419
90757Node: Text Props and Strings142887
90758Node: Vector Type144259
90759Node: Char-Table Type145043
90760Ref: Char-Table Type-Footnote-1146111
90761Node: Bool-Vector Type146179
90762Node: Hash Table Type147416
90763Node: Function Type148023
90764Node: Macro Type149181
90765Node: Primitive Function Type150107
90766Node: Byte-Code Type151712
90767Node: Record Type152342
90768Node: Type Descriptors152792
90769Node: Autoload Type153337
90770Node: Finalizer Type154386
90771Node: Editing Types155632
90772Node: Buffer Type156920
90773Node: Marker Type159094
90774Node: Window Type159831
90775Node: Frame Type161080
90776Node: Terminal Type161704
90777Node: Window Configuration Type162164
90778Node: Frame Configuration Type162753
90779Node: Process Type163370
90780Node: Thread Type164337
90781Node: Mutex Type164938
90782Node: Condition Variable Type165473
90783Node: Stream Type166126
90784Node: Keymap Type167294
90785Node: Overlay Type167768
90786Node: Font Type168420
90787Node: Circular Objects168974
90788Node: Type Predicates170500
90789Node: Equality Predicates176679
90790Node: Mutability182655
90791Ref: Mutability-Footnote-1184921
90792Node: Numbers185245
90793Node: Integer Basics186635
90794Node: Float Basics191408
90795Node: Predicates on Numbers195745
90796Node: Comparison of Numbers197766
90797Node: Numeric Conversions201850
90798Node: Arithmetic Operations204404
90799Node: Rounding Operations209404
90800Node: Bitwise Operations210631
90801Node: Math Functions218215
90802Node: Random Numbers220352
90803Node: Strings and Characters222417
90804Node: String Basics223786
90805Node: Predicates for Strings226902
90806Node: Creating Strings227623
90807Node: Modifying Strings236807
90808Node: Text Comparison238232
90809Node: String Conversion250814
90810Node: Formatting Strings254825
90811Node: Custom Format Strings266903
90812Node: Case Conversion273322
90813Node: Case Tables278149
90814Node: Lists283300
90815Node: Cons Cells284304
90816Ref: Cons Cells-Footnote-1286934
90817Node: List-related Predicates287058
90818Node: List Elements289215
90819Ref: Definition of nth292145
90820Ref: Definition of safe-length293516
90821Node: Building Lists295374
90822Ref: Building Lists-Footnote-1303547
90823Node: List Variables304036
90824Node: Modifying Lists308563
90825Node: Setcar309754
90826Node: Setcdr312362
90827Node: Rearrangement315007
90828Node: Sets And Lists317369
90829Node: Association Lists325444
90830Ref: Association Lists-Footnote-1337527
90831Node: Property Lists337740
90832Node: Plists and Alists339132
90833Node: Plist Access340992
90834Node: Sequences Arrays Vectors343049
90835Node: Sequence Functions345584
90836Ref: Definition of length345995
90837Ref: Definition of elt347072
90838Ref: seq-let370119
90839Node: Arrays371557
90840Node: Array Functions374077
90841Node: Vectors376646
90842Node: Vector Functions378144
90843Node: Char-Tables380409
90844Node: Bool-Vectors386790
90845Node: Rings390428
90846Node: Records393653
90847Node: Record Functions395511
90848Node: Backward Compatibility396296
90849Node: Hash Tables396870
90850Node: Creating Hash398559
90851Node: Hash Access404627
90852Ref: Definition of maphash406136
90853Node: Defining Hash406366
90854Node: Other Hash411047
90855Node: Symbols412235
90856Node: Symbol Components413293
90857Node: Definitions416519
90858Node: Creating Symbols419056
90859Ref: Definition of mapatoms425856
90860Node: Symbol Properties427039
90861Node: Symbol Plists427824
90862Node: Standard Properties430868
90863Node: Evaluation435544
90864Node: Intro Eval436495
90865Ref: Definition of side effect438926
90866Ref: Intro Eval-Footnote-1439579
90867Ref: Intro Eval-Footnote-2439721
90868Node: Forms439860
90869Node: Self-Evaluating Forms441083
90870Node: Symbol Forms442962
90871Node: Classifying Lists444101
90872Node: Function Indirection444870
90873Ref: Definition of indirect-function447575
90874Node: Function Forms448348
90875Node: Macro Forms449366
90876Node: Special Forms450990
90877Node: Autoloading453752
90878Node: Quoting454368
90879Node: Backquote456169
90880Node: Eval458195
90881Ref: Definition of eval-region461064
90882Ref: Definition of max-lisp-eval-depth463250
90883Node: Deferred Eval466057
90884Node: Control Structures469692
90885Node: Sequencing471558
90886Node: Conditionals474539
90887Node: Combining Conditions478733
90888Node: Pattern-Matching Conditional482975
90889Node: pcase Macro485455
90890Ref: rx in pcase490311
90891Ref: pcase-example-0490983
90892Ref: pcase-example-1491850
90893Ref: pcase-example-2492616
90894Ref: pcase-symbol-caveats496763
90895Node: Extending pcase503030
90896Node: Backquote Patterns504932
90897Node: Destructuring with pcase Patterns509281
90898Node: Iteration513506
90899Node: Generators516520
90900Node: Nonlocal Exits521230
90901Node: Catch and Throw521942
90902Node: Examples of Catch526263
90903Node: Errors528312
90904Node: Signaling Errors529845
90905Ref: Definition of signal532250
90906Node: Processing of Errors534729
90907Node: Handling Errors536680
90908Node: Error Symbols547253
90909Node: Cleanups550960
90910Node: Variables554760
90911Ref: Variables-Footnote-1557132
90912Node: Global Variables557364
90913Node: Constant Variables558529
90914Node: Local Variables560137
90915Ref: Definition of max-specpdl-size565829
90916Node: Void Variables566587
90917Node: Defining Variables569776
90918Node: Tips for Defining575789
90919Node: Accessing Variables579103
90920Node: Setting Variables580818
90921Node: Watching Variables583759
90922Node: Variable Scoping586393
90923Ref: Variable Scoping-Footnote-1588275
90924Node: Dynamic Binding588382
90925Node: Dynamic Binding Tips590724
90926Node: Lexical Binding592699
90927Node: Using Lexical Binding596987
90928Ref: Local defvar example598720
90929Node: Buffer-Local Variables601198
90930Node: Intro to Buffer-Local602119
90931Node: Creating Buffer-Local606341
90932Node: Default Value616215
90933Node: File Local Variables620912
90934Node: Directory Local Variables630065
90935Ref: Directory Local Variables-Footnote-1635748
90936Node: Connection Local Variables635862
90937Node: Variable Aliases641075
90938Node: Variables with Restricted Values644640
90939Node: Generalized Variables645976
90940Node: Setting Generalized Variables646971
90941Node: Adding Generalized Variables650477
90942Node: Functions654556
90943Node: What Is a Function656221
90944Node: Lambda Expressions662928
90945Node: Lambda Components664031
90946Node: Simple Lambda665900
90947Node: Argument List667486
90948Node: Function Documentation671830
90949Node: Function Names674921
90950Node: Defining Functions677468
90951Ref: Definition of defalias679648
90952Node: Calling Functions681582
90953Ref: Calling Functions-Footnote-1687215
90954Node: Mapping Functions687430
90955Ref: Definition of mapcar688414
90956Node: Anonymous Functions691545
90957Node: Generic Functions695447
90958Node: Function Cells706377
90959Node: Closures709786
90960Node: Advising Functions711388
90961Node: Core Advising Primitives714907
90962Node: Advising Named Functions721407
90963Node: Advice Combinators725620
90964Node: Porting Old Advice730419
90965Node: Obsolete Functions733455
90966Node: Inline Functions736777
90967Node: Declare Form742000
90968Ref: Definition of declare742380
90969Node: Declaring Functions746583
90970Node: Function Safety750668
90971Node: Related Topics752307
90972Node: Macros753625
90973Node: Simple Macro754929
90974Node: Expansion755873
90975Node: Compiling Macros759773
90976Node: Defining Macros761456
90977Node: Problems with Macros763426
90978Node: Wrong Time764219
90979Node: Argument Evaluation765284
90980Node: Surprising Local Vars768224
90981Node: Eval During Expansion770356
90982Node: Repeated Expansion772195
90983Node: Indenting Macros774624
90984Node: Customization777124
90985Node: Common Keywords778379
90986Node: Group Definitions784992
90987Node: Variable Definitions788235
90988Node: Customization Types799184
90989Node: Simple Types801096
90990Node: Composite Types804247
90991Node: Splicing into Lists817079
90992Node: Type Keywords819075
90993Node: Defining New Types823771
90994Node: Applying Customizations827253
90995Node: Custom Themes829579
90996Node: Loading834360
90997Node: How Programs Do Loading836789
90998Ref: Definition of load-read-function843987
90999Node: Load Suffixes844592
91000Node: Library Search847078
91001Node: Loading Non-ASCII853326
91002Node: Autoload854672
91003Ref: autoload cookie860051
91004Node: Autoload by Prefix865100
91005Node: When to Autoload865876
91006Node: Repeated Loading867376
91007Node: Named Features869426
91008Node: Where Defined876195
91009Node: Unloading878853
91010Node: Hooks for Loading881425
91011Node: Dynamic Modules883649
91012Node: Byte Compilation886876
91013Node: Speed of Byte-Code888549
91014Node: Compilation Functions889480
91015Node: Docs and Compilation895912
91016Node: Dynamic Loading898083
91017Node: Eval During Compile900877
91018Node: Compiler Errors904138
91019Node: Byte-Code Objects908190
91020Node: Disassembly911133
91021Node: Debugging917005
91022Node: Debugger919033
91023Node: Error Debugging920306
91024Node: Infinite Loops925588
91025Node: Function Debugging926908
91026Node: Variable Debugging929458
91027Node: Explicit Debug930814
91028Node: Using Debugger931983
91029Node: Backtraces934213
91030Node: Debugger Commands936673
91031Node: Invoking the Debugger940946
91032Node: Internals of Debugger945126
91033Node: Edebug951655
91034Node: Using Edebug953973
91035Node: Instrumenting956627
91036Node: Edebug Execution Modes960424
91037Node: Jumping964565
91038Node: Edebug Misc967901
91039Node: Breaks969799
91040Node: Breakpoints970327
91041Node: Global Break Condition973539
91042Node: Source Breakpoints974628
91043Node: Trapping Errors975616
91044Node: Edebug Views976772
91045Node: Edebug Eval978982
91046Node: Eval List980237
91047Node: Printing in Edebug984433
91048Node: Trace Buffer986219
91049Node: Coverage Testing988214
91050Node: The Outside Context991054
91051Node: Checking Whether to Stop991801
91052Node: Edebug Display Update992757
91053Node: Edebug Recursive Edit994937
91054Node: Edebug and Macros996629
91055Node: Instrumenting Macro Calls997201
91056Node: Specification List1000851
91057Node: Backtracking1009679
91058Node: Specification Examples1011880
91059Node: Edebug Options1014036
91060Node: Syntax Errors1022230
91061Node: Excess Open1023647
91062Node: Excess Close1025603
91063Node: Test Coverage1027036
91064Node: Profiling1028673
91065Node: Read and Print1032009
91066Node: Streams Intro1032999
91067Node: Input Streams1035157
91068Node: Input Functions1040141
91069Node: Output Streams1043442
91070Ref: external-debugging-output1047881
91071Node: Output Functions1048210
91072Node: Output Variables1053865
91073Node: Minibuffers1060127
91074Node: Intro to Minibuffers1061717
91075Node: Text from Minibuffer1065613
91076Ref: Definition of minibuffer-local-map1075132
91077Node: Object from Minibuffer1077147
91078Node: Minibuffer History1079995
91079Node: Initial Input1085575
91080Node: Completion1087328
91081Node: Basic Completion1089434
91082Ref: Definition of test-completion1094794
91083Node: Minibuffer Completion1098949
91084Node: Completion Commands1103913
91085Node: High-Level Completion1110293
91086Ref: Definition of read-variable1115099
91087Node: Reading File Names1116719
91088Node: Completion Variables1126045
91089Node: Programmed Completion1130555
91090Node: Completion in Buffers1136469
91091Node: Yes-or-No Queries1141545
91092Node: Multiple Queries1146047
91093Node: Reading a Password1152836
91094Node: Minibuffer Commands1153923
91095Node: Minibuffer Windows1156262
91096Ref: Definition of minibuffer-window1156600
91097Node: Minibuffer Contents1160876
91098Node: Recursive Mini1162378
91099Node: Minibuffer Misc1163828
91100Ref: Definition of minibuffer-help-form1165065
91101Ref: Definition of minibuffer-scroll-window1165240
91102Node: Command Loop1166464
91103Node: Command Overview1168051
91104Node: Defining Commands1171225
91105Ref: The interactive-only property1172258
91106Node: Using Interactive1173393
91107Ref: Using Interactive-Footnote-11180187
91108Node: Interactive Codes1180240
91109Node: Interactive Examples1188782
91110Node: Generic Commands1190275
91111Node: Interactive Call1191461
91112Node: Distinguish Interactive1197239
91113Node: Command Loop Info1199944
91114Ref: Definition of this-command-keys-vector1203964
91115Node: Adjusting Point1205861
91116Node: Input Events1207106
91117Node: Keyboard Events1209103
91118Node: Function Keys1212038
91119Node: Mouse Events1215116
91120Node: Click Events1216245
91121Node: Drag Events1223813
91122Node: Button-Down Events1225421
91123Ref: Button-Down Events-Footnote-11226643
91124Node: Repeat Events1226703
91125Node: Motion Events1231148
91126Node: Focus Events1232343
91127Node: Misc Events1233876
91128Node: Event Examples1239387
91129Node: Classifying Events1241193
91130Node: Accessing Mouse1245528
91131Node: Accessing Scroll1252246
91132Node: Strings of Events1253452
91133Node: Reading Input1257357
91134Node: Key Sequence Input1258431
91135Node: Reading One Event1264288
91136Node: Event Mod1272666
91137Node: Invoking the Input Method1276382
91138Node: Quoted Character Input1278412
91139Node: Event Input Misc1279965
91140Node: Special Events1285069
91141Node: Waiting1286394
91142Node: Quitting1289218
91143Node: Prefix Command Arguments1295169
91144Node: Recursive Editing1300228
91145Node: Disabling Commands1305405
91146Node: Command History1307605
91147Node: Keyboard Macros1309335
91148Node: Keymaps1312442
91149Node: Key Sequences1314409
91150Node: Keymap Basics1316903
91151Node: Format of Keymaps1319521
91152Node: Creating Keymaps1324659
91153Node: Inheritance and Keymaps1327552
91154Node: Prefix Keys1330752
91155Ref: Definition of define-prefix-command1334705
91156Node: Active Keymaps1335343
91157Node: Searching Keymaps1340122
91158Node: Controlling Active Maps1342371
91159Ref: Definition of minor-mode-map-alist1344900
91160Node: Key Lookup1350082
91161Node: Functions for Key Lookup1354731
91162Node: Changing Key Bindings1360262
91163Node: Remapping Commands1368720
91164Node: Translation Keymaps1371195
91165Node: Key Binding Commands1378042
91166Node: Scanning Keymaps1380876
91167Node: Menu Keymaps1387863
91168Node: Defining Menus1388741
91169Ref: Defining Menus-Footnote-11390885
91170Node: Simple Menu Items1390972
91171Node: Extended Menu Items1392917
91172Node: Menu Separators1397601
91173Node: Alias Menu Items1400187
91174Node: Mouse Menus1401445
91175Node: Keyboard Menus1403528
91176Node: Menu Example1404754
91177Node: Menu Bar1407429
91178Node: Tool Bar1410835
91179Node: Modifying Menus1419788
91180Node: Easy Menu1421343
91181Node: Modes1425976
91182Node: Hooks1427297
91183Node: Running Hooks1429831
91184Node: Setting Hooks1432022
91185Node: Major Modes1435768
91186Node: Major Mode Conventions1439929
91187Node: Auto Major Mode1452077
91188Node: Mode Help1459600
91189Node: Derived Modes1460544
91190Node: Basic Major Modes1466354
91191Node: Mode Hooks1468802
91192Node: Tabulated List Mode1471816
91193Node: Generic Modes1481495
91194Node: Example Major Modes1483699
91195Node: Minor Modes1488359
91196Node: Minor Mode Conventions1489561
91197Node: Keymaps and Minor Modes1495234
91198Node: Defining Minor Modes1496564
91199Node: Mode Line Format1504985
91200Node: Mode Line Basics1506355
91201Node: Mode Line Data1508288
91202Node: Mode Line Top1512808
91203Node: Mode Line Variables1515361
91204Ref: Definition of minor-mode-alist1520334
91205Node: %-Constructs1522302
91206Node: Properties in Mode1526846
91207Node: Header Lines1528410
91208Node: Emulating Mode Line1529575
91209Node: Imenu1531786
91210Node: Font Lock Mode1538677
91211Node: Font Lock Basics1540369
91212Node: Search-based Fontification1546306
91213Node: Customizing Keywords1556206
91214Node: Other Font Lock Variables1559491
91215Node: Levels of Font Lock1563683
91216Node: Precalculated Fontification1565063
91217Node: Faces for Font Lock1566400
91218Node: Syntactic Font Lock1568799
91219Node: Multiline Font Lock1571637
91220Node: Font Lock Multiline1574880
91221Node: Region to Refontify1577326
91222Node: Auto-Indentation1578713
91223Node: SMIE1582283
91224Node: SMIE setup1584112
91225Node: Operator Precedence Grammars1586057
91226Node: SMIE Grammar1589768
91227Node: SMIE Lexer1592629
91228Node: SMIE Tricks1594864
91229Node: SMIE Indentation1598215
91230Node: SMIE Indentation Helpers1601736
91231Node: SMIE Indentation Example1604075
91232Node: SMIE Customization1607243
91233Node: Desktop Save Mode1609022
91234Node: Documentation1610795
91235Node: Documentation Basics1612473
91236Node: Accessing Documentation1614772
91237Ref: describe-symbols example1617886
91238Ref: Definition of Snarf-documentation1621120
91239Node: Keys in Documentation1622157
91240Node: Text Quoting Style1626840
91241Node: Describing Characters1629308
91242Node: Help Functions1633239
91243Ref: Definition of data-directory1638883
91244Node: Files1642156
91245Node: Visiting Files1644690
91246Node: Visiting Functions1646158
91247Node: Subroutines of Visiting1653974
91248Node: Saving Buffers1656851
91249Ref: Definition of save-some-buffers1658588
91250Ref: Definition of write-file1659930
91251Node: Reading from Files1666322
91252Node: Writing to Files1669341
91253Ref: Definition of with-temp-file1674005
91254Node: File Locks1674608
91255Node: Information about Files1678497
91256Node: Testing Accessibility1679604
91257Node: Kinds of Files1685139
91258Node: Truenames1689366
91259Node: File Attributes1694434
91260Ref: Definition of file-attributes1695645
91261Node: Extended Attributes1701466
91262Node: Locating Files1704379
91263Node: Changing Files1707607
91264Node: Files and Storage1722137
91265Node: File Names1723258
91266Ref: File Names-Footnote-11725034
91267Node: File Name Components1725274
91268Node: Relative File Names1729679
91269Node: Directory Names1732328
91270Ref: abbreviate-file-name1735920
91271Node: File Name Expansion1736544
91272Ref: Definition of substitute-in-file-name1740674
91273Node: Unique File Names1743748
91274Node: File Name Completion1750100
91275Node: Standard File Names1753349
91276Node: Contents of Directories1756184
91277Node: Create/Delete Dirs1763641
91278Node: Magic File Names1766635
91279Node: Format Conversion1779641
91280Node: Format Conversion Overview1780435
91281Node: Format Conversion Round-Trip1781476
91282Node: Format Conversion Piecemeal1788921
91283Node: Backups and Auto-Saving1794027
91284Node: Backup Files1794708
91285Node: Making Backups1796337
91286Node: Rename or Copy1801039
91287Node: Numbered Backups1804261
91288Node: Backup Names1806659
91289Node: Auto-Saving1810448
91290Node: Reverting1820386
91291Ref: Definition of revert-buffer-function1823105
91292Node: Buffers1828624
91293Node: Buffer Basics1830159
91294Node: Current Buffer1832247
91295Ref: Definition of with-temp-buffer1838044
91296Node: Buffer Names1838925
91297Node: Buffer File Name1842636
91298Node: Buffer Modification1848879
91299Node: Modification Time1852696
91300Node: Read Only Buffers1857272
91301Node: Buffer List1860822
91302Node: Creating Buffers1868260
91303Node: Killing Buffers1870778
91304Node: Indirect Buffers1875722
91305Node: Swapping Text1878827
91306Node: Buffer Gap1881332
91307Node: Windows1882338
91308Node: Basic Windows1884955
91309Ref: Window Group1888518
91310Node: Windows and Frames1889709
91311Node: Window Sizes1901689
91312Node: Resizing Windows1916700
91313Node: Preserving Window Sizes1928725
91314Node: Splitting Windows1932939
91315Node: Deleting Windows1940317
91316Node: Recombining Windows1944856
91317Node: Selecting Windows1958655
91318Node: Cyclic Window Ordering1965358
91319Node: Buffers and Windows1973087
91320Node: Switching Buffers1978273
91321Node: Displaying Buffers1985903
91322Node: Choosing Window1987872
91323Node: Buffer Display Action Functions1994232
91324Node: Buffer Display Action Alists2007647
91325Node: Choosing Window Options2018873
91326Node: Precedence of Action Functions2027295
91327Node: The Zen of Buffer Display2039874
91328Node: Window History2050600
91329Node: Dedicated Windows2057865
91330Node: Quitting Windows2060889
91331Node: Side Windows2068903
91332Node: Displaying Buffers in Side Windows2070240
91333Node: Side Window Options and Functions2073388
91334Node: Frame Layouts with Side Windows2077402
91335Node: Atomic Windows2082448
91336Node: Window Point2088467
91337Node: Window Start and End2091154
91338Node: Textual Scrolling2102391
91339Node: Vertical Scrolling2114915
91340Node: Horizontal Scrolling2117681
91341Node: Coordinates and Windows2124108
91342Node: Mouse Window Auto-selection2135405
91343Node: Window Configurations2137690
91344Node: Window Parameters2145075
91345Node: Window Hooks2153270
91346Node: Frames2168057
91347Node: Creating Frames2173215
91348Node: Multiple Terminals2176681
91349Node: Frame Geometry2188073
91350Node: Frame Layout2188993
91351Node: Frame Font2206095
91352Node: Frame Position2208285
91353Node: Frame Size2211685
91354Node: Implied Frame Resizing2220730
91355Node: Frame Parameters2224121
91356Node: Parameter Access2225656
91357Node: Initial Parameters2228590
91358Node: Window Frame Parameters2231783
91359Node: Basic Parameters2233225
91360Node: Position Parameters2235030
91361Node: Size Parameters2242167
91362Node: Layout Parameters2249292
91363Node: Buffer Parameters2252904
91364Node: Frame Interaction Parameters2255015
91365Node: Mouse Dragging Parameters2258242
91366Node: Management Parameters2260755
91367Node: Cursor Parameters2266062
91368Node: Font and Color Parameters2269163
91369Node: Geometry2275192
91370Node: Terminal Parameters2276442
91371Node: Frame Titles2278927
91372Node: Deleting Frames2280626
91373Node: Finding All Frames2283313
91374Node: Minibuffers and Frames2285946
91375Node: Input Focus2287473
91376Node: Visibility of Frames2299930
91377Node: Raising and Lowering2303211
91378Node: Frame Configurations2307598
91379Node: Child Frames2308498
91380Node: Mouse Tracking2320202
91381Node: Mouse Position2322655
91382Node: Pop-Up Menus2325929
91383Node: Dialog Boxes2330061
91384Node: Pointer Shape2332570
91385Node: Window System Selections2334533
91386Node: Drag and Drop2338019
91387Node: Color Names2339362
91388Node: Text Terminal Colors2343804
91389Node: Resources2346552
91390Node: Display Feature Testing2348915
91391Ref: Display Face Attribute Testing2350961
91392Node: Positions2357084
91393Node: Point2358603
91394Node: Motion2361338
91395Node: Character Motion2362110
91396Node: Word Motion2363668
91397Node: Buffer End Motion2367879
91398Node: Text Lines2369649
91399Ref: Definition of count-lines2373438
91400Node: Screen Lines2374876
91401Node: List Motion2383536
91402Node: Skipping Characters2388246
91403Node: Excursions2390891
91404Node: Narrowing2393826
91405Node: Markers2398504
91406Node: Overview of Markers2399533
91407Node: Predicates on Markers2402761
91408Node: Creating Markers2403686
91409Node: Information from Markers2406766
91410Node: Marker Insertion Types2407722
91411Node: Moving Markers2408944
91412Node: The Mark2410127
91413Node: The Region2421504
91414Node: Text2423486
91415Node: Near Point2426957
91416Node: Buffer Contents2430256
91417Node: Comparing Text2437318
91418Node: Insertion2438781
91419Node: Commands for Insertion2443708
91420Node: Deletion2447740
91421Node: User-Level Deletion2452347
91422Node: The Kill Ring2457567
91423Node: Kill Ring Concepts2459824
91424Node: Kill Functions2460881
91425Node: Yanking2463725
91426Node: Yank Commands2467282
91427Node: Low-Level Kill Ring2470353
91428Node: Internals of Kill Ring2474770
91429Node: Undo2477759
91430Node: Maintaining Undo2485277
91431Node: Filling2488732
91432Ref: Definition of sentence-end-double-space2495366
91433Node: Margins2497719
91434Node: Adaptive Fill2502091
91435Node: Auto Filling2506263
91436Node: Sorting2508155
91437Node: Columns2519111
91438Node: Indentation2521660
91439Node: Primitive Indent2522446
91440Node: Mode-Specific Indent2523945
91441Node: Region Indent2529481
91442Node: Relative Indent2532577
91443Node: Indent Tabs2535034
91444Node: Motion by Indent2536497
91445Node: Case Changes2537435
91446Node: Text Properties2540740
91447Node: Examining Properties2543121
91448Node: Changing Properties2547287
91449Node: Property Search2554309
91450Node: Special Properties2564298
91451Ref: Text help-echo2568651
91452Ref: Inhibit point motion hooks2583949
91453Ref: Help display2584341
91454Node: Format Properties2585292
91455Node: Sticky Properties2586316
91456Node: Lazy Properties2590548
91457Node: Clickable Text2592783
91458Node: Fields2600261
91459Node: Not Intervals2605774
91460Node: Substitution2608315
91461Node: Registers2610205
91462Node: Transposition2614085
91463Node: Replacing2615055
91464Node: Decompression2618018
91465Node: Base 642619437
91466Ref: Base 64-Footnote-12622779
91467Node: Checksum/Hash2623058
91468Node: GnuTLS Cryptography2626932
91469Node: Format of GnuTLS Cryptography Inputs2627654
91470Node: GnuTLS Cryptographic Functions2629287
91471Node: Parsing HTML/XML2634651
91472Node: Document Object Model2637190
91473Node: Parsing JSON2640774
91474Node: JSONRPC2645495
91475Node: JSONRPC Overview2646083
91476Node: Process-based JSONRPC connections2650331
91477Node: JSONRPC JSON object format2652084
91478Node: JSONRPC deferred requests2653268
91479Node: Atomic Changes2655200
91480Node: Change Hooks2659536
91481Node: Non-ASCII Characters2666005
91482Node: Text Representations2667394
91483Ref: Text Representations-Footnote-12673962
91484Node: Disabling Multibyte2674257
91485Node: Converting Representations2676664
91486Node: Selecting a Representation2680259
91487Node: Character Codes2682997
91488Node: Character Properties2685504
91489Ref: Character Properties-Footnote-12697864
91490Node: Character Sets2698073
91491Node: Scanning Charsets2702873
91492Node: Translation of Characters2704572
91493Node: Coding Systems2709439
91494Node: Coding System Basics2710560
91495Node: Encoding and I/O2715494
91496Node: Lisp and Coding Systems2720007
91497Node: User-Chosen Coding Systems2727882
91498Node: Default Coding Systems2733034
91499Node: Specifying Coding Systems2743077
91500Node: Explicit Encoding2747732
91501Node: Terminal I/O Encoding2754359
91502Node: Input Methods2756364
91503Node: Locales2759300
91504Node: Searching and Matching2761679
91505Node: String Search2762917
91506Node: Searching and Case2769225
91507Node: Regular Expressions2771208
91508Node: Syntax of Regexps2772405
91509Node: Regexp Special2774330
91510Ref: Non-greedy repetition2777063
91511Node: Char Classes2787360
91512Node: Regexp Backslash2790634
91513Node: Regexp Example2800162
91514Node: Rx Notation2803214
91515Ref: Rx Notation-Footnote-12805006
91516Node: Rx Constructs2805131
91517Node: Rx Functions2819801
91518Node: Extending Rx2820911
91519Node: Regexp Functions2826524
91520Ref: regexp-unmatchable2830233
91521Ref: Regexp Functions-Footnote-12830526
91522Node: Regexp Search2830757
91523Ref: re-search-backward2833714
91524Node: POSIX Regexps2839048
91525Node: Match Data2840988
91526Node: Replacing Match2842451
91527Node: Simple Match Data2846087
91528Node: Entire Match Data2851449
91529Node: Saving Match Data2854503
91530Node: Search and Replace2855866
91531Node: Standard Regexps2864532
91532Node: Syntax Tables2867193
91533Node: Syntax Basics2868278
91534Node: Syntax Descriptors2871021
91535Node: Syntax Class Table2873516
91536Node: Syntax Flags2880280
91537Node: Syntax Table Functions2884387
91538Node: Syntax Properties2889079
91539Node: Motion and Syntax2892655
91540Node: Parsing Expressions2894261
91541Node: Motion via Parsing2896260
91542Node: Position Parse2899358
91543Node: Parser State2901454
91544Node: Low-Level Parsing2904854
91545Node: Control Parsing2906711
91546Node: Syntax Table Internals2908013
91547Node: Categories2911475
91548Node: Abbrevs2918028
91549Node: Abbrev Tables2920661
91550Node: Defining Abbrevs2923371
91551Node: Abbrev Files2926051
91552Node: Abbrev Expansion2928477
91553Node: Standard Abbrev Tables2934749
91554Node: Abbrev Properties2936346
91555Node: Abbrev Table Properties2937757
91556Node: Threads2939544
91557Node: Basic Thread Functions2941592
91558Node: Mutexes2945181
91559Node: Condition Variables2947005
91560Node: The Thread List2949761
91561Node: Processes2951681
91562Node: Subprocess Creation2955058
91563Node: Shell Arguments2960441
91564Node: Synchronous Processes2964473
91565Ref: Synchronous Processes-Footnote-12977831
91566Node: Asynchronous Processes2977935
91567Node: Deleting Processes2993932
91568Node: Process Information2996270
91569Ref: Coding systems for a subprocess3003974
91570Node: Input to Processes3005076
91571Node: Signals to Processes3008448
91572Node: Output from Processes3014643
91573Node: Process Buffers3017851
91574Node: Filter Functions3024036
91575Ref: Process Filter Example3026313
91576Node: Decoding Output3029513
91577Node: Accepting Output3031465
91578Node: Processes and Threads3034956
91579Node: Sentinels3036208
91580Node: Query Before Exit3041781
91581Node: System Processes3043177
91582Node: Transaction Queues3050004
91583Node: Network3051922
91584Node: Network Servers3060448
91585Node: Datagrams3062517
91586Node: Low-Level Network3063805
91587Node: Network Processes3064425
91588Node: Network Options3073459
91589Node: Network Feature Testing3077018
91590Node: Misc Network3078335
91591Node: Serial Ports3082777
91592Node: Byte Packing3090436
91593Node: Bindat Spec3091334
91594Node: Bindat Functions3097235
91595Node: Display3100068
91596Node: Refresh Screen3102000
91597Node: Forcing Redisplay3103435
91598Node: Truncation3105635
91599Node: The Echo Area3109431
91600Node: Displaying Messages3110355
91601Ref: message-box3115645
91602Node: Progress3117135
91603Node: Logging Messages3123906
91604Node: Echo Area Customization3126374
91605Node: Warnings3128243
91606Node: Warning Basics3128804
91607Node: Warning Variables3131712
91608Node: Warning Options3135186
91609Node: Delayed Warnings3136569
91610Node: Invisible Text3138466
91611Node: Selective Display3145858
91612Node: Temporary Displays3150070
91613Node: Overlays3159230
91614Node: Managing Overlays3160687
91615Node: Overlay Properties3166902
91616Node: Finding Overlays3178085
91617Node: Size of Displayed Text3180739
91618Node: Line Height3191648
91619Node: Faces3196360
91620Ref: Faces-Footnote-13198666
91621Node: Face Attributes3198808
91622Ref: face-font-attribute3206668
91623Node: Defining Faces3209638
91624Node: Attribute Functions3218063
91625Node: Displaying Faces3227029
91626Node: Face Remapping3230085
91627Node: Face Functions3235189
91628Node: Auto Faces3237243
91629Node: Basic Faces3238888
91630Node: Font Selection3241103
91631Ref: Font Selection-Footnote-13245456
91632Node: Font Lookup3245560
91633Node: Fontsets3248046
91634Node: Low-Level Font3254536
91635Node: Fringes3268681
91636Node: Fringe Size/Pos3269420
91637Node: Fringe Indicators3272549
91638Node: Fringe Cursors3276858
91639Node: Fringe Bitmaps3278632
91640Node: Customizing Bitmaps3282230
91641Node: Overlay Arrow3284440
91642Node: Scroll Bars3286933
91643Node: Window Dividers3294892
91644Node: Display Property3297772
91645Node: Replacing Specs3299558
91646Node: Specified Space3301734
91647Node: Pixel Specification3304636
91648Node: Other Display Specs3308360
91649Node: Display Margins3314002
91650Node: Images3317652
91651Node: Image Formats3319076
91652Node: Image Descriptors3321214
91653Node: XBM Images3332164
91654Node: XPM Images3334694
91655Node: ImageMagick Images3335279
91656Node: SVG Images3338943
91657Ref: SVG Path Commands3345450
91658Node: Other Image Types3352874
91659Node: Defining Images3354077
91660Node: Showing Images3360113
91661Node: Multi-Frame Images3365703
91662Node: Image Cache3368164
91663Node: Xwidgets3371220
91664Node: Buttons3375069
91665Node: Button Properties3376478
91666Node: Button Types3379074
91667Node: Making Buttons3380463
91668Node: Manipulating Buttons3382969
91669Node: Button Buffer Commands3385296
91670Node: Abstract Display3388623
91671Node: Abstract Display Functions3391531
91672Node: Abstract Display Example3396610
91673Node: Blinking3401336
91674Node: Character Display3403328
91675Node: Usual Display3404554
91676Node: Display Tables3408520
91677Node: Active Display Table3412793
91678Node: Glyphs3414734
91679Node: Glyphless Chars3416821
91680Node: Beeping3420755
91681Node: Window Systems3422101
91682Node: Tooltips3424270
91683Node: Bidirectional Display3427759
91684Node: System Interface3443640
91685Node: Starting Up3445598
91686Node: Startup Summary3446181
91687Node: Init File3456716
91688Node: Terminal-Specific3461692
91689Node: Command-Line Arguments3465212
91690Node: Getting Out3469389
91691Node: Killing Emacs3470005
91692Node: Suspending Emacs3472853
91693Node: System Environment3478228
91694Node: User Identification3486494
91695Node: Time of Day3490060
91696Ref: Time of Day-Footnote-13494879
91697Node: Time Zone Rules3495195
91698Node: Time Conversion3498143
91699Ref: Time Conversion-Footnote-13507337
91700Node: Time Parsing3507499
91701Node: Processor Run Time3518256
91702Node: Time Calculations3519869
91703Node: Timers3522376
91704Node: Idle Timers3529788
91705Node: Terminal Input3534060
91706Node: Input Modes3534494
91707Node: Recording Input3536990
91708Node: Terminal Output3538654
91709Node: Sound Output3541794
91710Node: X11 Keysyms3543988
91711Node: Batch Mode3545578
91712Node: Session Management3547481
91713Node: Desktop Notifications3549617
91714Node: File Notifications3562209
91715Node: Dynamic Libraries3569252
91716Node: Security Considerations3571481
91717Node: Packaging3578144
91718Node: Packaging Basics3579093
91719Node: Simple Packages3583900
91720Node: Multi-file Packages3586499
91721Node: Package Archives3589898
91722Node: Archive Web Server3593263
91723Node: Antinews3594013
91724Node: GNU Free Documentation License3602309
91725Node: GPL3627654
91726Node: Tips3665430
91727Node: Coding Conventions3666894
91728Ref: Coding Conventions-Footnote-13676720
91729Node: Key Binding Conventions3676821
91730Node: Programming Tips3679916
91731Node: Compilation Tips3684235
91732Node: Warning Tips3686208
91733Node: Documentation Tips3688039
91734Ref: Docstring hyperlinks3692655
91735Ref: Documentation Tips-Footnote-13700299
91736Node: Comment Tips3700363
91737Node: Library Headers3703310
91738Node: GNU Emacs Internals3710636
91739Node: Building Emacs3711690
91740Node: Pure Storage3721049
91741Node: Garbage Collection3724355
91742Node: Stack-allocated Objects3737352
91743Node: Memory Usage3738881
91744Node: C Dialect3740411
91745Node: Writing Emacs Primitives3741022
91746Ref: Defining Lisp variables in C3750497
91747Node: Writing Dynamic Modules3755951
91748Node: Module Initialization3757642
91749Ref: module initialization function3758168
91750Node: Module Functions3763076
91751Node: Module Values3770207
91752Node: Module Misc3788498
91753Ref: intern3790521
91754Ref: should_quit3792307
91755Ref: process_input3792752
91756Node: Module Nonlocal3793553
91757Node: Object Internals3798882
91758Node: Buffer Internals3802264
91759Node: Window Internals3812062
91760Node: Process Internals3821889
91761Node: C Integer Types3824761
91762Node: Standard Errors3829422
91763Node: Standard Keymaps3837511
91764Node: Standard Hooks3843016
91765Node: Index3849603
91766
91767End Tag Table
91768
91769
91770Local Variables:
91771coding: utf-8
91772End:
91773