O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing GNU Emacs Extensions

Book Description

Yes, it is possible to be all things to all people, if you're talking about the Emacs editor. As a user, you can make any kind of customization you want, from choosing the keystrokes that invoke your favorite commands to creating a whole new work environment that looks like nothing ever developed before. It's all in Emacs Lisp -- and in this short but fast-paced book.GNU Emacs is more than an editor; it's a programming environment, a communications package, and many other things. To provide such a broad range of functions, it offers a full version of the Lisp programming language -- something much more powerful than the little macro languages provided in other editors (including older versions of Emacs). GNU Emacs is a framework in which you can create whole new kinds of editors or just alter aspects of the many functions it already provides.In this book, Bob Glickstein delves deep into the features that permit far-reaching Emacs customizations. He teaches you the Lisp language and discusses Emacs topics (such as syntax tables and macro templates) in easy-to-digest portions. Examples progress in complexity from simple customizations to extensive major modes.You will learn how to write interactive commands, use hooks and advice, perform error recovery, manipulate windows, buffers, and keymaps, exploit and alter Emacs's main loop, and more. Each topic is explored through realistic examples and a series of successive refinements that illustrate not only the Emacs Lisp language, but the development process as well, making learning pleasant and natural.

Table of Contents

  1. Dedication
  2. A Note Regarding Supplemental Files
  3. Preface
    1. What Is Emacs?
    2. Conventions Used in This Book
      1. Typographic Conventions
      2. Emacs Commands
      3. Examples
    3. Organization of This Book
    4. Obtaining the Example Programs
      1. FTP
    5. Acknowledgments
  4. 1. Customizing Emacs
    1. Backspace and Delete
    2. Lisp
    3. Keys and Strings
      1. The META Key
      2. Binding Keystrokes to Commands
      3. Denoting Keys in Strings
    4. To What Is C-h Bound?
    5. To What Should C-h Be Bound?
    6. Evaluating Lisp Expressions
    7. Apropos
  5. 2. Simple New Commands
    1. Traversing Windows
      1. Defining other-window-backward
      2. Parameterizing other-window-backward
      3. Making the Argument Optional
      4. Condensing the Code
      5. Logical Expressions
      6. The Best other-window-backward
    2. Line-at-a-Time Scrolling
    3. Other Cursor and Text Motion Commands
    4. Clobbering Symbolic Links
      1. Hooks
      2. Anonymous Functions
      3. Handling the Symlink
    5. Advised Buffer Switching
    6. Addendum: Raw Prefix Argument
  6. 3. Cooperating Commands
    1. The Symptom
    2. A Cure
      1. Declaring Variables
      2. Saving and Restoring Point
      3. Window Appearance
      4. Detecting Errors
    3. Generalizing the Solution
      1. Using this-command
      2. Symbol Properties
      3. Markers
      4. Addendum: Efficiency Consideration
  7. 4. Searching and Modifying Buffers
    1. Inserting the Current Time
      1. User Options and Docstrings
      2. More Asterisk Magic
    2. Writestamps
      1. Updating Writestamps
      2. Generalizing Writestamps
      3. Regular Expressions
      4. Regexp Quoting
      5. Limited Searching
      6. More Regexp Power
    3. Modifystamps
      1. Simple Approach #1
      2. Simple Approach #2
      3. Clever Approach
      4. A Subtle Bug
  8. 5. Lisp Files
    1. Creating a Lisp File
    2. Loading the File
      1. Finding Lisp Files
      2. Interactive Loading
      3. Programmatic Loading
        1. Explicit loading
        2. Conditional loading
        3. Autoloading
    3. Compiling the File
    4. eval-after-load
    5. Local Variables Lists
    6. Addendum: Security Consideration
  9. 6. Lists
    1. The Simple View of Lists
    2. List Details
    3. Recursive List Functions
    4. Iterative List Functions
    5. Other Useful List Functions
    6. Destructive List Operations
    7. Circular Lists?!
  10. 7. Minor Mode
    1. Paragraph Filling
    2. Modes
    3. Defining a Minor Mode
    4. Mode Meat
      1. Naïve First Try
      2. Constraining refill
      3. Minor Adjustments
      4. Eliminating Unwanted Filling
      5. Trailing Whitespace
  11. 8. Evaluation and Error Recovery
    1. limited-save-excursion
    2. eval
    3. Macro Functions
    4. Backquote and Unquote
    5. Return Value
    6. Failing Gracefully
    7. Point Marker
  12. 9. A Major Mode
    1. My Quips File
    2. Major Mode Skeleton
    3. Changing the Definition of a Paragraph
    4. Quip Commands
    5. Keymaps
    6. Narrowing
    7. Derived Modes
  13. 10. A Comprehensive Example
    1. New York Times Rules
    2. Data Representation
      1. Vectors
      2. Matrix Package
      3. Crossword Variant of Matrix
      4. Using Cons Cells
      5. One-Letter Words
    3. User Interface
      1. Display
      2. Cursor Positioning
      3. Updating the Display
      4. User Commands
        1. Grid-changing commands
        2. Navigation
    4. Setting Up the Mode
      1. Keybindings
      2. Mouse Commands
      3. Menu Commands
    5. Tracking Unauthorized Changes
    6. Parsing the Buffer
    7. Word Finder
      1. First Try
      2. Second Try
      3. Asynchronous egrep
      4. Choosing Words
      5. Ambiguous Alignment
    8. Last Word
  14. A. Conclusion
  15. B. Lisp Quick Reference
    1. Basics
    2. Data Types
      1. Numbers
      2. Characters
      3. Strings
      4. Symbols
      5. Lists
      6. Vectors
      7. Sequences and Arrays
    3. Control Structures
      1. Variables
      2. Sequencing
      3. Conditionals
      4. Looping
      5. Function Call
      6. Literal Data
    4. Code Objects
      1. Functions
      2. Macro Functions
  16. C. Debugging and Profiling
    1. Evaluation
    2. The Debugger
    3. Edebug
    4. The Profiler
  17. D. Sharing Your Code
    1. Preparing Source Files
    2. Documentation
    3. Copyright
    4. Posting
  18. E. Obtaining and Building Emacs
    1. Availability of Packages
    2. Unpacking, Building, and Installing Emacs
      1. Unpacking
      2. Building and Installing
  19. Index
  20. About the Author
  21. Colophon
  22. Copyright