Now on revision 108158. ------------------------------------------------------------ revno: 108158 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 23:38:27 -0700 message: Stop keeping 3 copies of the lispref menu structure for no reason vol1.texi and vol2.texi are only used to generate TeX output, and this constructs its own table of contents and does not use the @menu stuff. * vol1.texi, vol2.texi: No need to keep menus in these files. * elisp.texi, anti.texi: Comments. diff: === modified file 'doc/lispref/ChangeLog' --- doc/lispref/ChangeLog 2012-05-05 16:38:22 +0000 +++ doc/lispref/ChangeLog 2012-05-08 06:38:27 +0000 @@ -1,3 +1,7 @@ +2012-05-08 Glenn Morris + + * vol1.texi, vol2.texi: No need to keep menus in these files. + 2012-05-05 Glenn Morris * objects.texi (Process Type, Overlay Type): Tweak page-breaks. @@ -10994,7 +10998,7 @@ ;; coding: utf-8 ;; End: - Copyright (C) 1998-2012 Free Software Foundation, Inc. + Copyright (C) 1998-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. === modified file 'doc/lispref/anti.texi' --- doc/lispref/anti.texi 2012-04-14 20:43:11 +0000 +++ doc/lispref/anti.texi 2012-05-08 06:38:27 +0000 @@ -7,8 +7,7 @@ @node Antinews, GNU Free Documentation License, Packaging, Top @appendix Emacs 23 Antinews -@c Update the elisp.texi, vol1.texi, vol2.texi Antinews menu entries -@c with the above version number. +@c Update the elisp.texi Antinews menu entry with the above version number. For those users who live backwards in time, here is information about downgrading to Emacs version 23.4. We hope you will enjoy the greater === modified file 'doc/lispref/elisp.texi' --- doc/lispref/elisp.texi 2012-05-05 04:32:58 +0000 +++ doc/lispref/elisp.texi 2012-05-08 06:38:27 +0000 @@ -108,7 +108,6 @@ @insertcopying @end ifnottex -@c Copy any updates to vol1.texi and vol2.texi. @menu * Introduction:: Introduction and conventions used. @@ -189,7 +188,6 @@ @c be correctly identified by `texinfo-multiple-files-update'. In @c particular, the detailed menu header line MUST be identical to the @c value of `texinfo-master-menu-header'. See texnfo-upd.el. -@c Copy any updates to vol1.texi and vol2.texi. @detailmenu --- The Detailed Node Listing --- @@ -1522,12 +1520,8 @@ @include package.texi -@c MOVE to Emacs Manual: include misc-modes.texi - @c appendices -@c REMOVE this: include non-hacker.texi - @include anti.texi @include doclicense.texi @include gpl.texi === modified file 'doc/lispref/vol1.texi' --- doc/lispref/vol1.texi 2012-04-26 17:56:38 +0000 +++ doc/lispref/vol1.texi 2012-05-08 06:38:27 +0000 @@ -66,7 +66,7 @@ This is edition @value{VERSION} of the GNU Emacs Lisp Reference Manual,@* corresponding to Emacs version @value{EMACSVER}. -Copyright @copyright{} 1990-1996, 1998-2012 Free Software Foundation, Inc. +Copyright @copyright{} 1990-1996, 1998-2012 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document @@ -114,7 +114,7 @@ @ifnottex -@node Top, Introduction, (dir), (dir) +@node Top @top Emacs Lisp This Info file contains edition @value{VERSION} of the GNU Emacs Lisp @@ -122,85 +122,8 @@ @end ifnottex @menu -* Introduction:: Introduction and conventions used. - -* Lisp Data Types:: Data types of objects in Emacs Lisp. -* Numbers:: Numbers and arithmetic functions. -* Strings and Characters:: Strings, and functions that work on them. -* Lists:: Lists, cons cells, and related functions. -* Sequences Arrays Vectors:: Lists, strings and vectors are called sequences. - Certain functions act on any kind of sequence. - The description of vectors is here as well. -* Hash Tables:: Very fast lookup-tables. -* Symbols:: Symbols represent names, uniquely. - -* Evaluation:: How Lisp expressions are evaluated. -* Control Structures:: Conditionals, loops, nonlocal exits. -* Variables:: Using symbols in programs to stand for values. -* Functions:: A function is a Lisp program - that can be invoked from other functions. -* Macros:: Macros are a way to extend the Lisp language. -* Customization:: Making variables and faces customizable. - -* Loading:: Reading files of Lisp code into Lisp. -* Byte Compilation:: Compilation makes programs run faster. -* Advising Functions:: Adding to the definition of a function. -* Debugging:: Tools and tips for debugging Lisp programs. - -* Read and Print:: Converting Lisp objects to text and back. -* Minibuffers:: Using the minibuffer to read input. -* Command Loop:: How the editor command loop works, - and how you can call its subroutines. -* Keymaps:: Defining the bindings from keys to commands. -* Modes:: Defining major and minor modes. -* Documentation:: Writing and using documentation strings. - -* Files:: Accessing files. -* Backups and Auto-Saving:: Controlling how backups and auto-save - files are made. -* Buffers:: Creating and using buffer objects. -* Windows:: Manipulating windows and displaying buffers. -* Frames:: Making multiple system-level windows. -* Positions:: Buffer positions and motion functions. -* Markers:: Markers represent positions and update - automatically when the text is changed. - -* Text:: Examining and changing text in buffers. -* Non-ASCII Characters:: Non-ASCII text in buffers and strings. -* Searching and Matching:: Searching buffers for strings or regexps. -* Syntax Tables:: The syntax table controls word and list parsing. -* Abbrevs:: How Abbrev mode works, and its data structures. - -* Processes:: Running and communicating with subprocesses. -* Display:: Features for controlling the screen display. -* System Interface:: Getting the user id, system type, environment - variables, and other such things. - -* Packaging:: Preparing Lisp code for distribution. - -Appendices - -* Antinews:: Info for users downgrading to Emacs 23. -* GNU Free Documentation License:: The license for this documentation. -* GPL:: Conditions for copying and changing GNU Emacs. -* Tips:: Advice and coding conventions for Emacs Lisp. -* GNU Emacs Internals:: Building and dumping Emacs; - internal data structures. -* Standard Errors:: List of some standard error symbols. -* Standard Keymaps:: List of some standard keymaps. -* Standard Hooks:: List of some standard hook variables. - -* Index:: Index including concepts, functions, variables, - and other terms. - -@ignore -* New Symbols:: New functions and variables in Emacs @value{EMACSVER}. -@end ignore - -@c Do NOT modify the following 3 lines! They must have this form to -@c be correctly identified by `texinfo-multiple-files-update'. In -@c particular, the detailed menu header line MUST be identical to the -@c value of `texinfo-master-menu-header'. See texnfo-upd.el. +* Not used:: This file is only used with tex, which + generates its own menu. @detailmenu --- The Detailed Node Listing --- @@ -209,1280 +132,10 @@ Here are other nodes that are subnodes of those already listed, mentioned here so you can get to them in one step: -Introduction - -* Caveats:: Flaws and a request for help. -* Lisp History:: Emacs Lisp is descended from Maclisp. -* Conventions:: How the manual is formatted. -* Version Info:: Which Emacs version is running? -* Acknowledgements:: The authors, editors, and sponsors of this manual. - -Conventions - -* Some Terms:: Explanation of terms we use in this manual. -* nil and t:: How the symbols @code{nil} and @code{t} are used. -* Evaluation Notation:: The format we use for examples of evaluation. -* Printing Notation:: The format we use when examples print text. -* Error Messages:: The format we use for examples of errors. -* Buffer Text Notation:: The format we use for buffer contents in examples. -* Format of Descriptions:: Notation for describing functions, variables, etc. - -Format of Descriptions - -* A Sample Function Description:: A description of an imaginary - function, @code{foo}. -* A Sample Variable Description:: A description of an imaginary - variable, @code{electric-future-map}. - -Lisp Data Types - -* Printed Representation:: How Lisp objects are represented as text. -* Comments:: Comments and their formatting conventions. -* Programming Types:: Types found in all Lisp systems. -* Editing Types:: Types specific to Emacs. -* Circular Objects:: Read syntax for circular structure. -* Type Predicates:: Tests related to types. -* Equality Predicates:: Tests of equality between any two objects. - -Programming Types - -* Integer Type:: Numbers without fractional parts. -* Floating Point Type:: Numbers with fractional parts and with a large range. -* Character Type:: The representation of letters, numbers and - control characters. -* Symbol Type:: A multi-use object that refers to a function, - variable, or property list, and has a unique identity. -* Sequence Type:: Both lists and arrays are classified as sequences. -* Cons Cell Type:: Cons cells, and lists (which are made from cons cells). -* Array Type:: Arrays include strings and vectors. -* String Type:: An (efficient) array of characters. -* Vector Type:: One-dimensional arrays. -* Char-Table Type:: One-dimensional sparse arrays indexed by characters. -* Bool-Vector Type:: One-dimensional arrays of @code{t} or @code{nil}. -* Hash Table Type:: Super-fast lookup tables. -* Function Type:: A piece of executable code you can call from elsewhere. -* Macro Type:: A method of expanding an expression into another - expression, more fundamental but less pretty. -* Primitive Function Type:: A function written in C, callable from Lisp. -* Byte-Code Type:: A function written in Lisp, then compiled. -* Autoload Type:: A type used for automatically loading seldom-used - functions. - -Character Type - -* Basic Char Syntax:: Syntax for regular characters. -* General Escape Syntax:: How to specify characters by their codes. -* Ctl-Char Syntax:: Syntax for control characters. -* Meta-Char Syntax:: Syntax for meta-characters. -* Other Char Bits:: Syntax for hyper-, super-, and alt-characters. - -Cons Cell and List Types - -* Box Diagrams:: Drawing pictures of lists. -* Dotted Pair Notation:: A general syntax for cons cells. -* Association List Type:: A specially constructed list. - -String Type - -* Syntax for Strings:: How to specify Lisp strings. -* Non-ASCII in Strings:: International characters in strings. -* Nonprinting Characters:: Literal unprintable characters in strings. -* Text Props and Strings:: Strings with text properties. - -Editing Types - -* Buffer Type:: The basic object of editing. -* Marker Type:: A position in a buffer. -* Window Type:: Buffers are displayed in windows. -* Frame Type:: Windows subdivide frames. -* Terminal Type:: A terminal device displays frames. -* Window Configuration Type:: Recording the way a frame is subdivided. -* Frame Configuration Type:: Recording the status of all frames. -* Process Type:: A subprocess of Emacs running on the underlying OS. -* Stream Type:: Receive or send characters. -* Keymap Type:: What function a keystroke invokes. -* Overlay Type:: How an overlay is represented. -* Font Type:: Fonts for displaying text. - -Numbers - -* Integer Basics:: Representation and range of integers. -* Float Basics:: Representation and range of floating point. -* Predicates on Numbers:: Testing for numbers. -* Comparison of Numbers:: Equality and inequality predicates. -* Numeric Conversions:: Converting float to integer and vice versa. -* Arithmetic Operations:: How to add, subtract, multiply and divide. -* Rounding Operations:: Explicitly rounding floating point numbers. -* Bitwise Operations:: Logical and, or, not, shifting. -* Math Functions:: Trig, exponential and logarithmic functions. -* Random Numbers:: Obtaining random integers, predictable or not. - -Strings and Characters - -* String Basics:: Basic properties of strings and characters. -* Predicates for Strings:: Testing whether an object is a string or char. -* Creating Strings:: Functions to allocate new strings. -* Modifying Strings:: Altering the contents of an existing string. -* Text Comparison:: Comparing characters or strings. -* String Conversion:: Converting to and from characters and strings. -* Formatting Strings:: @code{format}: Emacs's analogue of @code{printf}. -* Case Conversion:: Case conversion functions. -* Case Tables:: Customizing case conversion. - -Lists - -* Cons Cells:: How lists are made out of cons cells. -* List-related Predicates:: Is this object a list? Comparing two lists. -* List Elements:: Extracting the pieces of a list. -* Building Lists:: Creating list structure. -* List Variables:: Modifying lists stored in variables. -* Modifying Lists:: Storing new pieces into an existing list. -* Sets And Lists:: A list can represent a finite mathematical set. -* Association Lists:: A list can represent a finite relation or mapping. -* Rings:: Managing a fixed-size ring of objects. - -Modifying Existing List Structure - -* Setcar:: Replacing an element in a list. -* Setcdr:: Replacing part of the list backbone. - This can be used to remove or add elements. -* Rearrangement:: Reordering the elements in a list; combining lists. - -Sequences, Arrays, and Vectors - -* Sequence Functions:: Functions that accept any kind of sequence. -* Arrays:: Characteristics of arrays in Emacs Lisp. -* Array Functions:: Functions specifically for arrays. -* Vectors:: Special characteristics of Emacs Lisp vectors. -* Vector Functions:: Functions specifically for vectors. -* Char-Tables:: How to work with char-tables. -* Bool-Vectors:: How to work with bool-vectors. - -Hash Tables - -* Creating Hash:: Functions to create hash tables. -* Hash Access:: Reading and writing the hash table contents. -* Defining Hash:: Defining new comparison methods. -* Other Hash:: Miscellaneous. - -Symbols - -* Symbol Components:: Symbols have names, values, function definitions - and property lists. -* Definitions:: A definition says how a symbol will be used. -* Creating Symbols:: How symbols are kept unique. -* Property Lists:: Each symbol has a property list - for recording miscellaneous information. - -Property Lists - -* Plists and Alists:: Comparison of the advantages of property - lists and association lists. -* Symbol Plists:: Functions to access symbols' property lists. -* Other Plists:: Accessing property lists stored elsewhere. - -Evaluation - -* Intro Eval:: Evaluation in the scheme of things. -* Forms:: How various sorts of objects are evaluated. -* Quoting:: Avoiding evaluation (to put constants in - the program). -* Backquote:: Easier construction of list structure. -* Eval:: How to invoke the Lisp interpreter explicitly. - -Kinds of Forms - -* Self-Evaluating Forms:: Forms that evaluate to themselves. -* Symbol Forms:: Symbols evaluate as variables. -* Classifying Lists:: How to distinguish various sorts of list forms. -* Function Indirection:: When a symbol appears as the car of a list, - we find the real function via the symbol. -* Function Forms:: Forms that call functions. -* Macro Forms:: Forms that call macros. -* Special Forms:: "Special forms" are idiosyncratic primitives, - most of them extremely important. -* Autoloading:: Functions set up to load files - containing their real definitions. - -Control Structures - -* Sequencing:: Evaluation in textual order. -* Conditionals:: @code{if}, @code{cond}, @code{when}, @code{unless}. -* Combining Conditions:: @code{and}, @code{or}, @code{not}. -* Iteration:: @code{while} loops. -* Nonlocal Exits:: Jumping out of a sequence. - -Nonlocal Exits - -* Catch and Throw:: Nonlocal exits for the program's own purposes. -* Examples of Catch:: Showing how such nonlocal exits can be written. -* Errors:: How errors are signaled and handled. -* Cleanups:: Arranging to run a cleanup form if an - error happens. - -Errors - -* Signaling Errors:: How to report an error. -* Processing of Errors:: What Emacs does when you report an error. -* Handling Errors:: How you can trap errors and continue execution. -* Error Symbols:: How errors are classified for trapping them. - -Variables - -* Global Variables:: Variable values that exist permanently, everywhere. -* Constant Variables:: Certain "variables" have values that never change. -* Local Variables:: Variable values that exist only temporarily. -* Void Variables:: Symbols that lack values. -* Defining Variables:: A definition says a symbol is used as a variable. -* Tips for Defining:: Things you should think about when you - define a variable. -* Accessing Variables:: Examining values of variables whose names - are known only at run time. -* Setting Variables:: Storing new values in variables. -* Variable Scoping:: How Lisp chooses among local and global values. -* Buffer-Local Variables:: Variable values in effect only in one buffer. -* File Local Variables:: Handling local variable lists in files. -* Directory Local Variables:: Local variables common to all files in a - directory. -* Frame-Local Variables:: Frame-local bindings for variables. -* Variable Aliases:: Variables that are aliases for other variables. -* Variables with Restricted Values:: Non-constant variables whose value can - @emph{not} be an arbitrary Lisp object. - -Scoping Rules for Variable Bindings - -* Scope:: Scope means where in the program a value - is visible. Comparison with other languages. -* Extent:: Extent means how long in time a value exists. -* Impl of Scope:: Two ways to implement dynamic scoping. -* Using Scoping:: How to use dynamic scoping carefully and - avoid problems. - -Buffer-Local Variables - -* Intro to Buffer-Local:: Introduction and concepts. -* Creating Buffer-Local:: Creating and destroying buffer-local bindings. -* Default Value:: The default value is seen in buffers - that don't have their own buffer-local values. - -Functions - -* What Is a Function:: Lisp functions vs. primitives; terminology. -* Lambda Expressions:: How functions are expressed as Lisp objects. -* Function Names:: A symbol can serve as the name of a function. -* Defining Functions:: Lisp expressions for defining functions. -* Calling Functions:: How to use an existing function. -* Mapping Functions:: Applying a function to each element of a list, etc. -* Anonymous Functions:: Lambda expressions are functions with no names. -* Function Cells:: Accessing or setting the function definition - of a symbol. -* Closures:: Functions that enclose a lexical environment. -* Obsolete Functions:: Declaring functions obsolete. -* Inline Functions:: Defining functions that the compiler - will expand inline. -* Declaring Functions:: Telling the compiler that a function is defined. -* Function Safety:: Determining whether a function is safe to call. -* Related Topics:: Cross-references to specific Lisp primitives - that have a special bearing on how - functions work. - -Lambda Expressions - -* Lambda Components:: The parts of a lambda expression. -* Simple Lambda:: A simple example. -* Argument List:: Details and special features of argument lists. -* Function Documentation:: How to put documentation in a function. - -Macros - -* Simple Macro:: A basic example. -* Expansion:: How, when and why macros are expanded. -* Compiling Macros:: How macros are expanded by the compiler. -* Defining Macros:: How to write a macro definition. -* Problems with Macros:: Don't evaluate the macro arguments too many times. - Don't hide the user's variables. -* Indenting Macros:: Specifying how to indent macro calls. - -Common Problems Using Macros - -* Wrong Time:: Do the work in the expansion, not in the macro. -* Argument Evaluation:: The expansion should evaluate each macro arg once. -* Surprising Local Vars:: Local variable bindings in the expansion - require special care. -* Eval During Expansion:: Don't evaluate them; put them in the expansion. -* Repeated Expansion:: Avoid depending on how many times expansion is done. - -Customization Settings - -* Common Keywords:: Common keyword arguments for all kinds of - customization declarations. -* Group Definitions:: Writing customization group definitions. -* Variable Definitions:: Declaring user options. -* Customization Types:: Specifying the type of a user option. -* Applying Customizations:: Functions to apply customization settings. -* Custom Themes:: Writing Custom themes. - -Customization Types - -* Simple Types:: Simple customization types: sexp, integer, number, - string, file, directory, alist. -* Composite Types:: Build new types from other types or data. -* Splicing into Lists:: Splice elements into list with @code{:inline}. -* Type Keywords:: Keyword-argument pairs in a customization type. -* Defining New Types:: Give your type a name. - -Loading - -* How Programs Do Loading:: The @code{load} function and others. -* Load Suffixes:: Details about the suffixes that @code{load} tries. -* Library Search:: Finding a library to load. -* Loading Non-ASCII:: Non-@acronym{ASCII} characters in Emacs Lisp files. -* Autoload:: Setting up a function to autoload. -* Repeated Loading:: Precautions about loading a file twice. -* Named Features:: Loading a library if it isn't already loaded. -* Where Defined:: Finding which file defined a certain symbol. -* Unloading:: How to "unload" a library that was loaded. -* Hooks for Loading:: Providing code to be run when - particular libraries are loaded. - -Byte Compilation - -* Speed of Byte-Code:: An example of speedup from byte compilation. -* Compilation Functions:: Byte compilation functions. -* Docs and Compilation:: Dynamic loading of documentation strings. -* Dynamic Loading:: Dynamic loading of individual functions. -* Eval During Compile:: Code to be evaluated when you compile. -* Compiler Errors:: Handling compiler error messages. -* Byte-Code Objects:: The data type used for byte-compiled functions. -* Disassembly:: Disassembling byte-code; how to read byte-code. - -Advising Emacs Lisp Functions - -* Simple Advice:: A simple example to explain the basics of advice. -* Defining Advice:: Detailed description of @code{defadvice}. -* Around-Advice:: Wrapping advice around a function's definition. -* Computed Advice:: ...is to @code{defadvice} as @code{fset} is to @code{defun}. -* Activation of Advice:: Advice doesn't do anything until you activate it. -* Enabling Advice:: You can enable or disable each piece of advice. -* Preactivation:: Preactivation is a way of speeding up the - loading of compiled advice. -* Argument Access in Advice:: How advice can access the function's arguments. -* Combined Definition:: How advice is implemented. - -Debugging Lisp Programs - -* Debugger:: A debugger for the Emacs Lisp evaluator. -* Edebug:: A source-level Emacs Lisp debugger. -* Syntax Errors:: How to find syntax errors. -* Test Coverage:: Ensuring you have tested all branches in your code. - -The Lisp Debugger - -* Error Debugging:: Entering the debugger when an error happens. -* Infinite Loops:: Stopping and debugging a program that doesn't exit. -* Function Debugging:: Entering it when a certain function is called. -* Explicit Debug:: Entering it at a certain point in the program. -* Using Debugger:: What the debugger does; what you see while in it. -* Debugger Commands:: Commands used while in the debugger. -* Invoking the Debugger:: How to call the function @code{debug}. -* Internals of Debugger:: Subroutines of the debugger, and global variables. - -Edebug - -* Using Edebug:: Introduction to use of Edebug. -* Instrumenting:: You must instrument your code - in order to debug it with Edebug. -* Edebug Execution Modes:: Execution modes, stopping more or less often. -* Jumping:: Commands to jump to a specified place. -* Edebug Misc:: Miscellaneous commands. -* Breaks:: Setting breakpoints to make the program stop. -* Trapping Errors:: Trapping errors with Edebug. -* Edebug Views:: Views inside and outside of Edebug. -* Edebug Eval:: Evaluating expressions within Edebug. -* Eval List:: Expressions whose values are displayed - each time you enter Edebug. -* Printing in Edebug:: Customization of printing. -* Trace Buffer:: How to produce trace output in a buffer. -* Coverage Testing:: How to test evaluation coverage. -* The Outside Context:: Data that Edebug saves and restores. -* Edebug and Macros:: Specifying how to handle macro calls. -* Edebug Options:: Option variables for customizing Edebug. - -Breaks - -* Breakpoints:: Breakpoints at stop points. -* Global Break Condition:: Breaking on an event. -* Source Breakpoints:: Embedding breakpoints in source code. - -The Outside Context - -* Checking Whether to Stop::When Edebug decides what to do. -* Edebug Display Update:: When Edebug updates the display. -* Edebug Recursive Edit:: When Edebug stops execution. - -Edebug and Macros - -* Instrumenting Macro Calls::The basic problem. -* Specification List:: How to specify complex patterns of evaluation. -* Backtracking:: What Edebug does when matching fails. -* Specification Examples:: To help understand specifications. - -Debugging Invalid Lisp Syntax - -* Excess Open:: How to find a spurious open paren or missing close. -* Excess Close:: How to find a spurious close paren or missing open. - -Reading and Printing Lisp Objects - -* Streams Intro:: Overview of streams, reading and printing. -* Input Streams:: Various data types that can be used as - input streams. -* Input Functions:: Functions to read Lisp objects from text. -* Output Streams:: Various data types that can be used as - output streams. -* Output Functions:: Functions to print Lisp objects as text. -* Output Variables:: Variables that control what the printing - functions do. - -Minibuffers - -* Intro to Minibuffers:: Basic information about minibuffers. -* Text from Minibuffer:: How to read a straight text string. -* Object from Minibuffer:: How to read a Lisp object or expression. -* Minibuffer History:: Recording previous minibuffer inputs - so the user can reuse them. -* Initial Input:: Specifying initial contents for the minibuffer. -* Completion:: How to invoke and customize completion. -* Yes-or-No Queries:: Asking a question with a simple answer. -* Multiple Queries:: Asking a series of similar questions. -* Reading a Password:: Reading a password from the terminal. -* Minibuffer Commands:: Commands used as key bindings in minibuffers. -* Minibuffer Windows:: Operating on the special minibuffer windows. -* Minibuffer Contents:: How such commands access the minibuffer text. -* Recursive Mini:: Whether recursive entry to minibuffer is allowed. -* Minibuffer Misc:: Various customization hooks and variables. - -Completion - -* Basic Completion:: Low-level functions for completing strings. - (These are too low level to use the minibuffer.) -* Minibuffer Completion:: Invoking the minibuffer with completion. -* Completion Commands:: Minibuffer commands that do completion. -* High-Level Completion:: Convenient special cases of completion - (reading buffer names, variable names, etc.). -* Reading File Names:: Using completion to read file names and - shell commands. -* Completion Variables:: Variables controlling completion behavior. -* Programmed Completion:: Writing your own completion function. -* Completion in Buffers:: Completing text in ordinary buffers. - -Command Loop - -* Command Overview:: How the command loop reads commands. -* Defining Commands:: Specifying how a function should read arguments. -* Interactive Call:: Calling a command, so that it will read arguments. -* Distinguish Interactive:: Making a command distinguish interactive calls. -* Command Loop Info:: Variables set by the command loop for you to examine. -* Adjusting Point:: Adjustment of point after a command. -* Input Events:: What input looks like when you read it. -* Reading Input:: How to read input events from the keyboard or mouse. -* Special Events:: Events processed immediately and individually. -* Waiting:: Waiting for user input or elapsed time. -* Quitting:: How @kbd{C-g} works. How to catch or defer quitting. -* Prefix Command Arguments:: How the commands to set prefix args work. -* Recursive Editing:: Entering a recursive edit, - and why you usually shouldn't. -* Disabling Commands:: How the command loop handles disabled commands. -* Command History:: How the command history is set up, and how accessed. -* Keyboard Macros:: How keyboard macros are implemented. - -Defining Commands - -* Using Interactive:: General rules for @code{interactive}. -* Interactive Codes:: The standard letter-codes for reading arguments - in various ways. -* Interactive Examples:: Examples of how to read interactive arguments. - -Input Events - -* Keyboard Events:: Ordinary characters--keys with symbols on them. -* Function Keys:: Function keys--keys with names, not symbols. -* Mouse Events:: Overview of mouse events. -* Click Events:: Pushing and releasing a mouse button. -* Drag Events:: Moving the mouse before releasing the button. -* Button-Down Events:: A button was pushed and not yet released. -* Repeat Events:: Double and triple click (or drag, or down). -* Motion Events:: Just moving the mouse, not pushing a button. -* Focus Events:: Moving the mouse between frames. -* Misc Events:: Other events the system can generate. -* Event Examples:: Examples of the lists for mouse events. -* Classifying Events:: Finding the modifier keys in an event symbol. - Event types. -* Accessing Mouse:: Functions to extract info from mouse events. -* Accessing Scroll:: Functions to get info from scroll bar events. -* Strings of Events:: Special considerations for putting - keyboard character events in a string. - -Reading Input - -* Key Sequence Input:: How to read one key sequence. -* Reading One Event:: How to read just one event. -* Event Mod:: How Emacs modifies events as they are read. -* Invoking the Input Method:: How reading an event uses the input method. -* Quoted Character Input:: Asking the user to specify a character. -* Event Input Misc:: How to reread or throw away input events. - -Keymaps - -* Key Sequences:: Key sequences as Lisp objects. -* Keymap Basics:: Basic concepts of keymaps. -* Format of Keymaps:: What a keymap looks like as a Lisp object. -* Creating Keymaps:: Functions to create and copy keymaps. -* Inheritance and Keymaps:: How one keymap can inherit the bindings - of another keymap. -* Prefix Keys:: Defining a key with a keymap as its definition. -* Active Keymaps:: How Emacs searches the active keymaps - for a key binding. -* Searching Keymaps:: A pseudo-Lisp summary of searching active maps. -* Controlling Active Maps:: Each buffer has a local keymap - to override the standard (global) bindings. - A minor mode can also override them. -* Key Lookup:: Finding a key's binding in one keymap. -* Functions for Key Lookup:: How to request key lookup. -* Changing Key Bindings:: Redefining a key in a keymap. -* Remapping Commands:: A keymap can translate one command to another. -* Translation Keymaps:: Keymaps for translating sequences of events. -* Key Binding Commands:: Interactive interfaces for redefining keys. -* Scanning Keymaps:: Looking through all keymaps, for printing help. -* Menu Keymaps:: Defining a menu as a keymap. - -Menu Keymaps - -* Defining Menus:: How to make a keymap that defines a menu. -* Mouse Menus:: How users actuate the menu with the mouse. -* Keyboard Menus:: How users actuate the menu with the keyboard. -* Menu Example:: Making a simple menu. -* Menu Bar:: How to customize the menu bar. -* Tool Bar:: A tool bar is a row of images. -* Modifying Menus:: How to add new items to a menu. - -Defining Menus - -* Simple Menu Items:: A simple kind of menu key binding, - limited in capabilities. -* Extended Menu Items:: More powerful menu item definitions - let you specify keywords to enable - various features. -* Menu Separators:: Drawing a horizontal line through a menu. -* Alias Menu Items:: Using command aliases in menu items. -* Toolkit Differences:: Not all toolkits provide the same features. - -Major and Minor Modes - -* Hooks:: How to use hooks; how to write code that provides hooks. -* Major Modes:: Defining major modes. -* Minor Modes:: Defining minor modes. -* Mode Line Format:: Customizing the text that appears in the mode line. -* Imenu:: Providing a menu of definitions made in a buffer. -* Font Lock Mode:: How modes can highlight text according to syntax. -* Auto-Indentation:: How to teach Emacs to indent for a major mode. -* Desktop Save Mode:: How modes can have buffer state saved between - Emacs sessions. - -Hooks - -* Running Hooks:: How to run a hook. -* Setting Hooks:: How to put functions on a hook, or remove them. - -Major Modes - -* Major Mode Conventions:: Coding conventions for keymaps, etc. -* Auto Major Mode:: How Emacs chooses the major mode automatically. -* Mode Help:: Finding out how to use a mode. -* Derived Modes:: Defining a new major mode based on another major - mode. -* Basic Major Modes:: Modes that other modes are often derived from. -* Mode Hooks:: Hooks run at the end of major mode functions. -* Tabulated List Mode:: Parent mode for buffers containing tabulated data. -* Generic Modes:: Defining a simple major mode that supports - comment syntax and Font Lock mode. -* Example Major Modes:: Text mode and Lisp modes. - -Minor Modes - -* Minor Mode Conventions:: Tips for writing a minor mode. -* Keymaps and Minor Modes:: How a minor mode can have its own keymap. -* Defining Minor Modes:: A convenient facility for defining minor modes. - -Mode Line Format - -* Mode Line Basics:: Basic ideas of mode line control. -* Mode Line Data:: The data structure that controls the mode line. -* Mode Line Top:: The top level variable, mode-line-format. -* Mode Line Variables:: Variables used in that data structure. -* %-Constructs:: Putting information into a mode line. -* Properties in Mode:: Using text properties in the mode line. -* Header Lines:: Like a mode line, but at the top. -* Emulating Mode Line:: Formatting text as the mode line would. - -Font Lock Mode - -* Font Lock Basics:: Overview of customizing Font Lock. -* Search-based Fontification:: Fontification based on regexps. -* Customizing Keywords:: Customizing search-based fontification. -* Other Font Lock Variables:: Additional customization facilities. -* Levels of Font Lock:: Each mode can define alternative levels - so that the user can select more or less. -* Precalculated Fontification:: How Lisp programs that produce the buffer - contents can also specify how to fontify it. -* Faces for Font Lock:: Special faces specifically for Font Lock. -* Syntactic Font Lock:: Fontification based on syntax tables. -* Multiline Font Lock:: How to coerce Font Lock into properly - highlighting multiline constructs. - -Multiline Font Lock Constructs - -* Font Lock Multiline:: Marking multiline chunks with a text property. -* Region to Refontify:: Controlling which region gets refontified - after a buffer change. - -Automatic Indentation of code - -* SMIE:: A simple minded indentation engine. - -Simple Minded Indentation Engine - -* SMIE setup:: SMIE setup and features. -* Operator Precedence Grammars:: A very simple parsing technique. -* SMIE Grammar:: Defining the grammar of a language. -* SMIE Lexer:: Defining tokens. -* SMIE Tricks:: Working around the parser's limitations. -* SMIE Indentation:: Specifying indentation rules. -* SMIE Indentation Helpers:: Helper functions for indentation rules. -* SMIE Indentation Example:: Sample indentation rules. - -Documentation - -* Documentation Basics:: Where doc strings are defined and stored. -* Accessing Documentation:: How Lisp programs can access doc strings. -* Keys in Documentation:: Substituting current key bindings. -* Describing Characters:: Making printable descriptions of - non-printing characters and key sequences. -* Help Functions:: Subroutines used by Emacs help facilities. - -Files - -* Visiting Files:: Reading files into Emacs buffers for editing. -* Saving Buffers:: Writing changed buffers back into files. -* Reading from Files:: Reading files into buffers without visiting. -* Writing to Files:: Writing new files from parts of buffers. -* File Locks:: Locking and unlocking files, to prevent - simultaneous editing by two people. -* Information about Files:: Testing existence, accessibility, size of files. -* Changing Files:: Renaming files, changing permissions, etc. -* File Names:: Decomposing and expanding file names. -* Contents of Directories:: Getting a list of the files in a directory. -* Create/Delete Dirs:: Creating and Deleting Directories. -* Magic File Names:: Special handling for certain file names. -* Format Conversion:: Conversion to and from various file formats. - -Visiting Files - -* Visiting Functions:: The usual interface functions for visiting. -* Subroutines of Visiting:: Lower-level subroutines that they use. - -Information about Files - -* Testing Accessibility:: Is a given file readable? Writable? -* Kinds of Files:: Is it a directory? A symbolic link? -* Truenames:: Eliminating symbolic links from a file name. -* File Attributes:: How large is it? Any other names? Etc. -* Locating Files:: How to find a file in standard places. - -File Names - -* File Name Components:: The directory part of a file name, and the rest. -* Relative File Names:: Some file names are relative to a current directory. -* Directory Names:: A directory's name as a directory - is different from its name as a file. -* File Name Expansion:: Converting relative file names to absolute ones. -* Unique File Names:: Generating names for temporary files. -* File Name Completion:: Finding the completions for a given file name. -* Standard File Names:: If your package uses a fixed file name, - how to handle various operating systems simply. - -File Format Conversion - -* Format Conversion Overview:: @code{insert-file-contents} and @code{write-region}. -* Format Conversion Round-Trip:: Using @code{format-alist}. -* Format Conversion Piecemeal:: Specifying non-paired conversion. - -Backups and Auto-Saving - -* Backup Files:: How backup files are made; how their names - are chosen. -* Auto-Saving:: How auto-save files are made; how their - names are chosen. -* Reverting:: @code{revert-buffer}, and how to customize - what it does. - -Backup Files - -* Making Backups:: How Emacs makes backup files, and when. -* Rename or Copy:: Two alternatives: renaming the old file - or copying it. -* Numbered Backups:: Keeping multiple backups for each source file. -* Backup Names:: How backup file names are computed; customization. - -Buffers - -* Buffer Basics:: What is a buffer? -* Current Buffer:: Designating a buffer as current - so that primitives will access its contents. -* Buffer Names:: Accessing and changing buffer names. -* Buffer File Name:: The buffer file name indicates which file - is visited. -* Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved. -* Modification Time:: Determining whether the visited file was changed - "behind Emacs's back". -* Read Only Buffers:: Modifying text is not allowed in a - read-only buffer. -* The Buffer List:: How to look at all the existing buffers. -* Creating Buffers:: Functions that create buffers. -* Killing Buffers:: Buffers exist until explicitly killed. -* Indirect Buffers:: An indirect buffer shares text with some - other buffer. -* Swapping Text:: Swapping text between two buffers. -* Buffer Gap:: The gap in the buffer. - -Windows - -* Basic Windows:: Basic information on using windows. -* Splitting Windows:: Splitting one window into two windows. -* Deleting Windows:: Deleting a window gives its space to other windows. -* Selecting Windows:: The selected window is the one that you edit in. -* Cyclic Window Ordering:: Moving around the existing windows. -* Buffers and Windows:: Each window displays the contents of a buffer. -* Switching Buffers:: Higher-level functions for switching to a buffer. -* Choosing Window:: How to choose a window for displaying a buffer. -* Display Action Functions:: Subroutines for @code{display-buffer}. -* Choosing Window Options:: Extra options affecting how buffers are displayed. -* Window History:: Each window remembers the buffers displayed in it. -* Dedicated Windows:: How to avoid displaying another buffer in - a specific window. -* Window Point:: Each window has its own location of point. -* Window Start and End:: Buffer positions indicating which text is - on-screen in a window. -* Textual Scrolling:: Moving text up and down through the window. -* Vertical Scrolling:: Moving the contents up and down on the window. -* Horizontal Scrolling:: Moving the contents sideways on the window. -* Size of Window:: Accessing the size of a window. -* Resizing Windows:: Changing the size of a window. -* Coordinates and Windows:: Converting coordinates to windows. -* Window Tree:: The layout and sizes of all windows in a frame. -* Window Configurations:: Saving and restoring the state of the screen. -* Window Parameters:: Associating additional information with windows. -* Window Hooks:: Hooks for scrolling, window size changes, - redisplay going past a certain point, - or window configuration changes. - -Frames - -* Creating Frames:: Creating additional frames. -* Multiple Terminals:: Displaying on several different devices. -* Frame Parameters:: Controlling frame size, position, font, etc. -* Terminal Parameters:: Parameters common for all frames on terminal. -* Frame Titles:: Automatic updating of frame titles. -* Deleting Frames:: Frames last until explicitly deleted. -* Finding All Frames:: How to examine all existing frames. -* Frames and Windows:: A frame contains windows; - display of text always works through windows. -* Minibuffers and Frames:: How a frame finds the minibuffer to use. -* Input Focus:: Specifying the selected frame. -* Visibility of Frames:: Frames may be visible or invisible, or icons. -* Raising and Lowering:: Raising a frame makes it hide other windows; - lowering it makes the others hide it. -* Frame Configurations:: Saving the state of all frames. -* Mouse Tracking:: Getting events that say when the mouse moves. -* Mouse Position:: Asking where the mouse is, or moving it. -* Pop-Up Menus:: Displaying a menu for the user to select from. -* Dialog Boxes:: Displaying a box to ask yes or no. -* Pointer Shape:: Specifying the shape of the mouse pointer. -* Window System Selections::Transferring text to and from other X clients. -* Drag and Drop:: Internals of Drag-and-Drop implementation. -* Color Names:: Getting the definitions of color names. -* Text Terminal Colors:: Defining colors for text terminals. -* Resources:: Getting resource values from the server. -* Display Feature Testing:: Determining the features of a terminal. - -Frame Parameters - -* Parameter Access:: How to change a frame's parameters. -* Initial Parameters:: Specifying frame parameters when you make a frame. -* Window Frame Parameters:: List of frame parameters for window systems. -* Size and Position:: Changing the size and position of a frame. -* Geometry:: Parsing geometry specifications. - -Window Frame Parameters - -* Basic Parameters:: Parameters that are fundamental. -* Position Parameters:: The position of the frame on the screen. -* Size Parameters:: Frame's size. -* Layout Parameters:: Size of parts of the frame, and - enabling or disabling some parts. -* Buffer Parameters:: Which buffers have been or should be shown. -* Management Parameters:: Communicating with the window manager. -* Cursor Parameters:: Controlling the cursor appearance. -* Font and Color Parameters:: Fonts and colors for the frame text. - -Positions - -* Point:: The special position where editing takes place. -* Motion:: Changing point. -* Excursions:: Temporary motion and buffer changes. -* Narrowing:: Restricting editing to a portion of the buffer. - -Motion - -* Character Motion:: Moving in terms of characters. -* Word Motion:: Moving in terms of words. -* Buffer End Motion:: Moving to the beginning or end of the buffer. -* Text Lines:: Moving in terms of lines of text. -* Screen Lines:: Moving in terms of lines as displayed. -* List Motion:: Moving by parsing lists and sexps. -* Skipping Characters:: Skipping characters belonging to a certain set. - -Markers - -* Overview of Markers:: The components of a marker, and how it relocates. -* Predicates on Markers:: Testing whether an object is a marker. -* Creating Markers:: Making empty markers or markers at certain places. -* Information from Markers::Finding the marker's buffer or character position. -* Marker Insertion Types:: Two ways a marker can relocate when you - insert where it points. -* Moving Markers:: Moving the marker to a new buffer or position. -* The Mark:: How "the mark" is implemented with a marker. -* The Region:: How to access "the region". - -Text - -* Near Point:: Examining text in the vicinity of point. -* Buffer Contents:: Examining text in a general fashion. -* Comparing Text:: Comparing substrings of buffers. -* Insertion:: Adding new text to a buffer. -* Commands for Insertion:: User-level commands to insert text. -* Deletion:: Removing text from a buffer. -* User-Level Deletion:: User-level commands to delete text. -* The Kill Ring:: Where removed text sometimes is saved for - later use. -* Undo:: Undoing changes to the text of a buffer. -* Maintaining Undo:: How to enable and disable undo information. - How to control how much information is kept. -* Filling:: Functions for explicit filling. -* Margins:: How to specify margins for filling commands. -* Adaptive Fill:: Adaptive Fill mode chooses a fill prefix - from context. -* Auto Filling:: How auto-fill mode is implemented to break lines. -* Sorting:: Functions for sorting parts of the buffer. -* Columns:: Computing horizontal positions, and using them. -* Indentation:: Functions to insert or adjust indentation. -* Case Changes:: Case conversion of parts of the buffer. -* Text Properties:: Assigning Lisp property lists to text characters. -* Substitution:: Replacing a given character wherever it appears. -* Transposition:: Swapping two portions of a buffer. -* Registers:: How registers are implemented. Accessing - the text or position stored in a register. -* Base 64:: Conversion to or from base 64 encoding. -* Checksum/Hash:: Computing cryptographic hashes. -* Parsing HTML/XML:: Parsing HTML and XML. -* Atomic Changes:: Installing several buffer changes "atomically". -* Change Hooks:: Supplying functions to be run when text is changed. - -The Kill Ring - -* Kill Ring Concepts:: What text looks like in the kill ring. -* Kill Functions:: Functions that kill text. -* Yanking:: How yanking is done. -* Yank Commands:: Commands that access the kill ring. -* Low-Level Kill Ring:: Functions and variables for kill ring access. -* Internals of Kill Ring:: Variables that hold kill ring data. - -Indentation - -* Primitive Indent:: Functions used to count and insert indentation. -* Mode-Specific Indent:: Customize indentation for different modes. -* Region Indent:: Indent all the lines in a region. -* Relative Indent:: Indent the current line based on previous lines. -* Indent Tabs:: Adjustable, typewriter-like tab stops. -* Motion by Indent:: Move to first non-blank character. - -Text Properties - -* Examining Properties:: Looking at the properties of one character. -* Changing Properties:: Setting the properties of a range of text. -* Property Search:: Searching for where a property changes value. -* Special Properties:: Particular properties with special meanings. -* Format Properties:: Properties for representing formatting of text. -* Sticky Properties:: How inserted text gets properties from - neighboring text. -* Lazy Properties:: Computing text properties in a lazy fashion - only when text is examined. -* Clickable Text:: Using text properties to make regions of text - do something when you click on them. -* Fields:: The @code{field} property defines - fields within the buffer. -* Not Intervals:: Why text properties do not use - Lisp-visible text intervals. - -Non-@acronym{ASCII} Characters - -* Text Representations:: How Emacs represents text. -* Converting Representations:: Converting unibyte to multibyte and vice versa. -* Selecting a Representation:: Treating a byte sequence as unibyte or multi. -* Character Codes:: How unibyte and multibyte relate to - codes of individual characters. -* Character Properties:: Character attributes that define their - behavior and handling. -* Character Sets:: The space of possible character codes - is divided into various character sets. -* Scanning Charsets:: Which character sets are used in a buffer? -* Translation of Characters:: Translation tables are used for conversion. -* Coding Systems:: Coding systems are conversions for saving files. -* Input Methods:: Input methods allow users to enter various - non-ASCII characters without special keyboards. -* Locales:: Interacting with the POSIX locale. - -Coding Systems - -* Coding System Basics:: Basic concepts. -* Encoding and I/O:: How file I/O functions handle coding systems. -* Lisp and Coding Systems:: Functions to operate on coding system names. -* User-Chosen Coding Systems:: Asking the user to choose a coding system. -* Default Coding Systems:: Controlling the default choices. -* Specifying Coding Systems:: Requesting a particular coding system - for a single file operation. -* Explicit Encoding:: Encoding or decoding text without doing I/O. -* Terminal I/O Encoding:: Use of encoding for terminal I/O. -* MS-DOS File Types:: How DOS "text" and "binary" files - relate to coding systems. - -Searching and Matching - -* String Search:: Search for an exact match. -* Searching and Case:: Case-independent or case-significant searching. -* Regular Expressions:: Describing classes of strings. -* Regexp Search:: Searching for a match for a regexp. -* POSIX Regexps:: Searching POSIX-style for the longest match. -* Match Data:: Finding out which part of the text matched, - after a string or regexp search. -* Search and Replace:: Commands that loop, searching and replacing. -* Standard Regexps:: Useful regexps for finding sentences, pages,... - -Regular Expressions - -* Syntax of Regexps:: Rules for writing regular expressions. -* Regexp Example:: Illustrates regular expression syntax. -* Regexp Functions:: Functions for operating on regular expressions. - -Syntax of Regular Expressions - -* Regexp Special:: Special characters in regular expressions. -* Char Classes:: Character classes used in regular expressions. -* Regexp Backslash:: Backslash-sequences in regular expressions. - -The Match Data - -* Replacing Match:: Replacing a substring that was matched. -* Simple Match Data:: Accessing single items of match data, - such as where a particular subexpression started. -* Entire Match Data:: Accessing the entire match data at once, as a list. -* Saving Match Data:: Saving and restoring the match data. - -Syntax Tables - -* Syntax Basics:: Basic concepts of syntax tables. -* Syntax Descriptors:: How characters are classified. -* Syntax Table Functions:: How to create, examine and alter syntax tables. -* Syntax Properties:: Overriding syntax with text properties. -* Motion and Syntax:: Moving over characters with certain syntaxes. -* Parsing Expressions:: Parsing balanced expressions - using the syntax table. -* Standard Syntax Tables:: Syntax tables used by various major modes. -* Syntax Table Internals:: How syntax table information is stored. -* Categories:: Another way of classifying character syntax. - -Syntax Descriptors - -* Syntax Class Table:: Table of syntax classes. -* Syntax Flags:: Additional flags each character can have. - -Parsing Expressions - -* Motion via Parsing:: Motion functions that work by parsing. -* Position Parse:: Determining the syntactic state of a position. -* Parser State:: How Emacs represents a syntactic state. -* Low-Level Parsing:: Parsing across a specified region. -* Control Parsing:: Parameters that affect parsing. - -Abbrevs and Abbrev Expansion - -* Abbrev Tables:: Creating and working with abbrev tables. -* Defining Abbrevs:: Specifying abbreviations and their expansions. -* Abbrev Files:: Saving abbrevs in files. -* Abbrev Expansion:: Controlling expansion; expansion subroutines. -* Standard Abbrev Tables:: Abbrev tables used by various major modes. -* Abbrev Properties:: How to read and set abbrev properties. - Which properties have which effect. -* Abbrev Table Properties:: How to read and set abbrev table properties. - Which properties have which effect. - -Processes - -* Subprocess Creation:: Functions that start subprocesses. -* Shell Arguments:: Quoting an argument to pass it to a shell. -* Synchronous Processes:: Details of using synchronous subprocesses. -* Asynchronous Processes:: Starting up an asynchronous subprocess. -* Deleting Processes:: Eliminating an asynchronous subprocess. -* Process Information:: Accessing run-status and other attributes. -* Input to Processes:: Sending input to an asynchronous subprocess. -* Signals to Processes:: Stopping, continuing or interrupting - an asynchronous subprocess. -* Output from Processes:: Collecting output from an asynchronous subprocess. -* Sentinels:: Sentinels run when process run-status changes. -* Query Before Exit:: Whether to query if exiting will kill a process. -* System Processes:: Accessing other processes running on your system. -* Transaction Queues:: Transaction-based communication with subprocesses. -* Network:: Opening network connections. -* Network Servers:: Network servers let Emacs accept net connections. -* Datagrams:: UDP network connections. -* Low-Level Network:: Lower-level but more general function - to create connections and servers. -* Misc Network:: Additional relevant functions for net connections. -* Serial Ports:: Communicating with serial ports. -* Byte Packing:: Using bindat to pack and unpack binary data. - -Receiving Output from Processes - -* Process Buffers:: If no filter, output is put in a buffer. -* Filter Functions:: Filter functions accept output from the process. -* Decoding Output:: Filters can get unibyte or multibyte strings. -* Accepting Output:: How to wait until process output arrives. - -Low-Level Network Access - -* Network Processes:: Using @code{make-network-process}. -* Network Options:: Further control over network connections. -* Network Feature Testing:: Determining which network features work on - the machine you are using. - -Packing and Unpacking Byte Arrays - -* Bindat Spec:: Describing data layout. -* Bindat Functions:: Doing the unpacking and packing. -* Bindat Examples:: Samples of what bindat.el can do for you! - -Emacs Display - -* Refresh Screen:: Clearing the screen and redrawing everything on it. -* Forcing Redisplay:: Forcing redisplay. -* Truncation:: Folding or wrapping long text lines. -* The Echo Area:: Displaying messages at the bottom of the screen. -* Warnings:: Displaying warning messages for the user. -* Invisible Text:: Hiding part of the buffer text. -* Selective Display:: Hiding part of the buffer text (the old way). -* Temporary Displays:: Displays that go away automatically. -* Overlays:: Use overlays to highlight parts of the buffer. -* Width:: How wide a character or string is on the screen. -* Line Height:: Controlling the height of lines. -* Faces:: A face defines a graphics style - for text characters: font, colors, etc. -* Fringes:: Controlling window fringes. -* Scroll Bars:: Controlling vertical scroll bars. -* Display Property:: Enabling special display features. -* Images:: Displaying images in Emacs buffers. -* Buttons:: Adding clickable buttons to Emacs buffers. -* Abstract Display:: Emacs's Widget for Object Collections. -* Blinking:: How Emacs shows the matching open parenthesis. -* Character Display:: How Emacs displays individual characters. -* Beeping:: Audible signal to the user. -* Window Systems:: Which window system is being used. -* Bidirectional Display:: Display of bidirectional scripts, such as - Arabic and Farsi. - -The Echo Area - -* Displaying Messages:: Explicitly displaying text in the echo area. -* Progress:: Informing user about progress of a long operation. -* Logging Messages:: Echo area messages are logged for the user. -* Echo Area Customization:: Controlling the echo area. - -Reporting Warnings - -* Warning Basics:: Warnings concepts and functions to report them. -* Warning Variables:: Variables programs bind to customize - their warnings. -* Warning Options:: Variables users set to control display of warnings. -* Delayed Warnings:: Deferring warning display until the end of a command. - -Overlays - -* Managing Overlays:: Creating and moving overlays. -* Overlay Properties:: How to read and set properties. - What properties do to the screen display. -* Finding Overlays:: Searching for overlays. - -Faces - -* Defining Faces:: How to define a face. -* Face Attributes:: What is in a face? -* Attribute Functions:: Functions to examine and set face attributes. -* Displaying Faces:: How Emacs combines the faces specified for - a character. -* Face Remapping:: Remapping faces to alternative definitions. -* Face Functions:: How to define and examine faces. -* Auto Faces:: Hook for automatic face assignment. -* Basic Faces:: Faces that are defined by default. -* Font Selection:: Finding the best available font for a face. -* Font Lookup:: Looking up the names of available fonts - and information about them. -* Fontsets:: A fontset is a collection of fonts - that handle a range of character sets. -* Low-Level Font:: Lisp representation for character display fonts. - -Fringes - -* Fringe Size/Pos:: Specifying where to put the window fringes. -* Fringe Indicators:: Displaying indicator icons in the window fringes. -* Fringe Cursors:: Displaying cursors in the right fringe. -* Fringe Bitmaps:: Specifying bitmaps for fringe indicators. -* Customizing Bitmaps:: Specifying your own bitmaps to use in the fringes. -* Overlay Arrow:: Display of an arrow to indicate position. - -The @code{display} Property - -* Replacing Specs:: Display specs that replace the text. -* Specified Space:: Displaying one space with a specified width. -* Pixel Specification:: Specifying space width or height in pixels. -* Other Display Specs:: Displaying an image; adjusting the height, - spacing, and other properties of text. -* Display Margins:: Displaying text or images to the side of - the main text. - -Images - -* Image Formats:: Supported image formats. -* Image Descriptors:: How to specify an image for use in @code{:display}. -* XBM Images:: Special features for XBM format. -* XPM Images:: Special features for XPM format. -* GIF Images:: Special features for GIF format. -* TIFF Images:: Special features for TIFF format. -* PostScript Images:: Special features for PostScript format. -* ImageMagick Images:: Special features available through ImageMagick. -* Other Image Types:: Various other formats are supported. -* Defining Images:: Convenient ways to define an image for later use. -* Showing Images:: Convenient ways to display an image once - it is defined. -* Animated Images:: Some image formats can be animated. -* Image Cache:: Internal mechanisms of image display. - -Buttons - -* Button Properties:: Button properties with special meanings. -* Button Types:: Defining common properties for classes of buttons. -* Making Buttons:: Adding buttons to Emacs buffers. -* Manipulating Buttons:: Getting and setting properties of buttons. -* Button Buffer Commands:: Buffer-wide commands and bindings for buttons. - -Abstract Display - -* Abstract Display Functions:: Functions in the Ewoc package. -* Abstract Display Example:: Example of using Ewoc. - -Character Display - -* Usual Display:: The usual conventions for displaying characters. -* Display Tables:: What a display table consists of. -* Active Display Table:: How Emacs selects a display table to use. -* Glyphs:: How to define a glyph, and what glyphs mean. -* Glyphless Chars:: How glyphless characters are drawn. - -Operating System Interface - -* Starting Up:: Customizing Emacs startup processing. -* Getting Out:: How exiting works (permanent or temporary). -* System Environment:: Distinguish the name and kind of system. -* User Identification:: Finding the name and user id of the user. -* Time of Day:: Getting the current time. -* Time Conversion:: Converting a time from numeric form to - calendrical data and vice versa. -* Time Parsing:: Converting a time from numeric form to text - and vice versa. -* Processor Run Time:: Getting the run time used by Emacs. -* Time Calculations:: Adding, subtracting, comparing times, etc. -* Timers:: Setting a timer to call a function at a - certain time. -* Idle Timers:: Setting a timer to call a function when Emacs has - been idle for a certain length of time. -* Terminal Input:: Accessing and recording terminal input. -* Terminal Output:: Controlling and recording terminal output. -* Sound Output:: Playing sounds on the computer's speaker. -* X11 Keysyms:: Operating on key symbols for X Windows. -* Batch Mode:: Running Emacs without terminal interaction. -* Session Management:: Saving and restoring state with - X Session Management. -* Notifications:: Desktop notifications. -* Dynamic Libraries:: On-demand loading of support libraries. - -Starting Up Emacs - -* Startup Summary:: Sequence of actions Emacs performs at startup. -* Init File:: Details on reading the init file. -* Terminal-Specific:: How the terminal-specific Lisp file is read. -* Command-Line Arguments:: How command-line arguments are processed, - and how you can customize them. - -Getting Out of Emacs - -* Killing Emacs:: Exiting Emacs irreversibly. -* Suspending Emacs:: Exiting Emacs reversibly. - -Terminal Input - -* Input Modes:: Options for how input is processed. -* Recording Input:: Saving histories of recent or all input events. - -Preparing Lisp code for distribution - -* Packaging Basics:: The basic concepts of Emacs Lisp packages. -* Simple Packages:: How to package a single .el file. -* Multi-file Packages:: How to package multiple files. -* Package Archives:: Maintaining package archives. - -Tips and Conventions - -* Coding Conventions:: Conventions for clean and robust programs. -* Key Binding Conventions:: Which keys should be bound by which programs. -* Programming Tips:: Making Emacs code fit smoothly in Emacs. -* Compilation Tips:: Making compiled code run fast. -* Warning Tips:: Turning off compiler warnings. -* Documentation Tips:: Writing readable documentation strings. -* Comment Tips:: Conventions for writing comments. -* Library Headers:: Standard headers for library packages. - -GNU Emacs Internals - -* Building Emacs:: How the dumped Emacs is made. -* Pure Storage:: Kludge to make preloaded Lisp functions shareable. -* Garbage Collection:: Reclaiming space for Lisp objects no longer used. -* Memory Usage:: Info about total size of Lisp objects made so far. -* Writing Emacs Primitives:: Writing C code for Emacs. -* Object Internals:: Data formats of buffers, windows, processes. - -Object Internals - -* Buffer Internals:: Components of a buffer structure. -* Window Internals:: Components of a window structure. -* Process Internals:: Components of a process structure. +Not used + +* Not used:: This file is only used with TeX, which + generates its own menu. @end detailmenu @end menu @@ -1538,12 +191,8 @@ @c include display.texi @c include os.texi -@c MOVE to Emacs Manual: include misc-modes.texi - @c appendices -@c REMOVE this: include non-hacker.texi - @c include anti.texi @c include doclicense.texi @c include gpl.texi === modified file 'doc/lispref/vol2.texi' --- doc/lispref/vol2.texi 2012-04-26 17:56:38 +0000 +++ doc/lispref/vol2.texi 2012-05-08 06:38:27 +0000 @@ -113,7 +113,7 @@ @ifnottex -@node Top, Introduction, (dir), (dir) +@node Top @top Emacs Lisp This Info file contains edition @value{VERSION} of the GNU Emacs Lisp @@ -121,85 +121,8 @@ @end ifnottex @menu -* Introduction:: Introduction and conventions used. - -* Lisp Data Types:: Data types of objects in Emacs Lisp. -* Numbers:: Numbers and arithmetic functions. -* Strings and Characters:: Strings, and functions that work on them. -* Lists:: Lists, cons cells, and related functions. -* Sequences Arrays Vectors:: Lists, strings and vectors are called sequences. - Certain functions act on any kind of sequence. - The description of vectors is here as well. -* Hash Tables:: Very fast lookup-tables. -* Symbols:: Symbols represent names, uniquely. - -* Evaluation:: How Lisp expressions are evaluated. -* Control Structures:: Conditionals, loops, nonlocal exits. -* Variables:: Using symbols in programs to stand for values. -* Functions:: A function is a Lisp program - that can be invoked from other functions. -* Macros:: Macros are a way to extend the Lisp language. -* Customization:: Making variables and faces customizable. - -* Loading:: Reading files of Lisp code into Lisp. -* Byte Compilation:: Compilation makes programs run faster. -* Advising Functions:: Adding to the definition of a function. -* Debugging:: Tools and tips for debugging Lisp programs. - -* Read and Print:: Converting Lisp objects to text and back. -* Minibuffers:: Using the minibuffer to read input. -* Command Loop:: How the editor command loop works, - and how you can call its subroutines. -* Keymaps:: Defining the bindings from keys to commands. -* Modes:: Defining major and minor modes. -* Documentation:: Writing and using documentation strings. - -* Files:: Accessing files. -* Backups and Auto-Saving:: Controlling how backups and auto-save - files are made. -* Buffers:: Creating and using buffer objects. -* Windows:: Manipulating windows and displaying buffers. -* Frames:: Making multiple system-level windows. -* Positions:: Buffer positions and motion functions. -* Markers:: Markers represent positions and update - automatically when the text is changed. - -* Text:: Examining and changing text in buffers. -* Non-ASCII Characters:: Non-ASCII text in buffers and strings. -* Searching and Matching:: Searching buffers for strings or regexps. -* Syntax Tables:: The syntax table controls word and list parsing. -* Abbrevs:: How Abbrev mode works, and its data structures. - -* Processes:: Running and communicating with subprocesses. -* Display:: Features for controlling the screen display. -* System Interface:: Getting the user id, system type, environment - variables, and other such things. - -* Packaging:: Preparing Lisp code for distribution. - -Appendices - -* Antinews:: Info for users downgrading to Emacs 23. -* GNU Free Documentation License:: The license for this documentation. -* GPL:: Conditions for copying and changing GNU Emacs. -* Tips:: Advice and coding conventions for Emacs Lisp. -* GNU Emacs Internals:: Building and dumping Emacs; - internal data structures. -* Standard Errors:: List of some standard error symbols. -* Standard Keymaps:: List of some standard keymaps. -* Standard Hooks:: List of some standard hook variables. - -* Index:: Index including concepts, functions, variables, - and other terms. - -@ignore -* New Symbols:: New functions and variables in Emacs @value{EMACSVER}. -@end ignore - -@c Do NOT modify the following 3 lines! They must have this form to -@c be correctly identified by `texinfo-multiple-files-update'. In -@c particular, the detailed menu header line MUST be identical to the -@c value of `texinfo-master-menu-header'. See texnfo-upd.el. +* Not used:: This file is only used with tex, which + generates its own menu. @detailmenu --- The Detailed Node Listing --- @@ -208,1280 +131,13 @@ Here are other nodes that are subnodes of those already listed, mentioned here so you can get to them in one step: -Introduction - -* Caveats:: Flaws and a request for help. -* Lisp History:: Emacs Lisp is descended from Maclisp. -* Conventions:: How the manual is formatted. -* Version Info:: Which Emacs version is running? -* Acknowledgements:: The authors, editors, and sponsors of this manual. - -Conventions - -* Some Terms:: Explanation of terms we use in this manual. -* nil and t:: How the symbols @code{nil} and @code{t} are used. -* Evaluation Notation:: The format we use for examples of evaluation. -* Printing Notation:: The format we use when examples print text. -* Error Messages:: The format we use for examples of errors. -* Buffer Text Notation:: The format we use for buffer contents in examples. -* Format of Descriptions:: Notation for describing functions, variables, etc. - -Format of Descriptions - -* A Sample Function Description:: A description of an imaginary - function, @code{foo}. -* A Sample Variable Description:: A description of an imaginary - variable, @code{electric-future-map}. - -Lisp Data Types - -* Printed Representation:: How Lisp objects are represented as text. -* Comments:: Comments and their formatting conventions. -* Programming Types:: Types found in all Lisp systems. -* Editing Types:: Types specific to Emacs. -* Circular Objects:: Read syntax for circular structure. -* Type Predicates:: Tests related to types. -* Equality Predicates:: Tests of equality between any two objects. - -Programming Types - -* Integer Type:: Numbers without fractional parts. -* Floating Point Type:: Numbers with fractional parts and with a large range. -* Character Type:: The representation of letters, numbers and - control characters. -* Symbol Type:: A multi-use object that refers to a function, - variable, or property list, and has a unique identity. -* Sequence Type:: Both lists and arrays are classified as sequences. -* Cons Cell Type:: Cons cells, and lists (which are made from cons cells). -* Array Type:: Arrays include strings and vectors. -* String Type:: An (efficient) array of characters. -* Vector Type:: One-dimensional arrays. -* Char-Table Type:: One-dimensional sparse arrays indexed by characters. -* Bool-Vector Type:: One-dimensional arrays of @code{t} or @code{nil}. -* Hash Table Type:: Super-fast lookup tables. -* Function Type:: A piece of executable code you can call from elsewhere. -* Macro Type:: A method of expanding an expression into another - expression, more fundamental but less pretty. -* Primitive Function Type:: A function written in C, callable from Lisp. -* Byte-Code Type:: A function written in Lisp, then compiled. -* Autoload Type:: A type used for automatically loading seldom-used - functions. - -Character Type - -* Basic Char Syntax:: Syntax for regular characters. -* General Escape Syntax:: How to specify characters by their codes. -* Ctl-Char Syntax:: Syntax for control characters. -* Meta-Char Syntax:: Syntax for meta-characters. -* Other Char Bits:: Syntax for hyper-, super-, and alt-characters. - -Cons Cell and List Types - -* Box Diagrams:: Drawing pictures of lists. -* Dotted Pair Notation:: A general syntax for cons cells. -* Association List Type:: A specially constructed list. - -String Type - -* Syntax for Strings:: How to specify Lisp strings. -* Non-ASCII in Strings:: International characters in strings. -* Nonprinting Characters:: Literal unprintable characters in strings. -* Text Props and Strings:: Strings with text properties. - -Editing Types - -* Buffer Type:: The basic object of editing. -* Marker Type:: A position in a buffer. -* Window Type:: Buffers are displayed in windows. -* Frame Type:: Windows subdivide frames. -* Terminal Type:: A terminal device displays frames. -* Window Configuration Type:: Recording the way a frame is subdivided. -* Frame Configuration Type:: Recording the status of all frames. -* Process Type:: A subprocess of Emacs running on the underlying OS. -* Stream Type:: Receive or send characters. -* Keymap Type:: What function a keystroke invokes. -* Overlay Type:: How an overlay is represented. -* Font Type:: Fonts for displaying text. - -Numbers - -* Integer Basics:: Representation and range of integers. -* Float Basics:: Representation and range of floating point. -* Predicates on Numbers:: Testing for numbers. -* Comparison of Numbers:: Equality and inequality predicates. -* Numeric Conversions:: Converting float to integer and vice versa. -* Arithmetic Operations:: How to add, subtract, multiply and divide. -* Rounding Operations:: Explicitly rounding floating point numbers. -* Bitwise Operations:: Logical and, or, not, shifting. -* Math Functions:: Trig, exponential and logarithmic functions. -* Random Numbers:: Obtaining random integers, predictable or not. - -Strings and Characters - -* String Basics:: Basic properties of strings and characters. -* Predicates for Strings:: Testing whether an object is a string or char. -* Creating Strings:: Functions to allocate new strings. -* Modifying Strings:: Altering the contents of an existing string. -* Text Comparison:: Comparing characters or strings. -* String Conversion:: Converting to and from characters and strings. -* Formatting Strings:: @code{format}: Emacs's analogue of @code{printf}. -* Case Conversion:: Case conversion functions. -* Case Tables:: Customizing case conversion. - -Lists - -* Cons Cells:: How lists are made out of cons cells. -* List-related Predicates:: Is this object a list? Comparing two lists. -* List Elements:: Extracting the pieces of a list. -* Building Lists:: Creating list structure. -* List Variables:: Modifying lists stored in variables. -* Modifying Lists:: Storing new pieces into an existing list. -* Sets And Lists:: A list can represent a finite mathematical set. -* Association Lists:: A list can represent a finite relation or mapping. -* Rings:: Managing a fixed-size ring of objects. - -Modifying Existing List Structure - -* Setcar:: Replacing an element in a list. -* Setcdr:: Replacing part of the list backbone. - This can be used to remove or add elements. -* Rearrangement:: Reordering the elements in a list; combining lists. - -Sequences, Arrays, and Vectors - -* Sequence Functions:: Functions that accept any kind of sequence. -* Arrays:: Characteristics of arrays in Emacs Lisp. -* Array Functions:: Functions specifically for arrays. -* Vectors:: Special characteristics of Emacs Lisp vectors. -* Vector Functions:: Functions specifically for vectors. -* Char-Tables:: How to work with char-tables. -* Bool-Vectors:: How to work with bool-vectors. - -Hash Tables - -* Creating Hash:: Functions to create hash tables. -* Hash Access:: Reading and writing the hash table contents. -* Defining Hash:: Defining new comparison methods. -* Other Hash:: Miscellaneous. - -Symbols - -* Symbol Components:: Symbols have names, values, function definitions - and property lists. -* Definitions:: A definition says how a symbol will be used. -* Creating Symbols:: How symbols are kept unique. -* Property Lists:: Each symbol has a property list - for recording miscellaneous information. - -Property Lists - -* Plists and Alists:: Comparison of the advantages of property - lists and association lists. -* Symbol Plists:: Functions to access symbols' property lists. -* Other Plists:: Accessing property lists stored elsewhere. - -Evaluation - -* Intro Eval:: Evaluation in the scheme of things. -* Forms:: How various sorts of objects are evaluated. -* Quoting:: Avoiding evaluation (to put constants in - the program). -* Backquote:: Easier construction of list structure. -* Eval:: How to invoke the Lisp interpreter explicitly. - -Kinds of Forms - -* Self-Evaluating Forms:: Forms that evaluate to themselves. -* Symbol Forms:: Symbols evaluate as variables. -* Classifying Lists:: How to distinguish various sorts of list forms. -* Function Indirection:: When a symbol appears as the car of a list, - we find the real function via the symbol. -* Function Forms:: Forms that call functions. -* Macro Forms:: Forms that call macros. -* Special Forms:: "Special forms" are idiosyncratic primitives, - most of them extremely important. -* Autoloading:: Functions set up to load files - containing their real definitions. - -Control Structures - -* Sequencing:: Evaluation in textual order. -* Conditionals:: @code{if}, @code{cond}, @code{when}, @code{unless}. -* Combining Conditions:: @code{and}, @code{or}, @code{not}. -* Iteration:: @code{while} loops. -* Nonlocal Exits:: Jumping out of a sequence. - -Nonlocal Exits - -* Catch and Throw:: Nonlocal exits for the program's own purposes. -* Examples of Catch:: Showing how such nonlocal exits can be written. -* Errors:: How errors are signaled and handled. -* Cleanups:: Arranging to run a cleanup form if an - error happens. - -Errors - -* Signaling Errors:: How to report an error. -* Processing of Errors:: What Emacs does when you report an error. -* Handling Errors:: How you can trap errors and continue execution. -* Error Symbols:: How errors are classified for trapping them. - -Variables - -* Global Variables:: Variable values that exist permanently, everywhere. -* Constant Variables:: Certain "variables" have values that never change. -* Local Variables:: Variable values that exist only temporarily. -* Void Variables:: Symbols that lack values. -* Defining Variables:: A definition says a symbol is used as a variable. -* Tips for Defining:: Things you should think about when you - define a variable. -* Accessing Variables:: Examining values of variables whose names - are known only at run time. -* Setting Variables:: Storing new values in variables. -* Variable Scoping:: How Lisp chooses among local and global values. -* Buffer-Local Variables:: Variable values in effect only in one buffer. -* File Local Variables:: Handling local variable lists in files. -* Directory Local Variables:: Local variables common to all files in a - directory. -* Frame-Local Variables:: Frame-local bindings for variables. -* Variable Aliases:: Variables that are aliases for other variables. -* Variables with Restricted Values:: Non-constant variables whose value can - @emph{not} be an arbitrary Lisp object. - -Scoping Rules for Variable Bindings - -* Scope:: Scope means where in the program a value - is visible. Comparison with other languages. -* Extent:: Extent means how long in time a value exists. -* Impl of Scope:: Two ways to implement dynamic scoping. -* Using Scoping:: How to use dynamic scoping carefully and - avoid problems. - -Buffer-Local Variables - -* Intro to Buffer-Local:: Introduction and concepts. -* Creating Buffer-Local:: Creating and destroying buffer-local bindings. -* Default Value:: The default value is seen in buffers - that don't have their own buffer-local values. - -Functions - -* What Is a Function:: Lisp functions vs. primitives; terminology. -* Lambda Expressions:: How functions are expressed as Lisp objects. -* Function Names:: A symbol can serve as the name of a function. -* Defining Functions:: Lisp expressions for defining functions. -* Calling Functions:: How to use an existing function. -* Mapping Functions:: Applying a function to each element of a list, etc. -* Anonymous Functions:: Lambda expressions are functions with no names. -* Function Cells:: Accessing or setting the function definition - of a symbol. -* Closures:: Functions that enclose a lexical environment. -* Obsolete Functions:: Declaring functions obsolete. -* Inline Functions:: Defining functions that the compiler - will expand inline. -* Declaring Functions:: Telling the compiler that a function is defined. -* Function Safety:: Determining whether a function is safe to call. -* Related Topics:: Cross-references to specific Lisp primitives - that have a special bearing on how - functions work. - -Lambda Expressions - -* Lambda Components:: The parts of a lambda expression. -* Simple Lambda:: A simple example. -* Argument List:: Details and special features of argument lists. -* Function Documentation:: How to put documentation in a function. - -Macros - -* Simple Macro:: A basic example. -* Expansion:: How, when and why macros are expanded. -* Compiling Macros:: How macros are expanded by the compiler. -* Defining Macros:: How to write a macro definition. -* Problems with Macros:: Don't evaluate the macro arguments too many times. - Don't hide the user's variables. -* Indenting Macros:: Specifying how to indent macro calls. - -Common Problems Using Macros - -* Wrong Time:: Do the work in the expansion, not in the macro. -* Argument Evaluation:: The expansion should evaluate each macro arg once. -* Surprising Local Vars:: Local variable bindings in the expansion - require special care. -* Eval During Expansion:: Don't evaluate them; put them in the expansion. -* Repeated Expansion:: Avoid depending on how many times expansion is done. - -Customization Settings - -* Common Keywords:: Common keyword arguments for all kinds of - customization declarations. -* Group Definitions:: Writing customization group definitions. -* Variable Definitions:: Declaring user options. -* Customization Types:: Specifying the type of a user option. -* Applying Customizations:: Functions to apply customization settings. -* Custom Themes:: Writing Custom themes. - -Customization Types - -* Simple Types:: Simple customization types: sexp, integer, number, - string, file, directory, alist. -* Composite Types:: Build new types from other types or data. -* Splicing into Lists:: Splice elements into list with @code{:inline}. -* Type Keywords:: Keyword-argument pairs in a customization type. -* Defining New Types:: Give your type a name. - -Loading - -* How Programs Do Loading:: The @code{load} function and others. -* Load Suffixes:: Details about the suffixes that @code{load} tries. -* Library Search:: Finding a library to load. -* Loading Non-ASCII:: Non-@acronym{ASCII} characters in Emacs Lisp files. -* Autoload:: Setting up a function to autoload. -* Repeated Loading:: Precautions about loading a file twice. -* Named Features:: Loading a library if it isn't already loaded. -* Where Defined:: Finding which file defined a certain symbol. -* Unloading:: How to "unload" a library that was loaded. -* Hooks for Loading:: Providing code to be run when - particular libraries are loaded. - -Byte Compilation - -* Speed of Byte-Code:: An example of speedup from byte compilation. -* Compilation Functions:: Byte compilation functions. -* Docs and Compilation:: Dynamic loading of documentation strings. -* Dynamic Loading:: Dynamic loading of individual functions. -* Eval During Compile:: Code to be evaluated when you compile. -* Compiler Errors:: Handling compiler error messages. -* Byte-Code Objects:: The data type used for byte-compiled functions. -* Disassembly:: Disassembling byte-code; how to read byte-code. - -Advising Emacs Lisp Functions - -* Simple Advice:: A simple example to explain the basics of advice. -* Defining Advice:: Detailed description of @code{defadvice}. -* Around-Advice:: Wrapping advice around a function's definition. -* Computed Advice:: ...is to @code{defadvice} as @code{fset} is to @code{defun}. -* Activation of Advice:: Advice doesn't do anything until you activate it. -* Enabling Advice:: You can enable or disable each piece of advice. -* Preactivation:: Preactivation is a way of speeding up the - loading of compiled advice. -* Argument Access in Advice:: How advice can access the function's arguments. -* Combined Definition:: How advice is implemented. - -Debugging Lisp Programs - -* Debugger:: A debugger for the Emacs Lisp evaluator. -* Edebug:: A source-level Emacs Lisp debugger. -* Syntax Errors:: How to find syntax errors. -* Test Coverage:: Ensuring you have tested all branches in your code. - -The Lisp Debugger - -* Error Debugging:: Entering the debugger when an error happens. -* Infinite Loops:: Stopping and debugging a program that doesn't exit. -* Function Debugging:: Entering it when a certain function is called. -* Explicit Debug:: Entering it at a certain point in the program. -* Using Debugger:: What the debugger does; what you see while in it. -* Debugger Commands:: Commands used while in the debugger. -* Invoking the Debugger:: How to call the function @code{debug}. -* Internals of Debugger:: Subroutines of the debugger, and global variables. - -Edebug - -* Using Edebug:: Introduction to use of Edebug. -* Instrumenting:: You must instrument your code - in order to debug it with Edebug. -* Edebug Execution Modes:: Execution modes, stopping more or less often. -* Jumping:: Commands to jump to a specified place. -* Edebug Misc:: Miscellaneous commands. -* Breaks:: Setting breakpoints to make the program stop. -* Trapping Errors:: Trapping errors with Edebug. -* Edebug Views:: Views inside and outside of Edebug. -* Edebug Eval:: Evaluating expressions within Edebug. -* Eval List:: Expressions whose values are displayed - each time you enter Edebug. -* Printing in Edebug:: Customization of printing. -* Trace Buffer:: How to produce trace output in a buffer. -* Coverage Testing:: How to test evaluation coverage. -* The Outside Context:: Data that Edebug saves and restores. -* Edebug and Macros:: Specifying how to handle macro calls. -* Edebug Options:: Option variables for customizing Edebug. - -Breaks - -* Breakpoints:: Breakpoints at stop points. -* Global Break Condition:: Breaking on an event. -* Source Breakpoints:: Embedding breakpoints in source code. - -The Outside Context - -* Checking Whether to Stop::When Edebug decides what to do. -* Edebug Display Update:: When Edebug updates the display. -* Edebug Recursive Edit:: When Edebug stops execution. - -Edebug and Macros - -* Instrumenting Macro Calls::The basic problem. -* Specification List:: How to specify complex patterns of evaluation. -* Backtracking:: What Edebug does when matching fails. -* Specification Examples:: To help understand specifications. - -Debugging Invalid Lisp Syntax - -* Excess Open:: How to find a spurious open paren or missing close. -* Excess Close:: How to find a spurious close paren or missing open. - -Reading and Printing Lisp Objects - -* Streams Intro:: Overview of streams, reading and printing. -* Input Streams:: Various data types that can be used as - input streams. -* Input Functions:: Functions to read Lisp objects from text. -* Output Streams:: Various data types that can be used as - output streams. -* Output Functions:: Functions to print Lisp objects as text. -* Output Variables:: Variables that control what the printing - functions do. - -Minibuffers - -* Intro to Minibuffers:: Basic information about minibuffers. -* Text from Minibuffer:: How to read a straight text string. -* Object from Minibuffer:: How to read a Lisp object or expression. -* Minibuffer History:: Recording previous minibuffer inputs - so the user can reuse them. -* Initial Input:: Specifying initial contents for the minibuffer. -* Completion:: How to invoke and customize completion. -* Yes-or-No Queries:: Asking a question with a simple answer. -* Multiple Queries:: Asking a series of similar questions. -* Reading a Password:: Reading a password from the terminal. -* Minibuffer Commands:: Commands used as key bindings in minibuffers. -* Minibuffer Windows:: Operating on the special minibuffer windows. -* Minibuffer Contents:: How such commands access the minibuffer text. -* Recursive Mini:: Whether recursive entry to minibuffer is allowed. -* Minibuffer Misc:: Various customization hooks and variables. - -Completion - -* Basic Completion:: Low-level functions for completing strings. - (These are too low level to use the minibuffer.) -* Minibuffer Completion:: Invoking the minibuffer with completion. -* Completion Commands:: Minibuffer commands that do completion. -* High-Level Completion:: Convenient special cases of completion - (reading buffer names, variable names, etc.). -* Reading File Names:: Using completion to read file names and - shell commands. -* Completion Variables:: Variables controlling completion behavior. -* Programmed Completion:: Writing your own completion function. -* Completion in Buffers:: Completing text in ordinary buffers. - -Command Loop - -* Command Overview:: How the command loop reads commands. -* Defining Commands:: Specifying how a function should read arguments. -* Interactive Call:: Calling a command, so that it will read arguments. -* Distinguish Interactive:: Making a command distinguish interactive calls. -* Command Loop Info:: Variables set by the command loop for you to examine. -* Adjusting Point:: Adjustment of point after a command. -* Input Events:: What input looks like when you read it. -* Reading Input:: How to read input events from the keyboard or mouse. -* Special Events:: Events processed immediately and individually. -* Waiting:: Waiting for user input or elapsed time. -* Quitting:: How @kbd{C-g} works. How to catch or defer quitting. -* Prefix Command Arguments:: How the commands to set prefix args work. -* Recursive Editing:: Entering a recursive edit, - and why you usually shouldn't. -* Disabling Commands:: How the command loop handles disabled commands. -* Command History:: How the command history is set up, and how accessed. -* Keyboard Macros:: How keyboard macros are implemented. - -Defining Commands - -* Using Interactive:: General rules for @code{interactive}. -* Interactive Codes:: The standard letter-codes for reading arguments - in various ways. -* Interactive Examples:: Examples of how to read interactive arguments. - -Input Events - -* Keyboard Events:: Ordinary characters--keys with symbols on them. -* Function Keys:: Function keys--keys with names, not symbols. -* Mouse Events:: Overview of mouse events. -* Click Events:: Pushing and releasing a mouse button. -* Drag Events:: Moving the mouse before releasing the button. -* Button-Down Events:: A button was pushed and not yet released. -* Repeat Events:: Double and triple click (or drag, or down). -* Motion Events:: Just moving the mouse, not pushing a button. -* Focus Events:: Moving the mouse between frames. -* Misc Events:: Other events the system can generate. -* Event Examples:: Examples of the lists for mouse events. -* Classifying Events:: Finding the modifier keys in an event symbol. - Event types. -* Accessing Mouse:: Functions to extract info from mouse events. -* Accessing Scroll:: Functions to get info from scroll bar events. -* Strings of Events:: Special considerations for putting - keyboard character events in a string. - -Reading Input - -* Key Sequence Input:: How to read one key sequence. -* Reading One Event:: How to read just one event. -* Event Mod:: How Emacs modifies events as they are read. -* Invoking the Input Method:: How reading an event uses the input method. -* Quoted Character Input:: Asking the user to specify a character. -* Event Input Misc:: How to reread or throw away input events. - -Keymaps - -* Key Sequences:: Key sequences as Lisp objects. -* Keymap Basics:: Basic concepts of keymaps. -* Format of Keymaps:: What a keymap looks like as a Lisp object. -* Creating Keymaps:: Functions to create and copy keymaps. -* Inheritance and Keymaps:: How one keymap can inherit the bindings - of another keymap. -* Prefix Keys:: Defining a key with a keymap as its definition. -* Active Keymaps:: How Emacs searches the active keymaps - for a key binding. -* Searching Keymaps:: A pseudo-Lisp summary of searching active maps. -* Controlling Active Maps:: Each buffer has a local keymap - to override the standard (global) bindings. - A minor mode can also override them. -* Key Lookup:: Finding a key's binding in one keymap. -* Functions for Key Lookup:: How to request key lookup. -* Changing Key Bindings:: Redefining a key in a keymap. -* Remapping Commands:: A keymap can translate one command to another. -* Translation Keymaps:: Keymaps for translating sequences of events. -* Key Binding Commands:: Interactive interfaces for redefining keys. -* Scanning Keymaps:: Looking through all keymaps, for printing help. -* Menu Keymaps:: Defining a menu as a keymap. - -Menu Keymaps - -* Defining Menus:: How to make a keymap that defines a menu. -* Mouse Menus:: How users actuate the menu with the mouse. -* Keyboard Menus:: How users actuate the menu with the keyboard. -* Menu Example:: Making a simple menu. -* Menu Bar:: How to customize the menu bar. -* Tool Bar:: A tool bar is a row of images. -* Modifying Menus:: How to add new items to a menu. - -Defining Menus - -* Simple Menu Items:: A simple kind of menu key binding, - limited in capabilities. -* Extended Menu Items:: More powerful menu item definitions - let you specify keywords to enable - various features. -* Menu Separators:: Drawing a horizontal line through a menu. -* Alias Menu Items:: Using command aliases in menu items. -* Toolkit Differences:: Not all toolkits provide the same features. - -Major and Minor Modes - -* Hooks:: How to use hooks; how to write code that provides hooks. -* Major Modes:: Defining major modes. -* Minor Modes:: Defining minor modes. -* Mode Line Format:: Customizing the text that appears in the mode line. -* Imenu:: Providing a menu of definitions made in a buffer. -* Font Lock Mode:: How modes can highlight text according to syntax. -* Auto-Indentation:: How to teach Emacs to indent for a major mode. -* Desktop Save Mode:: How modes can have buffer state saved between - Emacs sessions. - -Hooks - -* Running Hooks:: How to run a hook. -* Setting Hooks:: How to put functions on a hook, or remove them. - -Major Modes - -* Major Mode Conventions:: Coding conventions for keymaps, etc. -* Auto Major Mode:: How Emacs chooses the major mode automatically. -* Mode Help:: Finding out how to use a mode. -* Derived Modes:: Defining a new major mode based on another major - mode. -* Basic Major Modes:: Modes that other modes are often derived from. -* Mode Hooks:: Hooks run at the end of major mode functions. -* Tabulated List Mode:: Parent mode for buffers containing tabulated data. -* Generic Modes:: Defining a simple major mode that supports - comment syntax and Font Lock mode. -* Example Major Modes:: Text mode and Lisp modes. - -Minor Modes - -* Minor Mode Conventions:: Tips for writing a minor mode. -* Keymaps and Minor Modes:: How a minor mode can have its own keymap. -* Defining Minor Modes:: A convenient facility for defining minor modes. - -Mode Line Format - -* Mode Line Basics:: Basic ideas of mode line control. -* Mode Line Data:: The data structure that controls the mode line. -* Mode Line Top:: The top level variable, mode-line-format. -* Mode Line Variables:: Variables used in that data structure. -* %-Constructs:: Putting information into a mode line. -* Properties in Mode:: Using text properties in the mode line. -* Header Lines:: Like a mode line, but at the top. -* Emulating Mode Line:: Formatting text as the mode line would. - -Font Lock Mode - -* Font Lock Basics:: Overview of customizing Font Lock. -* Search-based Fontification:: Fontification based on regexps. -* Customizing Keywords:: Customizing search-based fontification. -* Other Font Lock Variables:: Additional customization facilities. -* Levels of Font Lock:: Each mode can define alternative levels - so that the user can select more or less. -* Precalculated Fontification:: How Lisp programs that produce the buffer - contents can also specify how to fontify it. -* Faces for Font Lock:: Special faces specifically for Font Lock. -* Syntactic Font Lock:: Fontification based on syntax tables. -* Multiline Font Lock:: How to coerce Font Lock into properly - highlighting multiline constructs. - -Multiline Font Lock Constructs - -* Font Lock Multiline:: Marking multiline chunks with a text property. -* Region to Refontify:: Controlling which region gets refontified - after a buffer change. - -Automatic Indentation of code - -* SMIE:: A simple minded indentation engine. - -Simple Minded Indentation Engine - -* SMIE setup:: SMIE setup and features. -* Operator Precedence Grammars:: A very simple parsing technique. -* SMIE Grammar:: Defining the grammar of a language. -* SMIE Lexer:: Defining tokens. -* SMIE Tricks:: Working around the parser's limitations. -* SMIE Indentation:: Specifying indentation rules. -* SMIE Indentation Helpers:: Helper functions for indentation rules. -* SMIE Indentation Example:: Sample indentation rules. - -Documentation - -* Documentation Basics:: Where doc strings are defined and stored. -* Accessing Documentation:: How Lisp programs can access doc strings. -* Keys in Documentation:: Substituting current key bindings. -* Describing Characters:: Making printable descriptions of - non-printing characters and key sequences. -* Help Functions:: Subroutines used by Emacs help facilities. - -Files - -* Visiting Files:: Reading files into Emacs buffers for editing. -* Saving Buffers:: Writing changed buffers back into files. -* Reading from Files:: Reading files into buffers without visiting. -* Writing to Files:: Writing new files from parts of buffers. -* File Locks:: Locking and unlocking files, to prevent - simultaneous editing by two people. -* Information about Files:: Testing existence, accessibility, size of files. -* Changing Files:: Renaming files, changing permissions, etc. -* File Names:: Decomposing and expanding file names. -* Contents of Directories:: Getting a list of the files in a directory. -* Create/Delete Dirs:: Creating and Deleting Directories. -* Magic File Names:: Special handling for certain file names. -* Format Conversion:: Conversion to and from various file formats. - -Visiting Files - -* Visiting Functions:: The usual interface functions for visiting. -* Subroutines of Visiting:: Lower-level subroutines that they use. - -Information about Files - -* Testing Accessibility:: Is a given file readable? Writable? -* Kinds of Files:: Is it a directory? A symbolic link? -* Truenames:: Eliminating symbolic links from a file name. -* File Attributes:: How large is it? Any other names? Etc. -* Locating Files:: How to find a file in standard places. - -File Names - -* File Name Components:: The directory part of a file name, and the rest. -* Relative File Names:: Some file names are relative to a current directory. -* Directory Names:: A directory's name as a directory - is different from its name as a file. -* File Name Expansion:: Converting relative file names to absolute ones. -* Unique File Names:: Generating names for temporary files. -* File Name Completion:: Finding the completions for a given file name. -* Standard File Names:: If your package uses a fixed file name, - how to handle various operating systems simply. - -File Format Conversion - -* Format Conversion Overview:: @code{insert-file-contents} and @code{write-region}. -* Format Conversion Round-Trip:: Using @code{format-alist}. -* Format Conversion Piecemeal:: Specifying non-paired conversion. - -Backups and Auto-Saving - -* Backup Files:: How backup files are made; how their names - are chosen. -* Auto-Saving:: How auto-save files are made; how their - names are chosen. -* Reverting:: @code{revert-buffer}, and how to customize - what it does. - -Backup Files - -* Making Backups:: How Emacs makes backup files, and when. -* Rename or Copy:: Two alternatives: renaming the old file - or copying it. -* Numbered Backups:: Keeping multiple backups for each source file. -* Backup Names:: How backup file names are computed; customization. - -Buffers - -* Buffer Basics:: What is a buffer? -* Current Buffer:: Designating a buffer as current - so that primitives will access its contents. -* Buffer Names:: Accessing and changing buffer names. -* Buffer File Name:: The buffer file name indicates which file - is visited. -* Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved. -* Modification Time:: Determining whether the visited file was changed - "behind Emacs's back". -* Read Only Buffers:: Modifying text is not allowed in a - read-only buffer. -* The Buffer List:: How to look at all the existing buffers. -* Creating Buffers:: Functions that create buffers. -* Killing Buffers:: Buffers exist until explicitly killed. -* Indirect Buffers:: An indirect buffer shares text with some - other buffer. -* Swapping Text:: Swapping text between two buffers. -* Buffer Gap:: The gap in the buffer. - -Windows - -* Basic Windows:: Basic information on using windows. -* Splitting Windows:: Splitting one window into two windows. -* Deleting Windows:: Deleting a window gives its space to other windows. -* Selecting Windows:: The selected window is the one that you edit in. -* Cyclic Window Ordering:: Moving around the existing windows. -* Buffers and Windows:: Each window displays the contents of a buffer. -* Switching Buffers:: Higher-level functions for switching to a buffer. -* Choosing Window:: How to choose a window for displaying a buffer. -* Display Action Functions:: Subroutines for @code{display-buffer}. -* Choosing Window Options:: Extra options affecting how buffers are displayed. -* Window History:: Each window remembers the buffers displayed in it. -* Dedicated Windows:: How to avoid displaying another buffer in - a specific window. -* Window Point:: Each window has its own location of point. -* Window Start and End:: Buffer positions indicating which text is - on-screen in a window. -* Textual Scrolling:: Moving text up and down through the window. -* Vertical Scrolling:: Moving the contents up and down on the window. -* Horizontal Scrolling:: Moving the contents sideways on the window. -* Size of Window:: Accessing the size of a window. -* Resizing Windows:: Changing the size of a window. -* Coordinates and Windows:: Converting coordinates to windows. -* Window Tree:: The layout and sizes of all windows in a frame. -* Window Configurations:: Saving and restoring the state of the screen. -* Window Parameters:: Associating additional information with windows. -* Window Hooks:: Hooks for scrolling, window size changes, - redisplay going past a certain point, - or window configuration changes. - -Frames - -* Creating Frames:: Creating additional frames. -* Multiple Terminals:: Displaying on several different devices. -* Frame Parameters:: Controlling frame size, position, font, etc. -* Terminal Parameters:: Parameters common for all frames on terminal. -* Frame Titles:: Automatic updating of frame titles. -* Deleting Frames:: Frames last until explicitly deleted. -* Finding All Frames:: How to examine all existing frames. -* Frames and Windows:: A frame contains windows; - display of text always works through windows. -* Minibuffers and Frames:: How a frame finds the minibuffer to use. -* Input Focus:: Specifying the selected frame. -* Visibility of Frames:: Frames may be visible or invisible, or icons. -* Raising and Lowering:: Raising a frame makes it hide other windows; - lowering it makes the others hide it. -* Frame Configurations:: Saving the state of all frames. -* Mouse Tracking:: Getting events that say when the mouse moves. -* Mouse Position:: Asking where the mouse is, or moving it. -* Pop-Up Menus:: Displaying a menu for the user to select from. -* Dialog Boxes:: Displaying a box to ask yes or no. -* Pointer Shape:: Specifying the shape of the mouse pointer. -* Window System Selections::Transferring text to and from other X clients. -* Drag and Drop:: Internals of Drag-and-Drop implementation. -* Color Names:: Getting the definitions of color names. -* Text Terminal Colors:: Defining colors for text terminals. -* Resources:: Getting resource values from the server. -* Display Feature Testing:: Determining the features of a terminal. - -Frame Parameters - -* Parameter Access:: How to change a frame's parameters. -* Initial Parameters:: Specifying frame parameters when you make a frame. -* Window Frame Parameters:: List of frame parameters for window systems. -* Size and Position:: Changing the size and position of a frame. -* Geometry:: Parsing geometry specifications. - -Window Frame Parameters - -* Basic Parameters:: Parameters that are fundamental. -* Position Parameters:: The position of the frame on the screen. -* Size Parameters:: Frame's size. -* Layout Parameters:: Size of parts of the frame, and - enabling or disabling some parts. -* Buffer Parameters:: Which buffers have been or should be shown. -* Management Parameters:: Communicating with the window manager. -* Cursor Parameters:: Controlling the cursor appearance. -* Font and Color Parameters:: Fonts and colors for the frame text. - -Positions - -* Point:: The special position where editing takes place. -* Motion:: Changing point. -* Excursions:: Temporary motion and buffer changes. -* Narrowing:: Restricting editing to a portion of the buffer. - -Motion - -* Character Motion:: Moving in terms of characters. -* Word Motion:: Moving in terms of words. -* Buffer End Motion:: Moving to the beginning or end of the buffer. -* Text Lines:: Moving in terms of lines of text. -* Screen Lines:: Moving in terms of lines as displayed. -* List Motion:: Moving by parsing lists and sexps. -* Skipping Characters:: Skipping characters belonging to a certain set. - -Markers - -* Overview of Markers:: The components of a marker, and how it relocates. -* Predicates on Markers:: Testing whether an object is a marker. -* Creating Markers:: Making empty markers or markers at certain places. -* Information from Markers::Finding the marker's buffer or character position. -* Marker Insertion Types:: Two ways a marker can relocate when you - insert where it points. -* Moving Markers:: Moving the marker to a new buffer or position. -* The Mark:: How "the mark" is implemented with a marker. -* The Region:: How to access "the region". - -Text - -* Near Point:: Examining text in the vicinity of point. -* Buffer Contents:: Examining text in a general fashion. -* Comparing Text:: Comparing substrings of buffers. -* Insertion:: Adding new text to a buffer. -* Commands for Insertion:: User-level commands to insert text. -* Deletion:: Removing text from a buffer. -* User-Level Deletion:: User-level commands to delete text. -* The Kill Ring:: Where removed text sometimes is saved for - later use. -* Undo:: Undoing changes to the text of a buffer. -* Maintaining Undo:: How to enable and disable undo information. - How to control how much information is kept. -* Filling:: Functions for explicit filling. -* Margins:: How to specify margins for filling commands. -* Adaptive Fill:: Adaptive Fill mode chooses a fill prefix - from context. -* Auto Filling:: How auto-fill mode is implemented to break lines. -* Sorting:: Functions for sorting parts of the buffer. -* Columns:: Computing horizontal positions, and using them. -* Indentation:: Functions to insert or adjust indentation. -* Case Changes:: Case conversion of parts of the buffer. -* Text Properties:: Assigning Lisp property lists to text characters. -* Substitution:: Replacing a given character wherever it appears. -* Transposition:: Swapping two portions of a buffer. -* Registers:: How registers are implemented. Accessing - the text or position stored in a register. -* Base 64:: Conversion to or from base 64 encoding. -* Checksum/Hash:: Computing cryptographic hashes. -* Parsing HTML/XML:: Parsing HTML and XML. -* Atomic Changes:: Installing several buffer changes "atomically". -* Change Hooks:: Supplying functions to be run when text is changed. - -The Kill Ring - -* Kill Ring Concepts:: What text looks like in the kill ring. -* Kill Functions:: Functions that kill text. -* Yanking:: How yanking is done. -* Yank Commands:: Commands that access the kill ring. -* Low-Level Kill Ring:: Functions and variables for kill ring access. -* Internals of Kill Ring:: Variables that hold kill ring data. - -Indentation - -* Primitive Indent:: Functions used to count and insert indentation. -* Mode-Specific Indent:: Customize indentation for different modes. -* Region Indent:: Indent all the lines in a region. -* Relative Indent:: Indent the current line based on previous lines. -* Indent Tabs:: Adjustable, typewriter-like tab stops. -* Motion by Indent:: Move to first non-blank character. - -Text Properties - -* Examining Properties:: Looking at the properties of one character. -* Changing Properties:: Setting the properties of a range of text. -* Property Search:: Searching for where a property changes value. -* Special Properties:: Particular properties with special meanings. -* Format Properties:: Properties for representing formatting of text. -* Sticky Properties:: How inserted text gets properties from - neighboring text. -* Lazy Properties:: Computing text properties in a lazy fashion - only when text is examined. -* Clickable Text:: Using text properties to make regions of text - do something when you click on them. -* Fields:: The @code{field} property defines - fields within the buffer. -* Not Intervals:: Why text properties do not use - Lisp-visible text intervals. - -Non-@acronym{ASCII} Characters - -* Text Representations:: How Emacs represents text. -* Converting Representations:: Converting unibyte to multibyte and vice versa. -* Selecting a Representation:: Treating a byte sequence as unibyte or multi. -* Character Codes:: How unibyte and multibyte relate to - codes of individual characters. -* Character Properties:: Character attributes that define their - behavior and handling. -* Character Sets:: The space of possible character codes - is divided into various character sets. -* Scanning Charsets:: Which character sets are used in a buffer? -* Translation of Characters:: Translation tables are used for conversion. -* Coding Systems:: Coding systems are conversions for saving files. -* Input Methods:: Input methods allow users to enter various - non-ASCII characters without special keyboards. -* Locales:: Interacting with the POSIX locale. - -Coding Systems - -* Coding System Basics:: Basic concepts. -* Encoding and I/O:: How file I/O functions handle coding systems. -* Lisp and Coding Systems:: Functions to operate on coding system names. -* User-Chosen Coding Systems:: Asking the user to choose a coding system. -* Default Coding Systems:: Controlling the default choices. -* Specifying Coding Systems:: Requesting a particular coding system - for a single file operation. -* Explicit Encoding:: Encoding or decoding text without doing I/O. -* Terminal I/O Encoding:: Use of encoding for terminal I/O. -* MS-DOS File Types:: How DOS "text" and "binary" files - relate to coding systems. - -Searching and Matching - -* String Search:: Search for an exact match. -* Searching and Case:: Case-independent or case-significant searching. -* Regular Expressions:: Describing classes of strings. -* Regexp Search:: Searching for a match for a regexp. -* POSIX Regexps:: Searching POSIX-style for the longest match. -* Match Data:: Finding out which part of the text matched, - after a string or regexp search. -* Search and Replace:: Commands that loop, searching and replacing. -* Standard Regexps:: Useful regexps for finding sentences, pages,... - -Regular Expressions - -* Syntax of Regexps:: Rules for writing regular expressions. -* Regexp Example:: Illustrates regular expression syntax. -* Regexp Functions:: Functions for operating on regular expressions. - -Syntax of Regular Expressions - -* Regexp Special:: Special characters in regular expressions. -* Char Classes:: Character classes used in regular expressions. -* Regexp Backslash:: Backslash-sequences in regular expressions. - -The Match Data - -* Replacing Match:: Replacing a substring that was matched. -* Simple Match Data:: Accessing single items of match data, - such as where a particular subexpression started. -* Entire Match Data:: Accessing the entire match data at once, as a list. -* Saving Match Data:: Saving and restoring the match data. - -Syntax Tables - -* Syntax Basics:: Basic concepts of syntax tables. -* Syntax Descriptors:: How characters are classified. -* Syntax Table Functions:: How to create, examine and alter syntax tables. -* Syntax Properties:: Overriding syntax with text properties. -* Motion and Syntax:: Moving over characters with certain syntaxes. -* Parsing Expressions:: Parsing balanced expressions - using the syntax table. -* Standard Syntax Tables:: Syntax tables used by various major modes. -* Syntax Table Internals:: How syntax table information is stored. -* Categories:: Another way of classifying character syntax. - -Syntax Descriptors - -* Syntax Class Table:: Table of syntax classes. -* Syntax Flags:: Additional flags each character can have. - -Parsing Expressions - -* Motion via Parsing:: Motion functions that work by parsing. -* Position Parse:: Determining the syntactic state of a position. -* Parser State:: How Emacs represents a syntactic state. -* Low-Level Parsing:: Parsing across a specified region. -* Control Parsing:: Parameters that affect parsing. - -Abbrevs and Abbrev Expansion - -* Abbrev Tables:: Creating and working with abbrev tables. -* Defining Abbrevs:: Specifying abbreviations and their expansions. -* Abbrev Files:: Saving abbrevs in files. -* Abbrev Expansion:: Controlling expansion; expansion subroutines. -* Standard Abbrev Tables:: Abbrev tables used by various major modes. -* Abbrev Properties:: How to read and set abbrev properties. - Which properties have which effect. -* Abbrev Table Properties:: How to read and set abbrev table properties. - Which properties have which effect. - -Processes - -* Subprocess Creation:: Functions that start subprocesses. -* Shell Arguments:: Quoting an argument to pass it to a shell. -* Synchronous Processes:: Details of using synchronous subprocesses. -* Asynchronous Processes:: Starting up an asynchronous subprocess. -* Deleting Processes:: Eliminating an asynchronous subprocess. -* Process Information:: Accessing run-status and other attributes. -* Input to Processes:: Sending input to an asynchronous subprocess. -* Signals to Processes:: Stopping, continuing or interrupting - an asynchronous subprocess. -* Output from Processes:: Collecting output from an asynchronous subprocess. -* Sentinels:: Sentinels run when process run-status changes. -* Query Before Exit:: Whether to query if exiting will kill a process. -* System Processes:: Accessing other processes running on your system. -* Transaction Queues:: Transaction-based communication with subprocesses. -* Network:: Opening network connections. -* Network Servers:: Network servers let Emacs accept net connections. -* Datagrams:: UDP network connections. -* Low-Level Network:: Lower-level but more general function - to create connections and servers. -* Misc Network:: Additional relevant functions for - network connections. -* Serial Ports:: Communicating with serial ports. -* Byte Packing:: Using bindat to pack and unpack binary data. - -Receiving Output from Processes - -* Process Buffers:: If no filter, output is put in a buffer. -* Filter Functions:: Filter functions accept output from the process. -* Decoding Output:: Filters can get unibyte or multibyte strings. -* Accepting Output:: How to wait until process output arrives. - -Low-Level Network Access - -* Network Processes:: Using @code{make-network-process}. -* Network Options:: Further control over network connections. -* Network Feature Testing:: Determining which network features work on - the machine you are using. - -Packing and Unpacking Byte Arrays - -* Bindat Spec:: Describing data layout. -* Bindat Functions:: Doing the unpacking and packing. -* Bindat Examples:: Samples of what bindat.el can do for you! - -Emacs Display - -* Refresh Screen:: Clearing the screen and redrawing everything on it. -* Forcing Redisplay:: Forcing redisplay. -* Truncation:: Folding or wrapping long text lines. -* The Echo Area:: Displaying messages at the bottom of the screen. -* Warnings:: Displaying warning messages for the user. -* Invisible Text:: Hiding part of the buffer text. -* Selective Display:: Hiding part of the buffer text (the old way). -* Temporary Displays:: Displays that go away automatically. -* Overlays:: Use overlays to highlight parts of the buffer. -* Width:: How wide a character or string is on the screen. -* Line Height:: Controlling the height of lines. -* Faces:: A face defines a graphics style - for text characters: font, colors, etc. -* Fringes:: Controlling window fringes. -* Scroll Bars:: Controlling vertical scroll bars. -* Display Property:: Enabling special display features. -* Images:: Displaying images in Emacs buffers. -* Buttons:: Adding clickable buttons to Emacs buffers. -* Abstract Display:: Emacs's Widget for Object Collections. -* Blinking:: How Emacs shows the matching open parenthesis. -* Character Display:: How Emacs displays individual characters. -* Beeping:: Audible signal to the user. -* Window Systems:: Which window system is being used. -* Bidirectional Display:: Display of bidirectional scripts, such as - Arabic and Farsi. - -The Echo Area - -* Displaying Messages:: Explicitly displaying text in the echo area. -* Progress:: Informing user about progress of a long operation. -* Logging Messages:: Echo area messages are logged for the user. -* Echo Area Customization:: Controlling the echo area. - -Reporting Warnings - -* Warning Basics:: Warnings concepts and functions to report them. -* Warning Variables:: Variables programs bind to customize - their warnings. -* Warning Options:: Variables users set to control display of warnings. -* Delayed Warnings:: Deferring a warning until the end of a command. - -Overlays - -* Managing Overlays:: Creating and moving overlays. -* Overlay Properties:: How to read and set properties. - What properties do to the screen display. -* Finding Overlays:: Searching for overlays. - -Faces - -* Defining Faces:: How to define a face. -* Face Attributes:: What is in a face? -* Attribute Functions:: Functions to examine and set face attributes. -* Displaying Faces:: How Emacs combines the faces specified for - a character. -* Face Remapping:: Remapping faces to alternative definitions. -* Face Functions:: How to define and examine faces. -* Auto Faces:: Hook for automatic face assignment. -* Basic Faces:: Faces that are defined by default. -* Font Selection:: Finding the best available font for a face. -* Font Lookup:: Looking up the names of available fonts - and information about them. -* Fontsets:: A fontset is a collection of fonts - that handle a range of character sets. -* Low-Level Font:: Lisp representation for character display fonts. - -Fringes - -* Fringe Size/Pos:: Specifying where to put the window fringes. -* Fringe Indicators:: Displaying indicator icons in the window fringes. -* Fringe Cursors:: Displaying cursors in the right fringe. -* Fringe Bitmaps:: Specifying bitmaps for fringe indicators. -* Customizing Bitmaps:: Specifying your own bitmaps to use in the fringes. -* Overlay Arrow:: Display of an arrow to indicate position. - -The @code{display} Property - -* Replacing Specs:: Display specs that replace the text. -* Specified Space:: Displaying one space with a specified width. -* Pixel Specification:: Specifying space width or height in pixels. -* Other Display Specs:: Displaying an image; adjusting the height, - spacing, and other properties of text. -* Display Margins:: Displaying text or images to the side of - the main text. - -Images - -* Image Formats:: Supported image formats. -* Image Descriptors:: How to specify an image for use in @code{:display}. -* XBM Images:: Special features for XBM format. -* XPM Images:: Special features for XPM format. -* GIF Images:: Special features for GIF format. -* TIFF Images:: Special features for TIFF format. -* PostScript Images:: Special features for PostScript format. -* ImageMagick Images:: Special features available through ImageMagick. -* Other Image Types:: Various other formats are supported. -* Defining Images:: Convenient ways to define an image for later use. -* Showing Images:: Convenient ways to display an image once - it is defined. -* Animated Images:: Some image formats can be animated. -* Image Cache:: Internal mechanisms of image display. - -Buttons - -* Button Properties:: Button properties with special meanings. -* Button Types:: Defining common properties for classes of buttons. -* Making Buttons:: Adding buttons to Emacs buffers. -* Manipulating Buttons:: Getting and setting properties of buttons. -* Button Buffer Commands:: Buffer-wide commands and bindings for buttons. - -Abstract Display - -* Abstract Display Functions:: Functions in the Ewoc package. -* Abstract Display Example:: Example of using Ewoc. - -Character Display - -* Usual Display:: The usual conventions for displaying characters. -* Display Tables:: What a display table consists of. -* Active Display Table:: How Emacs selects a display table to use. -* Glyphs:: How to define a glyph, and what glyphs mean. -* Glyphless Chars:: How glyphless characters are drawn. - -Operating System Interface - -* Starting Up:: Customizing Emacs startup processing. -* Getting Out:: How exiting works (permanent or temporary). -* System Environment:: Distinguish the name and kind of system. -* User Identification:: Finding the name and user id of the user. -* Time of Day:: Getting the current time. -* Time Conversion:: Converting a time from numeric form to - calendrical data and vice versa. -* Time Parsing:: Converting a time from numeric form to text - and vice versa. -* Processor Run Time:: Getting the run time used by Emacs. -* Time Calculations:: Adding, subtracting, comparing times, etc. -* Timers:: Setting a timer to call a function at a - certain time. -* Idle Timers:: Setting a timer to call a function when Emacs has - been idle for a certain length of time. -* Terminal Input:: Accessing and recording terminal input. -* Terminal Output:: Controlling and recording terminal output. -* Sound Output:: Playing sounds on the computer's speaker. -* X11 Keysyms:: Operating on key symbols for X Windows. -* Batch Mode:: Running Emacs without terminal interaction. -* Session Management:: Saving and restoring state with - X Session Management. -* Notifications:: Desktop notifications. -* Dynamic Libraries:: On-demand loading of support libraries. - -Starting Up Emacs - -* Startup Summary:: Sequence of actions Emacs performs at startup. -* Init File:: Details on reading the init file. -* Terminal-Specific:: How the terminal-specific Lisp file is read. -* Command-Line Arguments:: How command-line arguments are processed, - and how you can customize them. - -Getting Out of Emacs - -* Killing Emacs:: Exiting Emacs irreversibly. -* Suspending Emacs:: Exiting Emacs reversibly. - -Terminal Input - -* Input Modes:: Options for how input is processed. -* Recording Input:: Saving histories of recent or all input events. - -Preparing Lisp code for distribution - -* Packaging Basics:: The basic concepts of Emacs Lisp packages. -* Simple Packages:: How to package a single .el file. -* Multi-file Packages:: How to package multiple files. - -Tips and Conventions - -* Coding Conventions:: Conventions for clean and robust programs. -* Key Binding Conventions:: Which keys should be bound by which programs. -* Programming Tips:: Making Emacs code fit smoothly in Emacs. -* Compilation Tips:: Making compiled code run fast. -* Warning Tips:: Turning off compiler warnings. -* Documentation Tips:: Writing readable documentation strings. -* Comment Tips:: Conventions for writing comments. -* Library Headers:: Standard headers for library packages. - -GNU Emacs Internals - -* Building Emacs:: How the dumped Emacs is made. -* Pure Storage:: Kludge to make preloaded Lisp functions shareable. -* Garbage Collection:: Reclaiming space for Lisp objects no longer used. -* Memory Usage:: Info about total size of Lisp objects made so far. -* Writing Emacs Primitives:: Writing C code for Emacs. -* Object Internals:: Data formats of buffers, windows, processes. - -Object Internals - -* Buffer Internals:: Components of a buffer structure. -* Window Internals:: Components of a window structure. -* Process Internals:: Components of a process structure. +Here are other nodes that are subnodes of those already listed, +mentioned here so you can get to them in one step: + +Not used + +* Not used:: This file is only used with TeX, which + generates its own menu. @end detailmenu @end menu @@ -1537,12 +193,8 @@ @include display.texi @include os.texi -@c MOVE to Emacs Manual: include misc-modes.texi - @c appendices -@c REMOVE this: include non-hacker.texi - @include anti.texi @include doclicense.texi @include gpl.texi ------------------------------------------------------------ revno: 108157 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 21:50:17 -0400 message: Remove no-byte-compile setting from some lisp/language files. Same comments as per r108075, 2012-04-30, for lisp/term: Not that compiling these will bring any noticeable speed benefit, but there's really no reason not to compile them. The extra disk space and build time is negligible, and it might reveal use of obsolete functions, bugs, etc. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-08 01:41:05 +0000 +++ lisp/ChangeLog 2012-05-08 01:50:17 +0000 @@ -1,5 +1,13 @@ 2012-05-08 Glenn Morris + * lisp/language/burmese.el, language/cham.el, language/czech.el: + * language/english.el, language/georgian.el, language/greek.el: + * language/japanese.el, language/khmer.el, language/korean.el: + * language/lao.el, language/misc-lang.el, language/romanian.el: + * language/sinhala.el, language/slovak.el, language/tai-viet.el: + * language/thai.el, language/utf-8-lang.el: + Remove no-byte-compile setting. + * play/zone.el (zone-pgm-stress): Don't pollute kill-ring. (Bug#11388) 2012-05-08 Aaron S. Hawley === modified file 'lisp/language/burmese.el' --- lisp/language/burmese.el 2011-01-15 23:16:57 +0000 +++ lisp/language/burmese.el 2012-05-08 01:50:17 +0000 @@ -1,4 +1,4 @@ -;;; burmese.el --- support for Burmese -*- coding: utf-8; no-byte-compile: t -*- +;;; burmese.el --- support for Burmese -*- coding: utf-8 -*- ;; Copyright (C) 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/cham.el' --- lisp/language/cham.el 2012-02-18 10:24:23 +0000 +++ lisp/language/cham.el 2012-05-08 01:50:17 +0000 @@ -1,4 +1,4 @@ -;;; cham.el --- support for Cham -*- coding: utf-8; no-byte-compile: t -*- +;;; cham.el --- support for Cham -*- coding: utf-8 -*- ;; Copyright (C) 2008, 2009, 2010, 2011, 2012 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/czech.el' --- lisp/language/czech.el 2012-01-19 07:21:25 +0000 +++ lisp/language/czech.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; czech.el --- support for Czech -*- coding: iso-2022-7bit; no-byte-compile: t -*- +;;; czech.el --- support for Czech -*- coding: iso-2022-7bit -*- -;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. ;; Author: Milan Zamazal ;; Maintainer: Pavel Jan,Am(Bk === modified file 'lisp/language/english.el' --- lisp/language/english.el 2012-01-19 07:21:25 +0000 +++ lisp/language/english.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; english.el --- support for English -*- no-byte-compile: t -*- +;;; english.el --- support for English -;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc. ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, ;; 2006, 2007, 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/georgian.el' --- lisp/language/georgian.el 2012-01-19 07:21:25 +0000 +++ lisp/language/georgian.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; georgian.el --- language support for Georgian -*- no-byte-compile: t -*- +;;; georgian.el --- language support for Georgian -;; Copyright (C) 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 2001-2012 Free Software Foundation, Inc. ;; Author: Dave Love ;; Keywords: i18n === modified file 'lisp/language/greek.el' --- lisp/language/greek.el 2011-01-15 23:16:57 +0000 +++ lisp/language/greek.el 2012-05-08 01:50:17 +0000 @@ -1,4 +1,4 @@ -;;; greek.el --- support for Greek -*- no-byte-compile: t -*- +;;; greek.el --- support for Greek ;; Copyright (C) 2002 Free Software Foundation, Inc. ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, === modified file 'lisp/language/japanese.el' --- lisp/language/japanese.el 2012-01-19 07:21:25 +0000 +++ lisp/language/japanese.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; japanese.el --- support for Japanese -*- coding: iso-2022-7bit; no-byte-compile: t -*- +;;; japanese.el --- support for Japanese -*- coding: iso-2022-7bit -*- -;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc. ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/khmer.el' --- lisp/language/khmer.el 2011-01-15 23:16:57 +0000 +++ lisp/language/khmer.el 2012-05-08 01:50:17 +0000 @@ -1,4 +1,4 @@ -;;; khmer.el --- support for Khmer -*- coding: utf-8; no-byte-compile: t -*- +;;; khmer.el --- support for Khmer -*- coding: utf-8 -*- ;; Copyright (C) 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/korean.el' --- lisp/language/korean.el 2012-01-19 07:21:25 +0000 +++ lisp/language/korean.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; korean.el --- support for Korean -*- coding: iso-2022-7bit; no-byte-compile: t -*- +;;; korean.el --- support for Korean -*- coding: iso-2022-7bit -*- -;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/lao.el' --- lisp/language/lao.el 2012-01-19 07:21:25 +0000 +++ lisp/language/lao.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; lao.el --- support for Lao -*- coding: utf-8; no-byte-compile: t -*- +;;; lao.el --- support for Lao -*- coding: utf-8 -*- -;; Copyright (C) 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 2001-2012 Free Software Foundation, Inc. ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, ;; 2007, 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/misc-lang.el' --- lisp/language/misc-lang.el 2011-01-15 23:16:57 +0000 +++ lisp/language/misc-lang.el 2012-05-08 01:50:17 +0000 @@ -1,4 +1,4 @@ -;;; misc-lang.el --- support for miscellaneous languages (characters) -*- no-byte-compile: t -*- +;;; misc-lang.el --- support for miscellaneous languages (characters) ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 === modified file 'lisp/language/romanian.el' --- lisp/language/romanian.el 2012-01-19 07:21:25 +0000 +++ lisp/language/romanian.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; romanian.el --- support for Romanian -*- coding: iso-latin-2; no-byte-compile: t -*- +;;; romanian.el --- support for Romanian -*- coding: iso-latin-2 -*- -;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. ;; Author: Dan Nicolaescu ;; Keywords: multilingual, Romanian, i18n === modified file 'lisp/language/sinhala.el' --- lisp/language/sinhala.el 2011-01-15 23:16:57 +0000 +++ lisp/language/sinhala.el 2012-05-08 01:50:17 +0000 @@ -1,4 +1,4 @@ -;;; sinhala.el --- support for Sinhala -*- coding: utf-8; no-byte-compile: t -*- +;;; sinhala.el --- support for Sinhala -*- coding: utf-8 -*- ;; Copyright (C) 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/slovak.el' --- lisp/language/slovak.el 2012-01-19 07:21:25 +0000 +++ lisp/language/slovak.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; slovak.el --- support for Slovak -*- coding: iso-2022-7bit; no-byte-compile: t -*- +;;; slovak.el --- support for Slovak -*- coding: iso-2022-7bit -*- -;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. ;; Authors: Tibor ,B)(Bimko , ;; Milan Zamazal === modified file 'lisp/language/tai-viet.el' --- lisp/language/tai-viet.el 2012-02-18 10:24:23 +0000 +++ lisp/language/tai-viet.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; tai-viet.el --- support for Tai Viet -*- coding: utf-8; no-byte-compile: t -*- +;;; tai-viet.el --- support for Tai Viet -*- coding: utf-8 -*- -;; Copyright (C) 2007-2012 Free Software Foundation, Inc. +;; Copyright (C) 2007-2012 Free Software Foundation, Inc. ;; Copyright (C) 2007, 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) ;; Registration Number H13PRO009 === modified file 'lisp/language/thai.el' --- lisp/language/thai.el 2012-01-19 07:21:25 +0000 +++ lisp/language/thai.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; thai.el --- support for Thai -*- coding: iso-2022-7bit; no-byte-compile: t -*- +;;; thai.el --- support for Thai -*- coding: iso-2022-7bit -*- -;; Copyright (C) 1997-1998, 2000-2012 Free Software Foundation, Inc. +;; Copyright (C) 1997-1998, 2000-2012 Free Software Foundation, Inc. ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 ;; National Institute of Advanced Industrial Science and Technology (AIST) === modified file 'lisp/language/utf-8-lang.el' --- lisp/language/utf-8-lang.el 2012-01-19 07:21:25 +0000 +++ lisp/language/utf-8-lang.el 2012-05-08 01:50:17 +0000 @@ -1,6 +1,6 @@ -;;; utf-8-lang.el --- generic UTF-8 language environment -*- no-byte-compile: t -*- +;;; utf-8-lang.el --- generic UTF-8 language environment -;; Copyright (C) 2001-2012 Free Software Foundation, Inc. +;; Copyright (C) 2001-2012 Free Software Foundation, Inc. ;; Author: Dave Love ;; Keywords: i18n ------------------------------------------------------------ revno: 108156 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 21:41:05 -0400 message: * lisp/play/zone.el (zone-pgm-stress): Don't pollute kill-ring. (Bug#11388) diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-08 01:25:52 +0000 +++ lisp/ChangeLog 2012-05-08 01:41:05 +0000 @@ -1,3 +1,7 @@ +2012-05-08 Glenn Morris + + * play/zone.el (zone-pgm-stress): Don't pollute kill-ring. (Bug#11388) + 2012-05-08 Aaron S. Hawley * progmodes/make-mode.el (makefile-browse): === modified file 'lisp/play/zone.el' --- lisp/play/zone.el 2012-04-09 13:05:48 +0000 +++ lisp/play/zone.el 2012-05-08 01:41:05 +0000 @@ -1,6 +1,6 @@ ;;; zone.el --- idle display hacks -;; Copyright (C) 2000-2012 Free Software Foundation, Inc. +;; Copyright (C) 2000-2012 Free Software Foundation, Inc. ;; Author: Victor Zandy ;; Maintainer: Thien-Thi Nguyen @@ -595,8 +595,7 @@ (when (< 50 (random 100)) (goto-char (point-max)) (forward-line -1) - (let ((kill-whole-line t)) - (kill-line)) + (delete-region (point) (line-beginning-position 2)) (goto-char (point-min)) (insert (nth (random (length lines)) lines))) (message (concat (make-string (random (- (frame-width) 5)) ? ) "grrr")) ------------------------------------------------------------ revno: 108155 fixes bug(s): http://debbugs.gnu.org/11324 author: Aaron S. Hawley committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 21:25:52 -0400 message: * progmodes/make-mode.el (makefile-browse): Remove unnecessary interactive. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-07 22:53:17 +0000 +++ lisp/ChangeLog 2012-05-08 01:25:52 +0000 @@ -1,3 +1,8 @@ +2012-05-08 Aaron S. Hawley + + * progmodes/make-mode.el (makefile-browse): + Remove unnecessary interactive. (Bug#11324) + 2012-05-07 Glenn Morris * forms-d2.el, forms-pass.el: Move to ../etc/forms directory. === modified file 'lisp/progmodes/make-mode.el' --- lisp/progmodes/make-mode.el 2012-04-09 13:05:48 +0000 +++ lisp/progmodes/make-mode.el 2012-05-08 01:25:52 +0000 @@ -1493,7 +1493,6 @@ (setq buffer-read-only t)) (defun makefile-browse (targets macros) - (interactive) (if (zerop (+ (length targets) (length macros))) (progn (beep) ------------------------------------------------------------ revno: 108154 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 19:02:28 -0400 message: * doc/misc/forms.texi (Long Example): Update for changed location of files. diff: === modified file 'doc/misc/ChangeLog' --- doc/misc/ChangeLog 2012-05-04 06:45:03 +0000 +++ doc/misc/ChangeLog 2012-05-07 23:02:28 +0000 @@ -1,3 +1,7 @@ +2012-05-07 Glenn Morris + + * forms.texi (Long Example): Update for changed location of files. + 2012-05-04 Glenn Morris * Makefile.in (INFO_EXT, INFO_OPTS): New, set by configure. === modified file 'doc/misc/forms.texi' --- doc/misc/forms.texi 2012-01-19 07:21:25 +0000 +++ doc/misc/forms.texi 2012-05-07 23:02:28 +0000 @@ -861,7 +861,7 @@ @chapter Long Example The following example exploits most of the features of Forms mode. -This example is included in the distribution as file @file{forms-d2.el}. +This example is included in the distribution as file @file{etc/forms/forms-d2.el}. @example ;; demo2 -- demo forms-mode -*- emacs-lisp -*- @@ -869,7 +869,8 @@ ;; @r{This sample forms exploit most of the features of forms mode.} ;; @r{Set the name of the data file.} -(setq forms-file "forms-d2.dat") +(setq forms-file + (expand-file-name "forms/forms-d2.dat" data-directory)) ;; @r{Use @code{forms-enumerate} to set field names and number thereof.} (setq forms-number-of-fields ------------------------------------------------------------ revno: 108153 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 18:53:17 -0400 message: Move some forms.el example files to etc/forms directory * etc/forms/README: New. * etc/forms/forms-d2.dat: Move to etc/forms/ subdirectory. * etc/forms/forms-d2.el, etc/forms/forms-pass.el: Move here from ../lisp. * lisp/forms.el: Related comment change. diff: === modified file 'etc/ChangeLog' --- etc/ChangeLog 2012-05-03 20:04:29 +0000 +++ etc/ChangeLog 2012-05-07 22:53:17 +0000 @@ -1,3 +1,9 @@ +2012-05-07 Glenn Morris + + * forms/forms-d2.el, forms/forms-pass.el: Move here from ../lisp. + * forms/forms-d2.dat: Move to forms/ subdirectory. + * forms/README: New. + 2012-05-03 Paul Eggert * NEWS: Do not limit current-time-string to years 1000..9999. === added directory 'etc/forms' === added file 'etc/forms/README' --- etc/forms/README 1970-01-01 00:00:00 +0000 +++ etc/forms/README 2012-05-07 22:53:17 +0000 @@ -0,0 +1,1 @@ +This directory contains some example files for the forms.el library. === renamed file 'etc/forms-d2.dat' => 'etc/forms/forms-d2.dat' === renamed file 'lisp/forms-d2.el' => 'etc/forms/forms-d2.el' --- lisp/forms-d2.el 2012-01-19 07:21:25 +0000 +++ etc/forms/forms-d2.el 2012-05-07 22:53:17 +0000 @@ -1,4 +1,4 @@ -;;; forms-d2.el --- demo forms-mode -*- no-byte-compile: t -*- +;;; forms-d2.el --- demo forms-mode ;; Copyright (C) 1991, 1994-1997, 2001-2012 Free Software Foundation, Inc. @@ -27,7 +27,7 @@ ;;; Code: ;; Set the name of the data file. -(setq forms-file (expand-file-name "forms-d2.dat" data-directory)) +(setq forms-file (expand-file-name "forms/forms-d2.dat" data-directory)) ;; Use 'forms-enumerate' to set field names and number thereof. (setq forms-number-of-fields === renamed file 'lisp/forms-pass.el' => 'etc/forms/forms-pass.el' --- lisp/forms-pass.el 2011-01-15 23:16:57 +0000 +++ etc/forms/forms-pass.el 2012-05-07 22:53:17 +0000 @@ -1,4 +1,4 @@ -;;; forms-pass.el --- passwd file demo for forms-mode -*- no-byte-compile: t -*- +;;; forms-pass.el --- passwd file demo for forms-mode ;; This file is part of GNU Emacs. === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-07 21:26:08 +0000 +++ lisp/ChangeLog 2012-05-07 22:53:17 +0000 @@ -1,5 +1,7 @@ 2012-05-07 Glenn Morris + * forms-d2.el, forms-pass.el: Move to ../etc/forms directory. + * international/mule.el (find-auto-coding): Make "unibyte: t" obsolete. 2012-05-07 Stefan Monnier === modified file 'lisp/forms.el' --- lisp/forms.el 2012-05-04 05:14:14 +0000 +++ lisp/forms.el 2012-05-07 22:53:17 +0000 @@ -21,7 +21,7 @@ ;;; Commentary: -;; Visit a file using a form. See forms-d2.el for examples. +;; Visit a file using a form. See etc/forms for examples. ;; ;; === Naming conventions ;; ------------------------------------------------------------ revno: 108152 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 18:40:58 -0400 message: Fix NEWS typo diff: === modified file 'etc/NEWS' --- etc/NEWS 2012-05-07 21:26:08 +0000 +++ etc/NEWS 2012-05-07 22:40:58 +0000 @@ -66,7 +66,7 @@ specifying any file to visit or expression to evaluate. ** Using "unibyte: t" in Lisp source files is obsolete. -Using "coding: raw-text" instead. +Use "coding: raw-text" instead. * Editing Changes in Emacs 24.2 ------------------------------------------------------------ revno: 108151 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 17:45:34 -0400 message: Also apply previous change to file locals at the end of the file diff: === modified file 'lisp/international/mule.el' --- lisp/international/mule.el 2012-05-07 21:26:08 +0000 +++ lisp/international/mule.el 2012-05-07 21:45:34 +0000 @@ -1890,6 +1890,8 @@ (goto-char pos) (when (and set-auto-coding-for-load (re-search-forward re-unibyte tail-end t)) + (display-warning 'mule "`unibyte: t' is obsolete; \ +use \"coding: 'raw-text\" instead." :warning) (setq coding-system 'raw-text)) (when (and (not coding-system) (re-search-forward re-coding tail-end t)) ------------------------------------------------------------ revno: 108150 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-05-07 17:26:08 -0400 message: * lisp/international/mule.el (find-auto-coding): Make "unibyte: t" obsolete. * etc/NEWS: Edits. Ref: http://lists.gnu.org/archive/html/emacs-devel/2012-04/msg00434.html diff: === modified file 'etc/NEWS' --- etc/NEWS 2012-05-07 19:51:25 +0000 +++ etc/NEWS 2012-05-07 21:26:08 +0000 @@ -65,6 +65,9 @@ frames, if emacsclient is only told to open a new frame without specifying any file to visit or expression to evaluate. +** Using "unibyte: t" in Lisp source files is obsolete. +Using "coding: raw-text" instead. + * Editing Changes in Emacs 24.2 @@ -128,7 +131,8 @@ ** Calendar -*** The calendars produced by cal-html can optionally include holidays. +*** The calendars produced by cal-html include holidays. +Customize cal-html-holidays to change this. ** Customize === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-07 20:48:41 +0000 +++ lisp/ChangeLog 2012-05-07 21:26:08 +0000 @@ -1,3 +1,7 @@ +2012-05-07 Glenn Morris + + * international/mule.el (find-auto-coding): Make "unibyte: t" obsolete. + 2012-05-07 Stefan Monnier * loadup.el: Preload newcomment.el. === modified file 'lisp/international/mule.el' --- lisp/international/mule.el 2012-04-12 01:09:15 +0000 +++ lisp/international/mule.el 2012-05-07 21:26:08 +0000 @@ -30,6 +30,7 @@ ;;; Code: +;; FIXME? Are these still relevant? Nothing uses them AFAICS. (defconst mule-version "6.0 (HANACHIRUSATO)" "\ Version number and name of this version of MULE (multilingual environment).") @@ -1835,6 +1836,8 @@ (re-search-forward "\\(.*;\\)?[ \t]*unibyte:[ \t]*\\([^ ;]+\\)" head-end t)) + (display-warning 'mule "`unibyte: t' is obsolete; \ +use \"coding: 'raw-text\" instead." :warning) (setq coding-system 'raw-text)) (when (and (not coding-system) (re-search-forward ------------------------------------------------------------ revno: 108149 committer: Stefan Monnier branch nick: trunk timestamp: Mon 2012-05-07 16:48:41 -0400 message: * loadup.el: Preload newcomment.el. * newcomment.el: Move autoload-only code to toplevel. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-07 16:29:55 +0000 +++ lisp/ChangeLog 2012-05-07 20:48:41 +0000 @@ -1,5 +1,8 @@ 2012-05-07 Stefan Monnier + * loadup.el: Preload newcomment.el. + * newcomment.el: Move autoload-only code to toplevel. + * buff-menu.el (list-buffers--refresh): Mark `size' as right-align. * emacs-lisp/tabulated-list.el (tabulated-list-init-header): Handle new :right-align column property. === modified file 'lisp/loadup.el' --- lisp/loadup.el 2012-05-06 16:45:46 +0000 +++ lisp/loadup.el 2012-05-07 20:48:41 +0000 @@ -186,6 +186,7 @@ (load "emacs-lisp/lisp-mode") (load "textmodes/text-mode") (load "textmodes/fill") +(load "newcomment") (load "replace") (load "emacs-lisp/tabulated-list") === modified file 'lisp/newcomment.el' --- lisp/newcomment.el 2012-04-17 03:06:56 +0000 +++ lisp/newcomment.el 2012-05-07 20:48:41 +0000 @@ -102,30 +102,35 @@ :type 'integer :group 'comment) (make-variable-buffer-local 'comment-column) -;;;###autoload(put 'comment-column 'safe-local-variable 'integerp) +;;;###autoload +(put 'comment-column 'safe-local-variable 'integerp) ;;;###autoload (defvar comment-start nil "String to insert to start a new comment, or nil if no comment syntax.") -;;;###autoload(put 'comment-start 'safe-local-variable 'string-or-null-p) +;;;###autoload +(put 'comment-start 'safe-local-variable 'string-or-null-p) ;;;###autoload (defvar comment-start-skip nil "Regexp to match the start of a comment plus everything up to its body. If there are any \\(...\\) pairs, the comment delimiter text is held to begin at the place matched by the close of the first pair.") -;;;###autoload(put 'comment-start-skip 'safe-local-variable 'string-or-null-p) +;;;###autoload +(put 'comment-start-skip 'safe-local-variable 'string-or-null-p) ;;;###autoload (defvar comment-end-skip nil "Regexp to match the end of a comment plus everything back to its body.") -;;;###autoload(put 'comment-end-skip 'safe-local-variable 'string-or-null-p) +;;;###autoload +(put 'comment-end-skip 'safe-local-variable 'string-or-null-p) ;;;###autoload (defvar comment-end (purecopy "") "String to insert to end a new comment. Should be an empty string if comments are terminated by end-of-line.") -;;;###autoload(put 'comment-end 'safe-local-variable 'string-or-null-p) +;;;###autoload +(put 'comment-end 'safe-local-variable 'string-or-null-p) ;;;###autoload (defvar comment-indent-function 'comment-indent-default ------------------------------------------------------------ revno: 108148 committer: Stefan Merten branch nick: trunk timestamp: Mon 2012-05-07 21:51:25 +0200 message: 2012-05-05 Stefan Merten * rst.el: Major merge with upstream development up to Docutils SVN r7399 / rst.el V1.2.1. Clarified maintainership and authors. (rst-extract-version, rst-cvs-header, rst-cvs-rev) (rst-cvs-timestamp, rst-svn-rev, rst-svn-timestamp) (rst-official-version, rst-official-cvs-rev, rst-version) (rst-package-emacs-version-alist): New functions and variables for version information. (rst-bullets, rst-uri-schemes, rst-adornment-chars) (rst-max-inline-length, rst-re-alist-def, rst-re-alist) (rst-mode-syntax-table, rst-mode): New and corrected functions and variables representing reStructuredText features. (rst-re): New function for reStructuredText regexes. Used in many places. (rst-deprecated-keys, rst-call-deprecated, rst-define-key) (rst-mode-map): Rebound keys. (rst-mode-lazy, rst-font-lock-keywords) (rst-font-lock-extend-region) (rst-font-lock-extend-region-internal) (rst-font-lock-extend-region-extend) (rst-font-lock-find-unindented-line-limit) (rst-font-lock-find-unindented-line-match) (rst-adornment-level, rst-font-lock-adornment-level) (rst-font-lock-adornment-match) (rst-font-lock-handle-adornment-pre-match-form) (rst-font-lock-handle-adornment-matcher): Major revision of font-locking. Integrated with other code. `jit-lock-mode' is used now. (rst-preferred-adornments, rst-adjust-hook) (rst-new-adornment-down, rst-preferred-bullets) (rst-preferred-bullets, rst-indent, rst-indent-width) (rst-indent-field, rst-indent-literal-normal) (rst-indent-literal-minimized, rst-indent-comment): Changed, extended and improved customization. (rst-line-homogeneous-p, rst-line-homogeneous-nodent-p) (rst-normalize-cursor-position, rst-get-decoration) (rst-straighten-deco-spacing, rst-re-bullets, rst-re-items) (rst-rstrip, rst-toc-insert-find-delete-contents) (rst-shift-fill-region, rst-compute-bullet-tabs) (rst-debug-print-tabs, rst-debug-mark-found) (rst-shift-region-guts, rst-shift-region-right) (rst-shift-region-left, rst-use-char-classes) (rst-font-lock-keywords-function) (rst-font-lock-indentation-point) (rst-font-lock-find-unindented-line-begin) (rst-font-lock-find-unindented-line-end) (rst-font-lock-find-unindented-line) (rst-font-lock-adornment-point, rst-font-lock-level) (rst-adornment-level-alist): Removed functions and variables. (rst-compare-adornments, rst-get-adornment-match) (rst-suggest-new-adornment, rst-get-adornments-around) (rst-adornment-complete-p, rst-get-next-adornment) (rst-adjust-adornment, rst-display-adornments-hierarchy) (rst-straighten-adornments): Standardized function names to use "adornment" instead of "decoration". Corrected callers. Similar standardizing happened in many places. (rst-update-section, rst-adjust, rst-promote-region) (rst-enumerate-region, rst-bullet-list-region) (rst-repeat-last-character): Corrected use of `interactive'. (rst-classify-adornment, rst-find-all-adornments) (rst-get-hierarchy, rst-adjust-adornment, rst-toc-update) (rst-find-leftmost-column, rst-repeat-last-character): Refactored functions. (rst-find-title-line, rst-reset-section-caches) (rst-get-adornments-around, rst-adjust-adornment-work) (rst-arabic-to-roman, rst-roman-to-arabic) (rst-insert-list-pos, rst-insert-list-new-item) (rst-insert-list-continue, rst-insert-list, rst-forward-line): New functions. (rst-all-sections, rst-section-hierarchy) (rst-arabic-to-roman, rst-initial-enums, rst-initial-items): New variables. (rst-toc-return-wincfg, rst-toc-quit-window): Using window configuration instead of only buffer. Changed where necessary. (rst-line-tabs, rst-compute-tabs, rst-indent-line) (rst-shift-region, rst-adaptive-fill): New functions for indentation and filling. (rst-comment-line-break, rst-comment-indent) (rst-comment-insert-comment, rst-comment-region) (rst-uncomment-region): New functions for handling comments. (rst-compile): Shell arguments are quoted. (rst-compile-pdf-preview, rst-compile-slides-preview): Temporary files are deleted after use. diff: === modified file 'etc/NEWS' --- etc/NEWS 2012-05-06 16:45:46 +0000 +++ etc/NEWS 2012-05-07 19:51:25 +0000 @@ -82,6 +82,38 @@ * Changes in Specialized Modes and Packages in Emacs 24.2 +** reStructuredText mode + +*** Major merge with upstream development. + +*** Nearly all keys are rebound making room for more keys and comply +better to usage in other modes. Bindings are described with C-c C-h. + +*** Major revision of indentation. Now works very similar to other +modes. TAB is your friend. + +*** Major revision of filling. Works fine with most of +reStructuredText syntax. Auto-filling is also supported. + +*** Major revision of comment handling. + +*** Major revision of fontification. Now works with `jit-lock-mode'. +Thanks to Stefan Monnier for help. + +*** reStructuredText syntax is covered more closely in many cases. +Among other things this improves the experience for Sphinx users. + +*** `rst-insert-list' inserts new list or continues existing lists. +Based on code by Wei-Wei Guo. + +*** Customization is extended, corrected and improved. + +*** Negative prefix argument always works for `rst-adjust'. + +*** Window configuration is reset after displaying TOC. + +*** There is a package version in `rst-version' + ** New `derived-mode' filter for Ibuffer, bound to `/ M'. `/ m' is now bound to filter by used-mode, which used to be bound to `/ M'. === modified file 'lisp/textmodes/rst.el' --- lisp/textmodes/rst.el 2012-01-19 07:21:25 +0000 +++ lisp/textmodes/rst.el 2012-05-07 19:51:25 +0000 @@ -2,9 +2,10 @@ ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. -;; Authors: Martin Blais , -;; Stefan Merten , -;; David Goodger +;; Maintainer: Stefan Merten +;; Author: Martin Blais , +;; David Goodger , +;; Wei-Wei Guo ;; This file is part of GNU Emacs. @@ -23,19 +24,23 @@ ;;; Commentary: -;; This package provides major mode rst-mode, which supports documents marked up -;; using the reStructuredText format. Support includes font locking as well as -;; some convenience functions for editing. It does this by defining a Emacs -;; major mode: rst-mode (ReST). This mode is derived from text-mode (and -;; inherits much of it). This package also contains: +;; This package provides major mode rst-mode, which supports documents marked +;; up using the reStructuredText format. Support includes font locking as well +;; as a lot of convenience functions for editing. It does this by defining a +;; Emacs major mode: rst-mode (ReST). This mode is derived from text-mode. This +;; package also contains: ;; ;; - Functions to automatically adjust and cycle the section underline -;; decorations; +;; adornments; ;; - A mode that displays the table of contents and allows you to jump anywhere ;; from it; ;; - Functions to insert and automatically update a TOC in your source ;; document; -;; - Font-lock highlighting of notable reStructuredText structures; +;; - Function to insert list, processing item bullets and enumerations +;; automatically; +;; - Font-lock highlighting of most reStructuredText structures; +;; - Indentation and filling according to reStructuredText syntax; +;; - Cursor movement according to reStructuredText syntax; ;; - Some other convenience functions. ;; ;; See the accompanying document in the docutils documentation about @@ -49,17 +54,8 @@ ;; ;; ;; There are a number of convenient keybindings provided by rst-mode. -;; The main one is -;; -;; C-c C-a (also C-=): rst-adjust -;; -;; Updates or rotates the section title around point or promotes/demotes the -;; decorations within the region (see full details below). Note that C-= is a -;; good binding, since it allows you to specify a negative arg easily with C-- -;; C-= (easy to type), as well as ordinary prefix arg with C-u C-=. -;; ;; For more on bindings, see rst-mode-map below. There are also many variables -;; that can be customized, look for defcustom and defvar in this file. +;; that can be customized, look for defcustom in this file. ;; ;; If you use the table-of-contents feature, you may want to add a hook to ;; update the TOC automatically everytime you adjust a section title:: @@ -71,52 +67,16 @@ ;; ;; (setq font-lock-global-modes '(not rst-mode ...)) ;; - - -;; CUSTOMIZATION -;; -;; rst -;; --- -;; This group contains some general customizable features. -;; -;; The group is contained in the wp group. -;; -;; rst-faces -;; --------- -;; This group contains all necessary for customizing fonts. The default -;; settings use standard font-lock-*-face's so if you set these to your -;; liking they are probably good in rst-mode also. -;; -;; The group is contained in the faces group as well as in the rst group. -;; -;; rst-faces-defaults -;; ------------------ -;; This group contains all necessary for customizing the default fonts used for -;; section title faces. -;; -;; The general idea for section title faces is to have a non-default background -;; but do not change the background. The section level is shown by the -;; lightness of the background color. If you like this general idea of -;; generating faces for section titles but do not like the details this group -;; is the point where you can customize the details. If you do not like the -;; general idea, however, you should customize the faces used in -;; rst-adornment-faces-alist. -;; -;; Note: If you are using a dark background please make sure the variable -;; frame-background-mode is set to the symbol dark. This triggers -;; some default values which are probably right for you. -;; -;; The group is contained in the rst-faces group. -;; -;; All customizable features have a comment explaining their meaning. -;; Refer to the customization of your Emacs (try ``M-x customize``). - +;; +;; +;; Customization is done by customizable variables contained in customization +;; group "rst" and subgroups. Group "rst" is contained in the "wp" group. +;; ;;; DOWNLOAD -;; The latest version of this file lies in the docutils source code repository: -;; http://svn.berlios.de/svnroot/repos/docutils/trunk/docutils/tools/editors/emacs/rst.el - +;; The latest release of this file lies in the docutils source code repository: +;; http://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils/tools/editors/emacs/rst.el ;;; INSTALLATION @@ -140,165 +100,542 @@ ;; ("\\.rest$" . rst-mode)) auto-mode-alist)) ;; -;;; BUGS - -;; - rst-enumeration-region: Select a single paragraph, with the top at one -;; blank line before the beginning, and it will fail. -;; - The active region goes away when we shift it left or right, and this -;; prevents us from refilling it automatically when shifting many times. -;; - The suggested decorations when adjusting should not have to cycle -;; below one below the last section decoration level preceding the -;; cursor. We need to fix that. - -;;; TODO LIST - -;; rst-toc-insert features -;; ------------------------ -;; - rst-toc-insert: We should parse the contents:: options to figure out how -;; deep to render the inserted TOC. -;; - On load, detect any existing TOCs and set the properties for links. -;; - TOC insertion should have an option to add empty lines. -;; - TOC insertion should deal with multiple lines. -;; - There is a bug on redo after undo of adjust when rst-adjust-hook uses the -;; automatic toc update. The cursor ends up in the TOC and this is -;; annoying. Gotta fix that. -;; - numbering: automatically detect if we have a section-numbering directive in -;; the corresponding section, to render the toc. -;; -;; bulleted and enumerated list items -;; ---------------------------------- -;; - We need to provide way to rebullet bulleted lists, and that would include -;; automatic enumeration as well. -;; -;; Other -;; ----- -;; - It would be nice to differentiate between text files using -;; reStructuredText_ and other general text files. If we had a -;; function to automatically guess whether a .txt file is following the -;; reStructuredText_ conventions, we could trigger rst-mode without -;; having to hard-code this in every text file, nor forcing the user to -;; add a local mode variable at the top of the file. -;; We could perform this guessing by searching for a valid decoration -;; at the top of the document or searching for reStructuredText_ -;; directives further on. -;; -;; - We should support imenu in our major mode, with the menu filled with the -;; section titles (this should be really easy). -;; -;; - We should rename "adornment" to "decoration" or vice-versa in this -;; document (Stefan's code ("adornment") vs Martin ("decoration")), maybe some -;; functions even overlap. -;; -;; - We need to automatically recenter on rst-forward-section movement commands. - - -;;; HISTORY -;; - ;;; Code: +(require 'cl) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Versions + +(defun rst-extract-version (delim-re head-re re tail-re var &optional default) + "Return the version matching RE after regex DELIM-RE and HEAD-RE +and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match" + (if (string-match + (concat delim-re head-re "\\(" re "\\)" tail-re delim-re) + var) + (match-string 1 var) + default)) + +;; Use CVSHeader to really get information from CVS and not other version +;; control systems +(defconst rst-cvs-header + "$CVSHeader: sm/rst_el/rst.el,v 1.257 2012-04-29 15:01:17 stefan Exp $") +(defconst rst-cvs-rev + (rst-extract-version "\\$" "CVSHeader: \\S + " "[0-9]+\\(?:\\.[0-9]+\\)+" + " .*" rst-cvs-header "0.0") + "The CVS revision of this file. CVS revision is the development revision.") +(defconst rst-cvs-timestamp + (rst-extract-version "\\$" "CVSHeader: \\S + \\S + " + "[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+" " .*" + rst-cvs-header "1970-01-01 00:00:00") + "The CVS timestamp of this file.") + +;; Use LastChanged... to really get information from SVN +(defconst rst-svn-rev + (rst-extract-version "\\$" "LastChangedRevision: " "[0-9]+" " " + "$LastChangedRevision: 7399 $") + "The SVN revision of this file. +SVN revision is the upstream (docutils) revision.") +(defconst rst-svn-timestamp + (rst-extract-version "\\$" "LastChangedDate: " ".+?+" " " + "$LastChangedDate: 2012-04-29 17:01:05 +0200 (Sun, 29 Apr 2012) $") + "The SVN timestamp of this file.") + +;; Maintained by the release process +(defconst rst-official-version + (rst-extract-version "%" "OfficialVersion: " "[0-9]+\\(?:\\.[0-9]+\\)+" " " + "%OfficialVersion: 1.2.1 %") + "Official version of the package.") +(defconst rst-official-cvs-rev + (rst-extract-version "[%$]" "Revision: " "[0-9]+\\(?:\\.[0-9]+\\)+" " " + "%Revision: 1.256 %") + "CVS revision of this file in the official version.") + +(defconst rst-version + (if (equal rst-official-cvs-rev rst-cvs-rev) + rst-official-version + (format "%s (development %s [%s])" rst-official-version + rst-cvs-rev rst-cvs-timestamp)) + "The version string. +Starts with the current official version. For developer versions +in parentheses follows the development revision and the timestamp.") + +(defconst rst-package-emacs-version-alist + '(("1.0.0" . "24.0") + ("1.1.0" . "24.0") + ("1.2.0" . "24.0") + ("1.2.1" . "24.0"))) + +(unless (assoc rst-official-version rst-package-emacs-version-alist) + (error "Version %s not listed in `rst-package-emacs-version-alist'" + rst-version)) + +(add-to-list 'customize-package-emacs-version-alist + (cons 'ReST rst-package-emacs-version-alist)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Initialize customization + (defgroup rst nil "Support for reStructuredText documents." :group 'wp :version "23.1" :link '(url-link "http://docutils.sourceforge.net/rst.html")) - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Define some generic support functions. - -(eval-when-compile (require 'cl)) ;; We need this for destructuring-bind below. - - -;; From Emacs-22 -(unless (fboundp 'line-number-at-pos) - (defun line-number-at-pos (&optional pos) - "Return (narrowed) buffer line number at position POS. - If POS is nil, use current buffer location." - (let ((opoint (or pos (point))) start) - (save-excursion - (goto-char (point-min)) - (setq start (point)) - (goto-char opoint) - (forward-line 0) - (1+ (count-lines start (point)))))) ) - +;; Facilities for regular expressions used everywhere + +;; The trailing numbers in the names give the number of referenceable regex +;; groups contained in the regex + +;; Used to be customizable but really is not customizable but fixed by the reST +;; syntax +(defconst rst-bullets + ;; Sorted so they can form a character class when concatenated + '(?- ?* ?+ ?\u2022 ?\u2023 ?\u2043) + "List of all possible bullet characters for bulleted lists.") + +(defconst rst-uri-schemes + '("acap" "cid" "data" "dav" "fax" "file" "ftp" "gopher" "http" "https" "imap" + "ldap" "mailto" "mid" "modem" "news" "nfs" "nntp" "pop" "prospero" "rtsp" + "service" "sip" "tel" "telnet" "tip" "urn" "vemmi" "wais") + "Supported URI schemes.") + +(defconst rst-adornment-chars + ;; Sorted so they can form a character class when concatenated + '(?\] + ?! ?\" ?# ?$ ?% ?& ?' ?\( ?\) ?* ?+ ?, ?. ?/ ?: ?\; ?< ?= ?> ?? ?@ ?\[ ?\\ + ?^ ?_ ?` ?{ ?| ?} ?~ + ?-) + "Characters which may be used in adornments for sections and transitions.") + +(defconst rst-max-inline-length + 1000 + "Maximum length of inline markup to recognize.") + +(defconst rst-re-alist-def + ;; `*-beg' matches * at the beginning of a line + ;; `*-end' matches * at the end of a line + ;; `*-prt' matches a part of * + ;; `*-tag' matches * + ;; `*-sta' matches the start of * which may be followed by respective content + ;; `*-pfx' matches the delimiter left of * + ;; `*-sfx' matches the delimiter right of * + ;; `*-hlp' helper for * + ;; + ;; A trailing number says how many referenceable groups are contained. + `( + + ;; Horizontal white space (`hws') + (hws-prt "[\t ]") + (hws-tag hws-prt "*") ; Optional sequence of horizontal white space + (hws-sta hws-prt "+") ; Mandatory sequence of horizontal white space + + ;; Lines (`lin') + (lin-beg "^" hws-tag) ; Beginning of a possibly indented line + (lin-end hws-tag "$") ; End of a line with optional trailing white space + (linemp-tag "^" hws-tag "$") ; Empty line with optional white space + + ;; Various tags and parts + (ell-tag "\\.\\.\\.") ; Ellipsis + (bul-tag ,(concat "[" rst-bullets "]")) ; A bullet + (ltr-tag "[a-zA-Z]") ; A letter enumerator tag + (num-prt "[0-9]") ; A number enumerator part + (num-tag num-prt "+") ; A number enumerator tag + (rom-prt "[IVXLCDMivxlcdm]") ; A roman enumerator part + (rom-tag rom-prt "+") ; A roman enumerator tag + (aut-tag "#") ; An automatic enumerator tag + (dcl-tag "::") ; Double colon + + ;; Block lead in (`bli') + (bli-sfx (:alt hws-sta "$")) ; Suffix of a block lead-in with *optional* + ; immediate content + + ;; Various starts + (bul-sta bul-tag bli-sfx) ; Start of a bulleted item + + ;; Explicit markup tag (`exm') + (exm-tag "\\.\\.") + (exm-sta exm-tag hws-sta) + (exm-beg lin-beg exm-sta) + + ;; Counters in enumerations (`cnt') + (cntany-tag (:alt ltr-tag num-tag rom-tag aut-tag)) ; An arbitrary counter + (cntexp-tag (:alt ltr-tag num-tag rom-tag)) ; An arbitrary explicit counter + + ;; Enumerator (`enm') + (enmany-tag (:alt + (:seq cntany-tag "\\.") + (:seq "(?" cntany-tag ")"))) ; An arbitrary enumerator + (enmexp-tag (:alt + (:seq cntexp-tag "\\.") + (:seq "(?" cntexp-tag ")"))) ; An arbitrary explicit + ; enumerator + (enmaut-tag (:alt + (:seq aut-tag "\\.") + (:seq "(?" aut-tag ")"))) ; An automatic enumerator + (enmany-sta enmany-tag bli-sfx) ; An arbitrary enumerator start + (enmexp-sta enmexp-tag bli-sfx) ; An arbitrary explicit enumerator start + (enmexp-beg lin-beg enmexp-sta) ; An arbitrary explicit enumerator start + ; at the beginning of a line + + ;; Items may be enumerated or bulleted (`itm') + (itmany-tag (:alt enmany-tag bul-tag)) ; An arbitrary item tag + (itmany-sta-1 (:grp itmany-tag) bli-sfx) ; An arbitrary item start, group + ; is the item tag + (itmany-beg-1 lin-beg itmany-sta-1) ; An arbitrary item start at the + ; beginning of a line, group is the + ; item tag + + ;; Inline markup (`ilm') + (ilm-pfx (:alt "^" hws-prt "[-'\"([{<\u2018\u201c\u00ab\u2019/:]")) + (ilm-sfx (:alt "$" hws-prt "[]-'\")}>\u2019\u201d\u00bb/:.,;!?\\]")) + + ;; Inline markup content (`ilc') + (ilcsgl-tag "\\S ") ; A single non-white character + (ilcast-prt (:alt "[^*\\]" "\\\\.")) ; Part of non-asterisk content + (ilcbkq-prt (:alt "[^`\\]" "\\\\.")) ; Part of non-backquote content + (ilcbkqdef-prt (:alt "[^`\\\n]" "\\\\.")) ; Part of non-backquote + ; definition + (ilcbar-prt (:alt "[^|\\]" "\\\\.")) ; Part of non-vertical-bar content + (ilcbardef-prt (:alt "[^|\\\n]" "\\\\.")) ; Part of non-vertical-bar + ; definition + (ilcast-sfx "[^\t *\\]") ; Suffix of non-asterisk content + (ilcbkq-sfx "[^\t `\\]") ; Suffix of non-backquote content + (ilcbar-sfx "[^\t |\\]") ; Suffix of non-vertical-bar content + (ilcrep-hlp ,(format "\\{0,%d\\}" rst-max-inline-length)) ; Repeat count + (ilcast-tag (:alt ilcsgl-tag + (:seq ilcsgl-tag + ilcast-prt ilcrep-hlp + ilcast-sfx))) ; Non-asterisk content + (ilcbkq-tag (:alt ilcsgl-tag + (:seq ilcsgl-tag + ilcbkq-prt ilcrep-hlp + ilcbkq-sfx))) ; Non-backquote content + (ilcbkqdef-tag (:alt ilcsgl-tag + (:seq ilcsgl-tag + ilcbkqdef-prt ilcrep-hlp + ilcbkq-sfx))) ; Non-backquote definition + (ilcbar-tag (:alt ilcsgl-tag + (:seq ilcsgl-tag + ilcbar-prt ilcrep-hlp + ilcbar-sfx))) ; Non-vertical-bar content + (ilcbardef-tag (:alt ilcsgl-tag + (:seq ilcsgl-tag + ilcbardef-prt ilcrep-hlp + ilcbar-sfx))) ; Non-vertical-bar definition + + ;; Fields (`fld') + (fldnam-prt (:alt "[^:\n]" "\\\\:")) ; Part of a field name + (fldnam-tag fldnam-prt "+") ; A field name + (fld-tag ":" fldnam-tag ":") ; A field marker + + ;; Options (`opt') + (optsta-tag (:alt "[-+/]" "--")) ; Start of an option + (optnam-tag "\\sw" (:alt "-" "\\sw") "*") ; Name of an option + (optarg-tag (:shy "[ =]\\S +")) ; Option argument + (optsep-tag (:shy "," hws-prt)) ; Separator between options + (opt-tag (:shy optsta-tag optnam-tag optarg-tag "?")) ; A complete option + + ;; Footnotes and citations (`fnc') + (fncnam-prt "[^\]\n]") ; Part of a footnote or citation name + (fncnam-tag fncnam-prt "+") ; A footnote or citation name + (fnc-tag "\\[" fncnam-tag "]") ; A complete footnote or citation tag + (fncdef-tag-2 (:grp exm-sta) + (:grp fnc-tag)) ; A complete footnote or citation definition + ; tag; first group is the explicit markup + ; start, second group is the footnote / + ; citation tag + (fnc-sta-2 fncdef-tag-2 bli-sfx) ; Start of a footnote or citation + ; definition; first group is the explicit + ; markup start, second group is the + ; footnote / citation tag + + ;; Substitutions (`sub') + (sub-tag "|" ilcbar-tag "|") ; A complete substitution tag + (subdef-tag "|" ilcbardef-tag "|") ; A complete substitution definition + ; tag + + ;; Symbol (`sym') + (sym-tag (:shy "\\sw+" (:shy "\\s_\\sw+") "*")) + + ;; URIs (`uri') + (uri-tag (:alt ,@rst-uri-schemes)) + + ;; Adornment (`ado') + (ado-prt "[" ,(concat rst-adornment-chars) "]") + (adorep3-hlp "\\{3,\\}") ; There must be at least 3 characters because + ; otherwise explicit markup start would be + ; recognized + (adorep2-hlp "\\{2,\\}") ; As `adorep3-hlp' but when the first of three + ; characters is matched differently + (ado-tag-1-1 (:grp ado-prt) + "\\1" adorep2-hlp) ; A complete adornment, group is the first + ; adornment character and MUST be the FIRST + ; group in the whole expression + (ado-tag-1-2 (:grp ado-prt) + "\\2" adorep2-hlp) ; A complete adornment, group is the first + ; adornment character and MUST be the + ; SECOND group in the whole expression + (ado-beg-2-1 "^" (:grp ado-tag-1-2) + lin-end) ; A complete adornment line; first group is the whole + ; adornment and MUST be the FIRST group in the whole + ; expression; second group is the first adornment + ; character + + ;; Titles (`ttl') + (ttl-tag "\\S *\\w\\S *") ; A title text + (ttl-beg lin-beg ttl-tag) ; A title text at the beginning of a line + + ;; Directives and substitution definitions (`dir') + (dir-tag-3 (:grp exm-sta) + (:grp (:shy subdef-tag hws-sta) "?") + (:grp sym-tag dcl-tag)) ; A directive or substitution definition + ; tag; first group is explicit markup + ; start, second group is a possibly + ; empty substitution tag, third group is + ; the directive tag including the double + ; colon + (dir-sta-3 dir-tag-3 bli-sfx) ; Start of a directive or substitution + ; definition; groups are as in dir-tag-3 + + ;; Literal block (`lit') + (lit-sta-2 (:grp (:alt "[^.\n]" "\\.[^.\n]") ".*") "?" + (:grp dcl-tag) "$") ; Start of a literal block; first group is + ; any text before the double colon tag which + ; may not exist, second group is the double + ; colon tag + + ;; Comments (`cmt') + (cmt-sta-1 (:grp exm-sta) "[^\[|_\n]" + (:alt "[^:\n]" (:seq ":" (:alt "[^:\n]" "$"))) + "*$") ; Start of a comment block; first group is explicit markup + ; start + + ;; Paragraphs (`par') + (par-tag- (:alt itmany-tag fld-tag opt-tag fncdef-tag-2 dir-tag-3 exm-tag) + ) ; Tag at the beginning of a paragraph; there may be groups in + ; certain cases + ) + "Definition alist of relevant regexes. +Each entry consists of the symbol naming the regex and an +argument list for `rst-re'.") + +;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel +(defun rst-re (&rest args) + "Interpret ARGS as regular expressions and return a regex string. +Each element of ARGS may be one of the following: + +A string which is inserted unchanged. + +A character which is resolved to a quoted regex. + +A symbol which is resolved to a string using `rst-re-alist-def'. + +A list with a keyword in the car. Each element of the cdr of such +a list is recursively interpreted as ARGS. The results of this +interpretation are concatenated according to the keyword. + +For the keyword `:seq' the results are simply concatenated. + +For the keyword `:shy' the results are concatenated and +surrounded by a shy-group (\"\\(?:...\\)\"). + +For the keyword `:alt' the results form an alternative (\"\\|\") +which is shy-grouped (\"\\(?:...\\)\"). + +For the keyword `:grp' the results are concatenated and form a +referencable grouped (\"\\(...\\)\"). + +After interpretation of ARGS the results are concatenated as for +`:seq'. +" + (apply 'concat + (mapcar + (lambda (re) + (cond + ((stringp re) + re) + ((symbolp re) + (cadr (assoc re rst-re-alist))) + ((char-valid-p re) + (regexp-quote (char-to-string re))) + ((listp re) + (let ((nested + (mapcar (lambda (elt) + (rst-re elt)) + (cdr re)))) + (cond + ((eq (car re) :seq) + (mapconcat 'identity nested "")) + ((eq (car re) :shy) + (concat "\\(?:" (mapconcat 'identity nested "") "\\)")) + ((eq (car re) :grp) + (concat "\\(" (mapconcat 'identity nested "") "\\)")) + ((eq (car re) :alt) + (concat "\\(?:" (mapconcat 'identity nested "\\|") "\\)")) + (t + (error "Unknown list car: %s" (car re)))))) + (t + (error "Unknown object type for building regex: %s" re)))) + args))) + +(defconst rst-re-alist + ;; Shadow global value we are just defining so we can construct it step by + ;; step + (let (rst-re-alist) + (dolist (re rst-re-alist-def) + (setq rst-re-alist + (nconc rst-re-alist + (list (list (car re) (apply 'rst-re (cdr re))))))) + rst-re-alist) + "Alist mapping symbols from `rst-re-alist-def' to regex strings.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Mode definition. +(defvar rst-deprecated-keys nil + "Alist mapping deprecated keys to the new key to use and the definition.") + +(require 'edmacro) + +(defun rst-call-deprecated () + (interactive) + (let* ((dep-key (this-command-keys-vector)) + (dep-key-s (format-kbd-macro dep-key)) + (fnd (assoc dep-key rst-deprecated-keys))) + (if (not fnd) + ;; Exact key sequence not found. Maybe a deprecated key sequence has + ;; been followed by another key. + (let* ((dep-key-pfx (butlast (append dep-key nil) 1)) + (dep-key-def (vconcat dep-key-pfx '(t))) + (fnd-def (assoc dep-key-def rst-deprecated-keys))) + (if (not fnd-def) + (error "Unknown deprecated key sequence %s" dep-key-s) + ;; Don't execute the command in this case + (message "[Deprecated use of key %s; use key %s instead]" + (format-kbd-macro dep-key-pfx) + (format-kbd-macro (second fnd-def))))) + (message "[Deprecated use of key %s; use key %s instead]" + dep-key-s (format-kbd-macro (second fnd))) + (call-interactively (third fnd))))) + +(defun rst-define-key (keymap key def &rest deprecated) + "Bind like `define-key' using DEPRECATED as deprecated key definitions. +DEPRECATED key definitions should be in vector notation. These +are defined as well but give an additional message." + (define-key keymap key def) + (dolist (dep-key deprecated) + (push (list dep-key key def) rst-deprecated-keys) + (define-key keymap dep-key 'rst-call-deprecated))) + ;; Key bindings. (defvar rst-mode-map (let ((map (make-sparse-keymap))) - ;; - ;; Section Decorations. - ;; - ;; The adjustment function that decorates or rotates a section title. - (define-key map [(control c) (control a)] 'rst-adjust) - (define-key map [(control c) (control ?=)] 'rst-adjust) - (define-key map [(control ?=)] 'rst-adjust) ;; (Does not work on the Mac OSX.) - ;; Display the hierarchy of decorations implied by the current document contents. - (define-key map [(control c) (control h)] 'rst-display-decorations-hierarchy) - ;; Homogenize the decorations in the document. - (define-key map [(control c) (control s)] 'rst-straighten-decorations) -;; (define-key map [(control c) (control s)] 'rst-straighten-deco-spacing) + ;; \C-c is the general keymap + (rst-define-key map [?\C-c ?\C-h] 'describe-prefix-bindings) + + ;; + ;; Section Adornments. + ;; + ;; The adjustment function that adorns or rotates a section title. + (rst-define-key map [?\C-c ?\C-=] 'rst-adjust [?\C-c ?\C-a t]) + (rst-define-key map [?\C-=] 'rst-adjust) ; (Does not work on the Mac OSX.) + + ;; \C-c \C-a is the keymap for adornments + (rst-define-key map [?\C-c ?\C-a ?\C-h] 'describe-prefix-bindings) + ;; Display the hierarchy of adornments implied by the current document contents. + (rst-define-key map [?\C-c ?\C-a ?\C-d] 'rst-display-adornments-hierarchy) + ;; Homogenize the adornments in the document. + (rst-define-key map [?\C-c ?\C-a ?\C-s] 'rst-straighten-adornments + [?\C-c ?\C-s]) ;; ;; Section Movement and Selection. ;; ;; Mark the subsection where the cursor is. - (define-key map [(control c) (control m)] 'rst-mark-section) + (rst-define-key map [?\C-\M-h] 'rst-mark-section + ;; same as mark-defun sgml-mark-current-element + [?\C-c ?\C-m]) ;; Move forward/backward between section titles. - (define-key map [(control c) (control n)] 'rst-forward-section) - (define-key map [(control c) (control p)] 'rst-backward-section) - - ;; - ;; Operating on Blocks of Text. - ;; + (rst-define-key map [?\C-\M-a] 'rst-forward-section + ;; same as beginning-of-defun + [?\C-c ?\C-n]) + (rst-define-key map [?\C-\M-e] 'rst-backward-section + ;; same as end-of-defun + [?\C-c ?\C-p]) + + ;; + ;; Operating on regions. + ;; + ;; \C-c \C-r is the keymap for regions + (rst-define-key map [?\C-c ?\C-r ?\C-h] 'describe-prefix-bindings) + ;; Makes region a line-block. + (rst-define-key map [?\C-c ?\C-r ?\C-l] 'rst-line-block-region + [?\C-c ?\C-d]) + ;; Shift region left or right according to tabs + (rst-define-key map [?\C-c ?\C-r tab] 'rst-shift-region + [?\C-c ?\C-r t] [?\C-c ?\C-l t]) + + ;; + ;; Operating on lists. + ;; + ;; \C-c \C-l is the keymap for lists + (rst-define-key map [?\C-c ?\C-l ?\C-h] 'describe-prefix-bindings) ;; Makes paragraphs in region as a bullet list. - (define-key map [(control c) (control b)] 'rst-bullet-list-region) + (rst-define-key map [?\C-c ?\C-l ?\C-b] 'rst-bullet-list-region + [?\C-c ?\C-b]) ;; Makes paragraphs in region as a enumeration. - (define-key map [(control c) (control e)] 'rst-enumerate-region) + (rst-define-key map [?\C-c ?\C-l ?\C-e] 'rst-enumerate-region + [?\C-c ?\C-e]) ;; Converts bullets to an enumeration. - (define-key map [(control c) (control v)] 'rst-convert-bullets-to-enumeration) - ;; Makes region a line-block. - (define-key map [(control c) (control d)] 'rst-line-block-region) + (rst-define-key map [?\C-c ?\C-l ?\C-c] 'rst-convert-bullets-to-enumeration + [?\C-c ?\C-v]) ;; Make sure that all the bullets in the region are consistent. - (define-key map [(control c) (control w)] 'rst-straighten-bullets-region) - ;; Shift region left or right (taking into account of enumerations/bullets, etc.). - (define-key map [(control c) (control l)] 'rst-shift-region-left) - (define-key map [(control c) (control r)] 'rst-shift-region-right) - ;; Comment/uncomment the active region. - (define-key map [(control c) (control c)] 'comment-region) + (rst-define-key map [?\C-c ?\C-l ?\C-s] 'rst-straighten-bullets-region + [?\C-c ?\C-w]) + ;; Insert a list item + (rst-define-key map [?\C-c ?\C-l ?\C-i] 'rst-insert-list) ;; ;; Table-of-Contents Features. ;; + ;; \C-c \C-t is the keymap for table of contents + (rst-define-key map [?\C-c ?\C-t ?\C-h] 'describe-prefix-bindings) ;; Enter a TOC buffer to view and move to a specific section. - (define-key map [(control c) (control t)] 'rst-toc) + (rst-define-key map [?\C-c ?\C-t ?\C-t] 'rst-toc) ;; Insert a TOC here. - (define-key map [(control c) (control i)] 'rst-toc-insert) + (rst-define-key map [?\C-c ?\C-t ?\C-i] 'rst-toc-insert + [?\C-c ?\C-i]) ;; Update the document's TOC (without changing the cursor position). - (define-key map [(control c) (control u)] 'rst-toc-update) + (rst-define-key map [?\C-c ?\C-t ?\C-u] 'rst-toc-update + [?\C-c ?\C-u]) ;; Got to the section under the cursor (cursor must be in TOC). - (define-key map [(control c) (control f)] 'rst-goto-section) + (rst-define-key map [?\C-c ?\C-t ?\C-j] 'rst-goto-section + [?\C-c ?\C-f]) ;; ;; Converting Documents from Emacs. ;; + ;; \C-c \C-c is the keymap for compilation + (rst-define-key map [?\C-c ?\C-c ?\C-h] 'describe-prefix-bindings) ;; Run one of two pre-configured toolset commands on the document. - (define-key map [(control c) (?1)] 'rst-compile) - (define-key map [(control c) (?2)] 'rst-compile-alt-toolset) + (rst-define-key map [?\C-c ?\C-c ?\C-c] 'rst-compile + [?\C-c ?1]) + (rst-define-key map [?\C-c ?\C-c ?\C-a] 'rst-compile-alt-toolset + [?\C-c ?2]) ;; Convert the active region to pseudo-xml using the docutils tools. - (define-key map [(control c) (?3)] 'rst-compile-pseudo-region) + (rst-define-key map [?\C-c ?\C-c ?\C-x] 'rst-compile-pseudo-region + [?\C-c ?3]) ;; Convert the current document to PDF and launch a viewer on the results. - (define-key map [(control c) (?4)] 'rst-compile-pdf-preview) + (rst-define-key map [?\C-c ?\C-c ?\C-p] 'rst-compile-pdf-preview + [?\C-c ?4]) ;; Convert the current document to S5 slides and view in a web browser. - (define-key map [(control c) (?5)] 'rst-compile-slides-preview) + (rst-define-key map [?\C-c ?\C-c ?\C-s] 'rst-compile-slides-preview + [?\C-c ?5]) map) "Keymap for reStructuredText mode commands. @@ -307,7 +644,7 @@ ;; Abbrevs. (defvar rst-mode-abbrev-table nil - "Abbrev table used while in Rst mode.") + "Abbrev table used while in `rst-mode'.") (define-abbrev-table 'rst-mode-abbrev-table (mapcar (lambda (x) (append x '(nil 0 system))) '(("contents" ".. contents::\n..\n ") @@ -328,38 +665,34 @@ (modify-syntax-entry ?& "." st) (modify-syntax-entry ?' "." st) (modify-syntax-entry ?* "." st) - (modify-syntax-entry ?+ "." st) + (modify-syntax-entry ?+ "_" st) (modify-syntax-entry ?. "_" st) (modify-syntax-entry ?/ "." st) + (modify-syntax-entry ?: "_" st) (modify-syntax-entry ?< "." st) (modify-syntax-entry ?= "." st) (modify-syntax-entry ?> "." st) (modify-syntax-entry ?\\ "\\" st) (modify-syntax-entry ?| "." st) - (modify-syntax-entry ?_ "." st) + (modify-syntax-entry ?_ "_" st) + (modify-syntax-entry ?\u00ab "." st) + (modify-syntax-entry ?\u00bb "." st) + (modify-syntax-entry ?\u2018 "." st) + (modify-syntax-entry ?\u2019 "." st) + (modify-syntax-entry ?\u201c "." st) + (modify-syntax-entry ?\u201d "." st) st) "Syntax table used while in `rst-mode'.") (defcustom rst-mode-hook nil - "Hook run when Rst mode is turned on. -The hook for Text mode is run before this one." + "Hook run when `rst-mode' is turned on. +The hook for `text-mode' is run before this one." :group 'rst :type '(hook)) -(defcustom rst-mode-lazy t - "If non-nil Rst mode tries to font-lock multi-line elements correctly. -Because this is really slow it should be set to nil if neither `jit-lock-mode' -not `lazy-lock-mode' and activated. - -If nil, comments and literal blocks are font-locked only on the line they start. - -The value of this variable is used when Rst mode is turned on." - :group 'rst - :type '(boolean)) - ;; Use rst-mode for *.rst and *.rest files. Many ReStructured-Text files ;; use *.txt, but this is too generic to be set as a default. ;;;###autoload (add-to-list 'auto-mode-alist (purecopy '("\\.re?st\\'" . rst-mode))) @@ -367,78 +700,74 @@ (define-derived-mode rst-mode text-mode "ReST" "Major mode for editing reStructuredText documents. \\ -There are a number of convenient keybindings provided by -Rst mode. The main one is \\[rst-adjust], it updates or rotates -the section title around point or promotes/demotes the -decorations within the region (see full details below). -Use negative prefix arg to rotate in the other direction. Turning on `rst-mode' calls the normal hooks `text-mode-hook' and `rst-mode-hook'. This mode also supports font-lock -highlighting. You may customize `rst-mode-lazy' to toggle -font-locking of blocks. +highlighting. \\{rst-mode-map}" :abbrev-table rst-mode-abbrev-table :syntax-table rst-mode-syntax-table :group 'rst - (set (make-local-variable 'paragraph-separate) paragraph-start) - (set (make-local-variable 'indent-line-function) 'indent-relative-maybe) + ;; Paragraph recognition + (set (make-local-variable 'paragraph-separate) + (rst-re '(:alt + "\f" + lin-end))) (set (make-local-variable 'paragraph-start) - "\f\\|>*[ \t]*$\\|>*[ \t]*[-+*] \\|>*[ \t]*[0-9#]+\\. ") + (rst-re '(:alt + "\f" + lin-end + (:seq hws-tag par-tag- bli-sfx)))) + + ;; Indenting and filling + (set (make-local-variable 'indent-line-function) 'rst-indent-line) (set (make-local-variable 'adaptive-fill-mode) t) - - ;; FIXME: No need to reset this. - ;; (set (make-local-variable 'indent-line-function) 'indent-relative) - - ;; The details of the following comment setup is important because it affects - ;; auto-fill, and it is pretty common in running text to have an ellipsis - ;; ("...") which trips because of the rest comment syntax (".. "). + (set (make-local-variable 'adaptive-fill-regexp) + (rst-re 'hws-tag 'par-tag- "?" 'hws-tag)) + (set (make-local-variable 'adaptive-fill-function) 'rst-adaptive-fill) + (set (make-local-variable 'fill-paragraph-handle-comment) nil) + + ;; Comments (set (make-local-variable 'comment-start) ".. ") - (set (make-local-variable 'comment-start-skip) "^\\.\\. ") - (set (make-local-variable 'comment-multi-line) nil) + (set (make-local-variable 'comment-start-skip) + (rst-re 'lin-beg 'exm-tag 'bli-sfx)) + (set (make-local-variable 'comment-continue) " ") + (set (make-local-variable 'comment-multi-line) t) + (set (make-local-variable 'comment-use-syntax) nil) + ;; reStructuredText has not really a comment ender but nil is not really a + ;; permissible value + (set (make-local-variable 'comment-end) "") + (set (make-local-variable 'comment-end-skip) nil) - ;; Special variables - (make-local-variable 'rst-adornment-level-alist) + (set (make-local-variable 'comment-line-break-function) + 'rst-comment-line-break) + (set (make-local-variable 'comment-indent-function) + 'rst-comment-indent) + (set (make-local-variable 'comment-insert-comment-function) + 'rst-comment-insert-comment) + (set (make-local-variable 'comment-region-function) + 'rst-comment-region) + (set (make-local-variable 'uncomment-region-function) + 'rst-uncomment-region) ;; Font lock - (set (make-local-variable 'font-lock-defaults) - '(rst-font-lock-keywords-function - t nil nil nil - (font-lock-mark-block-function . mark-paragraph))) - ;; `jit-lock-mode' has been the default since Emacs-21.1, so there's no - ;; point messing around with font-lock-support-mode any more. - ;; (when (boundp 'font-lock-support-mode) - ;; ;; rst-mode has its own mind about font-lock-support-mode - ;; (make-local-variable 'font-lock-support-mode) - ;; ;; jit-lock-mode replaced lazy-lock-mode in GNU Emacs 21. - ;; (let ((jit-or-lazy-lock-mode - ;; (cond - ;; ((fboundp 'lazy-lock-mode) 'lazy-lock-mode) - ;; ((fboundp 'jit-lock-mode) 'jit-lock-mode) - ;; ;; if neither lazy-lock nor jit-lock is supported, - ;; ;; tell user and disable rst-mode-lazy - ;; (t (when rst-mode-lazy - ;; (message "Disabled lazy fontification, because no known support mode found.") - ;; (setq rst-mode-lazy nil)))))) - ;; (cond - ;; ((and (not rst-mode-lazy) (not font-lock-support-mode))) - ;; ;; No support mode set and none required - leave it alone - ;; ((or (not font-lock-support-mode) ;; No support mode set (but required) - ;; (symbolp font-lock-support-mode)) ;; or a fixed mode for all - ;; (setq font-lock-support-mode - ;; (list (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode)) - ;; (cons t font-lock-support-mode)))) - ;; ((and (listp font-lock-support-mode) - ;; (not (assoc 'rst-mode font-lock-support-mode))) - ;; ;; A list of modes missing rst-mode - ;; (setq font-lock-support-mode - ;; (cons (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode)) - ;; font-lock-support-mode)))))) - - ) - + (setq font-lock-defaults + '(rst-font-lock-keywords + t nil nil nil + (font-lock-multiline . t) + (font-lock-mark-block-function . mark-paragraph) + ;; rst-mode does not need font-lock-support-mode because it's fast + ;; enough. In fact using `jit-lock-mode` slows things down + ;; considerably even if `rst-font-lock-extend-region` is in place and + ;; compiled. + ;;(font-lock-support-mode . nil) + )) + (add-hook 'font-lock-extend-region-functions 'rst-font-lock-extend-region t) + + ;; Text after a changed line may need new fontification + (set (make-local-variable 'jit-lock-contextually) t)) ;;;###autoload (define-minor-mode rst-minor-mode @@ -462,31 +791,19 @@ ;; :abbrev-table rst-mode-abbrev-table ;; :syntax-table rst-mode-syntax-table - - - - -;; Bulleted item lists. -(defcustom rst-bullets - '(?- ?* ?+) - "List of all possible bullet characters for bulleted lists." - :group 'rst) - - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Section Decoration Adjustment -;; ============================= +;; Section Adornment Adjustment +;; ============================ ;; ;; The following functions implement a smart automatic title sectioning feature. ;; The idea is that with the cursor sitting on a section title, we try to get as ;; much information from context and try to do the best thing automatically. ;; This function can be invoked many times and/or with prefix argument to rotate -;; between the various sectioning decorations. +;; between the various sectioning adornments. ;; ;; Definitions: the two forms of sectioning define semantically separate section -;; levels. A sectioning DECORATION consists in: +;; levels. A sectioning ADORNMENT consists in: ;; ;; - a CHARACTER ;; @@ -496,10 +813,7 @@ ;; how many characters and over-and-under style is hanging outside of the ;; title at the beginning and ending. ;; -;; Important note: an existing decoration must be formed by at least two -;; characters to be recognized. -;; -;; Here are two examples of decorations (| represents the window border, column +;; Here are two examples of adornments (| represents the window border, column ;; 0): ;; ;; | @@ -516,17 +830,15 @@ ;; - The underlining character that is used depends on context. The file is ;; scanned to find other sections and an appropriate character is selected. ;; If the function is invoked on a section that is complete, the character is -;; rotated among the existing section decorations. +;; rotated among the existing section adornments. ;; ;; Note that when rotating the characters, if we come to the end of the -;; hierarchy of decorations, the variable rst-preferred-decorations is -;; consulted to propose a new underline decoration, and if continued, we cycle -;; the decorations all over again. Set this variable to nil if you want to -;; limit the underlining character propositions to the existing decorations in +;; hierarchy of adornments, the variable rst-preferred-adornments is +;; consulted to propose a new underline adornment, and if continued, we cycle +;; the adornments all over again. Set this variable to nil if you want to +;; limit the underlining character propositions to the existing adornments in ;; the file. ;; -;; - A prefix argument can be used to alternate the style. -;; ;; - An underline/overline that is not extended to the column at which it should ;; be hanging is dubbed INCOMPLETE. For example:: ;; @@ -547,128 +859,108 @@ ;; ;; In over-and-under style, when alternating the style, a variable is ;; available to select how much default indent to use (it can be zero). Note -;; that if the current section decoration already has an indent, we don't +;; that if the current section adornment already has an indent, we don't ;; adjust it to the default, we rather use the current indent that is already ;; there for adjustment (unless we cycle, in which case we use the indent ;; that has been found previously). (defgroup rst-adjust nil - "Settings for adjustment and cycling of section title decorations." + "Settings for adjustment and cycling of section title adornments." :group 'rst :version "21.1") -(defcustom rst-preferred-decorations '( (?= over-and-under 1) - (?= simple 0) - (?- simple 0) - (?~ simple 0) - (?+ simple 0) - (?` simple 0) - (?# simple 0) - (?@ simple 0) ) - "Preferred ordering of section title decorations. - -This sequence is consulted to offer a new decoration suggestion +(define-obsolete-variable-alias + 'rst-preferred-decorations 'rst-preferred-adornments "r6506") +(defcustom rst-preferred-adornments '((?= over-and-under 1) + (?= simple 0) + (?- simple 0) + (?~ simple 0) + (?+ simple 0) + (?` simple 0) + (?# simple 0) + (?@ simple 0)) + "Preferred hierarchy of section title adornments. + +A list consisting of lists of the form (CHARACTER STYLE INDENT). +CHARACTER is the character used. STYLE is one of the symbols +OVER-AND-UNDER or SIMPLE. INDENT is an integer giving the wanted +indentation for STYLE OVER-AND-UNDER. CHARACTER and STYLE are +always used when a section adornment is described. In other +places t instead of a list stands for a transition. + +This sequence is consulted to offer a new adornment suggestion when we rotate the underlines at the end of the existing hierarchy of characters, or when there is no existing section -title in the file." - :group 'rst-adjust) +title in the file. +Set this to an empty list to use only the adornment found in the +file." + :group 'rst-adjust + :type `(repeat + (group :tag "Adornment specification" + (choice :tag "Adornment character" + ,@(mapcar (lambda (char) + (list 'const + :tag (char-to-string char) char)) + rst-adornment-chars)) + (radio :tag "Adornment type" + (const :tag "Overline and underline" over-and-under) + (const :tag "Underline only" simple)) + (integer :tag "Indentation for overline and underline type" + :value 0)))) (defcustom rst-default-indent 1 "Number of characters to indent the section title. -This is used for when toggling decoration styles, when switching -from a simple decoration style to a over-and-under decoration +This is used for when toggling adornment styles, when switching +from a simple adornment style to a over-and-under adornment style." - :group 'rst-adjust) - - -(defvar rst-section-text-regexp "^[ \t]*\\S-*\\w\\S-*" - "Regular expression for valid section title text.") - - -(defun rst-line-homogeneous-p (&optional accept-special) - "Return true if the line is homogeneous. - -Predicate that returns the unique char if the current line is -composed only of a single repeated non-whitespace character. -This returns the char even if there is whitespace at the -beginning of the line. - -If ACCEPT-SPECIAL is specified we do not ignore special sequences -which normally we would ignore when doing a search on many lines. -For example, normally we have cases to ignore commonly occurring -patterns, such as :: or ...; with the flag do not ignore them." - (save-excursion - (back-to-indentation) - (unless (looking-at "\n") - (let ((c (thing-at-point 'char))) - (if (and (looking-at (format "[%s]+[ \t]*$" c)) - (or accept-special - (and - ;; Common patterns. - (not (looking-at "::[ \t]*$")) - (not (looking-at "\\.\\.\\.[ \t]*$")) - ;; Discard one char line - (not (looking-at ".[ \t]*$")) - ))) - (string-to-char c)) - )) - )) - -(defun rst-line-homogeneous-nodent-p (&optional accept-special) - "Return true if the line is homogeneous with no indent. -See `rst-line-homogeneous-p' about ACCEPT-SPECIAL." - (save-excursion - (beginning-of-line) - (if (looking-at "^[ \t]+") - nil - (rst-line-homogeneous-p accept-special) - ))) - - -(defun rst-compare-decorations (deco1 deco2) - "Compare decorations. -Return true if both DECO1 and DECO2 decorations are equal, + :group 'rst-adjust + :type '(integer)) + + +(defun rst-compare-adornments (ado1 ado2) + "Compare adornments. +Return true if both ADO1 and ADO2 adornments are equal, according to restructured text semantics (only the character and the style are compared, the indentation does not matter)." - (and (eq (car deco1) (car deco2)) - (eq (cadr deco1) (cadr deco2)))) - - -(defun rst-get-decoration-match (hier deco) - "Return the index (level) in hierarchy HIER of decoration DECO. + (and (eq (car ado1) (car ado2)) + (eq (cadr ado1) (cadr ado2)))) + + +(defun rst-get-adornment-match (hier ado) + "Return the index (level) in hierarchy HIER of adornment ADO. This basically just searches for the item using the appropriate comparison and returns the index. Return nil if the item is not found." (let ((cur hier)) - (while (and cur (not (rst-compare-decorations (car cur) deco))) + (while (and cur (not (rst-compare-adornments (car cur) ado))) (setq cur (cdr cur))) cur)) -(defun rst-suggest-new-decoration (alldecos &optional prev) - "Suggest a new, different decoration from all that have been seen. +(defun rst-suggest-new-adornment (allados &optional prev) + "Suggest a new, different adornment from all that have been seen. -ALLDECOS is the set of all decorations, including the line numbers. -PREV is the optional previous decoration, in order to suggest a +ALLADOS is the set of all adornments, including the line numbers. +PREV is the optional previous adornment, in order to suggest a better match." - ;; For all the preferred decorations... + ;; For all the preferred adornments... (let* ( ;; If 'prev' is given, reorder the list to start searching after the ;; match. (fplist - (cdr (rst-get-decoration-match rst-preferred-decorations prev))) + (cdr (rst-get-adornment-match rst-preferred-adornments prev))) ;; List of candidates to search. - (curpotential (append fplist rst-preferred-decorations))) + (curpotential (append fplist rst-preferred-adornments))) (while - ;; For all the decorations... - (let ((cur alldecos) + ;; For all the adornments... + (let ((cur allados) found) (while (and cur (not found)) - (if (rst-compare-decorations (car cur) (car curpotential)) + (if (rst-compare-adornments (car cur) (car curpotential)) ;; Found it! (setq found (car curpotential)) (setq cur (cdr cur)))) @@ -684,7 +976,7 @@ (line-beginning-position 2))) (defun rst-update-section (char style &optional indent) - "Unconditionally update the style of a section decoration. + "Unconditionally update the style of a section adornment. Do this using the given character CHAR, with STYLE 'simple or 'over-and-under, and with indent INDENT. If the STYLE @@ -692,11 +984,9 @@ is always assumed to be 0). If there are existing overline and/or underline from the -existing decoration, they are removed before adding the -requested decoration." - - (interactive) - (end-of-line) +existing adornment, they are removed before adding the +requested adornment." + (end-of-line) (let ((marker (point-marker)) len) @@ -713,21 +1003,20 @@ ;; Set the current column, we're at the end of the title line (setq len (+ (current-column) indent)) - ;; Remove previous line if it consists only of a single repeated character + ;; Remove previous line if it is an adornment (save-excursion (forward-line -1) - (and (rst-line-homogeneous-p 1) - ;; Avoid removing the underline of a title right above us. - (save-excursion (forward-line -1) - (not (looking-at rst-section-text-regexp))) - (rst-delete-entire-line))) + (if (and (looking-at (rst-re 'ado-beg-2-1)) + ;; Avoid removing the underline of a title right above us. + (save-excursion (forward-line -1) + (not (looking-at (rst-re 'ttl-beg))))) + (rst-delete-entire-line))) - ;; Remove following line if it consists only of a single repeated - ;; character + ;; Remove following line if it is an adornment (save-excursion (forward-line +1) - (and (rst-line-homogeneous-p 1) - (rst-delete-entire-line)) + (if (looking-at (rst-re 'ado-beg-2-1)) + (rst-delete-entire-line)) ;; Add a newline if we're at the end of the buffer, for the subsequence ;; inserting of the underline (if (= (point) (buffer-end 1)) @@ -749,186 +1038,277 @@ (goto-char marker) )) - -(defun rst-normalize-cursor-position () - "Normalize the cursor position. -If the cursor is on a decoration line or an empty line , place it -on the section title line (at the end). Returns the line offset -by which the cursor was moved. This works both over or under a -line." - (if (save-excursion (beginning-of-line) - (or (rst-line-homogeneous-p 1) - (looking-at "^[ \t]*$"))) - (progn - (beginning-of-line) - (cond - ((save-excursion (forward-line -1) - (beginning-of-line) - (and (looking-at rst-section-text-regexp) - (not (rst-line-homogeneous-p 1)))) - (progn (forward-line -1) -1)) - ((save-excursion (forward-line +1) - (beginning-of-line) - (and (looking-at rst-section-text-regexp) - (not (rst-line-homogeneous-p 1)))) - (progn (forward-line +1) +1)) - (t 0))) - 0 )) - - -(defun rst-find-all-decorations () - "Find all the decorations in the file. -Return a list of (line, decoration) pairs. Each decoration -consists in a (char, style, indent) triple. - -This function does not detect the hierarchy of decorations, it -just finds all of them in a file. You can then invoke another -function to remove redundancies and inconsistencies." - - (let ((positions ()) - (curline 1)) - ;; Iterate over all the section titles/decorations in the file. - (save-excursion - (goto-char (point-min)) - (while (< (point) (buffer-end 1)) - (if (rst-line-homogeneous-nodent-p) - (progn - (setq curline (+ curline (rst-normalize-cursor-position))) - - ;; Here we have found a potential site for a decoration, - ;; characterize it. - (let ((deco (rst-get-decoration))) - (if (cadr deco) ;; Style is existing. - ;; Found a real decoration site. - (progn - (push (cons curline deco) positions) - ;; Push beyond the underline. - (forward-line 1) - (setq curline (+ curline 1)) - ))) - )) - (forward-line 1) - (setq curline (+ curline 1)) - )) - (reverse positions))) - - -(defun rst-infer-hierarchy (decorations) - "Build a hierarchy of decorations using the list of given DECORATIONS. - -This function expects a list of (char, style, indent) decoration +(defun rst-classify-adornment (adornment end) + "Classify adornment for section titles and transitions. +ADORNMENT is the complete adornment string as found in the buffer +with optional trailing whitespace. END is the point after the +last character of ADORNMENT. + +Return a list. The first entry is t for a transition or a +cons (CHARACTER . STYLE). Check `rst-preferred-adornments' for +the meaning of CHARACTER and STYLE. + +The remaining list forms four match groups as returned by +`match-data'. Match group 0 matches the whole construct. Match +group 1 matches the overline adornment if present. Match group 2 +matches the section title text or the transition. Match group 3 +matches the underline adornment. + +Return nil if no syntactically valid adornment is found." + (save-excursion + (save-match-data + (when (string-match (rst-re 'ado-beg-2-1) adornment) + (goto-char end) + (let* ((ado-ch (string-to-char (match-string 2 adornment))) + (ado-re (rst-re ado-ch 'adorep3-hlp)) + (end-pnt (point)) + (beg-pnt (progn + (forward-line 0) + (point))) + (nxt-emp ; Next line inexistant or empty + (save-excursion + (or (not (zerop (forward-line 1))) + (looking-at (rst-re 'lin-end))))) + (prv-emp ; Previous line inexistant or empty + (save-excursion + (or (not (zerop (forward-line -1))) + (looking-at (rst-re 'lin-end))))) + (ttl-blw ; Title found below starting here + (save-excursion + (and + (zerop (forward-line 1)) + (looking-at (rst-re 'ttl-beg)) + (point)))) + (ttl-abv ; Title found above starting here + (save-excursion + (and + (zerop (forward-line -1)) + (looking-at (rst-re 'ttl-beg)) + (point)))) + (und-fnd ; Matching underline found starting here + (save-excursion + (and ttl-blw + (zerop (forward-line 2)) + (looking-at (rst-re ado-re 'lin-end)) + (point)))) + (ovr-fnd ; Matching overline found starting here + (save-excursion + (and ttl-abv + (zerop (forward-line -2)) + (looking-at (rst-re ado-re 'lin-end)) + (point)))) + key beg-ovr end-ovr beg-txt end-txt beg-und end-und) + (cond + ((and nxt-emp prv-emp) + ;; A transition + (setq key t + beg-txt beg-pnt + end-txt end-pnt)) + ((or und-fnd ovr-fnd) + ;; An overline with an underline + (setq key (cons ado-ch 'over-and-under)) + (let (;; Prefer overline match over underline match + (und-pnt (if ovr-fnd beg-pnt und-fnd)) + (ovr-pnt (if ovr-fnd ovr-fnd beg-pnt)) + (txt-pnt (if ovr-fnd ttl-abv ttl-blw))) + (goto-char ovr-pnt) + (setq beg-ovr (point) + end-ovr (line-end-position)) + (goto-char txt-pnt) + (setq beg-txt (point) + end-txt (line-end-position)) + (goto-char und-pnt) + (setq beg-und (point) + end-und (line-end-position)))) + (ttl-abv + ;; An underline + (setq key (cons ado-ch 'simple) + beg-und beg-pnt + end-und end-pnt) + (goto-char ttl-abv) + (setq beg-txt (point) + end-txt (line-end-position))) + (t + ;; Invalid adornment + (setq key nil))) + (if key + (list key + (or beg-ovr beg-txt beg-und) + (or end-und end-txt end-ovr) + beg-ovr end-ovr beg-txt end-txt beg-und end-und))))))) + +(defun rst-find-title-line () + "Find a section title line around point and return its characteristics. +If the point is on an adornment line find the respective title +line. If the point is on an empty line check previous or next +line whether it is a suitable title line and use it if so. If +point is on a suitable title line use it. + +If no title line is found return nil. + +Otherwise return as `rst-classify-adornment' does. However, if +the title line has no syntactically valid adornment STYLE is nil +in the first element. If there is no adornment around the title +CHARACTER is also nil and match groups for overline and underline +are nil." + (save-excursion + (forward-line 0) + (let ((orig-pnt (point)) + (orig-end (line-end-position))) + (cond + ((looking-at (rst-re 'ado-beg-2-1)) + (let ((char (string-to-char (match-string-no-properties 2))) + (r (rst-classify-adornment (match-string-no-properties 0) + (match-end 0)))) + (cond + ((not r) + ;; Invalid adornment - check whether this is an incomplete overline + (if (and + (zerop (forward-line 1)) + (looking-at (rst-re 'ttl-beg))) + (list (cons char nil) orig-pnt (line-end-position) + orig-pnt orig-end (point) (line-end-position) nil nil))) + ((consp (car r)) + ;; A section title - not a transition + r)))) + ((looking-at (rst-re 'lin-end)) + (or + (save-excursion + (if (and (zerop (forward-line -1)) + (looking-at (rst-re 'ttl-beg))) + (list (cons nil nil) (point) (line-end-position) + nil nil (point) (line-end-position) nil nil))) + (save-excursion + (if (and (zerop (forward-line 1)) + (looking-at (rst-re 'ttl-beg))) + (list (cons nil nil) (point) (line-end-position) + nil nil (point) (line-end-position) nil nil))))) + ((looking-at (rst-re 'ttl-beg)) + ;; Try to use the underline + (let ((r (rst-classify-adornment + (buffer-substring-no-properties + (line-beginning-position 2) (line-end-position 2)) + (line-end-position 2)))) + (if r + r + ;; No valid adornment found + (list (cons nil nil) (point) (line-end-position) + nil nil (point) (line-end-position) nil nil)))))))) + +;; The following function and variables are used to maintain information about +;; current section adornment in a buffer local cache. Thus they can be used for +;; font-locking and manipulation commands. + +(defun rst-reset-section-caches () + "Reset all section cache variables. +Should be called by interactive functions which deal with sections." + (setq rst-all-sections nil + rst-section-hierarchy nil)) + +(defvar rst-all-sections nil + "All section adornments in the buffer as found by `rst-find-all-adornments'. +t when no section adornments were found.") +(make-variable-buffer-local 'rst-all-sections) + +;; FIXME: If this variable is set to a different value font-locking of section +;; headers is wrong +(defvar rst-section-hierarchy nil + "Section hierarchy in the buffer as determined by `rst-get-hierarchy'. +t when no section adornments were found. Value depends on +`rst-all-sections'.") +(make-variable-buffer-local 'rst-section-hierarchy) + +(defun rst-find-all-adornments () + "Return all the section adornments in the current buffer. +Return a list of (LINE . ADORNMENT) with ascending LINE where +LINE is the line containing the section title. ADORNMENT consists +of a (CHARACTER STYLE INDENT) triple as described for +`rst-preferred-adornments'. + +Uses and sets `rst-all-sections'." + (unless rst-all-sections + (let (positions) + ;; Iterate over all the section titles/adornments in the file. + (save-excursion + (goto-char (point-min)) + (while (re-search-forward (rst-re 'ado-beg-2-1) nil t) + (let ((ado-data (rst-classify-adornment + (match-string-no-properties 0) (point)))) + (when (and ado-data + (consp (car ado-data))) ; Ignore transitions + (set-match-data (cdr ado-data)) + (goto-char (match-beginning 2)) ; Goto the title start + (push (cons (1+ (count-lines (point-min) (point))) + (list (caar ado-data) + (cdar ado-data) + (current-indentation))) + positions) + (goto-char (match-end 0))))) ; Go beyond the whole thing + (setq positions (nreverse positions)) + (setq rst-all-sections (or positions t))))) + (if (eq rst-all-sections t) + nil + rst-all-sections)) + +(defun rst-infer-hierarchy (adornments) + "Build a hierarchy of adornments using the list of given ADORNMENTS. + +ADORNMENTS is a list of (CHARACTER STYLE INDENT) adornment specifications, in order that they appear in a file, and will -infer a hierarchy of section levels by removing decorations that -have already been seen in a forward traversal of the decorations, -comparing just the character and style. +infer a hierarchy of section levels by removing adornments that +have already been seen in a forward traversal of the adornments, +comparing just CHARACTER and STYLE. -Similarly returns a list of (char, style, indent), where each +Similarly returns a list of (CHARACTER STYLE INDENT), where each list element should be unique." - - (let ((hierarchy-alist (list))) - (dolist (x decorations) + (let (hierarchy-alist) + (dolist (x adornments) (let ((char (car x)) (style (cadr x))) (unless (assoc (cons char style) hierarchy-alist) - (push (cons (cons char style) x) hierarchy-alist)) - )) - - (mapcar 'cdr (nreverse hierarchy-alist)) - )) - - -(defun rst-get-hierarchy (&optional alldecos ignore) + (push (cons (cons char style) x) hierarchy-alist)))) + (mapcar 'cdr (nreverse hierarchy-alist)))) + +(defun rst-get-hierarchy (&optional ignore) "Return the hierarchy of section titles in the file. -Return a list of decorations that represents the hierarchy of -section titles in the file. Reuse the list of decorations -already computed in ALLDECOS if present. If the line number in -IGNORE is specified, the decoration found on that line (if there -is one) is not taken into account when building the hierarchy." - (let ((all (or alldecos (rst-find-all-decorations)))) - (setq all (assq-delete-all ignore all)) - (rst-infer-hierarchy (mapcar 'cdr all)))) - - -(defun rst-get-decoration (&optional point) - "Get the decoration at POINT. - -Looks around point and finds the characteristics of the -decoration that is found there. Assumes that the cursor is -already placed on the title line (and not on the overline or -underline). - -This function returns a (char, style, indent) triple. If the -characters of overline and underline are different, return -the underline character. The indent is always calculated. -A decoration can be said to exist if the style is not nil. - -A point can be specified to go to the given location before -extracting the decoration." - - (let (char style) - (save-excursion - (if point (goto-char point)) - (beginning-of-line) - (if (looking-at rst-section-text-regexp) - (let* ((over (save-excursion - (forward-line -1) - (rst-line-homogeneous-nodent-p))) - - (under (save-excursion - (forward-line +1) - (rst-line-homogeneous-nodent-p))) - ) - - ;; Check that the line above the overline is not part of a title - ;; above it. - (if (and over - (save-excursion - (and (equal (forward-line -2) 0) - (looking-at rst-section-text-regexp)))) - (setq over nil)) - - (cond - ;; No decoration found, leave all return values nil. - ((and (eq over nil) (eq under nil))) - - ;; Overline only, leave all return values nil. - ;; - ;; Note: we don't return the overline character, but it could - ;; perhaps in some cases be used to do something. - ((and over (eq under nil))) - - ;; Underline only. - ((and under (eq over nil)) - (setq char under - style 'simple)) - - ;; Both overline and underline. - (t - (setq char under - style 'over-and-under))))) - ;; Return values. - (list char style - ;; Find indentation. - (save-excursion (back-to-indentation) (current-column)))))) - - -(defun rst-get-decorations-around (&optional alldecos) - "Return the decorations around point. - -Given the list of all decorations ALLDECOS (with positions), -find the decorations before and after the given point. -A list of the previous and next decorations is returned." - (let* ((all (or alldecos (rst-find-all-decorations))) +Return a list of adornments that represents the hierarchy of +section titles in the file. Each element consists of (CHARACTER +STYLE INDENT) as described for `rst-find-all-adornments'. If the +line number in IGNORE is specified, a possibly adornment found on +that line is not taken into account when building the hierarchy. + +Uses and sets `rst-section-hierarchy' unless IGNORE is given." + (if (and (not ignore) rst-section-hierarchy) + (if (eq rst-section-hierarchy t) + nil + rst-section-hierarchy) + (let ((r (rst-infer-hierarchy + (mapcar 'cdr + (assq-delete-all + ignore + (rst-find-all-adornments)))))) + (setq rst-section-hierarchy + (if ignore + ;; Clear cache reflecting that a possible update is not + ;; reflected + nil + (or r t))) + r))) + +(defun rst-get-adornments-around () + "Return the adornments around point. +Return a list of the previous and next adornments." + (let* ((all (rst-find-all-adornments)) (curline (line-number-at-pos)) prev next (cur all)) - ;; Search for the decorations around the current line. + ;; Search for the adornments around the current line. (while (and cur (< (caar cur) curline)) (setq prev cur cur (cdr cur))) - ;; 'cur' is the following decoration. + ;; 'cur' is the following adornment. (if (and cur (caar cur)) (setq next (if (= curline (caar cur)) (cdr cur) cur))) @@ -937,23 +1317,21 @@ )) -(defun rst-decoration-complete-p (deco) - "Return true if the decoration DECO around point is complete." +(defun rst-adornment-complete-p (ado) + "Return true if the adornment ADO around point is complete." ;; Note: we assume that the detection of the overline as being the underline ;; of a preceding title has already been detected, and has been eliminated - ;; from the decoration that is given to us. + ;; from the adornment that is given to us. ;; There is some sectioning already present, so check if the current ;; sectioning is complete and correct. - (let* ((char (car deco)) - (style (cadr deco)) - (indent (caddr deco)) + (let* ((char (car ado)) + (style (cadr ado)) + (indent (caddr ado)) (endcol (save-excursion (end-of-line) (current-column))) ) (if char - (let ((exps (concat "^" - (regexp-quote (make-string (+ endcol indent) char)) - "$"))) + (let ((exps (rst-re "^" char (format "\\{%d\\}" (+ endcol indent)) "$"))) (and (save-excursion (forward-line +1) (beginning-of-line) @@ -966,57 +1344,56 @@ )) -(defun rst-get-next-decoration - (curdeco hier &optional suggestion reverse-direction) - "Get the next decoration for CURDECO, in given hierarchy HIER. -If suggesting, suggest for new decoration SUGGESTION. +(defun rst-get-next-adornment + (curado hier &optional suggestion reverse-direction) + "Get the next adornment for CURADO, in given hierarchy HIER. +If suggesting, suggest for new adornment SUGGESTION. REVERSE-DIRECTION is used to reverse the cycling order." (let* ( - (char (car curdeco)) - (style (cadr curdeco)) + (char (car curado)) + (style (cadr curado)) - ;; Build a new list of decorations for the rotation. - (rotdecos + ;; Build a new list of adornments for the rotation. + (rotados (append hier - ;; Suggest a new decoration. + ;; Suggest a new adornment. (list suggestion - ;; If nothing to suggest, use first decoration. + ;; If nothing to suggest, use first adornment. (car hier)))) ) (or - ;; Search for next decoration. + ;; Search for next adornment. (cadr - (let ((cur (if reverse-direction rotdecos - (reverse rotdecos)))) + (let ((cur (if reverse-direction rotados + (reverse rotados)))) (while (and cur (not (and (eq char (caar cur)) (eq style (cadar cur))))) (setq cur (cdr cur))) cur)) - ;; If not found, take the first of all decorations. + ;; If not found, take the first of all adornments. suggestion ))) -(defun rst-adjust () - "Auto-adjust the decoration around point. +;; FIXME: A line "``/`` full" is not accepted as a section title +(defun rst-adjust (pfxarg) + "Auto-adjust the adornment around point. -Adjust/rotate the section decoration for the section title -around point or promote/demote the decorations inside the region, +Adjust/rotate the section adornment for the section title +around point or promote/demote the adornments inside the region, depending on if the region is active. This function is meant to be invoked possibly multiple times, and can vary its behavior with a positive prefix argument (toggle style), or with a negative prefix argument (alternate behavior). -This function is the main focus of this module and is a bit of a -swiss knife. It is meant as the single most essential function -to be bound to invoke to adjust the decorations of a section -title in restructuredtext. It tries to deal with all the -possible cases gracefully and to do `the right thing' in all -cases. +This function is a bit of a swiss knife. It is meant to adjust +the adornments of a section title in reStructuredText. It tries +to deal with all the possible cases gracefully and to do `the +right thing' in all cases. -See the documentations of `rst-adjust-decoration' and +See the documentations of `rst-adjust-adornment-work' and `rst-promote-region' for full details. Prefix Arguments @@ -1025,28 +1402,24 @@ The method can take either (but not both) of a. a (non-negative) prefix argument, which means to toggle the - decoration style. Invoke with a prefix arg for example; + adornment style. Invoke with a prefix arg for example; b. a negative numerical argument, which generally inverts the direction of search in the file or hierarchy. Invoke with C-- prefix for example." - (interactive) + (interactive "P") (let* (;; Save our original position on the current line. (origpt (point-marker)) - ;; Parse the positive and negative prefix arguments. - (reverse-direction - (and current-prefix-arg - (< (prefix-numeric-value current-prefix-arg) 0))) - (toggle-style - (and current-prefix-arg (not reverse-direction)))) + (reverse-direction (and pfxarg (< (prefix-numeric-value pfxarg) 0))) + (toggle-style (and pfxarg (not reverse-direction)))) (if (rst-portable-mark-active-p) - ;; Adjust decorations within region. - (rst-promote-region current-prefix-arg) - ;; Adjust decoration around point. - (rst-adjust-decoration toggle-style reverse-direction)) + ;; Adjust adornments within region. + (rst-promote-region (and pfxarg t)) + ;; Adjust adornment around point. + (rst-adjust-adornment-work toggle-style reverse-direction)) ;; Run the hooks to run after adjusting. (run-hooks 'rst-adjust-hook) @@ -1056,18 +1429,32 @@ )) -(defvar rst-adjust-hook nil - "Hooks to be run after running `rst-adjust'.") - -(defvar rst-new-decoration-down nil - "Non-nil if new decoration is added deeper. -If non-nil, a new decoration being added will be initialized to -be one level down from the previous decoration. If nil, a new -decoration will be equal to the level of the previous -decoration.") - -(defun rst-adjust-decoration (&optional toggle-style reverse-direction) -"Adjust/rotate the section decoration for the section title around point. +(defcustom rst-adjust-hook nil + "Hooks to be run after running `rst-adjust'." + :group 'rst-adjust + :type '(hook) + :package-version '(rst . "1.1.0")) + +(defcustom rst-new-adornment-down nil + "Controls level of new adornment for section headers." + :group 'rst-adjust + :type '(choice + (const :tag "Same level as previous one" nil) + (const :tag "One level down relative to the previous one" t)) + :package-version '(rst . "1.1.0")) + +(defun rst-adjust-adornment (pfxarg) + "Call `rst-adjust-adornment-work' interactively. + +Keep this for compatibility for older bindings (are there any?)." + (interactive "P") + + (let* ((reverse-direction (and pfxarg (< (prefix-numeric-value pfxarg) 0))) + (toggle-style (and pfxarg (not reverse-direction)))) + (rst-adjust-adornment-work toggle-style reverse-direction))) + +(defun rst-adjust-adornment-work (toggle-style reverse-direction) +"Adjust/rotate the section adornment for the section title around point. This function is meant to be invoked possibly multiple times, and can vary its behavior with a true TOGGLE-STYLE argument, or with @@ -1080,13 +1467,13 @@ it is meant to be invoked possibly more than once to rotate among the various possibilities. Basically, this function deals with: -- adding a decoration if the title does not have one; +- adding a adornment if the title does not have one; - adjusting the length of the underline characters to fit a modified title; -- rotating the decoration in the set of already existing - sectioning decorations used in the file; +- rotating the adornment in the set of already existing + sectioning adornments used in the file; - switching between simple and over-and-under styles. @@ -1095,10 +1482,10 @@ would expect. -Decoration Definitions -====================== +Adornment Definitions +===================== -The decorations consist in +The adornments consist in 1. a CHARACTER @@ -1119,71 +1506,69 @@ complicated, but really, it does the most obvious thing in all the particular cases): -Before applying the decoration change, the cursor is placed on +Before applying the adornment change, the cursor is placed on the closest line that could contain a section title. -Case 1: No Decoration ---------------------- - -If the current line has no decoration around it, - -- search backwards for the last previous decoration, and apply - the decoration one level lower to the current line. If there - is no defined level below this previous decoration, we suggest - the most appropriate of the `rst-preferred-decorations'. +Case 1: No Adornment +-------------------- + +If the current line has no adornment around it, + +- search backwards for the last previous adornment, and apply + the adornment one level lower to the current line. If there + is no defined level below this previous adornment, we suggest + the most appropriate of the `rst-preferred-adornments'. If REVERSE-DIRECTION is true, we simply use the previous - decoration found directly. - -- if there is no decoration found in the given direction, we use - the first of `rst-preferred-decorations'. - -The prefix argument forces a toggle of the prescribed decoration -style. - -Case 2: Incomplete Decoration ------------------------------ - -If the current line does have an existing decoration, but the -decoration is incomplete, that is, the underline/overline does + adornment found directly. + +- if there is no adornment found in the given direction, we use + the first of `rst-preferred-adornments'. + +TOGGLE-STYLE forces a toggle of the prescribed adornment style. + +Case 2: Incomplete Adornment +---------------------------- + +If the current line does have an existing adornment, but the +adornment is incomplete, that is, the underline/overline does not extend to exactly the end of the title line (it is either too short or too long), we simply extend the length of the underlines/overlines to fit exactly the section title. -If the prefix argument is given, we toggle the style of the -decoration as well. +If TOGGLE-STYLE we toggle the style of the adornment as well. REVERSE-DIRECTION has no effect in this case. -Case 3: Complete Existing Decoration ------------------------------------- +Case 3: Complete Existing Adornment +----------------------------------- -If the decoration is complete (i.e. the underline (overline) +If the adornment is complete (i.e. the underline (overline) length is already adjusted to the end of the title line), we search/parse the file to establish the hierarchy of all the -decorations (making sure not to include the decoration around -point), and we rotate the current title's decoration from within +adornments (making sure not to include the adornment around +point), and we rotate the current title's adornment from within that list (by default, going *down* the hierarchy that is present in the file, i.e. to a lower section level). This is meant to be -used potentially multiple times, until the desired decoration is +used potentially multiple times, until the desired adornment is found around the title. If we hit the boundary of the hierarchy, exactly one choice from -the list of preferred decorations is suggested/chosen, the first -of those decoration that has not been seen in the file yet (and -not including the decoration around point), and the next +the list of preferred adornments is suggested/chosen, the first +of those adornment that has not been seen in the file yet (and +not including the adornment around point), and the next invocation rolls over to the other end of the hierarchy (i.e. it cycles). This allows you to avoid having to set which character to use. If REVERSE-DIRECTION is true, the effect is to change the -direction of rotation in the hierarchy of decorations, thus +direction of rotation in the hierarchy of adornments, thus instead going *up* the hierarchy. -However, if there is a non-negative prefix argument, we do not -rotate the decoration, but instead simply toggle the style of the -current decoration (this should be the most common way to toggle -the style of an existing complete decoration). +However, if TOGGLE-STYLE, we do not rotate the adornment, but +instead simply toggle the style of the current adornment (this +should be the most common way to toggle the style of an existing +complete adornment). Point Location @@ -1203,7 +1588,7 @@ My Title -------- -are invalid in restructuredtext and thus not recognized by the +are invalid in reStructuredText and thus not recognized by the parser. This code will thus not work in a way that would support indented sections (it would be ambiguous anyway). @@ -1213,166 +1598,103 @@ Section titles that are right next to each other may not be treated well. More work might be needed to support those, and -special conditions on the completeness of existing decorations +special conditions on the completeness of existing adornments might be required to make it non-ambiguous. -For now we assume that the decorations are disjoint, that is, -there is at least a single line between the titles/decoration -lines. - - -Suggested Binding -================= - -We suggest that you bind this function on C-=. It is close to -C-- so a negative argument can be easily specified with a flick -of the right hand fingers and the binding is unused in `text-mode'." - (interactive) - - ;; If we were invoked directly, parse the prefix arguments into the - ;; arguments of the function. - (if current-prefix-arg - (setq reverse-direction - (and current-prefix-arg - (< (prefix-numeric-value current-prefix-arg) 0)) - - toggle-style - (and current-prefix-arg (not reverse-direction)))) - - (let* (;; Check if we're on an underline around a section title, and move the - ;; cursor to the title if this is the case. - (moved (rst-normalize-cursor-position)) - - ;; Find the decoration and completeness around point. - (curdeco (rst-get-decoration)) - (char (car curdeco)) - (style (cadr curdeco)) - (indent (caddr curdeco)) - - ;; New values to be computed. - char-new style-new indent-new - ) - - ;; We've moved the cursor... if we're not looking at some text, we have - ;; nothing to do. - (if (save-excursion (beginning-of-line) - (looking-at rst-section-text-regexp)) - (progn - (cond - ;;------------------------------------------------------------------- - ;; Case 1: No Decoration - ((and (eq char nil) (eq style nil)) - - (let* ((alldecos (rst-find-all-decorations)) - - (around (rst-get-decorations-around alldecos)) - (prev (car around)) - cur - - (hier (rst-get-hierarchy alldecos)) - ) - - ;; Advance one level down. - (setq cur - (if prev - (if (not reverse-direction) - (or (funcall (if rst-new-decoration-down 'cadr 'car) - (rst-get-decoration-match hier prev)) - (rst-suggest-new-decoration hier prev)) - prev) - (copy-sequence (car rst-preferred-decorations)))) - - ;; Invert the style if requested. - (if toggle-style - (setcar (cdr cur) (if (eq (cadr cur) 'simple) - 'over-and-under 'simple)) ) - - (setq char-new (car cur) - style-new (cadr cur) - indent-new (caddr cur)) - )) - - ;;------------------------------------------------------------------- - ;; Case 2: Incomplete Decoration - ((not (rst-decoration-complete-p curdeco)) - - ;; Invert the style if requested. - (if toggle-style - (setq style (if (eq style 'simple) 'over-and-under 'simple))) - - (setq char-new char - style-new style - indent-new indent)) - - ;;------------------------------------------------------------------- - ;; Case 3: Complete Existing Decoration - (t - (if toggle-style - - ;; Simply switch the style of the current decoration. - (setq char-new char - style-new (if (eq style 'simple) 'over-and-under 'simple) - indent-new rst-default-indent) - - ;; Else, we rotate, ignoring the decoration around the current - ;; line... - (let* ((alldecos (rst-find-all-decorations)) - - (hier (rst-get-hierarchy alldecos (line-number-at-pos))) - - ;; Suggestion, in case we need to come up with something - ;; new - (suggestion (rst-suggest-new-decoration - hier - (car (rst-get-decorations-around alldecos)))) - - (nextdeco (rst-get-next-decoration - curdeco hier suggestion reverse-direction)) - - ) - - ;; Indent, if present, always overrides the prescribed indent. - (setq char-new (car nextdeco) - style-new (cadr nextdeco) - indent-new (caddr nextdeco)) - - ))) - ) - - ;; Override indent with present indent! - (setq indent-new (if (> indent 0) indent indent-new)) - - (if (and char-new style-new) - (rst-update-section char-new style-new indent-new)) - )) - - - ;; Correct the position of the cursor to more accurately reflect where it - ;; was located when the function was invoked. - (unless (= moved 0) - (forward-line (- moved)) - (end-of-line)) - - )) +For now we assume that the adornments are disjoint, that is, +there is at least a single line between the titles/adornment +lines." + (rst-reset-section-caches) + (let ((ttl-fnd (rst-find-title-line)) + (orig-pnt (point))) + (when ttl-fnd + (set-match-data (cdr ttl-fnd)) + (goto-char (match-beginning 2)) + (let* ((moved (- (line-number-at-pos) (line-number-at-pos orig-pnt))) + (char (caar ttl-fnd)) + (style (cdar ttl-fnd)) + (indent (current-indentation)) + (curado (list char style indent)) + char-new style-new indent-new) + (cond + ;;------------------------------------------------------------------- + ;; Case 1: No valid adornment + ((not style) + (let ((prev (car (rst-get-adornments-around))) + cur + (hier (rst-get-hierarchy))) + ;; Advance one level down. + (setq cur + (if prev + (if (or (and rst-new-adornment-down reverse-direction) + (and (not rst-new-adornment-down) + (not reverse-direction))) + prev + (or (cadr (rst-get-adornment-match hier prev)) + (rst-suggest-new-adornment hier prev))) + (copy-sequence (car rst-preferred-adornments)))) + ;; Invert the style if requested. + (if toggle-style + (setcar (cdr cur) (if (eq (cadr cur) 'simple) + 'over-and-under 'simple)) ) + (setq char-new (car cur) + style-new (cadr cur) + indent-new (caddr cur)))) + ;;------------------------------------------------------------------- + ;; Case 2: Incomplete Adornment + ((not (rst-adornment-complete-p curado)) + ;; Invert the style if requested. + (if toggle-style + (setq style (if (eq style 'simple) 'over-and-under 'simple))) + (setq char-new char + style-new style + indent-new indent)) + ;;------------------------------------------------------------------- + ;; Case 3: Complete Existing Adornment + (t + (if toggle-style + ;; Simply switch the style of the current adornment. + (setq char-new char + style-new (if (eq style 'simple) 'over-and-under 'simple) + indent-new rst-default-indent) + ;; Else, we rotate, ignoring the adornment around the current + ;; line... + (let* ((hier (rst-get-hierarchy (line-number-at-pos))) + ;; Suggestion, in case we need to come up with something new + (suggestion (rst-suggest-new-adornment + hier + (car (rst-get-adornments-around)))) + (nextado (rst-get-next-adornment + curado hier suggestion reverse-direction))) + ;; Indent, if present, always overrides the prescribed indent. + (setq char-new (car nextado) + style-new (cadr nextado) + indent-new (caddr nextado)))))) + ;; Override indent with present indent! + (setq indent-new (if (> indent 0) indent indent-new)) + (if (and char-new style-new) + (rst-update-section char-new style-new indent-new)) + ;; Correct the position of the cursor to more accurately reflect where + ;; it was located when the function was invoked. + (unless (zerop moved) + (forward-line (- moved)) + (end-of-line)))))) ;; Maintain an alias for compatibility. (defalias 'rst-adjust-section-title 'rst-adjust) -(defun rst-promote-region (&optional demote) +(defun rst-promote-region (demote) "Promote the section titles within the region. With argument DEMOTE or a prefix argument, demote the section titles instead. The algorithm used at the boundaries of the -hierarchy is similar to that used by `rst-adjust-decoration'." - (interactive) - - (let* ((demote (or current-prefix-arg demote)) - (alldecos (rst-find-all-decorations)) - (cur alldecos) - - (hier (rst-get-hierarchy alldecos)) - (suggestion (rst-suggest-new-decoration hier)) +hierarchy is similar to that used by `rst-adjust-adornment-work'." + (interactive "P") + (rst-reset-section-caches) + (let* ((cur (rst-find-all-adornments)) + (hier (rst-get-hierarchy)) + (suggestion (rst-suggest-new-adornment hier)) (region-begin-line (line-number-at-pos (region-beginning))) (region-end-line (line-number-at-pos (region-end))) @@ -1384,7 +1706,7 @@ (while (and cur (< (caar cur) region-begin-line)) (setq cur (cdr cur))) - ;; Create a list of markers for all the decorations which are found within + ;; Create a list of markers for all the adornments which are found within ;; the region. (save-excursion (let (line) @@ -1396,34 +1718,34 @@ ;; Apply modifications. (dolist (p marker-list) - ;; Go to the decoration to promote. - (goto-char (car p)) - - ;; Update the decoration. - (apply 'rst-update-section - ;; Rotate the next decoration. - (rst-get-next-decoration - (cadr p) hier suggestion demote)) - - ;; Clear marker to avoid slowing down the editing after we're done. - (set-marker (car p) nil)) + ;; Go to the adornment to promote. + (goto-char (car p)) + + ;; Update the adornment. + (apply 'rst-update-section + ;; Rotate the next adornment. + (rst-get-next-adornment + (cadr p) hier suggestion demote)) + + ;; Clear marker to avoid slowing down the editing after we're done. + (set-marker (car p) nil)) (setq deactivate-mark nil) ))) -(defun rst-display-decorations-hierarchy (&optional decorations) - "Display the current file's section title decorations hierarchy. -This function expects a list of (char, style, indent) triples in -DECORATIONS." +(defun rst-display-adornments-hierarchy (&optional adornments) + "Display the current file's section title adornments hierarchy. +This function expects a list of (CHARACTER STYLE INDENT) triples +in ADORNMENTS." (interactive) - - (if (not decorations) - (setq decorations (rst-get-hierarchy))) + (rst-reset-section-caches) + (if (not adornments) + (setq adornments (rst-get-hierarchy))) (with-output-to-temp-buffer "*rest section hierarchy*" (let ((level 1)) (with-current-buffer standard-output - (dolist (x decorations) + (dolist (x adornments) (insert (format "\nSection Level %d" level)) (apply 'rst-update-section x) (goto-char (point-max)) @@ -1437,32 +1759,30 @@ (let ((tail (member elem list))) (if tail (- (length list) (length tail))))) -(defun rst-straighten-decorations () - "Redo all the decorations in the current buffer. -This is done using our preferred set of decorations. This can be +(defun rst-straighten-adornments () + "Redo all the adornments in the current buffer. +This is done using our preferred set of adornments. This can be used, for example, when using somebody else's copy of a document, in order to adapt it to our preferred style." (interactive) + (rst-reset-section-caches) (save-excursion - (let* ((alldecos (rst-find-all-decorations)) - (hier (rst-get-hierarchy alldecos)) - - ;; Get a list of pairs of (level . marker) - (levels-and-markers (mapcar - (lambda (deco) - (cons (rst-position (cdr deco) hier) - (progn - (goto-char (point-min)) - (forward-line (1- (car deco))) - (point-marker)))) - alldecos)) - ) + (let (;; Get a list of pairs of (level . marker) + (levels-and-markers (mapcar + (lambda (ado) + (cons (rst-position (cdr ado) + (rst-get-hierarchy)) + (progn + (goto-char (point-min)) + (forward-line (1- (car ado))) + (point-marker)))) + (rst-find-all-adornments)))) (dolist (lm levels-and-markers) ;; Go to the appropriate position (goto-char (cdr lm)) ;; Apply the new styule - (apply 'rst-update-section (nth (car lm) rst-preferred-decorations)) + (apply 'rst-update-section (nth (car lm) rst-preferred-adornments)) ;; Reset the market to avoid slowing down editing until it gets GC'ed (set-marker (cdr lm) nil) @@ -1470,71 +1790,257 @@ ))) - - -(defun rst-straighten-deco-spacing () - "Adjust the spacing before and after decorations in the entire document. -The spacing will be set to two blank lines before the first two -section levels, and one blank line before any of the other -section levels." -;; FIXME: we need to take care of subtitle at some point. - (interactive) - (save-excursion - (let* ((alldecos (rst-find-all-decorations))) - - ;; Work the list from the end, so that we don't have to use markers to - ;; adjust for the changes in the document. - (dolist (deco (nreverse alldecos)) - ;; Go to the appropriate position. - (goto-char (point-min)) - (forward-line (1- (car deco))) - (insert "@\n") -;; FIXME: todo, we - ) - ))) - + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Insert list items +;; ================= + + +;================================================= +; Borrowed from a2r.el (version 1.3), by Lawrence Mitchell +; I needed to make some tiny changes to the functions, so I put it here. +; -- Wei-Wei Guo + +(defconst rst-arabic-to-roman + '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD") + (100 . "C") (90 . "XC") (50 . "L") (40 . "XL") + (10 . "X") (9 . "IX") (5 . "V") (4 . "IV") + (1 . "I")) + "List of maps between Arabic numbers and their Roman numeral equivalents.") + +(defun rst-arabic-to-roman (num &optional arg) + "Convert Arabic number NUM to its Roman numeral representation. + +Obviously, NUM must be greater than zero. Don't blame me, blame the +Romans, I mean \"what have the Romans ever _done_ for /us/?\" (with +apologies to Monty Python). +If optional prefix ARG is non-nil, insert in current buffer." + (let ((map rst-arabic-to-roman) + res) + (while (and map (> num 0)) + (if (or (= num (caar map)) + (> num (caar map))) + (setq res (concat res (cdar map)) + num (- num (caar map))) + (setq map (cdr map)))) + res)) + +(defun rst-roman-to-arabic (string &optional arg) + "Convert STRING of Roman numerals to an Arabic number. + +If STRING contains a letter which isn't a valid Roman numeral, the rest +of the string from that point onwards is ignored. + +Hence: +MMD == 2500 +and +MMDFLXXVI == 2500. +If optional ARG is non-nil, insert in current buffer." + (let ((res 0) + (map rst-arabic-to-roman)) + (while map + (if (string-match (concat "^" (cdar map)) string) + (setq res (+ res (caar map)) + string (replace-match "" nil t string)) + (setq map (cdr map)))) + res)) +;================================================= (defun rst-find-pfx-in-region (beg end pfx-re) "Find all the positions of prefixes in region between BEG and END. -This is used to find bullets and enumerated list items. PFX-RE -is a regular expression for matching the lines with items." +This is used to find bullets and enumerated list items. PFX-RE is +a regular expression for matching the lines after indentation +with items. Returns a list of cons cells consisting of the point +and the column of the point." (let ((pfx ())) (save-excursion (goto-char beg) (while (< (point) end) (back-to-indentation) (when (and - (looking-at pfx-re) + (looking-at pfx-re) ; pfx found and... (let ((pfx-col (current-column))) (save-excursion - (forward-line -1) + (forward-line -1) ; ...previous line is... (back-to-indentation) - (or (looking-at "^[ \t]*$") - (> (current-column) pfx-col) + (or (looking-at (rst-re 'lin-end)) ; ...empty, + (> (current-column) pfx-col) ; ...deeper level, or (and (= (current-column) pfx-col) - (looking-at pfx-re)))))) + (looking-at pfx-re)))))) ; ...pfx at same level (push (cons (point) (current-column)) pfx)) (forward-line 1)) ) (nreverse pfx))) -(defvar rst-re-bullets - (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets))) - "Regexp for finding bullets.") - -;; (defvar rst-re-enumerations -;; "\\(\\(#\\|[0-9]+\\)\\.[ \t]\\)[^ \t]" -;; "Regexp for finding bullets.") - -(defvar rst-re-items - (format "\\(%s\\|%s\\)[^ \t]" - (format "[%s][ \t]" (regexp-quote (concat rst-bullets))) - "\\(#\\|[0-9]+\\)\\.[ \t]") - "Regexp for finding bullets.") - -(defvar rst-preferred-bullets - '(?- ?* ?+) - "List of favorite bullets to set for straightening bullets.") +(defun rst-insert-list-pos (newitem) + "Arrange relative position of a newly inserted list item. + +Adding a new list might consider three situations: + + (a) Current line is a blank line. + (b) Previous line is a blank line. + (c) Following line is a blank line. + +When (a) and (b), just add the new list at current line. + +when (a) and not (b), a blank line is added before adding the new list. + +When not (a), first forward point to the end of the line, and add two +blank lines, then add the new list. + +Other situations are just ignored and left to users themselves." + (if (save-excursion + (beginning-of-line) + (looking-at (rst-re 'lin-end))) + (if (save-excursion + (forward-line -1) + (looking-at (rst-re 'lin-end))) + (insert newitem " ") + (insert "\n" newitem " ")) + (end-of-line) + (insert "\n\n" newitem " "))) + +(defvar rst-initial-enums + (let (vals) + (dolist (fmt '("%s." "(%s)" "%s)")) + (dolist (c '("1" "a" "A" "I" "i")) + (push (format fmt c) vals))) + (cons "#." (nreverse vals))) + "List of initial enumerations.") + +(defvar rst-initial-items + (append (mapcar 'char-to-string rst-bullets) rst-initial-enums) + "List of initial items. It's collection of bullets and enumerations.") + +(defun rst-insert-list-new-item () + "Insert a new list item. + +User is asked to select the item style first, for example (a), i), +. Use TAB +for completition and choices. + +If user selects bullets or #, it's just added with position arranged by +`rst-insert-list-pos'. + +If user selects enumerations, a further prompt is given. User need to input a +starting item, for example 'e' for 'A)' style. The position is also arranged by +`rst-insert-list-pos'." + (interactive) + ;; FIXME: Make this comply to `interactive' standards + (let* ((itemstyle (completing-read + "Select preferred item style [#.]: " + rst-initial-items nil t nil nil "#.")) + (cnt (if (string-match (rst-re 'cntexp-tag) itemstyle) + (match-string 0 itemstyle))) + (no + (save-match-data + ;; FIXME: Make this comply to `interactive' standards + (cond + ((equal cnt "a") + (let ((itemno (read-string "Give starting value [a]: " + nil nil "a"))) + (downcase (substring itemno 0 1)))) + ((equal cnt "A") + (let ((itemno (read-string "Give starting value [A]: " + nil nil "A"))) + (upcase (substring itemno 0 1)))) + ((equal cnt "I") + (let ((itemno (read-number "Give starting value [1]: " 1))) + (rst-arabic-to-roman itemno))) + ((equal cnt "i") + (let ((itemno (read-number "Give starting value [1]: " 1))) + (downcase (rst-arabic-to-roman itemno)))) + ((equal cnt "1") + (let ((itemno (read-number "Give starting value [1]: " 1))) + (number-to-string itemno))))))) + (if no + (setq itemstyle (replace-match no t t itemstyle))) + (rst-insert-list-pos itemstyle))) + +(defcustom rst-preferred-bullets + '(?* ?- ?+) + "List of favorite bullets." + :group 'rst + :type `(repeat + (choice ,@(mapcar (lambda (char) + (list 'const + :tag (char-to-string char) char)) + rst-bullets))) + :package-version '(rst . "1.1.0")) + +(defun rst-insert-list-continue (curitem prefer-roman) + "Insert a list item with list start CURITEM including its indentation level." + (end-of-line) + (insert + "\n" ; FIXME: Separating lines must be possible + (cond + ((string-match (rst-re '(:alt enmaut-tag + bul-tag)) curitem) + curitem) + ((string-match (rst-re 'num-tag) curitem) + (replace-match (number-to-string + (1+ (string-to-number (match-string 0 curitem)))) + nil nil curitem)) + ((and (string-match (rst-re 'rom-tag) curitem) + (save-match-data + (if (string-match (rst-re 'ltr-tag) curitem) ; Also a letter tag + (save-excursion + ;; FIXME: Assumes one line list items without separating + ;; empty lines + (if (and (zerop (forward-line -1)) + (looking-at (rst-re 'enmexp-beg))) + (string-match + (rst-re 'rom-tag) + (match-string 0)) ; Previous was a roman tag + prefer-roman)) ; Don't know - use flag + t))) ; Not a letter tag + (replace-match + (let* ((old (match-string 0 curitem)) + (new (save-match-data + (rst-arabic-to-roman + (1+ (rst-roman-to-arabic + (upcase old))))))) + (if (equal old (upcase old)) + (upcase new) + (downcase new))) + t nil curitem)) + ((string-match (rst-re 'ltr-tag) curitem) + (replace-match (char-to-string + (1+ (string-to-char (match-string 0 curitem)))) + nil nil curitem))))) + + +(defun rst-insert-list (&optional prefer-roman) + "Insert a list item at the current point. + +The command can insert a new list or a continuing list. When it is called at a +non-list line, it will promote to insert new list. When it is called at a list +line, it will insert a list with the same list style. + +1. When inserting a new list: + +User is asked to select the item style first, for example (a), i), +. Use TAB +for completition and choices. + + (a) If user selects bullets or #, it's just added. + (b) If user selects enumerations, a further prompt is given. User needs to + input a starting item, for example 'e' for 'A)' style. + +The position of the new list is arranged according to whether or not the +current line and the previous line are blank lines. + +2. When continuing a list, one thing need to be noticed: + +List style alphabetical list, such as 'a.', and roman numerical list, such as +'i.', have some overlapping items, for example 'v.' The function can deal with +the problem elegantly in most situations. But when those overlapped list are +preceded by a blank line, it is hard to determine which type to use +automatically. The function uses alphabetical list by default. If you want +roman numerical list, just use a prefix (\\[universal-argument])." + (interactive "P") + (beginning-of-line) + (if (looking-at (rst-re 'itmany-beg-1)) + (rst-insert-list-continue (match-string 0) prefer-roman) + (rst-insert-list-new-item))) (defun rst-straighten-bullets-region (beg end) "Make all the bulleted list items in the region consistent. @@ -1547,8 +2053,7 @@ `rst-preferred-bullets' list, they are not modified." (interactive "r") - (let ((bullets (rst-find-pfx-in-region beg end - rst-re-bullets)) + (let ((bullets (rst-find-pfx-in-region beg end (rst-re 'bul-sta))) (levtable (make-hash-table :size 4))) ;; Create a map of levels to list of positions. @@ -1573,25 +2078,25 @@ (insert (string (car bullets)))) (setq bullets (cdr bullets)))))))) -(defun rst-rstrip (str) - "Strips the whitespace at the end of string STR." - (string-match "[ \t\n]*\\'" str) - (substring str 0 (match-beginning 0))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Table of contents +;; ================= (defun rst-get-stripped-line () "Return the line at cursor, stripped from whitespace." - (re-search-forward "\\S-.*\\S-" (line-end-position)) + (re-search-forward (rst-re "\\S .*\\S ") (line-end-position)) (buffer-substring-no-properties (match-beginning 0) (match-end 0)) ) -(defun rst-section-tree (alldecos) +(defun rst-section-tree () "Get the hierarchical tree of section titles. Returns a hierarchical tree of the sections titles in the -document, for decorations ALLDECOS. This can be used to generate -a table of contents for the document. The top node will always -be a nil node, with the top level titles as children (there may -potentially be more than one). +document. This can be used to generate a table of contents for +the document. The top node will always be a nil node, with the +top level titles as children (there may potentially be more than +one). Each section title consists in a cons of the stripped title string and a marker to the section in the original text document. @@ -1603,57 +2108,56 @@ to be considered as being the same line as their first non-nil child. This has advantages later in processing the graph." - (let* ((hier (rst-get-hierarchy alldecos)) - (levels (make-hash-table :test 'equal :size 10)) - lines) + (let ((hier (rst-get-hierarchy)) + (levels (make-hash-table :test 'equal :size 10)) + lines) (let ((lev 0)) - (dolist (deco hier) + (dolist (ado hier) ;; Compare just the character and indent in the hash table. - (puthash (cons (car deco) (cadr deco)) lev levels) + (puthash (cons (car ado) (cadr ado)) lev levels) (incf lev))) ;; Create a list of lines that contains (text, level, marker) for each - ;; decoration. + ;; adornment. (save-excursion (setq lines - (mapcar (lambda (deco) + (mapcar (lambda (ado) (goto-char (point-min)) - (forward-line (1- (car deco))) - (list (gethash (cons (cadr deco) (caddr deco)) levels) + (forward-line (1- (car ado))) + (list (gethash (cons (cadr ado) (caddr ado)) levels) (rst-get-stripped-line) (progn (beginning-of-line 1) (point-marker)))) - alldecos))) - + (rst-find-all-adornments)))) (let ((lcontnr (cons nil lines))) (rst-section-tree-rec lcontnr -1)))) -(defun rst-section-tree-rec (decos lev) +(defun rst-section-tree-rec (ados lev) "Recursive guts of the section tree construction. -DECOS is a cons cell whose cdr is the remaining list of -decorations, and we change it as we consume them. LEV is +ADOS is a cons cell whose cdr is the remaining list of +adornments, and we change it as we consume them. LEV is the current level of that node. This function returns a -pair of the subtree that was built. This treats the DECOS +pair of the subtree that was built. This treats the ADOS list destructively." - (let ((ndeco (cadr decos)) + (let ((nado (cadr ados)) node children) - ;; If the next decoration matches our level - (when (and ndeco (= (car ndeco) lev)) - ;; Pop the next decoration and create the current node with it - (setcdr decos (cddr decos)) - (setq node (cdr ndeco)) ) + ;; If the next adornment matches our level + (when (and nado (= (car nado) lev)) + ;; Pop the next adornment and create the current node with it + (setcdr ados (cddr ados)) + (setq node (cdr nado)) ) ;; Else we let the node title/marker be unset. ;; Build the child nodes - (while (and (cdr decos) (> (caadr decos) lev)) + (while (and (cdr ados) (> (caadr ados) lev)) (setq children - (cons (rst-section-tree-rec decos (1+ lev)) + (cons (rst-section-tree-rec ados (1+ lev)) children))) (setq children (reverse children)) @@ -1749,9 +2253,8 @@ to the specified level. The TOC is inserted indented at the current column." - (interactive "P") - + (rst-reset-section-caches) (let* (;; Check maximum level override (rst-toc-insert-max-level (if (and (integerp pfxarg) (> (prefix-numeric-value pfxarg) 0)) @@ -1760,7 +2263,7 @@ ;; Get the section tree for the current cursor point. (sectree-pair (rst-section-tree-point - (rst-section-tree (rst-find-all-decorations)))) + (rst-section-tree))) ;; Figure out initial indent. (initial-indent (make-string (current-column) ? )) @@ -1830,8 +2333,9 @@ (if do-child-numbering (progn ;; Add a separating dot if there is already a prefix - (if (> (length pfx) 0) - (setq pfx (concat (rst-rstrip pfx) "."))) + (when (> (length pfx) 0) + (string-match (rst-re "[ \t\n]*\\'") pfx) + (setq pfx (concat (replace-match "" t t pfx) "."))) ;; Calculate the amount of space that the prefix will require ;; for the numbers. @@ -1852,59 +2356,48 @@ ))) -(defun rst-toc-insert-find-delete-contents () - "Find and delete an existing comment after the first contents directive. -Delete that region. Return t if found and the cursor is left after the comment." - (goto-char (point-min)) - ;; We look for the following and the following only (in other words, if your - ;; syntax differs, this won't work. If you would like a more flexible thing, - ;; contact the author, I just can't imagine that this requirement is - ;; unreasonable for now). - ;; - ;; .. contents:: [...anything here...] - ;; .. - ;; XXXXXXXX - ;; XXXXXXXX - ;; [more lines] - ;; - (let ((beg - (re-search-forward "^\\.\\. contents[ \t]*::\\(.*\\)\n\\.\\." - nil t)) - last-real) - (when beg - ;; Look for the first line that starts at the first column. - (forward-line 1) - (beginning-of-line) - (while (and - (< (point) (point-max)) - (or (and (looking-at "[ \t]+[^ \t]") (setq last-real (point)) t) - (looking-at "[ \t]*$"))) - (forward-line 1) - ) - (if last-real - (progn - (goto-char last-real) - (end-of-line) - (delete-region beg (point))) - (goto-char beg)) - t - ))) - (defun rst-toc-update () "Automatically find the contents section of a document and update. Updates the inserted TOC if present. You can use this in your file-write hook to always make it up-to-date automatically." (interactive) - (let ((p (point))) - (save-excursion - (when (rst-toc-insert-find-delete-contents) - (insert "\n ") - (rst-toc-insert) - )) - ;; Somehow save-excursion does not really work well. - (goto-char p)) + (save-excursion + ;; Find and delete an existing comment after the first contents directive. + ;; Delete that region. + (goto-char (point-min)) + ;; We look for the following and the following only (in other words, if your + ;; syntax differs, this won't work.). + ;; + ;; .. contents:: [...anything here...] + ;; [:field: value]... + ;; .. + ;; XXXXXXXX + ;; XXXXXXXX + ;; [more lines] + (let ((beg (re-search-forward + (rst-re "^" 'exm-sta "contents" 'dcl-tag ".*\n" + "\\(?:" 'hws-sta 'fld-tag ".*\n\\)*" 'exm-tag) nil t)) + last-real) + (when beg + ;; Look for the first line that starts at the first column. + (forward-line 1) + (while (and + (< (point) (point-max)) + (or (if (looking-at + (rst-re 'hws-sta "\\S ")) ; indented content + (setq last-real (point))) + (looking-at (rst-re 'lin-end)))) ; empty line + (forward-line 1)) + (if last-real + (progn + (goto-char last-real) + (end-of-line) + (delete-region beg (point))) + (goto-char beg)) + (insert "\n ") + (rst-toc-insert)))) ;; Note: always return nil, because this may be used as a hook. - ) + nil) ;; Note: we cannot bind the TOC update on file write because it messes with ;; undo. If we disable undo, since it adds and removes characters, the @@ -1916,7 +2409,7 @@ ;; ;; Disable undo for the write file hook. ;; (let ((buffer-undo-list t)) (rst-toc-update) )) -(defalias 'rst-toc-insert-update 'rst-toc-update) ;; backwards compat. +(defalias 'rst-toc-insert-update 'rst-toc-update) ; backwards compat. ;;------------------------------------------------------------------------------ @@ -1962,13 +2455,13 @@ (defvar rst-toc-buffer-name "*Table of Contents*" "Name of the Table of Contents buffer.") -(defvar rst-toc-return-buffer nil - "Buffer to which to return when leaving the TOC.") +(defvar rst-toc-return-wincfg nil + "Window configuration to which to return when leaving the TOC.") (defun rst-toc () "Display a table-of-contents. -Finds all the section titles and their decorations in the +Finds all the section titles and their adornments in the file, and displays a hierarchically-organized list of the titles, which is essentially a table-of-contents of the document. @@ -1976,11 +2469,9 @@ The Emacs buffer can be navigated, and selecting a section brings the cursor in that section." (interactive) - (let* ((curbuf (current-buffer)) - - ;; Get the section tree - (alldecos (rst-find-all-decorations)) - (sectree (rst-section-tree alldecos)) + (rst-reset-section-caches) + (let* ((curbuf (list (current-window-configuration) (point-marker))) + (sectree (rst-section-tree)) (our-node (cdr (rst-section-tree-point sectree))) line @@ -2006,7 +2497,7 @@ (pop-to-buffer buf) ;; Save the buffer to return to. - (set (make-local-variable 'rst-toc-return-buffer) curbuf) + (set (make-local-variable 'rst-toc-return-wincfg) curbuf) ;; Move the cursor near the right section in the TOC. (goto-char (point-min)) @@ -2023,11 +2514,15 @@ (error "Buffer for this section was killed")) pos)) +;; FIXME: Cursor before or behind the list must be handled properly; before the +;; list should jump to the top and behind the list to the last normal +;; paragraph (defun rst-goto-section (&optional kill) "Go to the section the current line describes." (interactive) (let ((pos (rst-toc-mode-find-section))) (when kill + (set-window-configuration (car rst-toc-return-wincfg)) (kill-buffer (get-buffer rst-toc-buffer-name))) (pop-to-buffer (marker-buffer pos)) (goto-char pos) @@ -2044,9 +2539,9 @@ EVENT is the input event." (interactive "e") (let ((pos - (with-current-buffer (window-buffer (posn-window (event-end event))) - (save-excursion - (goto-char (posn-point (event-end event))) + (with-current-buffer (window-buffer (posn-window (event-end event))) + (save-excursion + (goto-char (posn-point (event-end event))) (rst-toc-mode-find-section))))) (pop-to-buffer (marker-buffer pos)) (goto-char pos) @@ -2061,8 +2556,9 @@ (defun rst-toc-quit-window () "Leave the current TOC buffer." (interactive) - (quit-window) - (pop-to-buffer rst-toc-return-buffer)) + (let ((retbuf rst-toc-return-wincfg)) + (set-window-configuration (car retbuf)) + (goto-char (cadr retbuf)))) (defvar rst-toc-mode-map (let ((map (make-sparse-keymap))) @@ -2087,40 +2583,40 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Section movement commands. -;; +;; Section movement commands +;; ========================= (defun rst-forward-section (&optional offset) - "Skip to the next restructured text section title. + "Skip to the next reStructuredText section title. OFFSET specifies how many titles to skip. Use a negative OFFSET to move backwards in the file (default is to use 1)." (interactive) + (rst-reset-section-caches) (let* (;; Default value for offset. (offset (or offset 1)) - ;; Get all the decorations in the file, with their line numbers. - (alldecos (rst-find-all-decorations)) + ;; Get all the adornments in the file, with their line numbers. + (allados (rst-find-all-adornments)) ;; Get the current line. (curline (line-number-at-pos)) - (cur alldecos) + (cur allados) (idx 0) ) - ;; Find the index of the "next" decoration w.r.t. to the current line. + ;; Find the index of the "next" adornment w.r.t. to the current line. (while (and cur (< (caar cur) curline)) (setq cur (cdr cur)) (incf idx)) - ;; 'cur' is the decoration on or following the current line. + ;; 'cur' is the adornment on or following the current line. (if (and (> offset 0) cur (= (caar cur) curline)) (incf idx)) ;; Find the final index. (setq idx (+ idx (if (> offset 0) (- offset 1) offset))) - (setq cur (nth idx alldecos)) + (setq cur (nth idx allados)) ;; If the index is positive, goto the line, otherwise go to the buffer ;; boundaries. @@ -2156,245 +2652,25 @@ (push-mark nil t t) (rst-forward-section (- arg))))) - - - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions to work on item lists (e.g. indent/dedent, enumerate), which are ;; always 2 or 3 characters apart horizontally with rest. -;; (FIXME: there is currently a bug that makes the region go away when we do that.) -(defvar rst-shift-fill-region nil - "If non-nil, automatically re-fill the region that is being shifted.") - (defun rst-find-leftmost-column (beg end) - "Find the leftmost column in the region." - (let ((mincol 1000)) + "Return the leftmost column in region BEG to END." + (let (mincol) (save-excursion (goto-char beg) (while (< (point) end) (back-to-indentation) - (unless (looking-at "[ \t]*$") - (setq mincol (min mincol (current-column)))) - (forward-line 1) - )) + (unless (looking-at (rst-re 'lin-end)) + (setq mincol (if mincol + (min mincol (current-column)) + (current-column)))) + (forward-line 1))) mincol)) - -;; What we really need to do is compute all the possible alignment possibilities -;; and then select one. -;; -;; .. line-block:: -;; -;; a) sdjsds -;; -;; - sdjsd jsjds -;; -;; sdsdsjdsj -;; -;; 11. sjdss jddjs -;; -;; * * * * * * * -;; -;; Move backwards, accumulate the beginning positions, and also the second -;; positions, in case the line matches the bullet pattern, and then sort. - -(defun rst-compute-bullet-tabs (&optional pt) - "Build the list of possible horizontal alignment points. -Search backwards from point (or point PT if specified) to -build the list of possible horizontal alignment points that -includes the beginning and contents of a restructuredtext -bulleted or enumerated list item. Return a sorted list -of (COLUMN-NUMBER . LINE) pairs." - (save-excursion - (when pt (goto-char pt)) - - ;; We work our way backwards and towards the left. - (let ((leftcol 100000) ;; Current column. - (tablist nil) ;; List of tab positions. - ) - - ;; Start by skipping the current line. - (beginning-of-line 0) - - ;; Search backwards for each line. - (while (and (> (point) (point-min)) - (> leftcol 0)) - - ;; Skip empty lines. - (unless (looking-at "^[ \t]*$") - ;; Inspect the current non-empty line - (back-to-indentation) - - ;; Skip lines that are beyond the current column (we want to move - ;; towards the left). - (let ((col (current-column))) - (when (< col leftcol) - - ;; Add the beginning of the line as a tabbing point. - (unless (memq col (mapcar 'car tablist)) - (push (cons col (point)) tablist)) - - ;; Look at the line to figure out if it is a bulleted or enumerate - ;; list item. - (when (looking-at - (concat - "\\(?:" - "\\(\\(?:[0-9a-zA-Z#]\\{1,3\\}[.):-]\\|[*+-]\\)[ \t]+\\)[^ \t\n]" - "\\|" - (format "\\(%s%s+[ \t]+\\)[^ \t\n]" - (regexp-quote (thing-at-point 'char)) - (regexp-quote (thing-at-point 'char))) - "\\)" - )) - ;; Add the column of the contained item. - (let* ((matchlen (length (or (match-string 1) (match-string 2)))) - (newcol (+ col matchlen))) - (unless (or (>= newcol leftcol) - (memq (+ col matchlen) (mapcar 'car tablist))) - (push (cons (+ col matchlen) (+ (point) matchlen)) - tablist))) - ) - - (setq leftcol col) - ))) - - ;; Move backwards one line. - (beginning-of-line 0)) - - (sort tablist (lambda (x y) (<= (car x) (car y)))) - ))) - -(defun rst-debug-print-tabs (tablist) - "Insert a line and place special characters at the tab points in TABLIST." - (beginning-of-line) - (insert (concat "\n" (make-string 1000 ? ) "\n")) - (beginning-of-line 0) - (dolist (col tablist) - (beginning-of-line) - (forward-char (car col)) - (delete-char 1) - (insert "@") - )) - -(defun rst-debug-mark-found (tablist) - "Insert a line and place special characters at the tab points in TABLIST." - (dolist (col tablist) - (when (cdr col) - (goto-char (cdr col)) - (insert "@")))) - - -(defvar rst-shift-basic-offset 2 - "Basic horizontal shift distance when there is no preceding alignment tabs.") - -(defun rst-shift-region-guts (find-next-fun offset-fun) - "(See `rst-shift-region-right' for a description)." - (let* ((mbeg (copy-marker (region-beginning))) - (mend (copy-marker (region-end))) - (tabs (rst-compute-bullet-tabs mbeg)) - (leftmostcol (rst-find-leftmost-column (region-beginning) (region-end))) - ) - ;; Add basic offset tabs at the end of the list. This is a better - ;; implementation technique than hysteresis and a basic offset because it - ;; insures that movement in both directions is consistently using the same - ;; column positions. This makes it more predictable. - (setq tabs - (append tabs - (mapcar (lambda (x) (cons x nil)) - (let ((maxcol 120) - (max-lisp-eval-depth 2000)) - (flet ((addnum (x) - (if (> x maxcol) - nil - (cons x (addnum - (+ x rst-shift-basic-offset)))))) - (addnum (or (caar (last tabs)) 0)))) - ))) - - ;; (For debugging.) - ;;; (save-excursion (goto-char mbeg) (forward-char -1) (rst-debug-print-tabs tabs)))) - ;;; (print tabs) - ;;; (save-excursion (rst-debug-mark-found tabs)) - - ;; Apply the indent. - (indent-rigidly - mbeg mend - - ;; Find the next tab after the leftmost column. - (let ((tab (funcall find-next-fun tabs leftmostcol))) - - (if tab - (progn - (when (cdar tab) - (message "Aligned on '%s'" - (save-excursion - (goto-char (cdar tab)) - (buffer-substring-no-properties - (line-beginning-position) - (line-end-position)))) - ) - (- (caar tab) leftmostcol)) ;; Num chars. - - ;; Otherwise use the basic offset - (funcall offset-fun rst-shift-basic-offset) - ))) - - ;; Optionally reindent. - (when rst-shift-fill-region - (fill-region mbeg mend)) - )) - -(defun rst-shift-region-right (pfxarg) - "Indent region rigidly, by a few characters to the right. -This function first computes all possible alignment columns by -inspecting the lines preceding the region for bulleted or -enumerated list items. If the leftmost column is beyond the -preceding lines, the region is moved to the right by -`rst-shift-basic-offset'. With a prefix argument, do not -automatically fill the region." - (interactive "P") - (let ((rst-shift-fill-region - (if (not pfxarg) rst-shift-fill-region))) - (rst-shift-region-guts (lambda (tabs leftmostcol) - (let ((cur tabs)) - (while (and cur (<= (caar cur) leftmostcol)) - (setq cur (cdr cur))) - cur)) - 'identity - ))) - -(defun rst-shift-region-left (pfxarg) - "Like `rst-shift-region-right', except we move to the left. -Also, if invoked with a negative prefix arg, the entire -indentation is removed, up to the leftmost character in the -region, and automatic filling is disabled." - (interactive "P") - (let ((mbeg (copy-marker (region-beginning))) - (mend (copy-marker (region-end))) - (leftmostcol (rst-find-leftmost-column - (region-beginning) (region-end))) - (rst-shift-fill-region - (if (not pfxarg) rst-shift-fill-region))) - - (when (> leftmostcol 0) - (if (and pfxarg (< (prefix-numeric-value pfxarg) 0)) - (progn - (indent-rigidly (region-beginning) (region-end) (- leftmostcol)) - (when rst-shift-fill-region - (fill-region mbeg mend)) - ) - (rst-shift-region-guts (lambda (tabs leftmostcol) - (let ((cur (reverse tabs))) - (while (and cur (>= (caar cur) leftmostcol)) - (setq cur (cdr cur))) - cur)) - '- - )) - ))) - (defmacro rst-iterate-leftmost-paragraphs (beg end first-only body-consequent body-alternative) "FIXME This definition is old and deprecated / we need to move @@ -2419,9 +2695,9 @@ (current-column)) (valid (and (= curcol leftcol) - (not (looking-at "[ \t]*$"))) + (not (looking-at (rst-re 'lin-end)))) (and (= curcol leftcol) - (not (looking-at "[ \t]*$")))) + (not (looking-at (rst-re 'lin-end))))) ) ((>= (point) endm)) @@ -2433,7 +2709,6 @@ )))) - (defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body) "Evaluate BODY for each line in region defined by BEG END. LEFTMOST is set to true if the line is one of the leftmost of the @@ -2453,8 +2728,8 @@ (empty-line-previous nil ,isempty) - (,isempty (looking-at "[ \t]*$") - (looking-at "[ \t]*$")) + (,isempty (looking-at (rst-re 'lin-end)) + (looking-at (rst-re 'lin-end))) (,parabegin (not ,isempty) (and empty-line-previous @@ -2471,6 +2746,307 @@ ))))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Indentation + +;; FIXME: At the moment only block comments with leading empty comment line are +;; supported; comment lines with leading comment markup should be also +;; supported; may be a customizable option could control which style to prefer + +(defgroup rst-indent nil "Settings for indendation in reStructuredText. + +In reStructuredText indendation points are usually determined by +preceding lines. Sometimes the syntax allows arbitrary +indendation points such as where to start the first line +following a directive. These indentation widths can be customized +here." + :group 'rst + :package-version '(rst . "1.1.0")) + +(define-obsolete-variable-alias + 'rst-shift-basic-offset 'rst-indent-width "r6713") +(defcustom rst-indent-width 2 + "Indentation when there is no more indentation point given." + :group 'rst-indent + :type '(integer)) + +(defcustom rst-indent-field 3 + "Default indendation for first line after a field or 0 to always indent for +content." + :group 'rst-indent + :type '(integer)) + +(defcustom rst-indent-literal-normal 3 + "Default indendation for literal block after a markup on an own +line." + :group 'rst-indent + :type '(integer)) + +(defcustom rst-indent-literal-minimized 2 + "Default indendation for literal block after a minimized +markup." + :group 'rst-indent + :type '(integer)) + +(defcustom rst-indent-comment 3 + "Default indendation for first line of a comment." + :group 'rst-indent + :type '(integer)) + +;; FIXME: Must consider other tabs: +;; * Line blocks +;; * Definition lists +;; * Option lists +(defun rst-line-tabs () + "Return tabs of the current line or nil for no tab. +The list is sorted so the tab where writing continues most likely +is the first one. Each tab is of the form (COLUMN . INNER). +COLUMN is the column of the tab. INNER is non-nil if this is an +inner tab. I.e. a tab which does come from the basic indentation +and not from inner alignment points." + (save-excursion + (forward-line 0) + (save-match-data + (unless (looking-at (rst-re 'lin-end)) + (back-to-indentation) + ;; Current indendation is always the least likely tab + (let ((tabs (list (list (point) 0 nil)))) ; (POINT OFFSET INNER) + ;; Push inner tabs more likely to continue writing + (cond + ;; Item + ((looking-at (rst-re '(:grp itmany-tag hws-sta) '(:grp "\\S ") "?")) + (when (match-string 2) + (push (list (match-beginning 2) 0 t) tabs))) + ;; Field + ((looking-at (rst-re '(:grp fld-tag) '(:grp hws-tag) + '(:grp "\\S ") "?")) + (unless (zerop rst-indent-field) + (push (list (match-beginning 1) rst-indent-field t) tabs)) + (if (match-string 3) + (push (list (match-beginning 3) 0 t) tabs) + (if (zerop rst-indent-field) + (push (list (match-end 2) + (if (string= (match-string 2) "") 1 0) + t) tabs)))) + ;; Directive + ((looking-at (rst-re 'dir-sta-3 '(:grp "\\S ") "?")) + (push (list (match-end 1) 0 t) tabs) + (unless (string= (match-string 2) "") + (push (list (match-end 2) 0 t) tabs)) + (when (match-string 4) + (push (list (match-beginning 4) 0 t) tabs))) + ;; Footnote or citation definition + ((looking-at (rst-re 'fnc-sta-2 '(:grp "\\S ") "?")) + (push (list (match-end 1) 0 t) tabs) + (when (match-string 3) + (push (list (match-beginning 3) 0 t) tabs))) + ;; Comment + ((looking-at (rst-re 'cmt-sta-1)) + (push (list (point) rst-indent-comment t) tabs))) + ;; Start of literal block + (when (looking-at (rst-re 'lit-sta-2)) + (let ((tab0 (first tabs))) + (push (list (first tab0) + (+ (second tab0) + (if (match-string 1) + rst-indent-literal-minimized + rst-indent-literal-normal)) + t) tabs))) + (mapcar (lambda (tab) + (goto-char (first tab)) + (cons (+ (current-column) (second tab)) (third tab))) + tabs)))))) + +(defun rst-compute-tabs (pt) + "Build the list of possible tabs for all lines above. +Search backwards from point PT to build the list of possible +tabs. Return a list of tabs sorted by likeliness to continue +writing like `rst-line-tabs'. Nearer lines have generally a +higher likeliness than farer lines. Return nil if no tab is found +in the text above." + (save-excursion + (goto-char pt) + (let (leftmost ; Leftmost column found so far + innermost ; Leftmost column for inner tab + tablist) + (while (and (zerop (forward-line -1)) + (or (not leftmost) + (> leftmost 0))) + (let* ((tabs (rst-line-tabs)) + (leftcol (if tabs (apply 'min (mapcar 'car tabs))))) + (when tabs + ;; Consider only lines indented less or same if not INNERMOST + (when (or (not leftmost) + (< leftcol leftmost) + (and (not innermost) (= leftcol leftmost))) + (dolist (tab tabs) + (let ((inner (cdr tab)) + (newcol (car tab))) + (when (and + (or + (and (not inner) + (or (not leftmost) + (< newcol leftmost))) + (and inner + (or (not innermost) + (< newcol innermost)))) + (not (memq newcol tablist))) + (push newcol tablist)))) + (setq innermost (if (some 'identity + (mapcar 'cdr tabs)) ; Has inner + leftcol + innermost)) + (setq leftmost leftcol))))) + (nreverse tablist)))) + +(defun rst-indent-line (&optional dflt) + "Indent current line to next best reStructuredText tab. +The next best tab is taken from the tab list returned by +`rst-compute-tabs' which is used in a cyclic manner. If the +current indentation does not end on a tab use the first one. If +the current indentation is on a tab use the next tab. This allows +a repeated use of \\[indent-for-tab-command] to cycle through all +possible tabs. If no indentation is possible return `noindent' or +use DFLT. Return the indentation indented to. When point is in +indentation it ends up at its end. Otherwise the point is kept +relative to the content." + (let* ((pt (point-marker)) + (cur (current-indentation)) + (clm (current-column)) + (tabs (rst-compute-tabs (point))) + (fnd (position cur tabs)) + ind) + (if (and (not tabs) (not dflt)) + 'noindent + (if (not tabs) + (setq ind dflt) + (if (not fnd) + (setq fnd 0) + (setq fnd (1+ fnd)) + (if (>= fnd (length tabs)) + (setq fnd 0))) + (setq ind (nth fnd tabs))) + (indent-line-to ind) + (if (> clm cur) + (goto-char pt)) + (set-marker pt nil) + ind))) + +(defun rst-shift-region (beg end cnt) + "Shift region BEG to END by CNT tabs. +Shift by one tab to the right (CNT > 0) or left (CNT < 0) or +remove all indentation (CNT = 0). An tab is taken from the text +above. If no suitable tab is found `rst-indent-width' is used." + (interactive "r\np") + (let ((tabs (sort (rst-compute-tabs beg) (lambda (x y) (<= x y)))) + (leftmostcol (rst-find-leftmost-column beg end))) + (when (or (> leftmostcol 0) (> cnt 0)) + ;; Apply the indent + (indent-rigidly + beg end + (if (zerop cnt) + (- leftmostcol) + ;; Find the next tab after the leftmost column + (let* ((cmp (if (> cnt 0) '> '<)) + (tabs (if (> cnt 0) tabs (reverse tabs))) + (len (length tabs)) + (dir (signum cnt)) ; Direction to take + (abs (abs cnt)) ; Absolute number of steps to take + ;; Get the position of the first tab beyond leftmostcol + (fnd (position-if (lambda (elt) + (funcall cmp elt leftmostcol)) + tabs)) + ;; Virtual position of tab + (pos (+ (or fnd len) (1- abs))) + (tab (if (< pos len) + ;; Tab exists - use it + (nth pos tabs) + ;; Column needs to be computed + (let ((col (+ (or (car (last tabs)) leftmostcol) + ;; Base on last known column + (* (- pos (1- len)) ; Distance left + dir ; Direction to take + rst-indent-width)))) + (if (< col 0) 0 col))))) + (- tab leftmostcol))))))) + +;; FIXME: A paragraph with an (incorrectly) indented second line is not filled +;; correctly:: +;; +;; Some start +;; continued wrong +(defun rst-adaptive-fill () + "Return fill prefix found at point. +Value for `adaptive-fill-function'." + (let ((fnd (if (looking-at adaptive-fill-regexp) + (match-string-no-properties 0)))) + (if (save-match-data + (not (string-match comment-start-skip fnd))) + ;; An non-comment prefix is fine + fnd + ;; Matches a comment - return whitespace instead + (make-string (- + (save-excursion + (goto-char (match-end 0)) + (current-column)) + (save-excursion + (goto-char (match-beginning 0)) + (current-column))) ? )))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Comments + +(defun rst-comment-line-break (&optional soft) + "Break line and indent, continuing reStructuredText comment if within one. +Value for `comment-line-break-function'." + (if soft + (insert-and-inherit ?\n) + (newline 1)) + (save-excursion + (forward-char -1) + (delete-horizontal-space)) + (delete-horizontal-space) + (let ((tabs (rst-compute-tabs (point)))) + (when tabs + (indent-line-to (car tabs))))) + +(defun rst-comment-indent () + "Return indentation for current comment line." + (car (rst-compute-tabs (point)))) + +(defun rst-comment-insert-comment () + "Insert a comment in the current line." + (rst-indent-line 0) + (insert comment-start)) + +(defun rst-comment-region (beg end &optional arg) + "Comment the current region or uncomment it if ARG is \\[universal-argument]." + (save-excursion + (if (consp arg) + (rst-uncomment-region beg end arg) + (goto-char beg) + (let ((ind (current-indentation)) + bol) + (forward-line 0) + (setq bol (point)) + (indent-rigidly bol end rst-indent-comment) + (goto-char bol) + (open-line 1) + (indent-line-to ind) + (insert (comment-string-strip comment-start t t)))))) + +(defun rst-uncomment-region (beg end &optional arg) + "Uncomment the current region. +ARG is ignored" + (save-excursion + (let (bol eol) + (goto-char beg) + (forward-line 0) + (setq bol (point)) + (forward-line 1) + (setq eol (point)) + (indent-rigidly eol end (- rst-indent-comment)) + (delete-region bol eol)))) ;;------------------------------------------------------------------------------ @@ -2478,60 +3054,54 @@ ;; bullets in bulleted lists. The enumerate would just be one of the possible ;; outputs. ;; -;; FIXME: TODO we need to do the enumeration removal as well. +;; FIXME: We need to do the enumeration removal as well. -(defun rst-enumerate-region (beg end) +(defun rst-enumerate-region (beg end all) "Add enumeration to all the leftmost paragraphs in the given region. -The region is specified between BEG and END. With prefix argument, +The region is specified between BEG and END. With ALL, do all lines instead of just paragraphs." - (interactive "r") + (interactive "r\nP") (let ((count 0) (last-insert-len nil)) (rst-iterate-leftmost-paragraphs - beg end (not current-prefix-arg) + beg end (not all) (let ((ins-string (format "%d. " (incf count)))) (setq last-insert-len (length ins-string)) (insert ins-string)) (insert (make-string last-insert-len ?\ )) ))) -(defun rst-bullet-list-region (beg end) +(defun rst-bullet-list-region (beg end all) "Add bullets to all the leftmost paragraphs in the given region. -The region is specified between BEG and END. With prefix argument, +The region is specified between BEG and END. With ALL, do all lines instead of just paragraphs." - (interactive "r") + (interactive "r\nP") (rst-iterate-leftmost-paragraphs - beg end (not current-prefix-arg) - (insert "- ") + beg end (not all) + (insert (car rst-preferred-bullets) " ") (insert " ") )) - -;; FIXME: there are some problems left with the following function -;; implementation: -;; -;; * It does not deal with a varying number of digits appropriately -;; * It does not deal with multiple levels independently, and it should. -;; -;; I suppose it does 90% of the job for now. - +;; FIXME: Does not deal with a varying number of digits appropriately +;; FIXME: Does not deal with multiple levels independently +;; FIXME: Does not indent a multiline item correctly (defun rst-convert-bullets-to-enumeration (beg end) - "Convert all the bulleted items and enumerated items in the -region to enumerated lists, renumbering as necessary." + "Convert the bulleted and enumerated items in the region to enumerated lists. +Renumber as necessary." (interactive "r") (let* (;; Find items and convert the positions to markers. (items (mapcar (lambda (x) (cons (copy-marker (car x)) (cdr x))) - (rst-find-pfx-in-region beg end rst-re-items))) + (rst-find-pfx-in-region beg end (rst-re 'itmany-sta-1)))) (count 1) ) (save-excursion (dolist (x items) (goto-char (car x)) - (looking-at rst-re-items) - (replace-match (format "%d. " count) nil nil nil 1) + (looking-at (rst-re 'itmany-beg-1)) + (replace-match (format "%d." count) nil nil nil 1) (incf count) )) )) @@ -2559,9 +3129,13 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Font lock +;; ========= (require 'font-lock) +;; FIXME: The obsolete variables need to disappear + (defgroup rst-faces nil "Faces used in Rst Mode." :group 'rst :group 'faces @@ -2724,8 +3298,7 @@ :type '(integer) :set 'rst-set-level-default) (defcustom rst-level-face-base-color "grey" - "The base name of the color to be used for creating background colors in -section title faces for all levels." + "Base name of the color for creating background colors in section title faces." :group 'rst-faces-defaults :type '(string) :set 'rst-set-level-default) @@ -2788,6 +3361,7 @@ :value-type (face)) :set-after '(rst-level-face-max)) +;; FIXME: It should be possible to give "#RRGGBB" type of color values (defun rst-define-level-faces () "Define the faces for the section title text faces from the values." ;; All variables used here must be checked in `rst-set-level-default' @@ -2804,214 +3378,277 @@ (set-face-doc-string sym doc) (set-face-background sym col) (set sym sym)) - (setq i (1+ i)))))) + (setq i (1+ i)))))) (rst-define-level-faces) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Font lock - -(defvar rst-use-char-classes - (string-match "[[:alpha:]]" "b") - "Non-nil if we can use the character classes in our regexps.") - -(defun rst-font-lock-keywords-function () - "Return keywords to highlight in Rst mode according to current settings." + +(defvar rst-font-lock-keywords ;; The reST-links in the comments below all relate to sections in ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html - (let* ( ;; This gets big - so let's define some abbreviations - ;; horizontal white space - (re-hws "[\t ]") - ;; beginning of line with possible indentation - (re-bol (concat "^" re-hws "*")) - ;; Separates block lead-ins from their content - (re-blksep1 (concat "\\(" re-hws "+\\|$\\)")) - ;; explicit markup tag - (re-emt "\\.\\.") - ;; explicit markup start - (re-ems (concat re-emt re-hws "+")) - ;; inline markup prefix - (re-imp1 (concat "\\(^\\|" re-hws "\\|[-'\"([{/:.,;!?\\]\\|$\\)")) - ;; symbol character - (re-sym1 "\\(\\sw\\|\\s_\\)") - ;; inline markup content begin - (re-imbeg2 "\\(\\S \\|\\S \\([^") - - ;; There seems to be a bug leading to error "Stack overflow in regexp - ;; matcher" when "|" or "\\*" are the characters searched for - (re-imendbeg "\\]\\|\\\\.") - ;; inline markup content end - (re-imend (concat re-imendbeg "\\)*[^\t \\\\]\\)")) - ;; inline markup content without asterisk - (re-ima2 (concat re-imbeg2 "*" re-imend)) - ;; inline markup content without backquote - (re-imb2 (concat re-imbeg2 "`" re-imend)) - ;; inline markup content without vertical bar - (re-imv2 (concat re-imbeg2 "|" re-imend)) - ;; Supported URI schemes - (re-uris1 "\\(acap\\|cid\\|data\\|dav\\|fax\\|file\\|ftp\\|gopher\\|http\\|https\\|imap\\|ldap\\|mailto\\|mid\\|modem\\|news\\|nfs\\|nntp\\|pop\\|prospero\\|rtsp\\|service\\|sip\\|tel\\|telnet\\|tip\\|urn\\|vemmi\\|wais\\)") - ;; Line starting with adornment and optional whitespace; complete - ;; adornment is in (match-string 1); there must be at least 3 - ;; characters because otherwise explicit markup start would be - ;; recognized - (re-ado2 (concat "^\\(\\([" - (if rst-use-char-classes - "^[:word:][:space:][:cntrl:]" "^\\w \t\x00-\x1F") - "]\\)\\2\\2+\\)" re-hws "*$")) - ) - (list - ;; FIXME: Block markup is not recognized in blocks after explicit markup - ;; start - - ;; Simple `Body Elements`_ - ;; `Bullet Lists`_ - `(,(concat re-bol "\\([-*+]" re-blksep1 "\\)") - 1 rst-block-face) - ;; `Enumerated Lists`_ - `(,(concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]" - re-blksep1 "\\)") - 1 rst-block-face) - ;; `Definition Lists`_ FIXME: missing - ;; `Field Lists`_ - `(,(concat re-bol "\\(:[^:\n]+:\\)" re-blksep1) - 1 rst-external-face) - ;; `Option Lists`_ - `(,(concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*" - "\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)") - 1 rst-block-face) - - ;; `Tables`_ FIXME: missing - - ;; All the `Explicit Markup Blocks`_ - ;; `Footnotes`_ / `Citations`_ - `(,(concat re-bol "\\(" re-ems "\\[[^[\n]+\\]\\)" re-blksep1) - 1 rst-definition-face) - ;; `Directives`_ / `Substitution Definitions`_ - `(,(concat re-bol "\\(" re-ems "\\)\\(\\(|[^|\n]+|[\t ]+\\)?\\)\\(" - re-sym1 "+::\\)" re-blksep1) - (1 rst-directive-face) - (2 rst-definition-face) - (4 rst-directive-face)) - ;; `Hyperlink Targets`_ - `(,(concat re-bol "\\(" re-ems "_\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+:\\)" - re-blksep1) - 1 rst-definition-face) - `(,(concat re-bol "\\(__\\)" re-blksep1) - 1 rst-definition-face) - - ;; All `Inline Markup`_ - ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented - ;; `Strong Emphasis`_ - `(,(concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1) - 2 rst-emphasis2-face) - ;; `Emphasis`_ - `(,(concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1) - 2 rst-emphasis1-face) - ;; `Inline Literals`_ - `(,(concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1) - 2 rst-literal-face) - ;; `Inline Internal Targets`_ - `(,(concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1) - 2 rst-definition-face) - ;; `Hyperlink References`_ - ;; FIXME: `Embedded URIs`_ not considered - `(,(concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\(\\sw\\(\\sw\\|-\\)+\\sw\\)\\)__?\\)" re-ims1) - 2 rst-reference-face) - ;; `Interpreted Text`_ - `(,(concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:" - re-sym1 "+:\\)?\\)" re-ims1) - (2 rst-directive-face) - (5 rst-external-face) - (8 rst-directive-face)) - ;; `Footnote References`_ / `Citation References`_ - `(,(concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1) - 2 rst-reference-face) - ;; `Substitution References`_ - `(,(concat re-imp1 "\\(|" re-imv2 "|\\)" re-ims1) - 2 rst-reference-face) - ;; `Standalone Hyperlinks`_ - `(;; FIXME: This takes it easy by using a whitespace as delimiter - ,(concat re-imp1 "\\(" re-uris1 ":\\S +\\)" re-ims1) - 2 rst-definition-face) - `(,(concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1) - 2 rst-definition-face) - - ;; Do all block fontification as late as possible so 'append works - - ;; Sections_ / Transitions_ - (append - (list - re-ado2) - (if (not rst-mode-lazy) - '(1 rst-block-face) - (list - (list 'rst-font-lock-handle-adornment - '(progn - (setq rst-font-lock-adornment-point (match-end 1)) - (point-max)) - nil - (list 1 '(cdr (assoc nil rst-adornment-faces-alist)) - 'append t) - (list 2 '(cdr (assoc rst-font-lock-level - rst-adornment-faces-alist)) - 'append t) - (list 3 '(cdr (assoc nil rst-adornment-faces-alist)) - 'append t))))) - - ;; `Comments`_ - (append - (list - (concat re-bol "\\(" re-ems "\\)\[^[|_]\\([^:\n]\\|:\\([^:\n]\\|$\\)\\)*$") - - '(1 rst-comment-face)) - (if rst-mode-lazy - (list - (list 'rst-font-lock-find-unindented-line - '(progn - (setq rst-font-lock-indentation-point (match-end 1)) - (point-max)) - nil - '(0 rst-comment-face append))))) - (append - (list - (concat re-bol "\\(" re-emt "\\)\\(\\s *\\)$") - '(1 rst-comment-face) - '(2 rst-comment-face)) - (if rst-mode-lazy - (list - (list 'rst-font-lock-find-unindented-line - '(progn - (setq rst-font-lock-indentation-point 'next) - (point-max)) - nil - '(0 rst-comment-face append))))) - - ;; `Literal Blocks`_ - (append - (list - (concat re-bol "\\(\\([^.\n]\\|\\.[^.\n]\\).*\\)?\\(::\\)$") - '(3 rst-block-face)) - (if rst-mode-lazy - (list - (list 'rst-font-lock-find-unindented-line - '(progn - (setq rst-font-lock-indentation-point t) - (point-max)) - nil - '(0 rst-literal-face append))))) + `(;; FIXME: Block markup is not recognized in blocks after explicit markup + ;; start + + ;; Simple `Body Elements`_ + ;; `Bullet Lists`_ + ;; FIXME: A bullet directly after a field name is not recognized + (,(rst-re 'lin-beg '(:grp bul-sta)) + 1 rst-block-face) + ;; `Enumerated Lists`_ + (,(rst-re 'lin-beg '(:grp enmany-sta)) + 1 rst-block-face) + ;; `Definition Lists`_ FIXME: missing + ;; `Field Lists`_ + (,(rst-re 'lin-beg '(:grp fld-tag) 'bli-sfx) + 1 rst-external-face) + ;; `Option Lists`_ + (,(rst-re 'lin-beg '(:grp opt-tag (:shy optsep-tag opt-tag) "*") + '(:alt "$" (:seq hws-prt "\\{2\\}"))) + 1 rst-block-face) + ;; `Line Blocks`_ + ;; Only for lines containing no more bar - to distinguish from tables + (,(rst-re 'lin-beg '(:grp "|" bli-sfx) "[^|\n]*$") + 1 rst-block-face) + + ;; `Tables`_ FIXME: missing + + ;; All the `Explicit Markup Blocks`_ + ;; `Footnotes`_ / `Citations`_ + (,(rst-re 'lin-beg 'fnc-sta-2) + (1 rst-definition-face) + (2 rst-definition-face)) + ;; `Directives`_ / `Substitution Definitions`_ + (,(rst-re 'lin-beg 'dir-sta-3) + (1 rst-directive-face) + (2 rst-definition-face) + (3 rst-directive-face)) + ;; `Hyperlink Targets`_ + (,(rst-re 'lin-beg + '(:grp exm-sta "_" (:alt + (:seq "`" ilcbkqdef-tag "`") + (:seq (:alt "[^:\\\n]" "\\\\.") "+")) ":") + 'bli-sfx) + 1 rst-definition-face) + (,(rst-re 'lin-beg '(:grp "__") 'bli-sfx) + 1 rst-definition-face) + + ;; All `Inline Markup`_ - most of them may be multiline though this is + ;; uninteresting + + ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented + ;; `Strong Emphasis`_ + (,(rst-re 'ilm-pfx '(:grp "\\*\\*" ilcast-tag "\\*\\*") 'ilm-sfx) + 1 rst-emphasis2-face) + ;; `Emphasis`_ + (,(rst-re 'ilm-pfx '(:grp "\\*" ilcast-tag "\\*") 'ilm-sfx) + 1 rst-emphasis1-face) + ;; `Inline Literals`_ + (,(rst-re 'ilm-pfx '(:grp "``" ilcbkq-tag "``") 'ilm-sfx) + 1 rst-literal-face) + ;; `Inline Internal Targets`_ + (,(rst-re 'ilm-pfx '(:grp "_`" ilcbkq-tag "`") 'ilm-sfx) + 1 rst-definition-face) + ;; `Hyperlink References`_ + ;; FIXME: `Embedded URIs`_ not considered + ;; FIXME: Directly adjacing marked up words are not fontified correctly + ;; unless they are not separated by two spaces: foo_ bar_ + (,(rst-re 'ilm-pfx '(:grp (:alt (:seq "`" ilcbkq-tag "`") + (:seq "\\sw" (:alt "\\sw" "-") "+\\sw")) + "__?") 'ilm-sfx) + 1 rst-reference-face) + ;; `Interpreted Text`_ + (,(rst-re 'ilm-pfx '(:grp (:shy ":" sym-tag ":") "?") + '(:grp "`" ilcbkq-tag "`") + '(:grp (:shy ":" sym-tag ":") "?") 'ilm-sfx) + (1 rst-directive-face) + (2 rst-external-face) + (3 rst-directive-face)) + ;; `Footnote References`_ / `Citation References`_ + (,(rst-re 'ilm-pfx '(:grp fnc-tag "_") 'ilm-sfx) + 1 rst-reference-face) + ;; `Substitution References`_ + ;; FIXME: References substitutions like |this|_ or |this|__ are not + ;; fontified correctly + (,(rst-re 'ilm-pfx '(:grp sub-tag) 'ilm-sfx) + 1 rst-reference-face) + ;; `Standalone Hyperlinks`_ + ;; FIXME: This takes it easy by using a whitespace as delimiter + (,(rst-re 'ilm-pfx '(:grp uri-tag ":\\S +") 'ilm-sfx) + 1 rst-definition-face) + (,(rst-re 'ilm-pfx '(:grp sym-tag "@" sym-tag ) 'ilm-sfx) + 1 rst-definition-face) + + ;; Do all block fontification as late as possible so 'append works + + ;; Sections_ / Transitions_ - for sections this is multiline + (,(rst-re 'ado-beg-2-1) + (rst-font-lock-handle-adornment-matcher + (rst-font-lock-handle-adornment-pre-match-form + (match-string-no-properties 1) (match-end 1)) + nil + (1 (cdr (assoc nil rst-adornment-faces-alist)) append t) + (2 (cdr (assoc rst-font-lock-adornment-level + rst-adornment-faces-alist)) append t) + (3 (cdr (assoc nil rst-adornment-faces-alist)) append t))) + + ;; FIXME: FACESPEC could be used instead of ordinary faces to set + ;; properties on comments and literal blocks so they are *not* + ;; inline fontified; see (elisp)Search-based Fontification + + ;; FIXME: And / or use `syntax-propertize` functions as in `octave-mod.el` + ;; and other V24 modes; may make `font-lock-extend-region` + ;; superfluous + + ;; `Comments`_ - this is multiline + (,(rst-re 'lin-beg 'cmt-sta-1) + (1 rst-comment-face) + (rst-font-lock-find-unindented-line-match + (rst-font-lock-find-unindented-line-limit (match-end 1)) + nil + (0 rst-comment-face append))) + (,(rst-re 'lin-beg '(:grp exm-tag) '(:grp hws-tag) "$") + (1 rst-comment-face) + (2 rst-comment-face) + (rst-font-lock-find-unindented-line-match + (rst-font-lock-find-unindented-line-limit 'next) + nil + (0 rst-comment-face append))) + + ;; FIXME: This is not rendered as comment:: + ;; .. .. list-table:: + ;; :stub-columns: 1 + ;; :header-rows: 1 + + ;; FIXME: This is rendered wrong:: + ;; + ;; xxx yyy:: + ;; + ;; ----|> KKKKK <|---- + ;; / \ + ;; -|> AAAAAAAAAAPPPPPP <|- -|> AAAAAAAAAABBBBBBB <|- + ;; | | | | + ;; | | | | + ;; PPPPPP PPPPPPDDDDDDD BBBBBBB PPPPPPBBBBBBB + ;; + ;; Indentation needs to be taken from the line with the ``::`` and not from + ;; the first content line. + + ;; `Indented Literal Blocks`_ - this is multiline + (,(rst-re 'lin-beg 'lit-sta-2) + (2 rst-block-face) + (rst-font-lock-find-unindented-line-match + (rst-font-lock-find-unindented-line-limit t) + nil + (0 rst-literal-face append))) + + ;; FIXME: `Quoted Literal Blocks`_ missing - this is multiline ;; `Doctest Blocks`_ - (append - (list - (concat re-bol "\\(>>>\\|\\.\\.\\.\\)\\(.+\\)") - '(1 rst-block-face) - '(2 rst-literal-face))) - ))) - - + ;; FIXME: This is wrong according to the specification: + ;; + ;; Doctest blocks are text blocks which begin with ">>> ", the Python + ;; interactive interpreter main prompt, and end with a blank line. + ;; Doctest blocks are treated as a special case of literal blocks, + ;; without requiring the literal block syntax. If both are present, the + ;; literal block syntax takes priority over Doctest block syntax: + ;; + ;; This is an ordinary paragraph. + ;; + ;; >>> print 'this is a Doctest block' + ;; this is a Doctest block + ;; + ;; The following is a literal block:: + ;; + ;; >>> This is not recognized as a doctest block by + ;; reStructuredText. It *will* be recognized by the doctest + ;; module, though! + ;; + ;; Indentation is not required for doctest blocks. + (,(rst-re 'lin-beg '(:grp (:alt ">>>" ell-tag)) '(:grp ".+")) + (1 rst-block-face) + (2 rst-literal-face)) + ) + "Keywords to highlight in rst mode.") + +(defun rst-font-lock-extend-region () + "Extend the region `font-lock-beg' / `font-lock-end' iff it may +be in the middle of a multiline construct and return non-nil if so." + (let ((r (rst-font-lock-extend-region-internal font-lock-beg font-lock-end))) + (when r + (setq font-lock-beg (car r)) + (setq font-lock-end (cdr r)) + t))) + +(defun rst-font-lock-extend-region-internal (beg end) + "Check the region BEG / END for being in the middle of a multiline construct. +Return nil if not or a cons with new values for BEG / END" + (let ((nbeg (rst-font-lock-extend-region-extend beg -1)) + (nend (rst-font-lock-extend-region-extend end 1))) + (if (or nbeg nend) + (cons (or nbeg beg) (or nend end))))) + +(defun rst-forward-line (&optional n) + "Like `forward-line' but always end up in column 0 and return accordingly." + (let ((moved (forward-line n))) + (if (bolp) + moved + (forward-line 0) + (- moved (signum n))))) + +(defun rst-font-lock-extend-region-extend (pt dir) + "Extend the region starting at point PT and extending in direction DIR. +Return extended point or nil if not moved." + ;; There are many potential multiline constructs but there are two groups + ;; which are really relevant. The first group consists of + ;; + ;; * comment lines without leading explicit markup tag and + ;; + ;; * literal blocks following "::" + ;; + ;; which are both indented. Thus indendation is the first thing recognized + ;; here. The second criteria is an explicit markup tag which may be a comment + ;; or a double colon at the end of a line. + ;; + ;; The second group consists of the adornment cases. + (if (not (get-text-property pt 'font-lock-multiline)) + ;; Move only if we don't start inside a multiline construct already + (save-excursion + (let (;; non-empty non-indented line, explicit markup tag or literal + ;; block tag + (stop-re (rst-re '(:alt "[^ \t\n]" + (:seq hws-tag exm-tag) + (:seq ".*" dcl-tag lin-end))))) + ;; The comments below are for dir == -1 / dir == 1 + (goto-char pt) + (forward-line 0) + (setq pt (point)) + (while (and (not (looking-at stop-re)) + (zerop (rst-forward-line dir)))) ; try previous / next + ; line if it exists + (if (looking-at (rst-re 'ado-beg-2-1)) ; may be an underline / + ; overline + (if (zerop (rst-forward-line dir)) + (if (looking-at (rst-re 'ttl-beg)) ; title found, i.e. + ; underline / overline + ; found + (if (zerop (rst-forward-line dir)) + (if (not + (looking-at (rst-re 'ado-beg-2-1))) ; no + ; overline / + ; underline + (rst-forward-line (- dir)))) ; step back to title + ; / adornment + (if (< dir 0) ; keep downward adornment + (rst-forward-line (- dir))))) ; step back to adornment + (if (looking-at (rst-re 'ttl-beg)) ; may be a title + (if (zerop (rst-forward-line dir)) + (if (not + (looking-at (rst-re 'ado-beg-2-1))) ; no overline / + ; underline + (rst-forward-line (- dir)))))) ; step back to line + (if (not (= (point) pt)) + (point)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Indented blocks @@ -3034,198 +3671,154 @@ (forward-line 1) (when (< (point) limit) (setq beg (point)) - (if (looking-at "\\s *$") + (if (looking-at (rst-re 'lin-end)) (setq cand (or cand beg)) ; An empty line is a candidate (move-to-column clm) ;; FIXME: No indentation [(zerop clm)] must be handled in some ;; useful way - though it is not clear what this should mean at all (if (string-match - "^\\s *$" (buffer-substring-no-properties beg (point))) + (rst-re 'linemp-tag) + (buffer-substring-no-properties beg (point))) (setq cand nil) ; An indented line resets a candidate (setq fnd (or cand beg))))))) (goto-char (or fnd start)) fnd)) -;; Stores the point where the current indentation ends if a number. If `next' -;; indicates `rst-font-lock-find-unindented-line' shall take the indentation -;; from the next line if this is not empty. If non-nil indicates -;; `rst-font-lock-find-unindented-line' shall take the indentation from the -;; next non-empty line. Also used as a trigger for -;; `rst-font-lock-find-unindented-line'. -(defvar rst-font-lock-indentation-point nil) - -(defun rst-font-lock-find-unindented-line (limit) - (let* ((ind-pnt rst-font-lock-indentation-point) - (beg-pnt ind-pnt)) - ;; May run only once - enforce this - (setq rst-font-lock-indentation-point nil) - (when (and ind-pnt (not (numberp ind-pnt))) - ;; Find indentation point in next line if any - (setq ind-pnt - (save-excursion - (save-match-data - (if (eq ind-pnt 'next) - (when (and (zerop (forward-line 1)) (< (point) limit)) - (setq beg-pnt (point)) - (when (not (looking-at "\\s *$")) - (looking-at "\\s *") - (match-end 0))) - (while (and (zerop (forward-line 1)) (< (point) limit) - (looking-at "\\s *$"))) - (when (< (point) limit) - (setq beg-pnt (point)) - (looking-at "\\s *") - (match-end 0))))))) - (when ind-pnt - (goto-char ind-pnt) - ;; Always succeeds because the limit set by PRE-MATCH-FORM is the - ;; ultimate point to find - (goto-char (or (rst-forward-indented-block nil limit) limit)) - (save-excursion - ;; Include subsequent empty lines in the font-lock block, - ;; in case the user subsequently changes the indentation of the next - ;; non-empty line to move it into the indented element. - (skip-chars-forward " \t\n") - (put-text-property beg-pnt (point) 'font-lock-multiline t)) - (set-match-data (list beg-pnt (point))) - t))) +(defvar rst-font-lock-find-unindented-line-begin nil + "Beginning of the match if `rst-font-lock-find-unindented-line-end'") + +(defvar rst-font-lock-find-unindented-line-end nil + "End of the match as determined by `rst-font-lock-find-unindented-line-limit'. +Also used as a trigger for +`rst-font-lock-find-unindented-line-match'.") + +(defun rst-font-lock-find-unindented-line-limit (ind-pnt) + "Find the next unindented line relative to indenation at IND-PNT. +Return this point, the end of the buffer or nil if nothing found. +If IND-PNT is `next' take the indentation from the next line if +this is not empty and indented more than the current one. If +IND-PNT is non-nil but not a number take the indentation from the +next non-empty line if this is indented more than the current +one." + (setq rst-font-lock-find-unindented-line-begin ind-pnt) + (setq rst-font-lock-find-unindented-line-end + (save-excursion + (when (not (numberp ind-pnt)) + ;; Find indentation point in next line if any + (setq ind-pnt + ;; FIXME: Should be refactored to two different functions + ;; giving their result to this function, may be + ;; integrated in caller + (save-match-data + (let ((cur-ind (current-indentation))) + (if (eq ind-pnt 'next) + (when (and (zerop (forward-line 1)) + (< (point) (point-max))) + ;; Not at EOF + (setq rst-font-lock-find-unindented-line-begin + (point)) + (when (and (not (looking-at (rst-re 'lin-end))) + (> (current-indentation) cur-ind)) + ;; Use end of indentation if non-empty line + (looking-at (rst-re 'hws-tag)) + (match-end 0))) + ;; Skip until non-empty line or EOF + (while (and (zerop (forward-line 1)) + (< (point) (point-max)) + (looking-at (rst-re 'lin-end)))) + (when (< (point) (point-max)) + ;; Not at EOF + (setq rst-font-lock-find-unindented-line-begin + (point)) + (when (> (current-indentation) cur-ind) + ;; Indentation bigger than line of departure + (looking-at (rst-re 'hws-tag)) + (match-end 0)))))))) + (when ind-pnt + (goto-char ind-pnt) + (or (rst-forward-indented-block nil (point-max)) + (point-max)))))) + +(defun rst-font-lock-find-unindented-line-match (limit) + "Set the match found by +`rst-font-lock-find-unindented-line-limit' the first time called +or nil." + (when rst-font-lock-find-unindented-line-end + (set-match-data + (list rst-font-lock-find-unindented-line-begin + rst-font-lock-find-unindented-line-end)) + (put-text-property rst-font-lock-find-unindented-line-begin + rst-font-lock-find-unindented-line-end + 'font-lock-multiline t) + ;; Make sure this is called only once + (setq rst-font-lock-find-unindented-line-end nil) + t)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Adornments -(defvar rst-font-lock-adornment-point nil - "Stores the point where the current adornment ends. -Also used as a trigger for `rst-font-lock-handle-adornment'.") - -;; Here `rst-font-lock-handle-adornment' stores the section level of the -;; current adornment or t for a transition. -(defvar rst-font-lock-level nil) - -;; FIXME: It would be good if this could be used to markup section titles of -;; given level with a special key; it would be even better to be able to -;; customize this so it can be used for a generally available personal style -;; -;; FIXME: There should be some way to reset and reload this variable - probably -;; a special key -;; -;; FIXME: Some support for `outline-mode' would be nice which should be based -;; on this information -(defvar rst-adornment-level-alist nil - "Associates adornments with section levels. -The key is a two character string. The first character is the adornment -character. The second character distinguishes underline section titles (`u') -from overline/underline section titles (`o'). The value is the section level. - -This is made buffer local on start and adornments found during font lock are -entered.") - -;; Returns section level for adornment key KEY. Adds new section level if KEY -;; is not found and ADD. If KEY is not a string it is simply returned. -(defun rst-adornment-level (key &optional add) - (let ((fnd (assoc key rst-adornment-level-alist)) - (new 1)) - (cond - ((not (stringp key)) - key) - (fnd - (cdr fnd)) - (add - (while (rassoc new rst-adornment-level-alist) - (setq new (1+ new))) - (setq rst-adornment-level-alist - (append rst-adornment-level-alist (list (cons key new)))) - new)))) - -;; Classifies adornment for section titles and transitions. ADORNMENT is the -;; complete adornment string as found in the buffer. END is the point after the -;; last character of ADORNMENT. For overline section adornment LIMIT limits the -;; search for the matching underline. Returns a list. The first entry is t for -;; a transition, or a key string for `rst-adornment-level' for a section title. -;; The following eight values forming four match groups as can be used for -;; `set-match-data'. First match group contains the maximum points of the whole -;; construct. Second and last match group matched pure section title adornment -;; while third match group matched the section title text or the transition. -;; Each group but the first may or may not exist. -(defun rst-classify-adornment (adornment end limit) - (save-excursion - (save-match-data - (goto-char end) - (let ((ado-ch (aref adornment 0)) - (ado-re (regexp-quote adornment)) - (end-pnt (point)) - (beg-pnt (progn - (forward-line 0) - (point))) - (nxt-emp - (save-excursion - (or (not (zerop (forward-line 1))) - (looking-at "\\s *$")))) - (prv-emp - (save-excursion - (or (not (zerop (forward-line -1))) - (looking-at "\\s *$")))) - key beg-ovr end-ovr beg-txt end-txt beg-und end-und) - (cond - ((and nxt-emp prv-emp) - ;; A transition - (setq key t) - (setq beg-txt beg-pnt) - (setq end-txt end-pnt)) - (prv-emp - ;; An overline - (setq key (concat (list ado-ch) "o")) - (setq beg-ovr beg-pnt) - (setq end-ovr end-pnt) - (forward-line 1) - (setq beg-txt (point)) - (while (and (< (point) limit) (not end-txt)) - (if (looking-at "\\s *$") - ;; No underline found - (setq end-txt (1- (point))) - (when (looking-at (concat "\\(" ado-re "\\)\\s *$")) - (setq end-und (match-end 1)) - (setq beg-und (point)) - (setq end-txt (1- beg-und)))) - (forward-line 1))) - (t - ;; An underline - (setq key (concat (list ado-ch) "u")) - (setq beg-und beg-pnt) - (setq end-und end-pnt) - (setq end-txt (1- beg-und)) - (setq beg-txt (progn - (if (re-search-backward "^\\s *$" 1 'move) - (forward-line 1)) - (point))))) - (list key - (or beg-ovr beg-txt beg-und) - (or end-und end-txt end-und) - beg-ovr end-ovr beg-txt end-txt beg-und end-und))))) - -;; Handles adornments for font-locking section titles and transitions. Returns -;; three match groups. First and last match group matched pure overline / -;; underline adornment while second group matched section title text. Each -;; group may not exist. -(defun rst-font-lock-handle-adornment (limit) - (let ((ado-pnt rst-font-lock-adornment-point)) +(defvar rst-font-lock-adornment-level nil + "Storage for `rst-font-lock-handle-adornment-matcher'. +Either section level of the current adornment or t for a transition.") + +(defun rst-adornment-level (key) + "Return section level for adornment KEY. +KEY is the first element of the return list of +`rst-classify-adornment'. If KEY is not a cons return it. If KEY is found +in the hierarchy return its level. Otherwise return a level one +beyond the existing hierarchy." + (if (not (consp key)) + key + (let* ((hier (rst-get-hierarchy)) + (char (car key)) + (style (cdr key))) + (1+ (or (position-if (lambda (elt) + (and (equal (car elt) char) + (equal (cadr elt) style))) hier) + (length hier)))))) + +(defvar rst-font-lock-adornment-match nil + "Storage for match for current adornment. +Set by `rst-font-lock-handle-adornment-pre-match-form'. Also used +as a trigger for `rst-font-lock-handle-adornment-matcher'.") + +(defun rst-font-lock-handle-adornment-pre-match-form (ado ado-end) + "Determine limit for adornments for font-locking section titles and transitions. +In fact determine all things necessary and put the result to +`rst-font-lock-adornment-match' and +`rst-font-lock-adornment-level'. ADO is the complete adornment +matched. ADO-END is the point where ADO ends. Return the point +where the whole adorned construct ends. + +Called as a PRE-MATCH-FORM in the sense of `font-lock-keywords'." + (let ((ado-data (rst-classify-adornment ado ado-end))) + (if (not ado-data) + (setq rst-font-lock-adornment-level nil + rst-font-lock-adornment-match nil) + (setq rst-font-lock-adornment-level + (rst-adornment-level (car ado-data))) + (setq rst-font-lock-adornment-match (cdr ado-data)) + (goto-char (nth 1 ado-data)) ; Beginning of construct + (nth 2 ado-data)))) ; End of construct + +(defun rst-font-lock-handle-adornment-matcher (limit) + "Set the match found by `rst-font-lock-handle-adornment-pre-match-form' +the first time called or nil. + +Called as a MATCHER in the sense of `font-lock-keywords'." + (let ((match rst-font-lock-adornment-match)) ;; May run only once - enforce this - (setq rst-font-lock-adornment-point nil) - (if ado-pnt - (let* ((ado (rst-classify-adornment (match-string-no-properties 1) - ado-pnt limit)) - (key (car ado)) - (mtc (cdr ado))) - (setq rst-font-lock-level (rst-adornment-level key t)) - (goto-char (nth 1 mtc)) - (put-text-property (nth 0 mtc) (nth 1 mtc) 'font-lock-multiline t) - (set-match-data mtc) - t)))) - - + (setq rst-font-lock-adornment-match nil) + (when match + (set-match-data match) + (goto-char (match-end 0)) + (put-text-property (match-beginning 0) (match-end 0) + 'font-lock-multiline t) + t))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Support for conversion from within Emacs +;; Compilation (defgroup rst-compile nil "Settings for support of conversion of reStructuredText @@ -3254,6 +3847,8 @@ An association list of the toolset to a list of the (command to use, extension of produced filename, options to the tool (nil or a string)) to be used for converting the document." + ;; FIXME: These are not options but symbols which may be referenced by + ;; `rst-compile-*-toolset` below :type '(alist :options (html latex newlatex pseudoxml xml pdf s5) :key-type symbol :value-type (list :tag "Specification" @@ -3265,15 +3860,11 @@ :group 'rst :version "24.1") -;; Note for Python programmers not familiar with association lists: you can set -;; values in an alists like this, e.g. : -;; (setcdr (assq 'html rst-compile-toolsets) -;; '("rst2html.py" ".htm" "--stylesheet=/docutils.css")) - - +;; FIXME: Must be `defcustom` (defvar rst-compile-primary-toolset 'html "The default toolset for `rst-compile'.") +;; FIXME: Must be `defcustom` (defvar rst-compile-secondary-toolset 'latex "The default toolset for `rst-compile' with a prefix argument.") @@ -3301,15 +3892,15 @@ (require 'compile) -(defun rst-compile (&optional pfxarg) +(defun rst-compile (&optional use-alt) "Compile command to convert reST document into some output file. Attempts to find configuration file, if it can, overrides the -options. There are two commands to choose from, with a prefix -argument, select the alternative toolset." +options. There are two commands to choose from, with USE-ALT, +select the alternative toolset." (interactive "P") ;; Note: maybe we want to check if there is a Makefile too and not do anything ;; if that is the case. I dunno. - (let* ((toolset (cdr (assq (if pfxarg + (let* ((toolset (cdr (assq (if use-alt rst-compile-secondary-toolset rst-compile-primary-toolset) rst-compile-toolsets))) @@ -3326,14 +3917,14 @@ (list command (or options "") (if conffile - (concat "--config=\"" conffile "\"") + (concat "--config=" (shell-quote-argument conffile)) "") - bufname - (concat outname extension)) + (shell-quote-argument bufname) + (shell-quote-argument (concat outname extension))) " ")) ;; Invoke the compile command. - (if (or compilation-read-command current-prefix-arg) + (if (or compilation-read-command use-alt) (call-interactively 'compile) (compile compile-command)) )) @@ -3341,7 +3932,7 @@ (defun rst-compile-alt-toolset () "Compile command with the alternative toolset." (interactive) - (rst-compile 't)) + (rst-compile t)) (defun rst-compile-pseudo-region () "Show the pseudo-XML rendering of the current active region, @@ -3354,45 +3945,45 @@ (cadr (assq 'pseudoxml rst-compile-toolsets)) standard-output))) +;; FIXME: Should be `defcustom` (defvar rst-pdf-program "xpdf" "Program used to preview PDF files.") (defun rst-compile-pdf-preview () "Convert the document to a PDF file and launch a preview program." (interactive) - (let* ((tmp-filename (make-temp-file "rst-out" nil ".pdf")) - (command (format "%s %s %s && %s %s" + (let* ((tmp-filename (make-temp-file "rst_el" nil ".pdf")) + (command (format "%s %s %s && %s %s ; rm %s" (cadr (assq 'pdf rst-compile-toolsets)) buffer-file-name tmp-filename - rst-pdf-program tmp-filename))) + rst-pdf-program tmp-filename tmp-filename))) (start-process-shell-command "rst-pdf-preview" nil command) ;; Note: you could also use (compile command) to view the compilation ;; output. )) +;; FIXME: Should be `defcustom` or use something like `browse-url` (defvar rst-slides-program "firefox" "Program used to preview S5 slides.") (defun rst-compile-slides-preview () "Convert the document to an S5 slide presentation and launch a preview program." (interactive) - (let* ((tmp-filename (make-temp-file "rst-slides" nil ".html")) - (command (format "%s %s %s && %s %s" + (let* ((tmp-filename (make-temp-file "rst_el" nil ".html")) + (command (format "%s %s %s && %s %s ; rm %s" (cadr (assq 's5 rst-compile-toolsets)) buffer-file-name tmp-filename - rst-slides-program tmp-filename))) + rst-slides-program tmp-filename tmp-filename))) (start-process-shell-command "rst-slides-preview" nil command) ;; Note: you could also use (compile command) to view the compilation ;; output. )) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; Generic text functions that are more convenient than the defaults. -;; +;; FIXME: Unbound command - should be bound or removed (defun rst-replace-lines (fromchar tochar) "Replace flush-left lines, consisting of multiple FROMCHAR characters, with equal-length lines of TOCHAR." @@ -3400,7 +3991,7 @@ cSearch for flush-left lines of char: cand replace with char: ") (save-excursion - (let ((searchre (concat "^" (regexp-quote (string fromchar)) "+\\( *\\)$")) + (let ((searchre (rst-re "^" fromchar "+\\( *\\)$")) (found 0)) (while (search-forward-regexp searchre nil t) (setq found (1+ found)) @@ -3410,12 +4001,14 @@ (insert-char tochar width))) (message (format "%d lines replaced." found))))) +;; FIXME: Unbound command - should be bound or removed (defun rst-join-paragraph () "Join lines in current paragraph into one line, removing end-of-lines." (interactive) (let ((fill-column 65000)) ; some big number (call-interactively 'fill-paragraph))) +;; FIXME: Unbound command - should be bound or removed (defun rst-force-fill-paragraph () "Fill paragraph at point, first joining the paragraph's lines into one. This is useful for filling list item paragraphs." @@ -3424,41 +4017,40 @@ (fill-paragraph nil)) +;; FIXME: Unbound command - should be bound or removed ;; Generic character repeater function. ;; For sections, better to use the specialized function above, but this can ;; be useful for creating separators. -(defun rst-repeat-last-character (&optional tofill) +(defun rst-repeat-last-character (use-next) "Fill the current line up to the length of the preceding line (if not empty), using the last character on the current line. If the preceding line is empty, we use the `fill-column'. -If a prefix argument is provided, use the next line rather than the preceding -line. +If USE-NEXT, use the next line rather than the preceding line. If the current line is longer than the desired length, shave the characters off the current line to fit the desired length. As an added convenience, if the command is repeated immediately, the alternative column is used (fill-column vs. end of previous/next line)." - (interactive) + (interactive "P") (let* ((curcol (current-column)) (curline (+ (count-lines (point-min) (point)) - (if (eq curcol 0) 1 0))) + (if (zerop curcol) 1 0))) (lbp (line-beginning-position 0)) - (prevcol (if (and (= curline 1) (not current-prefix-arg)) + (prevcol (if (and (= curline 1) (not use-next)) fill-column (save-excursion - (forward-line (if current-prefix-arg 1 -1)) + (forward-line (if use-next 1 -1)) (end-of-line) (skip-chars-backward " \t" lbp) (let ((cc (current-column))) - (if (= cc 0) fill-column cc))))) + (if (zerop cc) fill-column cc))))) (rightmost-column - (cond (tofill fill-column) - ((equal last-command 'rst-repeat-last-character) + (cond ((equal last-command 'rst-repeat-last-character) (if (= curcol fill-column) prevcol fill-column)) (t (save-excursion - (if (= prevcol 0) fill-column prevcol))) + (if (zerop prevcol) fill-column prevcol))) )) ) (end-of-line) (if (> (current-column) rightmost-column) @@ -3481,5 +4073,4 @@ (provide 'rst) - ;;; rst.el ends here ------------------------------------------------------------ revno: 108147 committer: Stefan Monnier branch nick: trunk timestamp: Mon 2012-05-07 12:29:55 -0400 message: * lisp/buff-menu.el (list-buffers--refresh): Mark `size' as right-align. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-init-header): Handle new :right-align column property. (tabulated-list-print-col): Idem, plus use `display' text-property to try and preserve alignment for variable pitch fonts. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-07 05:37:38 +0000 +++ lisp/ChangeLog 2012-05-07 16:29:55 +0000 @@ -1,3 +1,11 @@ +2012-05-07 Stefan Monnier + + * buff-menu.el (list-buffers--refresh): Mark `size' as right-align. + * emacs-lisp/tabulated-list.el (tabulated-list-init-header): + Handle new :right-align column property. + (tabulated-list-print-col): Idem, plus use `display' text-property to + try and preserve alignment for variable pitch fonts. + 2012-05-07 Chong Yidong * emacs-lisp/tabulated-list.el: Add no-header-line alternative. @@ -11,8 +19,8 @@ (tabulated-list-col-sort): Handle non-header-line button case. (tabulated-list--sort-by-column-name): Fix a corner case. - * buff-menu.el (list-buffers--refresh): Handle - Buffer-menu-use-header-line. + * buff-menu.el (list-buffers--refresh): + Handle Buffer-menu-use-header-line. 2012-05-06 Chong Yidong @@ -32,7 +40,7 @@ (Buffer-menu-bury): Use Tabulated List machinery. (Buffer-menu-mouse-select, Buffer-menu-sort-by-column) (Buffer-menu-sort-button-map, Buffer-menu-make-sort-button): - Deleted. + Delete. (list-buffers--refresh): New function. (list-buffers-noselect): Use it. (tabulated-list-entry-size->, Buffer-menu--pretty-name) === modified file 'lisp/buff-menu.el' --- lisp/buff-menu.el 2012-05-07 05:37:38 +0000 +++ lisp/buff-menu.el 2012-05-07 16:29:55 +0000 @@ -269,6 +269,7 @@ (message "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) +;;;###autoload (defun list-buffers (&optional arg) "Display a list of existing buffers. The list is displayed in a buffer named \"*Buffer List*\". @@ -543,6 +544,7 @@ ;;; Functions for populating the Buffer Menu. +;;;###autoload (defun list-buffers-noselect (&optional files-only buffer-list) "Create and return a Buffer Menu buffer. This is called by `buffer-menu' and others as a subroutine. @@ -571,7 +573,8 @@ '("R" 1 t :pad-right 0) '("M" 1 t) `("Buffer" ,name-width t) - `("Size" ,size-width tabulated-list-entry-size->) + `("Size" ,size-width tabulated-list-entry-size-> + :right-align t) `("Mode" ,Buffer-menu-mode-width t) '("File" 1 t)))) (setq tabulated-list-use-header-line Buffer-menu-use-header-line) === modified file 'lisp/emacs-lisp/tabulated-list.el' --- lisp/emacs-lisp/tabulated-list.el 2012-05-07 05:37:38 +0000 +++ lisp/emacs-lisp/tabulated-list.el 2012-05-07 16:29:55 +0000 @@ -52,6 +52,7 @@ of `tabulated-list-entries'. - PROPS is a plist of additional column properties. Currently supported properties are: + - `:right-align': if non-nil, the column should be right-aligned. - `:pad-right': Number of additional padding spaces to the right of the column (defaults to 1 if omitted).") (make-variable-buffer-local 'tabulated-list-format) @@ -179,6 +180,7 @@ (defun tabulated-list-init-header () "Set up header line for the Tabulated List buffer." + ;; FIXME: Should share code with tabulated-list-print-col! (let ((x (max tabulated-list-padding 0)) (button-props `(help-echo "Click to sort by column" mouse-face highlight @@ -190,8 +192,9 @@ (label (nth 0 col)) (width (nth 1 col)) (props (nthcdr 3 col)) - (pad-right (or (plist-get props :pad-right) 1))) - (setq x (+ x pad-right width)) + (pad-right (or (plist-get props :pad-right) 1)) + (right-align (plist-get props :right-align)) + (next-x (+ x pad-right width))) (push (cond ;; An unsortable column @@ -202,10 +205,8 @@ (apply 'propertize (concat label (cond - ((> (+ 2 (length label)) width) - "") - ((cdr tabulated-list-sort-key) - " ▲") + ((> (+ 2 (length label)) width) "") + ((cdr tabulated-list-sort-key) " ▲") (t " ▼"))) 'face 'bold 'tabulated-list-column-name label @@ -215,11 +216,22 @@ 'tabulated-list-column-name label button-props))) cols) + (when right-align + (let ((shift (- width (string-width (car cols))))) + (when (> shift 0) + (setq cols + (cons (car cols) + (cons (propertize (make-string shift ?\s) + 'display + `(space :align-to ,(+ x shift))) + (cdr cols)))) + (setq x (+ x shift))))) (if (> pad-right 0) (push (propertize " " - 'display `(space :align-to ,x) + 'display `(space :align-to ,next-x) 'face 'fixed-pitch) - cols)))) + cols)) + (setq x next-x))) (setq cols (apply 'concat (nreverse cols))) (if tabulated-list-use-header-line (setq header-line-format cols) @@ -276,7 +288,7 @@ (erase-buffer) (unless tabulated-list-use-header-line (tabulated-list-print-fake-header)) - ;; Sort the buffers, if necessary. + ;; Sort the entries, if necessary. (when (and tabulated-list-sort-key (car tabulated-list-sort-key)) (let* ((sort-column (car tabulated-list-sort-key)) @@ -332,29 +344,43 @@ N is the column number, COL-DESC is a column descriptor \(see `tabulated-list-entries'), and X is the column number at point. Return the column number after insertion." + ;; TODO: don't truncate to `width' if the next column is align-right + ;; and has some space left. (let* ((format (aref tabulated-list-format n)) (name (nth 0 format)) (width (nth 1 format)) (props (nthcdr 3 format)) (pad-right (or (plist-get props :pad-right) 1)) + (right-align (plist-get props :right-align)) (label (if (stringp col-desc) col-desc (car col-desc))) + (label-width (string-width label)) (help-echo (concat (car format) ": " label)) (opoint (point)) (not-last-col (< (1+ n) (length tabulated-list-format)))) ;; Truncate labels if necessary (except last column). (and not-last-col - (> (string-width label) width) - (setq label (truncate-string-to-width label width nil nil t))) + (> label-width width) + (setq label (truncate-string-to-width label width nil nil t) + label-width width)) (setq label (bidi-string-mark-left-to-right label)) + (when (and right-align (> width label-width)) + (let ((shift (- width label-width))) + (insert (propertize (make-string shift ?\s) + 'display `(space :align-to ,(+ x shift)))) + (setq width (- width shift)) + (setq x (+ x shift)))) (if (stringp col-desc) (insert (propertize label 'help-echo help-echo)) (apply 'insert-text-button label (cdr col-desc))) - (setq x (+ x pad-right width)) - ;; No need to append any spaces if this is the last column. - (if not-last-col - (indent-to x pad-right)) - (put-text-property opoint (point) 'tabulated-list-column-name name) - x)) + (let ((next-x (+ x pad-right width))) + ;; No need to append any spaces if this is the last column. + (when not-last-col + (when (> pad-right 0) (insert (make-string pad-right ?\s))) + (insert (propertize + (make-string (- next-x x label-width pad-right) ?\s) + 'display `(space :align-to ,next-x)))) + (put-text-property opoint (point) 'tabulated-list-column-name name) + next-x))) (defun tabulated-list-delete-entry () "Delete the Tabulated List entry at point. ------------------------------------------------------------ revno: 108146 author: Jérémy Compostella committer: Stefan Monnier branch nick: trunk timestamp: Mon 2012-05-07 12:09:51 -0400 message: Fix up display of the *Minibuf-0* buffer in the mini window. * src/keyboard.c (read_char): Don't clear the echo area if there's no message to clear. * src/xdisp.c (redisplay_internal): Redisplay the mini window (with the contents of *Minibuf-0*) if there' no message displayed in its stead. diff: === modified file 'src/ChangeLog' --- src/ChangeLog 2012-05-07 14:57:18 +0000 +++ src/ChangeLog 2012-05-07 16:09:51 +0000 @@ -1,3 +1,11 @@ +2012-05-07 Jérémy Compostella + + Fix up display of the *Minibuf-0* buffer in the mini window. + * keyboard.c (read_char): Don't clear the echo area if there's no + message to clear. + * xdisp.c (redisplay_internal): Redisplay the mini window (with the + contents of *Minibuf-0*) if there' no message displayed in its stead. + 2012-05-07 Michael Albinus * dbusbind.c (XD_DEBUG_MESSAGE): Don't print message twice in === modified file 'src/keyboard.c' --- src/keyboard.c 2012-05-04 23:16:47 +0000 +++ src/keyboard.c 2012-05-07 16:09:51 +0000 @@ -2996,8 +2996,10 @@ && !(EQ (Qselect_window, XCAR (c))))) { if (!NILP (echo_area_buffer[0])) - safe_run_hooks (Qecho_area_clear_hook); - clear_message (1, 0); + { + safe_run_hooks (Qecho_area_clear_hook); + clear_message (1, 0); + } } reread_for_input_method: === modified file 'src/xdisp.c' --- src/xdisp.c 2012-05-02 07:20:29 +0000 +++ src/xdisp.c 2012-05-07 16:09:51 +0000 @@ -12727,6 +12727,9 @@ frames. Zero means, only selected_window is considered. */ int consider_all_windows_p; + /* Non-zero means redisplay has to redisplay the miniwindow */ + int update_miniwindow_p = 0; + TRACE ((stderr, "redisplay_internal %d\n", redisplaying_p)); /* No redisplay if running in batch mode or frame is not yet fully @@ -12913,6 +12916,10 @@ && !MINI_WINDOW_P (XWINDOW (selected_window)))) { int window_height_changed_p = echo_area_display (0); + + if (message_cleared_p) + update_miniwindow_p = 1; + must_finish = 1; /* If we don't display the current message, don't clear the @@ -12949,7 +12956,7 @@ /* FIXME: this causes all frames to be updated, which seems unnecessary since only the current frame needs to be considered. This function needs to be rewritten with two variables, consider_all_windows and - consider_all_frames. */ + consider_all_frames. */ consider_all_windows_p = 1; ++windows_or_buffers_changed; ++update_mode_lines; @@ -13135,7 +13142,8 @@ then we can't just move the cursor. */ else if (! (!NILP (Vtransient_mark_mode) && !NILP (BVAR (current_buffer, mark_active))) - && (EQ (selected_window, BVAR (current_buffer, last_selected_window)) + && (EQ (selected_window, + BVAR (current_buffer, last_selected_window)) || highlight_nonselected_windows) && NILP (w->region_showing) && NILP (Vshow_trailing_whitespace) @@ -13288,7 +13296,7 @@ } else if (FRAME_VISIBLE_P (sf) && !FRAME_OBSCURED_P (sf)) { - Lisp_Object mini_window; + Lisp_Object mini_window = FRAME_MINIBUF_WINDOW (sf); struct frame *mini_frame; displayed_buffer = XBUFFER (XWINDOW (selected_window)->buffer); @@ -13297,6 +13305,10 @@ internal_condition_case_1 (redisplay_window_1, selected_window, list_of_error, redisplay_window_error); + if (update_miniwindow_p) + internal_condition_case_1 (redisplay_window_1, mini_window, + list_of_error, + redisplay_window_error); /* Compare desired and current matrices, perform output. */ ------------------------------------------------------------ revno: 108145 committer: Michael Albinus branch nick: trunk timestamp: Mon 2012-05-07 16:57:18 +0200 message: * dbusbind.c (XD_DEBUG_MESSAGE): Don't print message twice in batch mode. diff: === modified file 'src/ChangeLog' --- src/ChangeLog 2012-05-06 16:45:46 +0000 +++ src/ChangeLog 2012-05-07 14:57:18 +0000 @@ -1,3 +1,8 @@ +2012-05-07 Michael Albinus + + * dbusbind.c (XD_DEBUG_MESSAGE): Don't print message twice in + batch mode. + 2012-05-06 Chong Yidong * lisp.mk (lisp): Update. @@ -245,7 +250,7 @@ (xd_close_bus): Rename from Fdbus_close_bus. Not needed on Lisp level. (Fdbus_init_bus): New optional arg PRIVATE. Cache address. - Return number of recounts. + Return number of refcounts. (Fdbus_get_unique_name): Make stronger parameter check. (Fdbus_message_internal): New defun. (Fdbus_call_method, Fdbus_call_method_asynchronously) === modified file 'src/dbusbind.c' --- src/dbusbind.c 2012-04-22 17:46:49 +0000 +++ src/dbusbind.c 2012-05-07 14:57:18 +0000 @@ -111,12 +111,13 @@ /* Macros for debugging. In order to enable them, build with "env MYCPPFLAGS='-DDBUS_DEBUG -Wall' make". */ #ifdef DBUS_DEBUG -#define XD_DEBUG_MESSAGE(...) \ - do { \ - char s[1024]; \ - snprintf (s, sizeof s, __VA_ARGS__); \ - printf ("%s: %s\n", __func__, s); \ - message ("%s: %s", __func__, s); \ +#define XD_DEBUG_MESSAGE(...) \ + do { \ + char s[1024]; \ + snprintf (s, sizeof s, __VA_ARGS__); \ + if (!noninteractive) \ + printf ("%s: %s\n", __func__, s); \ + message ("%s: %s", __func__, s); \ } while (0) #define XD_DEBUG_VALID_LISP_OBJECT_P(object) \ do { \ ------------------------------------------------------------ revno: 108144 committer: Chong Yidong branch nick: trunk timestamp: Mon 2012-05-07 13:37:38 +0800 message: Restore Buffer-menu-use-header-line functionality. * lisp/emacs-lisp/tabulated-list.el: Add no-header-line alternative. (tabulated-list-use-header-line): New var. (tabulated-list-init-header): Use it. (tabulated-list-print-fake-header): New function. (tabulated-list-print): Use it. (tabulated-list-sort-button-map): Add non-header-line commands. (tabulated-list-init-header): Add column name property to basic labels as well. (tabulated-list-col-sort): Handle non-header-line button case. (tabulated-list--sort-by-column-name): Fix a corner case. * lisp/buff-menu.el (list-buffers--refresh): Handle Buffer-menu-use-header-line. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-05-06 16:45:46 +0000 +++ lisp/ChangeLog 2012-05-07 05:37:38 +0000 @@ -1,3 +1,19 @@ +2012-05-07 Chong Yidong + + * emacs-lisp/tabulated-list.el: Add no-header-line alternative. + (tabulated-list-use-header-line): New var. + (tabulated-list-init-header): Use it. + (tabulated-list-print-fake-header): New function. + (tabulated-list-print): Use it. + (tabulated-list-sort-button-map): Add non-header-line commands. + (tabulated-list-init-header): Add column name property to basic + labels as well. + (tabulated-list-col-sort): Handle non-header-line button case. + (tabulated-list--sort-by-column-name): Fix a corner case. + + * buff-menu.el (list-buffers--refresh): Handle + Buffer-menu-use-header-line. + 2012-05-06 Chong Yidong * buff-menu.el: Convert to Tabulated List mode. === modified file 'lisp/buff-menu.el' --- lisp/buff-menu.el 2012-05-06 16:45:46 +0000 +++ lisp/buff-menu.el 2012-05-07 05:37:38 +0000 @@ -574,6 +574,7 @@ `("Size" ,size-width tabulated-list-entry-size->) `("Mode" ,Buffer-menu-mode-width t) '("File" 1 t)))) + (setq tabulated-list-use-header-line Buffer-menu-use-header-line) ;; Collect info for each buffer we're interested in. (let ((buffer-menu-buffer (current-buffer)) (show-non-file (not Buffer-menu-files-only)) === modified file 'lisp/emacs-lisp/tabulated-list.el' --- lisp/emacs-lisp/tabulated-list.el 2012-05-06 16:45:46 +0000 +++ lisp/emacs-lisp/tabulated-list.el 2012-05-07 05:37:38 +0000 @@ -56,6 +56,10 @@ right of the column (defaults to 1 if omitted).") (make-variable-buffer-local 'tabulated-list-format) +(defvar tabulated-list-use-header-line t + "Whether the Tabulated List buffer should use a header line.") +(make-variable-buffer-local 'tabulated-list-use-header-line) + (defvar tabulated-list-entries nil "Entries displayed in the current Tabulated List buffer. This should be either a function, or a list. @@ -154,6 +158,9 @@ (let ((map (make-sparse-keymap))) (define-key map [header-line mouse-1] 'tabulated-list-col-sort) (define-key map [header-line mouse-2] 'tabulated-list-col-sort) + (define-key map [mouse-1] 'tabulated-list-col-sort) + (define-key map [mouse-2] 'tabulated-list-col-sort) + (define-key map "\C-m" 'tabulated-list-sort) (define-key map [follow-link] 'mouse-face) map) "Local keymap for `tabulated-list-mode' sort buttons.") @@ -167,6 +174,9 @@ table) "The `glyphless-char-display' table in Tabulated List buffers.") +(defvar tabulated-list--header-string nil) +(defvar tabulated-list--header-overlay nil) + (defun tabulated-list-init-header () "Set up header line for the Tabulated List buffer." (let ((x (max tabulated-list-padding 0)) @@ -185,7 +195,8 @@ (push (cond ;; An unsortable column - ((not (nth 2 col)) label) + ((not (nth 2 col)) + (propertize label 'tabulated-list-column-name label)) ;; The selected sort column ((equal (car col) (car tabulated-list-sort-key)) (apply 'propertize @@ -197,11 +208,11 @@ " ▲") (t " ▼"))) 'face 'bold - 'tabulated-list-column-name (car col) + 'tabulated-list-column-name label button-props)) ;; Unselected sortable column. (t (apply 'propertize label - 'tabulated-list-column-name (car col) + 'tabulated-list-column-name label button-props))) cols) (if (> pad-right 0) @@ -209,7 +220,22 @@ 'display `(space :align-to ,x) 'face 'fixed-pitch) cols)))) - (setq header-line-format (mapconcat 'identity (nreverse cols) "")))) + (setq cols (apply 'concat (nreverse cols))) + (if tabulated-list-use-header-line + (setq header-line-format cols) + (setq header-line-format nil) + (set (make-local-variable 'tabulated-list--header-string) cols)))) + +(defun tabulated-list-print-fake-header () + "Insert a fake Tabulated List \"header line\" at the start of the buffer." + (goto-char (point-min)) + (let ((inhibit-read-only t)) + (insert tabulated-list--header-string "\n") + (if tabulated-list--header-overlay + (move-overlay tabulated-list--header-overlay (point-min) (point)) + (set (make-local-variable 'tabulated-list--header-overlay) + (make-overlay (point-min) (point)))) + (overlay-put tabulated-list--header-overlay 'face 'underline))) (defun tabulated-list-revert (&rest ignored) "The `revert-buffer-function' for `tabulated-list-mode'. @@ -248,6 +274,8 @@ (setq entry-id (tabulated-list-get-id)) (setq saved-col (current-column))) (erase-buffer) + (unless tabulated-list-use-header-line + (tabulated-list-print-fake-header)) ;; Sort the buffers, if necessary. (when (and tabulated-list-sort-key (car tabulated-list-sort-key)) @@ -391,12 +419,12 @@ "Sort Tabulated List entries by the column of the mouse click E." (interactive "e") (let* ((pos (event-start e)) - (obj (posn-object pos)) - (name (get-text-property (if obj (cdr obj) (posn-point pos)) - 'tabulated-list-column-name - (car obj)))) + (obj (posn-object pos))) (with-current-buffer (window-buffer (posn-window pos)) - (tabulated-list--sort-by-column-name name)))) + (tabulated-list--sort-by-column-name + (get-text-property (if obj (cdr obj) (posn-point pos)) + 'tabulated-list-column-name + (car obj)))))) (defun tabulated-list-sort (&optional n) "Sort Tabulated List entries by the column at point. @@ -409,7 +437,7 @@ (tabulated-list--sort-by-column-name name))) (defun tabulated-list--sort-by-column-name (name) - (when (derived-mode-p 'tabulated-list-mode) + (when (and name (derived-mode-p 'tabulated-list-mode)) ;; Flip the sort order on a second click. (if (equal name (car tabulated-list-sort-key)) (setcdr tabulated-list-sort-key