Help
RSS
API
Feed
Maltego
Contact
Domain > speakwithanemacslisp.com
×
More information on this domain is in
AlienVault OTX
Is this malicious?
Yes
No
DNS Resolutions
Date
IP Address
2025-09-22
3.5.77.153
(
ClassC
)
2025-12-08
3.5.83.33
(
ClassC
)
2026-01-05
3.5.81.247
(
ClassC
)
2026-01-05
3.5.81.29
(
ClassC
)
2026-03-03
3.5.86.23
(
ClassC
)
Port 80
HTTP/1.1 200 OKx-amz-id-2: DKHCPwL7qY7U8DejWgjZCsOH0Sm4DS9JRkeMTWkyefmfGLsD4r3QyLD27ehnGQtC+umUKyl+90cx-amz-request-id: FXSSNZ2GY37STSTKDate: Tue, 03 Mar 2026 14:16:44 GMTLast-Modified: Fri, 05 Jun 2015 02:49:20 GMTETag: 3990453eb3ea917cdb01a774d456a562Content-Type: text/htmlContent-Length: 95219Server: AmazonS3 ?xml version1.0 encodingutf-8?>!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>html xmlnshttp://www.w3.org/1999/xhtml langen xml:langen>head>title>Speak with an Emacs Lisp/title>!-- 2015-06-04 Thu 19:47 -->meta http-equivContent-Type contenttext/html;charsetutf-8 />meta namegenerator contentOrg-mode />meta nameauthor contentCam Saul />style typetext/css> !--/*-->!CDATA/*>!--*/ .title { text-align: center; } .todo { font-family: monospace; color: red; } .done { color: green; } .tag { background-color: #eee; font-family: monospace; padding: 2px; font-size: 80%; font-weight: normal; } .timestamp { color: #bebebe; } .timestamp-kwd { color: #5f9ea0; } .right { margin-left: auto; margin-right: 0px; text-align: right; } .left { margin-left: 0px; margin-right: auto; text-align: left; } .center { margin-left: auto; margin-right: auto; text-align: center; } .underline { text-decoration: underline; } #postamble p, #preamble p { font-size: 90%; margin: .2em; } p.verse { margin-left: 3%; } pre { border: 1px solid #ccc; box-shadow: 3px 3px 3px #eee; padding: 8pt; font-family: monospace; overflow: auto; margin: 1.2em; } pre.src { position: relative; overflow: visible; padding-top: 1.2em; } pre.src:before { display: none; position: absolute; background-color: white; top: -10px; right: 10px; padding: 3px; border: 1px solid black; } pre.src:hover:before { display: inline;} pre.src-sh:before { content: sh; } pre.src-bash:before { content: sh; } pre.src-emacs-lisp:before { content: Emacs Lisp; } pre.src-R:before { content: R; } pre.src-perl:before { content: Perl; } pre.src-java:before { content: Java; } pre.src-sql:before { content: SQL; } table { border-collapse:collapse; } caption.t-above { caption-side: top; } caption.t-bottom { caption-side: bottom; } td, th { vertical-align:top; } th.right { text-align: center; } th.left { text-align: center; } th.center { text-align: center; } td.right { text-align: right; } td.left { text-align: left; } td.center { text-align: center; } dt { font-weight: bold; } .footpara:nth-child(2) { display: inline; } .footpara { display: block; } .footdef { margin-bottom: 1em; } .figure { padding: 1em; } .figure p { text-align: center; } .inlinetask { padding: 10px; border: 2px solid gray; margin: 10px; background: #ffffcc; } #org-div-home-and-up { text-align: right; font-size: 70%; white-space: nowrap; } textarea { overflow-x: auto; } .linenr { font-size: smaller } .code-highlighted { background-color: #ffff00; } .org-info-js_info-navigation { border-style: none; } #org-info-js_console-label { font-size: 10px; font-weight: bold; white-space: nowrap; } .org-info-js_search-highlight { background-color: #ffff00; color: #000000; font-weight: bold; } /*>*/-->/style>link relstylesheet typetext/css hrefhttp://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/default.min.css />link relstylesheet typetext/css hrefstyle.css />link hrefhttp://fonts.googleapis.com/css?familyLato relstylesheet typetext/css>link hrefhttp://fonts.googleapis.com/css?familySource+Code+Pro:400,600 relstylesheet typetext/css>script srchttp://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js>/script>script srchighlight.pack.js>/script>script srcsite.js>/script>script typetext/javascript srchttp://orgmode.org/org-info.js>/** * * @source: http://orgmode.org/org-info.js * * @licstart The following is the entire license notice for the * JavaScript code in http://orgmode.org/org-info.js. * * Copyright (C) 2012-2013 Free Software Foundation, Inc. * * * The JavaScript code in this tag is free software: you can * redistribute it and/or modify it under the terms of the GNU * General Public License (GNU GPL) as published by the Free Software * Foundation, either version 3 of the License, or (at your option) * any later version. The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in http://orgmode.org/org-info.js. * *//script>script typetext/javascript>/*@licstart The following is the entire license notice for theJavaScript code in this tag.Copyright (C) 2012-2013 Free Software Foundation, Inc.The JavaScript code in this tag is free software: you canredistribute it and/or modify it under the terms of the GNUGeneral Public License (GNU GPL) as published by the Free SoftwareFoundation, either version 3 of the License, or (at your option)any later version. The code is distributed WITHOUT ANY WARRANTY;without even the implied warranty of MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE. See the GNU GPL for more details.As additional permission under GNU GPL version 3 section 7, youmay distribute non-source (e.g., minimized or compacted) forms ofthat code without the copy of the GNU GPL normally required bysection 4, provided you include this license notice and a URLthrough which recipients can access the Corresponding Source.@licend The above is the entire license noticefor the JavaScript code in this tag.*/!--/*-->!CDATA/*>!--*/org_html_manager.set(TOC_DEPTH, 2);org_html_manager.set(LINK_HOME, );org_html_manager.set(LINK_UP, );org_html_manager.set(LOCAL_TOC, above);org_html_manager.set(VIEW_BUTTONS, 0);org_html_manager.set(MOUSE_HINT, underline);org_html_manager.set(FIXED_TOC, 0);org_html_manager.set(TOC, 1);org_html_manager.set(VIEW, info);org_html_manager.setup(); // activate after the parameters are set/*>*///-->/script>script typetext/javascript>/*@licstart The following is the entire license notice for theJavaScript code in this tag.Copyright (C) 2012-2013 Free Software Foundation, Inc.The JavaScript code in this tag is free software: you canredistribute it and/or modify it under the terms of the GNUGeneral Public License (GNU GPL) as published by the Free SoftwareFoundation, either version 3 of the License, or (at your option)any later version. The code is distributed WITHOUT ANY WARRANTY;without even the implied warranty of MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE. See the GNU GPL for more details.As additional permission under GNU GPL version 3 section 7, youmay distribute non-source (e.g., minimized or compacted) forms ofthat code without the copy of the GNU GPL normally required bysection 4, provided you include this license notice and a URLthrough which recipients can access the Corresponding Source.@licend The above is the entire license noticefor the JavaScript code in this tag.*/!--/*-->!CDATA/*>!--*/ function CodeHighlightOn(elem, id) { var target document.getElementById(id); if(null ! target) { elem.cacheClassElem elem.className; elem.cacheClassTarget target.className; target.className code-highlighted; elem.className code-highlighted; } } function CodeHighlightOff(elem, id) { var target document.getElementById(id); if(elem.cacheClassElem) elem.className elem.cacheClassElem; if(elem.cacheClassTarget) target.className elem.cacheClassTarget; }/*>*///-->/script>/head>body>div idcontent>h1 classtitle>Speak with an Emacs Lisp/h1>div idtable-of-contents>h2>Table of Contents/h2>div idtext-table-of-contents>ul>li>a href#sec-1>1. The Basics/a>ul>li>a href#sec-1-1>1.1. Intro/a>/li>li>a href#sec-1-2>1.2. Core Concepts/a>/li>/ul>/li>li>a href#sec-2>2. Speak with an Emacs Lisp/a>ul>li>a href#sec-2-1>2.1. Emacs Lisp Types/a>/li>li>a href#sec-2-2>2.2. Controlling Flow/a>/li>li>a href#sec-2-3>2.3. Functions/a>/li>li>a href#sec-2-4>2.4. Macros/a>/li>/ul>/li>li>a href#sec-3>3. Intermediate/a>ul>li>a href#sec-3-1>3.1. Defining Code to Be Ran On a Later Occasion/a>/li>li>a href#sec-3-2>3.2. Moving Around/a>/li>li>a href#sec-3-3>3.3. Working With Buffers, Windows, and Frames/a>/li>li>a href#sec-3-4>3.4. Operating on Strings/a>/li>li>a href#sec-3-5>3.5. Packages/a>/li>/ul>/li>li>a href#sec-4>4. Advanced/a>ul>li>a href#sec-4-1>4.1. Syntax Tables/a>/li>li>a href#sec-4-2>4.2. Font Locking/a>/li>li>a href#sec-4-3>4.3. Custom Variables/a>/li>li>a href#sec-4-4>4.4. Byte Compilation ?/a>/li>li>a href#sec-4-5>4.5. Keymaps/a>/li>/ul>/li>li>a href#sec-5>5. Libraries/a>ul>li>a href#sec-5-1>5.1. cl-lib/a>/li>li>a href#sec-5-2>5.2. subr-x/a>/li>li>a href#sec-5-3>5.3. dash/a>/li>li>a href#sec-5-4>5.4. s/a>/li>li>a href#sec-5-5>5.5. EIEIO/a>/li>/ul>/li>li>a href#sec-6>6. Putting it All Together/a>ul>li>a href#sec-6-1>6.1. Debugging with Edebug/a>/li>li>a href#sec-6-2>6.2. Writing a Minor Mode/a>/li>li>a href#sec-6-3>6.3. Writing a Major Mode/a>/li>li>a href#sec-6-4>6.4. Packaging/a>/li>/ul>/li>li>a href#sec-7>7. Possibilities/a>ul>li>a href#sec-7-1>7.1. Keyboard Macros/a>/li>li>a href#sec-7-2>7.2. identity, ignore/a>/li>li>a href#sec-7-3>7.3. Primitive Functions ?/a>/li>/ul>/li>/ul>/div>/div>div idoutline-container-sec-1 classoutline-2>h2 idsec-1>span classsection-number-2>1/span> The Basics/h2>div classoutline-text-2 idtext-1>/div>div idoutline-container-sec-1-1 classoutline-3>h3 idsec-1-1>span classsection-number-3>1.1/span> Intro/h3>div classoutline-text-3 idtext-1-1>/div>div idoutline-container-sec-1-1-1 classoutline-4>h4 idsec-1-1-1>span classsection-number-4>1.1.1/span> Why Learn Emacs?/h4>div classoutline-text-4 idtext-1-1-1>p>Theres been a lot of jibber-jabber on the net lately about Emacs. And maybe you know that one guy who wont stop preaching its gospel. Or maybe youre just sick of being a n00b who edits code in Notepad. Isnt it time you learned what all the fuss is about?/p>p>Recently at a Clojure conference I was suprised by the lack of people using Emacs. A casual survey others computer screens showed barely a third of people using it. Surely, if they i>knew/i> Emacs, I thought, theyd use it instead. Why i>wouldnt/i> Lisp programmers want an editor that could be customized to do almost anything i>in Lisp/i>?/p>p>Because its hard to learn. And even harder to get started learning. Emacs is meant to be customized, which is good because its default settings are horrible. You need to do a lot of customization to get it working nicely, which entails writing Emacs Lisp, which (surprise!) is hard to do if you dont know Emacs Lisp./p>p>And thats the problem with Emacs. There are a lot of good packages that provide sane default settings, with the intent of making it easier for beginners to get started with Emacs without having to write any Emacs Lisp. But what do you do when things stop working? How can you i>debug/i> Emacs Lisp if you dont understand the language?/p>p>Were up to our ears in books about nearly every programming language under the sun, and there are several books published in the last few years about other editors such as vim. But Emacs just sits in the corner, getting no love, with just a couple books, published in the 90s, about versions so old theyre barely relevant. There are other resources online for learning Emacs, including many good intoductory tutorials, but to really get the most out of Emacs youll want to learn more than just the basics./p>p>Hence this book. Well learn Emacs Lisp by first using to fix all those nasty default settings, and then by customizing Emacs to do i>crazy shit/i>. By the end, youll know enough that youll be able to turn it into i>your/i> perfect editor. If youre reading this book, hopefully you dont need me to sell Emacs to you, but I just did. Thats the elevator pitch: if you learn Emacs, youll be able to make it work however you want and do almost anything./p>p>You should definitely have past programming experience before reading this book. Another Lisp language like Clojure will make things a lot easier for you, but isnt necessary nor assumed./p>p>Ive seen too many people give up on Emacs after a few weeks because of one minor quirk or another that they had no idea how to fix. This book is dedicated to those people./p>/div>/div>div idoutline-container-sec-1-1-2 classoutline-4>h4 idsec-1-1-2>span classsection-number-4>1.1.2/span> Installing/h4>div classoutline-text-4 idtext-1-1-2>p>Before we go any further, youll need to install Emacs. Hopefully you already know how to install things and dont need me wasting my breath, but make sure you have version 24.5 or newer with full GUI support (unlike VIM, most Emacs users dont run Emacs inside a terminal). Beware that OS X and many Linux distributions come with an ancient version of Emacs installed. Check the output of code>emacs --version/code> from your command line to make sure you have the latest version./p>/div>ol classorg-ol>li>a idsec-1-1-2-1 namesec-1-1-2-1>/a>Mac OS Xbr />div classoutline-text-5 idtext-1-1-2-1>p>I recommend installing Emacs via Homebrew. Hopefully, you already have Homebrew installed, but if not, check out a hrefhttp://brew.sh/>http://brew.sh//a> for instructions on how to install it. After that, run/p>div classorg-src-container>pre classsrc src-sh>brew update # update package infobrew install emacs --cocoa # install Emacs with Cocoa GUIbrew link emacs # set up symlinks to Homebrew version of Emacsbrew linkapps # create Emacs.app in /Applications/pre>/div>p>Another good option is installing a pre-built binary from a hrefhttp://emacsformacosx.com/>http://emacsformacosx.com//a>./p>/div>/li>li>a idsec-1-1-2-2 namesec-1-1-2-2>/a>Windowsbr />div classoutline-text-5 idtext-1-1-2-2>p>Head over to a hrefhttps://www.gnu.org/software/emacs/#Obtaining>https://www.gnu.org/software/emacs/#Obtaining/a> and follow the links to find a nearby GNU mirror. Look in the code>windows//code> folder of the mirrors file listing and download the appropriate ZIP file./p>/div>/li>li>a idsec-1-1-2-3 namesec-1-1-2-3>/a>Linuxbr />div classoutline-text-5 idtext-1-1-2-3>p>If youre running Linux, you know how to install packages. Again, just make sure you have an up-to-date version./p>/div>/li>/ol>/div>/div>div idoutline-container-sec-1-2 classoutline-3>h3 idsec-1-2>span classsection-number-3>1.2/span> Core Concepts/h3>div classoutline-text-3 idtext-1-2>p>If youre interested in (better) learning Emacs Lisp, you probably have at least a vague familiarity with Emacs itself. If so, feel free to skim over this chapter or skip it altogether. Otherwise, well quickly go over some fundamental Emacs concepts./p>/div>div idoutline-container-sec-1-2-1 classoutline-4>h4 idsec-1-2-1>span classsection-number-4>1.2.1/span> Frames & Windows/h4>div classoutline-text-4 idtext-1-2-1>p>Lets jump right into it. Fire up Emacs and well get started. You should see a screen like this:/p>div classfigure>p>img src./images/emacs_with_initial_splashscreen.png altemacs_with_initial_splashscreen.png />/p>p>span classfigure-number>Figure 1:/span> Emacs with Welcome Splashscreen/p>/div>p>Its important to remember Emacs started its long evolution in the seventies, before GUIs became wide-spread. Emacs predates many of the standard terms used to describe computer interfaces today. And so Emacs uses some of these terms in a different, sometime counterintuitive way./p>p>What wed think of today as an application window is called a i>frame/i> in Emacs. A i>window/i>, on the other hand, is a subdivision of a frame. The picture above is of a single frame with a single normal window, displaying a slashscreen with a neat 90s-era Emacs logo, and a i>minibuffer/i> window, which is the single line of text at the bottom of the frame, used for displaying messages or prompting for input. A frame can only have a single minibuffer windowsup>a idfnr.1 namefnr.1 classfootref href#fn.1>1/a>/sup>, but it can have many regular windows. The minibuffer window is a special case, and you can safely ignore it for much of our discussion of windows going forward./p>p>The current window is said to be i>selected/i>, as is the current frame; switiching to a different window or frame is known as i>selecting/i> it./p>/div>/div>div idoutline-container-sec-1-2-2 classoutline-4>h4 idsec-1-2-2>span classsection-number-4>1.2.2/span> Buffers & Visting Files/h4>div classoutline-text-4 idtext-1-2-2>p>Heres a (customized) i>frame/i> with a window with a i>Diredsup>a idfnr.2 namefnr.2 classfootref href#fn.2>2/a>/sup>/i> buffer, and another with a i>buffer/i> thats i>visiting/i> an Emacs Lisp file./p>div classfigure>p>img src./images/emacs_with_2_windows.png altemacs_with_2_windows.png />/p>/div>p>i>Visiting a file/i> is Emacs-speak for opening it. A i>buffer/i> contains text to be edited, and other context you can access through various variables or functions. That text might be the contents of the file its visiting, although not all buffers are neccessarily visiting files: their content can be generated programatically. Each window i>displays/i> a single buffer at a time; a buffer can be displayed in any number of windows – one, several, or even none./p>p>One buffer is always said to be i>current/i>. Typing (usually) inserts text in the current buffer; most editing commands will affect it. The current buffer is often the buffer currently displayed by the selected window, but not always; Emacs Lisp code can i>switch/i> to a differenty buffer (usually temporarily), in order to make changes to it./p>/div>/div>div idoutline-container-sec-1-2-3 classoutline-4>h4 idsec-1-2-3>span classsection-number-4>1.2.3/span> Modes & Keymaps/h4>div classoutline-text-4 idtext-1-2-3>p>Every buffer has a b>single/b> i>major mode/i> that fills a specific purpose, such as editing code in a certain language or EDiting DIRectories. A major mode can defines everything from syntax highlighting and indentation rules to special commands specific to that major-mode./p>p>i>Keymaps/i> bind i>events/i> such as keystrokes or mouse actions to specific commands. Global keybindings, available throughout Emacs, are defined in the code>global-map/code>. Major modes usually define a keymap of their own; this keymap will only be i>active/i> when the current buffer has that major mode. Keybindings in major mode keymaps are used in preference to ones in the global keymap in case of a conflict; conventionally, major (and minor) mode keybindings start with the prefix code>C-c/code> (Ctrl-C) to avoid clashes./p>p>Emacs automatically knows which major mode to use for when visiting a new file thanks to patterns and functions defined in a variable named code>auto-mode-alist/code>, which well look at a little later./p>/div>/div>div idoutline-container-sec-1-2-4 classoutline-4>h4 idsec-1-2-4>span classsection-number-4>1.2.4/span> Minor Modes/h4>div classoutline-text-4 idtext-1-2-4>p>In addition to a single major mode, a buffer can have one or more i>minor modes/i>. Minor modes add additional functionality independently of major modes, such as code>linum-mode/code>, which shows line numbers in the left margin, and code>auto-complete/code> or code>company/code>, which provide auto-completion. Many minor modes work across a variety of major modes; others augment a specific one, such as code>elisp-slime-nav-mode/code>, which adds handy navigation commands to code>emacs-lisp-mode/code>./p>p>Like major modes, minor modes can define their own keymaps; bindings in these may override those in the current major mode keymap./p>/div>/div>div idoutline-container-sec-1-2-5 classoutline-4>h4 idsec-1-2-5>span classsection-number-4>1.2.5/span> Key Sequences/h4>div classoutline-text-4 idtext-1-2-5>p>Throughout the Emacs world, youll see i>key sequences/i>, or i>keys/i> for short, which are simple sequences of keystrokes written like this: code>C-l/code>. This example means press control and l at the same time. code>C/code> simply means Control, and dashes are used to group together keys pressed simultaneously. Youd pronounce this as Control-l./p>p>Sequences of several keystrokes are separated by spaces. Thus, code>C-x C-f/code> is simply shorthand for press Control and x at the same time, then press Control and f at the same time. Youd read this example aloud as Control-X Control-F. code>C-c c/code> means press Control and c at the same time, then press c by itself./p>p>code>M/code> is short for Meta, which probably isnt a button on your keyboard, unless you have something like this Space Cadet Keyboard:/p>div classfigure>p>img src./images/space_cadet_keyboard.jpg altspace_cadet_keyboard.jpg />/p>/div>p>Many things in Emacs are they way they are because it was originally written on computers that looked very different from modern ones, as youll see throughout this book. Keyboards like this are similar to what users of Emacs would probably be using back in the day. But since modern keyboards dont have a Meta button, the Alt key on your keyboard (or Option on a Mac)sup>a idfnr.3 namefnr.3 classfootref href#fn.3>3/a>/sup> is used in its place. So code>M-x/code>, pronounced meta-X, is typed by holding down Alt/Option and pressing X./p>p>Keystrokes can use multiple modifiers, such as code>C-M-x/code>, which means hold Control i>and/i> Meta (Alt) and press x; youd read it as Control-Meta-X. Shift can be specified with code>S/code>, so code>M-S-v/code> means hold Shift and Meta and press v, but would more commonly be written as code>M-V/code>. Conventially, multiple modifiers are written in alphabetical order, so youd write code>C-M-x/code> istead of code>M-C-x/code>, although they both mean the same thing./p>p>Besides Meta, you might have noticed some of the other wacky keys on the Space Cadet Keyboard, such as Hyper and Super. Emacs understands the Windows Key on a PC or Command on a Mac as Supersup>a idfnr.4 namefnr.4 classfootref href#fn.4>4/a>/sup>, which is written with code>s/code>. So code>s-u/code> means Super-U, which means press Windows/Command and U at the same time./p>p>Emacs also understands the modifiers Hyper, written as code>H/code>, and Alt, which is different from Meta and written as code>A/code>. On a hardware level, the modifier keys on the left-hand side of your keyboard send codes that are distinct from those on the right-hand side; that is, Left Control and Right Control are two distinct keys. It just so happens that theyre usually treated as though they i>are/i> the same, but you do things like tell Emacs to treat Right Control as Hyper if you are so inclinedsup>a idfnr.5 namefnr.5 classfootref href#fn.5>5/a>/sup>./p>p>Certain keys are referred to by name, such as code>left/code> for the left arrow key. When writing a named key in a key sequence, you need to wrap it in angle brackets, e.g. code><M-left>/code>./p>/div>ol classorg-ol>li>a idsec-1-2-5-1 namesec-1-2-5-1>/a>span classtodo TODO>TODO/span> - Get a better keyboard image from a hrefhttp://xahlee.info/kbd/lisp_keyboards.html>http://xahlee.info/kbd/lisp_keyboards.html/a>br />/li>/ol>/div>div idoutline-container-sec-1-2-6 classoutline-4>h4 idsec-1-2-6>span classsection-number-4>1.2.6/span> Commands & Getting Help/h4>div classoutline-text-4 idtext-1-2-6>p>When you enter a key sequence like code>C-x C-f/code>, Emacs runs the corresponding command. A command is nothing more than an Emacs Lisp function that contains the code>(interactive)/code> form, which well investigate a little later. In this case, code>C-x C-f/code> is bound to the function code>find-file/code>. You can also run commands by typing code>M-x/code> and entering the name of the command and pressing return; so you could type code>M-x find-file/code> instead./p>p>If you ever wonder what a key binding does (or what command its mapped to), you can type code>C-h k <key sequence>/code> (e.g., code>C-h k C-x C-f/code>), which opens the documentation for the command in questionsup>a idfnr.6 namefnr.6 classfootref href#fn.6>6/a>/sup>. Alternatively, code>C-h f <function name>/code> (e.g. code>C-h f find-file/code>) will let you look up the documentation of a function by its name. Notice how these bindings both start with the prefix code>C-h/code>; the same is true for bindings to other help commandssup>a idfnr.7 namefnr.7 classfootref href#fn.7>7/a>/sup>. In this case, the code>h/code> in code>C-h/code> is short for help; youll have an easy time remembering Emacs keybindings if you remember them this way (code>C-h k/code> is help keys, code>C-h f/code> is help function)./p>p>You can see a list of all commands bound to a key sequence starting with some prefix by typing code><prefix> C-h/code>. So code>C-h C-h/code> will give you a list of all the commands that can be invoked with a key sequence that starts with code>C-h/code>./p>p>Youll be learning many such keybindings in your quest for Emacs greatness. This is good, however; learn them well enough and youll be able to edit code faster than you ever thought possible. Personally, I find it extremely helpful to write key bindings Im trying to memorize on sticky notes and stick them to the edge of my screen until Ive memorized them. Cheatsheets are helpful too; at one point or another, Ive taped a few to my desk. You can also try writing them on yourself with a Sharpie, and uploading selfies of your new tatoos to Instagram with the hashtag code>#EmacsLyfe/code>./p>p>While were on the subject, another extremely useful keybinding is code>C-h v/code> (code>describe-variable/code>), which lets you look up the documentation of a i>variable/i> by name./p>/div>/div>div idoutline-container-sec-1-2-7 classoutline-4>h4 idsec-1-2-7>span classsection-number-4>1.2.7/span> The Init File – ~/.emacs.d/init.el/h4>div classoutline-text-4 idtext-1-2-7>p>In 2015, your Emacs customizations live in the i>init file/i>, located at code>~/.emacs.d/init.el/code>. In the past, they lived in code>~/.emacs/code>, but youll want to put your init file in a directory in case you decide to break it out into smaller files once it gets big and hairy./p>/div>/div>div idoutline-container-sec-1-2-8 classoutline-4>h4 idsec-1-2-8>span classsection-number-4>1.2.8/span> Opening init.el/h4>div classoutline-text-4 idtext-1-2-8>p>Lets get started writing some Emacs Lisp! You can open a file using the code>find-file/code> command discussed above (in Emacs, opening a file is usually called visiting a file). Well use it to open our init file, code>~/.emacs.d/init.el/code>, so we can tell Emacs not to show us that annoying splash screen. So type code>C-x C-f/code> (or code>M-x find-file/code>), and youll see a prompt at the bottom of the screen that says Find file:. The bottom part of the screen is whats known as the i>minibuffer/i>. Well discuss it in more detail later, but for now just know that commands can, and often do, prompt you for input here, and messages are frequently displayed there./p>p>Go ahead and type the following code:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(setq inhibit-splash-screen t)/pre>/div>p>Save the file by typing code>C-x C-s/code>, then close Emacs by typing code>C-x C-c/code>. Again, notice how these commands all start with the prefix code>C-x/code>. Many important global Emacs commands start with the prefix code>C-x/code>, so just remember code>s/code> for save and code>c/code> for close./p>/div>/div>div idoutline-container-sec-1-2-9 classoutline-4>h4 idsec-1-2-9>span classsection-number-4>1.2.9/span> Packages/h4>div classoutline-text-4 idtext-1-2-9>p>Before we go any futher, youll want to get Emacs configured to install packages. Add the following to your init file:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(require package) ; TODO - is this neccesary ?(package-initialize)(nconc package-archives ((melpa . http://melpa.milkbox.net/packages/) (marmalade . http://marmalade-repo.org/packages/)))/pre>/div>p>Now youll be able to install third-party packages through the Package Menu (code>M-x package-list-packages/code>) or via code>M-x package-install RET package-name/code>./p>/div>/div>/div>/div>div idoutline-container-sec-2 classoutline-2>h2 idsec-2>span classsection-number-2>2/span> Speak with an Emacs Lisp/h2>div classoutline-text-2 idtext-2>/div>div idoutline-container-sec-2-1 classoutline-3>h3 idsec-2-1>span classsection-number-3>2.1/span> Emacs Lisp Types/h3>div classoutline-text-3 idtext-2-1>p>If youve picked up a book on Emacs Lisp, you probably already know languages in the Lisp family look a little different than ones from the Fortan/C tradition. So Im going to try to harp on these differences as little as possible. Just know that the syntax is a little different. But then again, Objective-Cs syntax is different too, and that didnt stop people from writing iPhone apps, did it?/p>p>If youd like to follow along with the examples, Id recommend using code>ielm/code> (code>M-x ielm/code>), the Emacs Lisp REPL, to interactively evaluate Emacs Lisp expressions. Alternatively, you can visit an Emacs Lisp file, enter and expression, and type code>C-x C-e/code> (code>eval-last-sexp/code>) to evaluate the i>symbolic expression/i> that precedes the cursor, and display the results in the minibuffer./p>/div>div idoutline-container-sec-2-1-1 classoutline-4>h4 idsec-2-1-1>span classsection-number-4>2.1.1/span> Hello, World! (Everything is an Expression)/h4>div classoutline-text-4 idtext-2-1-1>p>Lets start with a traditional example:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(message Hello, World!)/pre>/div>p>Evaluating that code will display the message code>Hello, World!/code> in the minibuffer, and add it to the end of the code>*Messages*/code> buffer. Lisp stands for LISt Processing; all code in Lisp is written in lists, denoted by parentheses. Lists are composed of i>atoms/i> (symbols, strings, numbers, and the like) and of other lists. The list in the example above is composed of two atoms: the symbol code>message/code>, and the string code>Hello, World!/code>./p>p>Formally, atoms and lists are collectively known as i>symbolic-expressions/i>, or i>s-expressions/i> or i>sexps/i> for short. Every sexp produces a result when evaluated; atoms like strings or numbers evaluate to themselves, but variables evaluate to their value. Even code>if...else/code> constructs return a value; contrast that with more conventional languages, where there is a separate concept of a i>statement/i> that does not return a value./p>p>When a list is evaluated, the first item is treated as a function, and all other items are evaluated and then passed to that function as arguments. Written in a more conventional language, the example above would look something like:/p>div classorg-src-container>pre classsrc src-javascript>message(Hello, World!);/pre>/div>p>This syntax can take some getting used to, but it makes Lisp extremely flexible and powerful, as youll see later when we discuss macros. It also has some advantages. In other languages, you might write:/p>div classorg-src-container>pre classsrc src-python>1 + 2 + 3/pre>/div>p>But in Emacs Lisp, the function code>+/code> can accept a variable number of arguments:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(+ 1 2 3)/pre>/div>p>As do functions like code>>/code>, which returns code>t/code> (true) if each arg is greater than the next:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(> 3 2 1)/pre>/div>p>Unlike many other languages, code>+/code> and code>>/code> i>arent/i> special built-in operators. Theyre regular functions, just like any other, and you can replace them if youre so inclined./p>p>As aforementioned, you can nest lists:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(* (+ 1 2) 4)/pre>/div>p>Since the arguments of a function are evaluated first, this becomes:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(* 3 4)/pre>/div>p>which evaluates to code>12/code>. You can prevent a list from being evaluated by using the special form code>quote/code>:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(quote (1 2 3))/pre>/div>p>Evaluating the form above will return the list code>(1 2 3)/code>. Because quoting lists and symbols is quite commonplace in Lisp code, as a bit of syntactic sugar you can instead simply put a single quote in front of the sexp in question:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(1 2 3)/pre>/div>p>Lisp has just a tiny handful of special forms like code>quote/code>; the rest of the language can be defined by simply building upon these special forms./p>/div>/div>div idoutline-container-sec-2-1-2 classoutline-4>h4 idsec-2-1-2>span classsection-number-4>2.1.2/span> t and nil/h4>div classoutline-text-4 idtext-2-1-2>p>code>nil/code> is used to represent falsity and nothingness (code>null/code> and code>false/code> in other languages). code>t/code> is used to represent true, but everything that is non-nil is considered true. The empty list is the same as code>nil/code>, for reasons well discuss later in this chapter./p>/div>/div>div idoutline-container-sec-2-1-3 classoutline-4>h4 idsec-2-1-3>span classsection-number-4>2.1.3/span> Comments/h4>div classoutline-text-4 idtext-2-1-3>p>Comments in Lisp start with a code>;/code> and extend to the end of the line. In Emacs Lisp convention, comments that share a line with Lisp source code start with a single semicolon; comments that are on their own line start with two semicolons; comments serving as headers denoting large chunks of code start with 3./p>div classorg-src-container>pre classsrc src-emacs-lisp>;;; Big Chunk Of Code Starts Here() ; the empty list (nil);; TODO - Check logic here(when (> x 100) ;; if x > 100 ... (message OK!))/pre>/div>p>Unlike Common Lisp or Scheme, Emacs Lisp does not syntax for multiple-line comments./p>/div>/div>div idoutline-container-sec-2-1-4 classoutline-4>h4 idsec-2-1-4>span classsection-number-4>2.1.4/span> Symbols/h4>div classoutline-text-4 idtext-2-1-4>p>Symbols are uniquely-named global objects, used for referring to variables and functions, stored in an internal table. When the i>reader/i> (i.e., interpreter) encounters a symbol, it looks for an existing object with the corresponding name in an internal table and returns it if found; otherwise a new symbol is created, added to the table, and then returned. This process is known as i>interning/i> a symbol./p>p>These symbol objects have several cells, such as its current value as a variable. Evaluating a symbol directly will return this value; you can quote it to prevent this from happening:/p>div classorg-src-container>pre classsrc src-emacs-lisp>major-mode ; -> emacs-lisp-modemajor-mode ; -> major-mode/pre>/div>p>Emacs Lisp has no namespaces. Like other such languages, it is customary to prefix the name of b>every/b> symbol in a package/library with the name of that package and a hypen (code>package-symbol/code>). Thus, symbols from code>dired.el/code> start with code>dired-/code>, such as code>dired-recursive-copies/code>. Youll also occasionally see prefixes like code>package/symbol/code> or code>package:symbol/code>. Note that symbols in Emacs Lisp can contain many characters that would be invalid in other languages: they can be anything except whitespace and these: code>( ) , ` ; # | \ _ /code>. A variable that is should be treated as private is usually prefixed with code>pacakge-name--/code>./p>p>You can get the string name of a symbol using the function code>symbol-name/code>:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(symbol-name emacs-lisp-mode) ; -> emacs-lisp-mode/pre>/div>/div>/div>div idoutline-container-sec-2-1-5 classoutline-4>h4 idsec-2-1-5>span classsection-number-4>2.1.5/span> Variables/h4>div classoutline-text-4 idtext-2-1-5>p>You can set a variable using code>set/code>:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(set require-final-newline t) ; add a final newline to files when saving/pre>/div>p>(Technically, what youre doing here is setting the symbol code>require-final-newline/code>s current value as a variable to code>t/code>.) Note how you have to quote code>require-final-newline/code> to prevent it from being evaluated. Because this pattern is so common, the variation code>setq/code> (i>SET Quoted/i>) exists:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(setq require-final-newline t) ; add a final newline to files when saving/pre>/div>p>You can also set multiple variables at once with code>setq/code>:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(setq echo-keystrokes 0.1 ; show keystrokes in progress in minibuffer sooner select-enable-clipboard t) ; cutting and pasting uses the system clipboard/pre>/div>/div>ol classorg-ol>li>a idsec-2-1-5-1 namesec-2-1-5-1>/a>span classtodo TODO>TODO/span> defvarbr />/li>li>a idsec-2-1-5-2 namesec-2-1-5-2>/a>span classtodo TODO>TODO/span> defcustombr />/li>li>a idsec-2-1-5-3 namesec-2-1-5-3>/a>span classtodo TODO>TODO/span> defconstbr />/li>/ol>/div>div idoutline-container-sec-2-1-6 classoutline-4>h4 idsec-2-1-6>span classsection-number-4>2.1.6/span> Functions/h4>div classoutline-text-4 idtext-2-1-6>p>You can define a function with code>defun/code>, whose syntax looks like:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun function-name args-list body-forms...)/pre>/div>p>A function consists of a name, a list of arguments, and any number of forms that make up the functions body. When called, the result of function is the result of its last form – no code>return/code> statements here./p>div classorg-src-container>pre classsrc src-emacs-lisp>;; Define a new function(defun square (x) (* x x));; Now call it(square 12) ; -> 144/pre>/div>p>In JavaScript, this might look like:/p>div classorg-src-container>pre classsrc src-javascript>function square(x) { return x * x;}square(12); // -> 144/pre>/div>p>In addition to variable cells, symbols have a i>function cell/i>. So what youre really doing when youre calling defun is setting the i>function definition/i> of the symbol i>square/i>.sup>a idfnr.8 namefnr.8 classfootref href#fn.8>8/a>/sup>/p>p>Functions are treated just like any other object in Lisp: they can be passed as arguments, created on the fly, and returned from functions./p>/div>/div>div idoutline-container-sec-2-1-7 classoutline-4>h4 idsec-2-1-7>span classsection-number-4>2.1.7/span> Emacs Lisp is a Lisp-2/h4>div classoutline-text-4 idtext-2-1-7>p>Since a symbol has both a variable cell and a function cell, its whats known as a i>Lisp-2/i> (as is Common Lisp). The value that you get when you evaluate it depends on the context: evaluate it at the beginning of a list, and its function definition is used; otherwise, its value as a variable is returned. Thus, you can do something like this:/p>div classorg-src-container>pre classsrc src-emacs-lisp>;; Set the variable value of x(setq x 100);; Set the function definition of x(defun x (y) (+ y 1));; Evaluating x as an atom gives us its variable valuex ; -> 100;; When x is at the beginning of a list, it is used as a function(x x) ; -> 101/pre>/div>p>The term Lisp-2 simply refers to the fact that Emacs Lisp has 2 separate namespaces for functions and variablessup>a idfnr.9 namefnr.9 classfootref href#fn.9>9/a>/sup>, as opposed to a single combined one, such as in a Lisp-1 such as Scheme or Clojure:/p>div classorg-src-container>pre classsrc src-clojure>;; Define x as the value 100(def x 100);; Define x as a function (overwriting its previous value)(defn x y (+ y 1))x ; -> #<fn ...>(x x) ; Error! Cannot cast function to a number/pre>/div>p>There are pros and cons to each approach. In Lisp-1 languages, youll often see weird function parameter names like code>varr/code> and code>klass/code> to avoid overshadowing functions like code>var/code> and code>class/code>, respectively. However, in some ways it is cleaner – for example, you can call a function passed as a parameter directly:/p>div classorg-src-container>pre classsrc src-clojure>(defn call-some-fn f (f))/pre>/div>p>In Lisp-2 languages, however, you have to use code>funcall/code> to call a function passed as a parameter:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun call-some-fun (f) (funcall f))/pre>/div>p>Well examine code>funcall/code> more a bit later. Emacs Lisp takes advantage of its separate namespaces in many places. For example, minor modes usually define a variable that tells you whether it is currently active, and a function that can be used to turn it on or off:/p>div classorg-src-container>pre classsrc src-emacs-lisp>;; Variable whitespace-mode tells you whether the minor mode is activewhitespace-mode ; -> nil;; toggle it(whitespace-mode);; Check the variable againwhitespace-mode ; -> t/pre>/div>/div>/div>div idoutline-container-sec-2-1-8 classoutline-4>h4 idsec-2-1-8>span classsection-number-4>2.1.8/span> Buffer-Local Variables/h4>div classoutline-text-4 idtext-2-1-8>div classorg-src-container>pre classsrc src-emacs-lisp>make-local-variablemake-variable-buffer-localsetq-defaultsetq-localkill-local-variablekill-all-local-variables/pre>/div>/div>/div>div idoutline-container-sec-2-1-9 classoutline-4>h4 idsec-2-1-9>span classsection-number-4>2.1.9/span> Dynamic & Lexical Binding/h4>div classoutline-text-4 idtext-2-1-9>/div>ol classorg-ol>li>a idsec-2-1-9-1 namesec-2-1-9-1>/a>letbr />/li>/ol>/div>div idoutline-container-sec-2-1-10 classoutline-4>h4 idsec-2-1-10>span classsection-number-4>2.1.10/span> Cons Cells/h4>div classoutline-text-4 idtext-2-1-10>div classorg-src-container>pre classsrc src-emacs-lisp>(x . y)/pre>/div>/div>/div>div idoutline-container-sec-2-1-11 classoutline-4>h4 idsec-2-1-11>span classsection-number-4>2.1.11/span> Chars & Strings/h4>/div>div idoutline-container-sec-2-1-12 classoutline-4>h4 idsec-2-1-12>span classsection-number-4>2.1.12/span> Keywords/h4>/div>div idoutline-container-sec-2-1-13 classoutline-4>h4 idsec-2-1-13>span classsection-number-4>2.1.13/span> Association Lists/h4>/div>div idoutline-container-sec-2-1-14 classoutline-4>h4 idsec-2-1-14>span classsection-number-4>2.1.14/span> Property Lists/h4>/div>div idoutline-container-sec-2-1-15 classoutline-4>h4 idsec-2-1-15>span classsection-number-4>2.1.15/span> Vectors + Hash Maps ?/h4>/div>div idoutline-container-sec-2-1-16 classoutline-4>h4 idsec-2-1-16>span classsection-number-4>2.1.16/span> Registers/h4>/div>/div>div idoutline-container-sec-2-2 classoutline-3>h3 idsec-2-2>span classsection-number-3>2.2/span> Controlling Flow/h3>div classoutline-text-3 idtext-2-2>/div>div idoutline-container-sec-2-2-1 classoutline-4>h4 idsec-2-2-1>span classsection-number-4>2.2.1/span> progn/h4>/div>div idoutline-container-sec-2-2-2 classoutline-4>h4 idsec-2-2-2>span classsection-number-4>2.2.2/span> if/h4>div classoutline-text-4 idtext-2-2-2>p>Like many other languages, Emacs Lisp provides an code>if...else/code> construct for controlling program execution. Unlike other languages, it is an expression and returns a value. In fact, it is somewhat similar to the ternary if operator found in the C family of languages:/p>div classorg-src-container>pre classsrc src-c>int error_code explosion_count() > 0 ? 1 : 0;/pre>/div>p>In Emacs Lisp, an code>if/code> statement takes the form/p>div classorg-src-container>pre classsrc src-emacs-lisp>(if condtion then-form else-form)/pre>/div>p>So the example above would look like the following in Emacs Lisp:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(setq error-code (if (> explosion-count 0) 1 0))/pre>/div>/div>/div>div idoutline-container-sec-2-2-3 classoutline-4>h4 idsec-2-2-3>span classsection-number-4>2.2.3/span> when, unless, cond/h4>/div>div idoutline-container-sec-2-2-4 classoutline-4>h4 idsec-2-2-4>span classsection-number-4>2.2.4/span> Predicate Functions/h4>/div>div idoutline-container-sec-2-2-5 classoutline-4>h4 idsec-2-2-5>span classsection-number-4>2.2.5/span> mapcar/h4>/div>div idoutline-container-sec-2-2-6 classoutline-4>h4 idsec-2-2-6>span classsection-number-4>2.2.6/span> mapc/h4>/div>div idoutline-container-sec-2-2-7 classoutline-4>h4 idsec-2-2-7>span classsection-number-4>2.2.7/span> mapconcat/h4>/div>div idoutline-container-sec-2-2-8 classoutline-4>h4 idsec-2-2-8>span classsection-number-4>2.2.8/span> maphash/h4>/div>div idoutline-container-sec-2-2-9 classoutline-4>h4 idsec-2-2-9>span classsection-number-4>2.2.9/span> dolist/h4>/div>div idoutline-container-sec-2-2-10 classoutline-4>h4 idsec-2-2-10>span classsection-number-4>2.2.10/span> Errors/h4>div classoutline-text-4 idtext-2-2-10>/div>ol classorg-ol>li>a idsec-2-2-10-1 namesec-2-2-10-1>/a>errorbr />/li>li>a idsec-2-2-10-2 namesec-2-2-10-2>/a>warnbr />/li>li>a idsec-2-2-10-3 namesec-2-2-10-3>/a>unwind-protectbr />/li>li>a idsec-2-2-10-4 namesec-2-2-10-4>/a>condition-casebr />/li>li>a idsec-2-2-10-5 namesec-2-2-10-5>/a>ignore-errorsbr />/li>/ol>/div>/div>div idoutline-container-sec-2-3 classoutline-3>h3 idsec-2-3>span classsection-number-3>2.3/span> Functions/h3>div classoutline-text-3 idtext-2-3>/div>div idoutline-container-sec-2-3-1 classoutline-4>h4 idsec-2-3-1>span classsection-number-4>2.3.1/span> # (function) vs (quote)/h4>div classoutline-text-4 idtext-2-3-1>/div>ol classorg-ol>li>a idsec-2-3-1-1 namesec-2-3-1-1>/a>a hrefhttp://stackoverflow.com/a/18982769/1198455>Allows byte compiler to check if you have used function names that are actually defined/a>br />/li>li>a idsec-2-3-1-2 namesec-2-3-1-2>/a>Makes Intention Clearerbr />/li>li>a idsec-2-3-1-3 namesec-2-3-1-3>/a>Documentation for code>function/code>:br />div classoutline-text-5 idtext-2-3-1-3>p>Like `quote, but preferred for objects which are functions.In byte compilation, `function causes its argument to be compiled.`quote cannot do that./p>/div>/li>li>a idsec-2-3-1-4 namesec-2-3-1-4>/a>a hrefhttp://stackoverflow.com/questions/3325499/why-is-used-before-lambda-in-common-lisp/3325572#3325572>As in Common Lisp, lambda is a macro that expands to #(lambda …)/a>br />/li>li>a idsec-2-3-1-5 namesec-2-3-1-5>/a>a hrefhttp://stackoverflow.com/questions/25275842/does-function-serve-any-purpose-in-emacs?lq1>Was different on old versions of Emacs. Needed for cl-flet and cl-labels/a>br />/li>li>a idsec-2-3-1-6 namesec-2-3-1-6>/a>a hrefhttp://www.reddit.com/r/emacs/comments/2ddwgc/does_the_function_form_serve_any_actual_purpose/>Funcall Behavior/a> & cl-fletbr />/li>/ol>/div>div idoutline-container-sec-2-3-2 classoutline-4>h4 idsec-2-3-2>span classsection-number-4>2.3.2/span> Lambdas/h4>/div>div idoutline-container-sec-2-3-3 classoutline-4>h4 idsec-2-3-3>span classsection-number-4>2.3.3/span> &rest args/h4>/div>div idoutline-container-sec-2-3-4 classoutline-4>h4 idsec-2-3-4>span classsection-number-4>2.3.4/span> Interactive/h4>/div>div idoutline-container-sec-2-3-5 classoutline-4>h4 idsec-2-3-5>span classsection-number-4>2.3.5/span> funcall/h4>/div>div idoutline-container-sec-2-3-6 classoutline-4>h4 idsec-2-3-6>span classsection-number-4>2.3.6/span> fboundp/h4>/div>div idoutline-container-sec-2-3-7 classoutline-4>h4 idsec-2-3-7>span classsection-number-4>2.3.7/span> symbol-function/h4>/div>div idoutline-container-sec-2-3-8 classoutline-4>h4 idsec-2-3-8>span classsection-number-4>2.3.8/span> apply/h4>/div>div idoutline-container-sec-2-3-9 classoutline-4>h4 idsec-2-3-9>span classsection-number-4>2.3.9/span> apply-partially/h4>/div>div idoutline-container-sec-2-3-10 classoutline-4>h4 idsec-2-3-10>span classsection-number-4>2.3.10/span> recursion/h4>div classoutline-text-4 idtext-2-3-10>/div>ol classorg-ol>li>a idsec-2-3-10-1 namesec-2-3-10-1>/a>No Tail-Call Optimizationbr />/li>/ol>/div>div idoutline-container-sec-2-3-11 classoutline-4>h4 idsec-2-3-11>span classsection-number-4>2.3.11/span> defsubst – inline functions/h4>/div>div idoutline-container-sec-2-3-12 classoutline-4>h4 idsec-2-3-12>span classsection-number-4>2.3.12/span> fset / defalias/h4>/div>div idoutline-container-sec-2-3-13 classoutline-4>h4 idsec-2-3-13>span classsection-number-4>2.3.13/span> indirect-function/h4>/div>/div>div idoutline-container-sec-2-4 classoutline-3>h3 idsec-2-4>span classsection-number-3>2.4/span> Macros/h3>div classoutline-text-3 idtext-2-4>p>Ask any Lisper what makes Lisp special and i>macros/i> are sure to be mentioned. Im sure youve heard the hype before: Lisp macros are magical, they make it more powerful than any other language, they will clean your house and make you dinner, etc. etc. So Ill save my breath and skip the macro hype. If you havent drank the macro Kool-Aid just yet Id highly recommend you read Paul Grahams i>Beating the Averages/i> (a hrefhttp://www.paulgraham.com/avg.html>http://www.paulgraham.com/avg.html/a>), which explains why macros are so special better than I could ever hope to do./p>p>Before we jump into discussing macros themselves, youll need to understand how i>backquoting/i> works./p>/div>div idoutline-container-sec-2-4-1 classoutline-4>h4 idsec-2-4-1>span classsection-number-4>2.4.1/span> Backquoting/h4>div classoutline-text-4 idtext-2-4-1>p>The i>backquote/i>, also known as i>backtick/i> or i>syntax quote/i>, makes it easy to construct a list where some elements are evaluated and others arent. Lets say you want to define a function that takes one argument and will return a list with the elements code>a/code>, code>b/code>, and that argument./p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun a-b-arg (x) (list a b x))(a-b-arg c) ; -> (a b c)/pre>/div>p>This is a bit of a pain, since you have to quote i>every/i> form that you dont want to be evaluated. You cant quote the entire list, because then code>x/code> would never get evaluated:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun a-b-arg (x) (a b x))(a-b-arg c) ; -> (a b x)/pre>/div>p>Thats not what we wanted! Luckily, backquoting exists to ease our pain:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun a-b-arg (x) `(a b ,x))(a-b-arg c) ; -> (a b c)/pre>/div>p>Using backquote is just using regular quote, but any forms that are preceded with a comma, or i>unquote/i>, are evaluated and the result is subsituted in its place. You can also use ,@ (i>unquote-splicing/i>) to splice arguments into a list:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun a-b-args (&rest args) `(a b ,@args))(a-b-args c) ; -> (a b c)(a-b-args c d) ; -> (a b c d)/pre>/div>p>When ,@ precedes a form, it is evaluated, and the elements of the resulting list are spliced into the list in its place. You can nest multiple levels of backquoting and unquoting as well:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun a-b-doubled-args (&rest args) `(a b ,@(mapcar (lambda (x) `(,x ,x)) args)))(a-b-doubled-args c d) ; -> (a b (c c) (d d))/pre>/div>p>The code>mapcar/code> form is evaluated and generates the list code>((c c) (d d))/code>, which is then spliced into the final result. Backquoting will become your best friend when writing macros, as well see shortly./p>/div>/div>div idoutline-container-sec-2-4-2 classoutline-4>h4 idsec-2-4-2>span classsection-number-4>2.4.2/span> Macros/h4>div classoutline-text-4 idtext-2-4-2>p>So, i>what is/i> a macro? Its code that writes code. A macro is very much like a function that recieves its arguments before theyre evaluated, and returns a new sexp to be evaluated in its place. This process is known as i>macro expansion/i>. Lets look at a real world example. Heres how code>unless/code> could be implemented:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defmacro my-unless (condition &rest body) `(when (not ,condition) ,@body));; Whenever you type(my-unless ( 1 2) (message new-math-mode is not enabled.));; It is expanded and replaced with:(when (not ( 1 2)) (message new-math-mode is not enabled.))/pre>/div>p>Just like the functions we defined in the previous section, code>my-unless/code> uses backquoting to return a new list. The key difference here is that the reader then replaces the code>my-unless/code> form with the result before anything is ever evaluated./p>p>Macros can return forms that contain macros, which are then themselves expanded./p>div classorg-src-container>pre classsrc src-emacs-lisp>(defmacro my-when (condition &rest body) `(my-unless (not ,condition) ,@body))(my-when ( 1 2) (message new-math-mode is enabled.));; The first time this is expanded, it becomes:(my-unless (not ( 1 2)) (message new-math-mode is enabled.));; After being expanded again, it becomes:(when (not (not ( 1 2))) (message new-math-mode is enabled.))/pre>/div>p>When writing macros, youll find it very helpful to see such expansions, one step at a time. You can use the function code>macroexpand-1/code> to expand a macro:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(macroexpand-1 (my-when ( 1 2) do-something));; -> (my-unless (not ( 1 2)) do-something)/pre>/div>p>Note you must quote the macro form when passing it to code>macroexpand-1/code>. Similarly, code>macroexpand/code> will expand a macro, but instead of doing it one step at a time, it will completely expand the form, which is rarely as useful. More useful still is code>pp-macroexpand-expression/code>, which is similar to code>macroexpand-1/code> but pretty-prints the results in a new buffer./p>p>You can use the command code>pp-macroexpand-last-sexp/code>, which calls code>pp-macroexpand-expression/code> on the sexp before code>point/code>. You can call it again on resulting form in the new buffer, allowing you to step through the expansion of a macro. This command is so handy Id recommend binding it; I like code>C-c RET/code> because its used for the same purpose in other Lisp modes (code>cider/code>, for Clojure development, is one example)./p>p>Also worth a look is the code>macrostep/code> package. code>macrostep/code> provides a minor mode, code>macrostep-mode/code>, that when enabled lets you interactively expand and collapse macros one step at a time in your Emacs Lisp sources themselves./p>p>Lets look at some ways macros are commonly used in the real world./p>/div>/div>div idoutline-container-sec-2-4-3 classoutline-4>h4 idsec-2-4-3>span classsection-number-4>2.4.3/span> def Macros/h4>div classoutline-text-4 idtext-2-4-3>p>Youll often see macros that make it easier to define something, such as code>defun/code> or even code>defmacro/code> itself. Conventionally such macros have names that start with code>def/code>. Lets say you wanted to create a new version of code>defvar/code> that would add every var created with it to a secret list that you could use for nefarious purposes. Well call it code>def-tracked-var/code>./p>div classorg-src-container>pre classsrc src-emacs-lisp>(defvar tracked-vars () Variables created with `def-tracked-var.)(defmacro def-tracked-var (symbol &rest args) `(progn (add-to-list tracked-vars ,symbol) (defvar ,symbol ,@args)))(def-tracked-var b 100 Number of friends to recommend this book to);; this expands to:(progn (add-to-list tracked-vars b) (defvar b 100 Number of friends to recommend this book to));; Which is then evaluated.b ; -> 100tracked-vars ; -> (b)/pre>/div>p>Note our macro returns a code>progn/code>, since macros can only return a single form. Notice too how we use both a quote and and unquote with code>symbol/code>. Recall that arg is just shorthand for code>(quote arg)/code>, so ,arg just becomes code>(quote ,arg)/code>; this allows us to pass a b to code>add-to-list/code> instead of code>b/code>, which is what we want in this case./p>p>code>defvar/code> takes 3 args, the last of which is optional. But since code>def-tracked-var/code> is only concerned with the first we can just gather the rest of the arguments to code>def-tracked-var/code> with code>&rest/code> and unquote-splice them into the code>defvar/code> form we create./p>/div>/div>div idoutline-container-sec-2-4-4 classoutline-4>h4 idsec-2-4-4>span classsection-number-4>2.4.4/span> Abstracting Away Boilerplate & Common Patterns/h4>div classoutline-text-4 idtext-2-4-4>p>Its obnoxious to write similar-looking boilerplate code over and over (unless you are a fan of Java). Worse yet, it wastes space, distracts readers from the important parts of your code, and can lead to bugs if you write said boilerplate wrong. Wouldnt it be nice if we could just tell computers how to write this code for us? They can! So long as youre writing Lisp./p>p>When byte compiling an Emacs Lisp file, the byte compiler will complain when it sees functions it doesnt know to be defined. You can use code>declare-function/code> to tell it that a function exists in a certain file:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(declare-function paredit-backward-delete paredit)/pre>/div>p>But what if you want you want to tell it i>two/i> functions exist in code>paredit.el/code>? Youd have to use two calls to code>declare-function/code>:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(declare-function paredit-backward-delete paredit)(declare-function paredit-doublequote paredit)/pre>/div>p>Why couldnt we just use code>mapc/code>?/p>div classorg-src-container>pre classsrc src-emacs-lisp>(mapc (lambda (f) (declare-function f paredit)) (paredit-backward-delete paredit-doublequote))/pre>/div>p>code>declare-function/code> is itself a macro, and since code>f/code> is passed to code>declare-function/code> i>before/i> its evaluated, were effectively just telling the byte compiler that a function named code>f/code> exists in code>paredit.el/code>, twice. Which is not at all what we want. Instead, we could use backquoting to create code>declare-function/code> forms and call code>eval/code> on them:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(mapc (lambda (f) (eval `(declare-function-2 ,f paredit))) (paredit-backward-delete paredit-doublequote))/pre>/div>p>This would work, in theory, but code>eval/code> forms are evaluated at runtime and not by the byte compiler. So well still see warnings. And what if we wanted to declare functions in multiple files? Lets write a macro instead:/p>div classorg-src-container>pre classsrc src-emacs-lisp>;; Switch the position of the file argument to the front;; so we can accept a variable number of functions.(defmacro declare-functions (file &rest functions) (declare (indent 1)) `(progn ,@(mapcar (lambda (f) `(declare-function ,f ,file)) functions)))(declare-functions paredit paredit-backward-delete paredit-doublequote paredit-newline);; Expands to:(progn (declare-function paredit-backward-delete paredit) (declare-function paredit-doublequote paredit) (declare-function paredit-newline paredit))/pre>/div>p>Much better! Notice how we added code>(declare (indent 1))/code> to the Emacs how to indent our macro. You could instead define the macro recursively, if you were so inclined:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defmacro declare-functions (file fn &rest more) (declare (indent 1)) `(progn (declare-function ,fn ,file) ,(when more `(declare-functions ,file ,@more))));; The previous example...(declare-functions paredit paredit-backward-delete paredit-doublequote paredit-newline);; Expands to:(progn (declare-function paredit-backward-delete paredit) (declare-functions paredit paredit-doublequote paredit-newline));; Which then expands to:(progn (declare-function paredit-backward-delete paredit) (progn (declare-function paredit-doublequote paredit) (declare-functions paredit paredit-newline)));; And finally:(progn (declare-function paredit-backward-delete paredit) (progn (declare-function paredit-doublequote paredit) (progn (declare-function paredit-newline paredit) nil)))/pre>/div>p>Here, we take the first arg after file and create a code>declare-function/code> form. Then, if code>&rest more/code> is non-nil (i.e., non-empty), we create a recursive code>declare-functions/code> form with the remaining arguments. Each iteration of the macroexpansion generates a single code>declare-function/code> form. Theres no real benefit to defining code>declare-functions/code> recursively, but there are cases where it makes sense to define a macro this way./p>/div>/div>div idoutline-container-sec-2-4-5 classoutline-4>h4 idsec-2-4-5>span classsection-number-4>2.4.5/span> Wrapper Macros/h4>div classoutline-text-4 idtext-2-4-5>div classorg-src-container>pre classsrc src-emacs-lisp>(defmacro cam/suppress-messages (&rest body) (declare (indent 0)) `(cl-letf (((symbol-function message) (lambda (&rest _)))) ,@body))/pre>/div>/div>/div>div idoutline-container-sec-2-4-6 classoutline-4>h4 idsec-2-4-6>span classsection-number-4>2.4.6/span> with- macros/h4>/div>div idoutline-container-sec-2-4-7 classoutline-4>h4 idsec-2-4-7>span classsection-number-4>2.4.7/span> Controlling Execution Flow/h4>div classoutline-text-4 idtext-2-4-7>/div>ol classorg-ol>li>a idsec-2-4-7-1 namesec-2-4-7-1>/a>when-letbr />/li>li>a idsec-2-4-7-2 namesec-2-4-7-2>/a>threading macrosbr />/li>/ol>/div>div idoutline-container-sec-2-4-8 classoutline-4>h4 idsec-2-4-8>span classsection-number-4>2.4.8/span> Macro Techinques / Gotchas/h4>div classoutline-text-4 idtext-2-4-8>/div>ol classorg-ol>li>a idsec-2-4-8-1 namesec-2-4-8-1>/a>implicit prognbr />/li>li>a idsec-2-4-8-2 namesec-2-4-8-2>/a>Double Evaluationbr />/li>li>a idsec-2-4-8-3 namesec-2-4-8-3>/a>Gensymsbr />/li>/ol>/div>/div>/div>div idoutline-container-sec-3 classoutline-2>h2 idsec-3>span classsection-number-2>3/span> Intermediate/h2>div classoutline-text-2 idtext-3>/div>div idoutline-container-sec-3-1 classoutline-3>h3 idsec-3-1>span classsection-number-3>3.1/span> Defining Code to Be Ran On a Later Occasion/h3>div classoutline-text-3 idtext-3-1>p>Emacs is flexible and customizable. Perhaps you want to convert all tabs to spaces in files before theyre saved to disk. Maybe you want to tell a command to re-indent the current line whenever its ran. Or maybe you want to run code after a certain package is loaded. Well be looking at how to do all of these things in this chapter./p>/div>div idoutline-container-sec-3-1-1 classoutline-4>h4 idsec-3-1-1>span classsection-number-4>3.1.1/span> Hooks/h4>div classoutline-text-4 idtext-3-1-1>p>A i>hook/i> is simply a list of functionssup>a idfnr.10 namefnr.10 classfootref href#fn.10>10/a>/sup> that are ran at some specific occasion. Hooks exist for a wide variety of occasions. code>before-save-hook/code> is ran whenever a user saves a buffer, before its actually written to disk; here you might want to add functions to reindent your code or sort your imports. code>after-save-hook/code> is ran after the file is written; perhaps this is a good place to restart some external process? Every major mode is supposed to run a i>mode hook/i> (which is just the name of the major mode with code>-hook/code> appended) as the end of its initialization; many minor modes run modes hooks as well. code>emacs-lisp-mode-hook/code> gets ran right as code>emacs-lisp-mode/code> finishes initializing. Maybe you want to add a i>hook function/i> to enable a minor mode?/p>p>To add a function to a hook, you use the function code>add-hook/code>:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(add-hook emacs-lisp-mode-hook #paredit-mode)/pre>/div>p>Whenever you visit an Emacs Lisp file, code>emacs-lisp-mode/code> is activated, and the functions in code>emacs-lisp-mode-hook/code> are ran, including code>#paredit-mode/code>. Recall that minor mode functions toggle minor modes in the current buffer when called without an arg; since the minor mode was off to begin with, it will now be enabled./p>p>The best part about hooks is that theyre automatically created if needed when you call code>add-hook/code>. This means you dont need to call code>(require clojure-mode)/code> before adding a function to code>clojure-mode-hook/code>. You can add custom hooks for hundreds of major modes in your code>init.el/code> without sacrificing your Emacs startup speed./p>p>Instead of adding a named function to a hood, you can add a lambda:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(add-hook before-save-hook (lambda () ;; Untabify the current buffer (untabify (point-min) (point-max))))/pre>/div>p>Generally, however, its probably worth the trouble of upgrading the lambda in question to a named function, since youll be able to modify the hook function without touching the hook itself, which is handy if you accidently make a mistake in your hook function. Either way, you can remove a hook function by calling code>remove-hook/code>; this works for both function symbols and lambdas. Alternaltively, you can simply code>setq/code> a hook to code>nil/code> and re-add the desired hook functions./p>p>code>add-hook/code> accepts two optional arguments: code>append/code> and code>local/code>. By default, hooks function are added to the beginning of a hook, meaning it will run i>before/i> any previously added hooks. By passing a non-nil value for code>append/code>, the hook function will be added to the end instead. By default, it also adds hook functions to the global value of a hook. This isnt an issue when adding functions to a major mode hook, which only affect certain buffers. But the example above that untabifies the current buffer will run when b>any/b> buffer is saved. There are cases where this probably isnt what you want – consider a code>Makefile/code>, where tabs are neccesary. If you save one after adding this hook, your tabs will be no more./p>p>Passing a non-nil value for code>local/code> makes the hook buffer-local in the current buffer and modifies that value instead of the global one. It also adds code>t/code> to the buffer-local value, which tells code>run-hooks/code> to run the functions in the global value as well as those in the buffer-local one. The example above can be better rewritten as:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(defun my-untabify-buffer () (untabify (point-min) (point-max)))(defun my-emacs-lisp-mode-setup () (add-hook before-save-hook #my-untabify-buffer nil :local))(add-hook emacs-lisp-mode-hook #my-emacs-lisp-mode-setup)/pre>/div>p>Now, were adding a buffer-local hook to untabify the current buffer whenever we enter code>emacs-lisp-mode/code>. Whenever you save an Emacs Lisp file, code>#my-untabify-buffer/code> is called; your Makefiles are unaffected./p>p>code>append/code> and code>local/code> just check for any non-nil value, so you can pass it anything you want. I find it more readable to use a keyword like code>:append/code> than simply using code>t/code>; it makes it clear what the argument youre passing means./p>p>Most hooks are i>normal hooks/i>, which means its functions are called with no arguments, and there return values arent used in any way. By convention, normal hooks are any hook whose name ends in code>-hook/code>. i>Abnormal hooks/i>, on the other hand, are hooks whose functions are passed arguments, whose return values are used, or both. By convention, abnormal-hooks have names ending in code>-functions/code>. There are also abnormal hooks whose value is a single function (as opposed to a list of functions); these have names that end in code>-function/code>./p>p>You can run hooks with the function code>run-hooks/code>, which accepts a variable number of arguments:/p>div classorg-src-container>pre classsrc src-emacs-lisp>(run-hooks before-exploding-hook before-crashing-and-burning-hook)/pre>/div>p>code>run-hooks/code> simply calls the functions in the hook one-by-one, as with code>add-hook/code>, this symbol doesnt actually have to be defined as a variable anywhere./p>p>There are several variations on code>run-hooks/code>, such as code>run-hook-with-args/code>, code>run-hook-with-args-until-failure/code>, code>run-hook-with-args-until-success/code>, and code>run-hook-wrapped/code>, which can be used to run abnormal hooks./p>p>A major mode is supposed to finish initialization by calling code>change-major-mode-after-body-hook/code>, its mode hook, and code>after-change-major-mode-hook/code>. The function code>run-mode-hooks/code> is provided to run these hooks.sup>a idfnr.11 namefnr.11 classfootref href#fn.11>11/a>/sup>/p>p>The following is a partial list of some of the standard hooks:/p>table border2 cellspacing0 cellpadding6 rulesgroups framehsides>colgroup>col classleft />col classleft />/colgroup>thead>tr>th scopecol classleft>Hook Name/th>th scopecol classleft>Description/th>/tr>/thead>tbody>tr>td classleft>active-mark-hook/td>td classleft>Called when the mark becomes active./td>/tr>/tbody>tbody>tr>td classleft>after-change-functions/td>td classleft>Called after each text change./td>/tr>/tbody>tbody>tr>td classleft>after-change-major-mode-hook/td>td classleft>Called immediately after a major mode hook./td>/tr>/tbody>tbody>tr>td classleft>after-init-hook/td>td classleft>Ran after Emacs initialization has/td>/tr>tr>td classleft> /td>td classleft>completely finished./td>/tr>/tbody>tbody>tr>td classleft>after-insert-file-functions/td>td classleft>Called after insert-file-contents./td>/tr>/tbody>tbody>tr>td classleft>after-make-frame-functions/td>td classleft>Ran after a frame is created./td>/tr>/tbody>tbody>tr>td classleft>after-save-hook/td>td classleft>Ran after a buffer is saved to its file./td>/tr>/tbody>tbody>tr>td classleft>auto-save-hook/td>td classleft>Ran just before auto-saving./td>/tr>/tbody>tbody>tr>td classleft>before-change-functions/td>td classleft>Called before each text change./td>/tr>/tbody>tbody>tr>td classleft>before-hack-local-variables-hook/td>td classleft>Ran before setting file-local variables,/td>/tr>tr>td classleft> /td>td classleft>after checking for unsafe/risky ones./td>/tr>tr>td classleft> /td>td classleft>Only called if there are file-local/td>/tr>tr>td classleft> /td>td classleft>variables to set./td>/tr>/tbody>tbody>tr>td classleft>before-init-hook/td>td classleft>Ran before loading init files./td>/tr>/tbody>tbody>tr>td classleft>before-make-frame-hook/td>td classleft>Ran before a frame is created./td>/tr>/tbody>tbody>tr>td classleft>before-save-hook/td>td classleft>Ran before a buffer is saved to its file./td>/tr>/tbody>tbody>tr>td classleft>buffer-access-fontify-functions/td>td classleft>List of functions called by buffer-substring/td>/tr>tr>td classleft> /td>td classleft>to fontify if neccessary./td>/tr>/tbody>tbody>tr>td classleft>buffer-list-update-hook/td>td classleft>Ran when the buffer list changes./td>/tr>/tbody>tbody>tr>td classleft>buffer-quit-function/td>td classleft>Function to call to quit the current buffer,/td>/tr>tr>td classleft> /td>td classleft>or nil if none./td>/tr>/tbody>tbody>tr>td classleft>change-major-mode-after-body-hook/td>td classleft>Called immediately before a major mode hook./td>/tr>/tbody>tbody>tr>td classleft>change-major-mode-hook/td>td classleft>Ran before changing the major mode./td>/tr>/tbody>tbody>tr>td classleft>command-line-functions/td>td classleft>List of functions to process unrecognized/td>/tr>tr>td classleft> /td>td classleft>command-line arguments./td>/tr>/tbody>tbody>tr>td classleft>deactive-mark-hook/td>td classleft>Called when the mark becomes inactive./td>/tr>/tbody>tbody>tr>td classleft>delete-frame-functions/td>td classleft>Ran before deleting a frame./td>/tr>/tbody>tbody>tr>td classleft>delete-terminal-functions/td>td classleft>Ran when a terminal is deleted./td>/tr>/tbody>tbody>tr>td classleft>echo-area-clear-hook/td>td classleft>Ran when clearing the echo area./td>/tr>/tbody>tbody>tr>td classleft>emacs-startup-hook/td>td classleft>Ran after loading init files and handling/td>/tr>tr>td classleft> /td>td classleft>the command line./td>/tr>/tbody>tbody>tr>td classleft>find-file-hook/td>td classleft>Called after a buffer is loaded from a file./td>/tr>/tbody>tbody>tr>td classleft>find-file-not-found-functions/td>td classleft>Functions to be called for find-file on a/td>/tr>tr>td classleft> /td>td classleft>non-existent file./td>/tr>/tbody>tbody>tr>td classleft>first-change-hook/td>td classleft>Called when changing an unmodified buffer./td>/tr>/tbody>tbody>tr>td classleft>focus-in-hook/td>td classleft>Ran when a frame gains input focus./td>/tr>/tbody>tbody>tr>td classleft>focus-out-hook/td>td classleft>Ran when a frame loses input focus./td>/tr>/tbody>tbody>tr>td classleft>frame-auto-hide-function/td>td classleft>Function called to automatically hide/td>/tr>tr>td classleft> /td>td classleft>frames./td>/tr>/tbody>tbody>tr>td classleft>hack-local-variables-hook/td>td classleft>Ran after processing a files local/td>/tr>tr>td classleft> /td>td classleft>variables/td>/tr>/tbody>tbody>tr>td classleft>kill-buffer-hook/td>td classleft>Ran when a buffer is killed./td>/tr>/tbody>tbody>tr>td classleft>kill-buffer-query-functions/td>td classleft>Functions to call before killing a buffer./td>/tr>tr>td classleft> /td>td classleft>If any of them returns nil, the buffer will/td>/tr>tr>td classleft> /td>td classleft>not be killed./td>/tr>/tbody>tbody>tr>td classleft>kill-emacs-hook/td>td classleft>Ran when kill-emacs is called./td>/tr>/tbody>tbody>tr>td classleft>kill-emacs-query-functions/td>td classleft>Functions to call before killing Emacs. If/td>/tr>tr>td classleft> /td>td classleft>any of these functions retuns nil, killing/td>/tr>tr>td classleft> /td>td classleft>Emacs is cancelled./td>/tr>/tbody>tbody>tr>td classleft>menu-bar-update-hook/td>td classleft>Ran to update menu definitions before/td>/tr>tr>td classleft> /td>td classleft>redisplaying the menu bar./td>/tr>/tbody>tbody>tr>td classleft>minibuffer-exit-hook/td>td classleft>Ran just after exit from the minibuffer./td>/tr>/tbody>tbody>tr>td classleft>minibuffer-setup-hook/td>td classleft>Ran just after entry to the minibuffer./td>/tr>/tbody>tbody>tr>td classleft>pop-up-frame-function/td>td classleft>Function used by display-buffer for/td>/tr>tr>td classleft> /td>td classleft>creating a new frame./td>/tr>/tbody>tbody>tr>td classleft>post-command-hook/td>td classleft>Ran after each command is executed./td>/tr>/tbody>tbody>tr>td classleft>post-gc-hook/td>td classleft>Ran after garbage collection finishes./td>/tr>/tbody>tbody>tr>td classleft>post-self-insert-hook/td>td classleft>Ran at the end of self-insert-command,/td>/tr>tr>td classleft> /td>td classleft>after inserting the character./td>/tr>/tbody>tbody>tr>td classleft>pre-command-hook/td>td classleft>Ran before each command is executed./td>/tr>/tbody>tbody>tr>td classleft>split-window-preferred-function/td>td classleft>Function called by display-buffer to split/td>/tr>tr>td classleft> /td>td classleft>a window./td>/tr>/tbody>tbody>tr>td classleft>suspend-hook/td>td classleft>Ran before suspending Emacs./td>/tr>/tbody>tbody>tr>td classleft>suspend-resume-hook/td>td classleft>Ran after Emacs is unsuspended./td>/tr>/tbody>tbody>tr>td classleft>temp-buffer-setup-hook/td>td classleft>Ran at the start of/td>/tr>tr>td classleft> /td>td classleft>with-output-to-temp-buffer; the temporary/td>/tr>tr>td classleft> /td>td classleft>buffer is current when the hook runs./td>/tr>/tbody>tbody>tr>td classleft>temp-buffer-show-hook/td>td classleft>Ran by with-output-to-temp-buffer after/td>/tr>tr>td classleft> /td>td classleft>displaying the buffer./td>/tr>/tbody>tbody>tr>td classleft>window-configuration-change-hook/td>td classleft>Called when the window configuration/td>/tr>tr>td classleft> /td>td classleft>changes./td>/tr>/tbody>tbody>tr>td classleft>window-scroll-functions/td>td classleft>Functions to call before redisplaying a/td>/tr>tr>td classleft> /td>td classleft>buffer when scrolling./td>/tr>/tbody>tbody>tr>td classleft>window-setup-hook/td>td classleft>Similar to emacs-startup-hook, but runs after/td>/tr>tr>td classleft> /td>td classleft>frame parameters have been set up in response/td>/tr>tr>td classleft> /td>td classleft>to any settings in the init file./td>/tr>/tbody>tbody>tr>td classleft>window-size-change-functions/td>td classleft>Functions called before redisplay when a/td>/tr>tr>td classleft> /td>td classleft>windows size changes./td>/tr>/tbody>tbody>tr>td classleft>window-text-change-functions/td>td classleft>Functions to call in redisplay when text in/td>/tr>tr>td classleft> /td>td classleft>the window might change./td>/tr>/tbody>tbody>tr>td classleft>write-contents-functions/td>td classleft>Called before writing out a buffer to a file./td>/tr>tr>td classleft> /td>td classleft>If one of them returns non-nil, the file is/td>/tr>tr>td classleft> /td>td classleft>considered already written, and the rest of/td>/tr>tr>td classleft> /td>td classleft>the functions are skipped, as are the ones/td>/tr>tr>td classleft> /td>td classleft>in write-file-functions./td>/tr>/tbody>tbody>tr>td classleft>write-file-functions/td>td classleft>Called before writing out a buffer to a file./td>/tr>tr>td classleft> /td>td classleft>If one of them returns non-nil, the rest are/td>/tr>tr>td classleft> /td>td classleft>skipped./td>/tr>/tbody>tbody>tr>td classleft>write-region-annotate-functions/td>td classleft>Called at the start of write-region./td>/tr>/tbody>tbody>tr>td classleft>write-region-post-annotation-function/td>td classleft>Called after write-region completes./td>/tr>/tbody>/table>/div>/div>div idoutline-container-sec-3-1-2 classoutline-4>h4 idsec-3-1-2>span classsection-number-4>3.1.2/span> Advice/h4>/div>div idoutline-container-sec-3-1-3 classoutline-4>h4 idsec-3-1-3>span classsection-number-4>3.1.3/span> eval-after-load/h4>/div>/div>div idoutline-container-sec-3-2 classoutline-3>h3 idsec-3-2>span classsection-number-3>3.2/span> Moving Around/h3>div classoutline-text-3 idtext-3-2>/div>div idoutline-container-sec-3-2-1 classoutline-4>h4 idsec-3-2-1>span classsection-number-4>3.2.1/span> Point/h4>/div>div idoutline-container-sec-3-2-2 classoutline-4>h4 idsec-3-2-2>span classsection-number-4>3.2.2/span> Mark/h4>/div>div idoutline-container-sec-3-2-3 classoutline-4>h4 idsec-3-2-3>span classsection-number-4>3.2.3/span> Positions/h4>/div>div idoutline-container-sec-3-2-4 classoutline-4>h4 idsec-3-2-4>span classsection-number-4>3.2.4/span> Markers/h4>/div>/div>div idoutline-container-sec-3-3 classoutline-3>h3 idsec-3-3>span classsection-number-3>3.3/span> Working With Buffers, Windows, and Frames/h3>/div>div idoutline-container-sec-3-4 classoutline-3>h3 idsec-3-4>span classsection-number-3>3.4/span> Operating on Strings/h3>/div>div idoutline-container-sec-3-5 classoutline-3>h3 idsec-3-5>span classsection-number-3>3.5/span> Packages/h3>div classoutline-text-3 idtext-3-5>/div>div idoutline-container-sec-3-5-1 classoutline-4>h4 idsec-3-5-1>span classsection-number-4>3.5.1/span> Autoloads/h4>/div>div idoutline-container-sec-3-5-2 classoutline-4>h4 idsec-3-5-2>span classsection-number-4>3.5.2/span> Require & Provide/h4>/div>/div>/div>div idoutline-container-sec-4 classoutline-2>h2 idsec-4>span classsection-number-2>4/span> Advanced/h2>div classoutline-text-2 idtext-4>/div>div idoutline-container-sec-4-1 classoutline-3>h3 idsec-4-1>span classsection-number-3>4.1/span> Syntax Tables/h3>/div>div idoutline-container-sec-4-2 classoutline-3>h3 idsec-4-2>span classsection-number-3>4.2/span> Font Locking/h3>/div>div idoutline-container-sec-4-3 classoutline-3>h3 idsec-4-3>span classsection-number-3>4.3/span> Custom Variables/h3>/div>div idoutline-container-sec-4-4 classoutline-3>h3 idsec-4-4>span classsection-number-3>4.4/span> Byte Compilation ?/h3>/div>div idoutline-container-sec-4-5 classoutline-3>h3 idsec-4-5>span classsection-number-3>4.5/span> Keymaps/h3>/div>/div>div idoutline-container-sec-5 classoutline-2>h2 idsec-5>span classsection-number-2>5/span> Libraries/h2>div classoutline-text-2 idtext-5>/div>div idoutline-container-sec-5-1 classoutline-3>h3 idsec-5-1>span classsection-number-3>5.1/span> cl-lib/h3>/div>div idoutline-container-sec-5-2 classoutline-3>h3 idsec-5-2>span classsection-number-3>5.2/span> subr-x/h3>/div>div idoutline-container-sec-5-3 classoutline-3>h3 idsec-5-3>span classsection-number-3>5.3/span> dash/h3>/div>div idoutline-container-sec-5-4 classoutline-3>h3 idsec-5-4>span classsection-number-3>5.4/span> s/h3>/div>div idoutline-container-sec-5-5 classoutline-3>h3 idsec-5-5>span classsection-number-3>5.5/span> EIEIO/h3>div classoutline-text-3 idtext-5-5>p>a hrefhttp://www.randomsample.de/cedetdocs/eieio/>EIEIO Documentation/a>/p>/div>/div>/div>div idoutline-container-sec-6 classoutline-2>h2 idsec-6>span classsection-number-2>6/span> Putting it All Together/h2>div classoutline-text-2 idtext-6>/div>div idoutline-container-sec-6-1 classoutline-3>h3 idsec-6-1>span classsection-number-3>6.1/span> Debugging with Edebug/h3>/div>div idoutline-container-sec-6-2 classoutline-3>h3 idsec-6-2>span classsection-number-3>6.2/span> Writing a Minor Mode/h3>/div>div idoutline-container-sec-6-3 classoutline-3>h3 idsec-6-3>span classsection-number-3>6.3/span> Writing a Major Mode/h3>div classoutline-text-3 idtext-6-3>/div>div idoutline-container-sec-6-3-1 classoutline-4>h4 idsec-6-3-1>span classsection-number-4>6.3.1/span> define-generic-mode/h4>/div>/div>div idoutline-container-sec-6-4 classoutline-3>h3 idsec-6-4>span classsection-number-3>6.4/span> Packaging/h3>/div>/div>div idoutline-container-sec-7 classoutline-2>h2 idsec-7>span classsection-number-2>7/span> Possibilities/h2>div classoutline-text-2 idtext-7>/div>div idoutline-container-sec-7-1 classoutline-3>h3 idsec-7-1>span classsection-number-3>7.1/span> Keyboard Macros/h3>/div>div idoutline-container-sec-7-2 classoutline-3>h3 idsec-7-2>span classsection-number-3>7.2/span> identity, ignore/h3>/div>div idoutline-container-sec-7-3 classoutline-3>h3 idsec-7-3>span classsection-number-3>7.3/span> Primitive Functions ?/h3>/div>/div>div idfootnotes>h2 classfootnotes>Footnotes: /h2>div idtext-footnotes>div classfootdef>sup>a idfn.1 namefn.1 classfootnum href#fnr.1>1/a>/sup> p classfootpara>Its possible to create a frame without a minibuffer window, but it must use the minibuffer of some other frame. You can do this passing the frame parameter code>minibuffer/code> when creating it; pass an existing minibuffer window, or code>nil/code> for it to use the minibuffer of code>default-minibuffer-frame/code>./p>/div>div classfootdef>sup>a idfn.2 namefn.2 classfootnum href#fnr.2>2/a>/sup> p classfootpara>The Emacs DIRectory EDitor./p>/div>div classfootdef>sup>a idfn.3 namefn.3 classfootnum href#fnr.3>3/a>/sup> p classfootpara>If youre using Emacs in terminal (code>-nw/code>) mode, you might have to tell your terminal to use Alt/Option as Meta (this is the case on OS X). But Id strongly recommend using Emacs in GUI mode. Terminals are limited. Try typing code>C-i/code> and code>TAB/code>. Theyre the same thing!/p>/div>div classfootdef>sup>a idfn.4 namefn.4 classfootnum href#fnr.4>4/a>/sup> p classfootpara>Unless youre using Emacs in terminal (code>-nw/code>) mode, in which case youre SOL./p>/div>div classfootdef>sup>a idfn.5 namefn.5 classfootnum href#fnr.5>5/a>/sup> p classfootpara>You can tell Emacs to interpret keycodes for the modifier keys on either side of your keyboard differently by setting corresponding variables. On a Mac, for example, code>(setq ns-right-command-modifier hyper)/code> tells Emacs to treat the right command key as code>hyper/code> instead of code>super/code>. Other similar variables are prefixed with code>ns-/code>. On Windows, similar variables such as code>w32-rwindow-modifier/code> exist. Alternatively, you can also use code>C-x @ <modifier letter> <key sequence>/code> to simulate modfier keys like Hyper. code>C-x @ h g/code> will be understood as code>h-g/code>, but thats a lot of typing./p>/div>div classfootdef>sup>a idfn.6 namefn.6 classfootnum href#fnr.6>6/a>/sup> p classfootpara>This is also a good way to see if a key sequence isnt bound to any command, as it will give you an error if it isnt./p>/div>div classfootdef>sup>a idfn.7 namefn.7 classfootnum href#fnr.7>7/a>/sup> p classfootpara>You can use the code><f1>/code> prefix instead of code>C-h/code> for invoking help commands, too./p>/div>div classfootdef>sup>a idfn.8 namefn.8 classfootnum href#fnr.8>8/a>/sup> p classfootpara>Actually, code>defun/code> is a just a macro that rewrites the sexp as a code>defalias/code> form that sets the function definition of a symbol to an anonymous function. Internally, code>defalias/code> usually calls code>fset/code>, which actually does the function cell-setting./p>/div>div classfootdef>sup>a idfn.9 namefn.9 classfootnum href#fnr.9>9/a>/sup> p classfootpara>Lisps with more than one namespace are also referred to as i>Lisp-Ns/i>, since Common Lisp actually has at least 7 namespaces, according to Peter Norvig in i>Paradigms of AI Programming/i>./p>/div>div classfootdef>sup>a idfn.10 namefn.10 classfootnum href#fnr.10>10/a>/sup> p classfootpara>A hook can also be a single function, but this usage is obsolete. Calling code>add-hook/code> on such a hook will automatically upgrade it to a list./p>/div>div classfootdef>sup>a idfn.11 namefn.11 classfootnum href#fnr.11>11/a>/sup> p classfootpara>The rules are a little different for derived major modes, which well get into a little bit later./p>/div>/div>/div>/div>div idpostamble classstatus>p classauthor>Author: Cam Saul/p>p classdate>Created: 2015-06-04 Thu 19:47/p>p classcreator>a hrefhttp://www.gnu.org/software/emacs/>Emacs/a> 25.0.50.1 (a hrefhttp://orgmode.org>Org/a> mode 8.2.10)/p>p classvalidation>a hrefhttp://validator.w3.org/check?urireferer>Validate/a>/p>/div>/body>/html>
View on OTX
|
View on ThreatMiner
Please enable JavaScript to view the
comments powered by Disqus.
Data with thanks to
AlienVault OTX
,
VirusTotal
,
Malwr
and
others
. [
Sitemap
]