An Introduction to Programming in Emacs Lisp - GNU.org

software—the sets of instructions—that tell the computer what to do when you give it commands. Emacs ... In addition to learning about Emacs as an editor and Emacs Lisp as a program- ...... Note that we have here an illustration of how setq is.
1018KB Sizes 0 Downloads 205 Views
An Introduction to Programming in Emacs Lisp

An Introduction to Programming in Emacs Lisp Revised Third Edition

by Robert J. Chassell

This is an Introduction to Programming in Emacs Lisp, for people who are not programmers. Edition 3.10, 28 October 2009 c 1990–1995, 1997, 2001–2017 Free Software Foundation, Inc. Copyright Published by the: GNU Press, a division of the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA

http://www.fsf.org/licensing/gnu-press/ email: [email protected] Tel: +1 (617) 542-5942 Fax: +1 (617) 542-2652

ISBN 1-882114-43-4 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; there being no Invariant Section, with the Front-Cover Texts being “A GNU Manual”, and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License”. (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual. Buying copies from the FSF supports it in developing GNU and promoting software freedom.”

i

Short Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1

List Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2

Practicing Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3 4

How To Write Function Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 A Few Buffer-Related Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

5

A Few More Complex Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6

Narrowing and Widening. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

7 8

car, cdr, cons: Fundamental Functions . . . . . . . . . . . . . . . . . . . . . . 71 Cutting and Storing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

9

How Lists are Implemented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

10 Yanking Text Back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 11 Loops and Recursion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 12 Regular Expression Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 13 Counting via Repetition and Regexps . . . . . . . . . . . . . . . . . . . . . . . 143 14 Counting Words in a defun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 15 Readying a Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 16 Your .emacs File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 17 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 18 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 A B

The the-the Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Handling the Kill Ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

C

A Graph with Labeled Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

D

Free Software and Free Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238

E GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .